Skip to content

Commit 87c78b5

Browse files
minimize clickable events and ensure correct paths, add entrypoint to docker for hot reloading on dev mode
1 parent 92efefc commit 87c78b5

File tree

6 files changed

+55
-10
lines changed

6 files changed

+55
-10
lines changed

backend/Dockerfile

+10-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,16 @@ RUN pip install --no-cache-dir -r requirements.txt
1313
# Copy application code
1414
COPY . .
1515

16+
# Create and set permissions for entrypoint script
17+
COPY entrypoint.sh /app/
18+
RUN chmod +x /app/entrypoint.sh && \
19+
# Ensure the script uses Unix line endings
20+
sed -i 's/\r$//' /app/entrypoint.sh && \
21+
# Double check permissions
22+
ls -la /app/entrypoint.sh
23+
1624
# Expose port
1725
EXPOSE 8000
1826

19-
# Run the application
20-
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--workers", "2"]
27+
# Use entrypoint script
28+
CMD ["/bin/bash", "/app/entrypoint.sh"]

backend/app/prompts.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@
133133
- Do not try to include the full url. This will be processed by another program afterwards. All you need to do is include the path.
134134
- For example:
135135
- This is a correct click event: `click Example "app/example.js"`
136-
- This is an incorrect click event: `click Example "https://github.com/username/repo/tree/main/app/example.js"`
136+
- This is an incorrect click event: `click Example "https://github.com/username/repo/blob/main/app/example.js"`
137137
- Do this for as many components as specified in the component mapping, include directories and files.
138138
- If you believe the component contains files and is a directory, include the directory path.
139139
- If you believe the component references a specific file, include the file path.

backend/app/routers/generate.py

+33-5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from anthropic._exceptions import RateLimitError
99
from pydantic import BaseModel
1010
from functools import lru_cache
11+
import re
1112

1213
load_dotenv()
1314

@@ -122,11 +123,13 @@ async def generate(request: Request, body: ApiRequest):
122123
if "BAD_INSTRUCTIONS" in mermaid_code:
123124
return {"error": "Invalid or unclear instructions provided"}
124125

125-
# Process the diagram text before sending to client
126-
processed_diagram = mermaid_code\
127-
.replace("[username]", body.username)\
128-
.replace("[repo]", body.repo)\
129-
.replace("[branch]", default_branch)
126+
# Process click events to include full GitHub URLs
127+
processed_diagram = process_click_events(
128+
mermaid_code,
129+
body.username,
130+
body.repo,
131+
default_branch
132+
)
130133

131134
print("component_mapping_text:", component_mapping_text)
132135

@@ -167,3 +170,28 @@ async def get_generation_cost(request: Request, body: ApiRequest):
167170
return {"cost": cost_string}
168171
except Exception as e:
169172
return {"error": str(e)}
173+
174+
175+
def process_click_events(diagram: str, username: str, repo: str, branch: str) -> str:
176+
"""
177+
Process click events in Mermaid diagram to include full GitHub URLs.
178+
Detects if path is file or directory and uses appropriate URL format.
179+
"""
180+
def replace_path(match):
181+
# Extract the path from the click event
182+
path = match.group(2).strip('"\'')
183+
184+
# Determine if path is likely a file (has extension) or directory
185+
is_file = '.' in path.split('/')[-1]
186+
187+
# Construct GitHub URL
188+
base_url = f"https://github.com/{username}/{repo}"
189+
path_type = "blob" if is_file else "tree"
190+
full_url = f"{base_url}/{path_type}/{branch}/{path}"
191+
192+
# Return the full click event with the new URL
193+
return f'click {match.group(1)} "{full_url}"'
194+
195+
# Match click events: click ComponentName "path/to/something"
196+
click_pattern = r'click ([^\s"]+)\s+"([^"]+)"'
197+
return re.sub(click_pattern, replace_path, diagram)

backend/deploy.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ git pull origin main
1111

1212
# Build and restart containers
1313
docker-compose down
14-
docker-compose up --build -d
14+
ENVIRONMENT=production docker-compose up --build -d
1515

1616
# Remove unused images
1717
docker image prune -f

backend/entrypoint.sh

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
3+
if [ "$ENVIRONMENT" = "development" ]; then
4+
exec uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload
5+
else
6+
exec uvicorn app.main:app --host 0.0.0.0 --port 8000 --workers 2
7+
fi

docker-compose.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@ services:
99
- ./backend:/app
1010
env_file:
1111
- .env
12-
restart: unless-stopped # Automatically restarts if container crashes
12+
environment:
13+
- ENVIRONMENT=development
14+
restart: unless-stopped

0 commit comments

Comments
 (0)