Here’s my current workflow to create technical architecture diagrams from code.
STEP 1: Copy the code
Here’s a one-liner using files-to-prompt to copy all files in the current directory:
fd | xargs uvx files-to-prompt --cxml | xclip -selection clipboard
Or, you can specify individual files:
uvx files-to-prompt --cxml README.md ... | xclip -selection clipboard
STEP 2: Prompt for the a Mermaid diagram
Mermaid is a Markdown charting language. I use this prompt with O4-Mini-High or O3:
Create a Mermaid architecture diagram for the files below.
Make sure that the diagram is rich in visual detail and looks impressive.
Use the “neutral” theme.
Name nodes and links semantically and label them clearly. Avoid parantheses.
Quote subgraph labels.
Use aptshape: rect|rounded|stadium|...
for nodes.
Add suitable emoticons to every node.
Style nodes and links with classes most apt for them.Follow that with a bulleted explanation of the architectural elements that is suitable for adding to a slide.
Finally, double-check the architecture against the codebase and provide a step-by-step validation report.
[PASTE CODE]
STEP 3: Copy the diagram into Mermaid Live Editor
Here’s a sample output that you can paste into a new Mermaid Playground:
%%{init: {'theme':'neutral'}}%%
flowchart TB
%% Source files
subgraph "Source Files π"
direction LR
RT_wr[wrangler.toml π§]:::config
PK_pkg[package.json π¦]:::config
JS_idx[src/index.js π₯οΈ]:::code
JSON_spec[openapi.json π]:::assets
HTML_swagger[swagger.html π]:::assets
end
%% Build & deploy steps
subgraph "Build & Deploy π οΈ"
direction LR
DEV["npm run dev / wrangler dev βΆοΈ"]:::action
SECRET["npx wrangler secret put LLMFOUNDRY_TOKEN π"]:::action
DEPLOY["npm run deploy / wrangler deploy π"]:::action
end
%% Runtime environment
subgraph "Runtime Environment βοΈ"
direction TB
CF_WORKER["Cloudflare Worker β¨"]:::worker
subgraph "Request Processing π"
direction LR
API_ROUTER["API Router π"]:::logic
subgraph "Endpoints π"
EXTRACT["/extract π"]:::endpoint
OPENAPI["/openapi.json π"]:::endpoint
DOCS["/docs (or /) π"]:::endpoint
end
subgraph "Handlers π οΈ"
HANDLE["handleExtract π"]:::logic
SERVE_SPEC["serveOpenApi (spec) π"]:::logic
SERVE_SWAGGER["serveSwaggerUI π₯οΈ"]:::logic
NOT_FOUND["404 NotFound β"]:::logic
end
end
subgraph "Extraction Flow π€"
PROMPT["createExtractionPrompt π€"]:::logic
GPT_API["LLM Foundry API π"]:::external
end
end
%% Connections
RT_wr --> CF_WORKER
PK_pkg --> DEV
JS_idx --> CF_WORKER
JSON_spec --> CF_WORKER
HTML_swagger --> CF_WORKER
DEV --> CF_WORKER
SECRET --> CF_WORKER
DEPLOY --> CF_WORKER
CF_WORKER --> API_ROUTER
API_ROUTER --> EXTRACT
API_ROUTER --> OPENAPI
API_ROUTER --> DOCS
EXTRACT --> HANDLE
OPENAPI --> SERVE_SPEC
DOCS --> SERVE_SWAGGER
HANDLE --> PROMPT
PROMPT --> GPT_API
API_ROUTER --> NOT_FOUND
%% Styling classes
classDef config fill:#f0f0f0,stroke:#333,stroke-width:1px;
classDef code fill:#e0f7fa,stroke:#333,stroke-width:1px;
classDef assets fill:#fce4ec,stroke:#333,stroke-width:1px;
classDef action fill:#fff9c4,stroke:#333,stroke-width:1px;
classDef worker fill:#e8f5e9,stroke:#333,stroke-width:1px;
classDef logic fill:#e3f2fd,stroke:#333,stroke-width:1px;
classDef endpoint fill:#ffebee,stroke:#333,stroke-width:1px;
classDef external fill:#ede7f6,stroke:#333,stroke-width:1px;

STEP 4: Export the diagram
- If you log in, you can export as PNG.
- If not, you can export it as SVG or take a screenshot.
Note: Technically, this is a flowchart, not an architecture diagram. Mermaid does support architecture diagrams, but they are in beta and don’t look good.