How to make an architecture diagram of your codebase with AI
An AI coding tool can read your repo and draw its architecture: Cursor, Claude Code, Codex and GitHub Copilot all do it. Open the repo, ask for one level of the system at a time, check the result against the code, and share it. Connect Diagram first and each diagram is saved at a link that stays current, so you are not pasting Mermaid text into another app to see it.
1. Open the repo in a tool that can read it
You need an AI tool that works inside the repo, not a chat you paste files into. Pick yours for the one-minute setup:
2. Ask for one level at a time
“Draw the architecture” gets you a crowded picture. Say which level you want. These four cover most needs, and each is one request:
The whole system
One page for someone new: the apps, the databases, the outside services, and what talks to what.
- “Make an architecture diagram of this repo: the services, the data stores, and the outside services it calls. Give me a link I can share.”
- “Before drawing, list the files you read to work it out, and say what you left out.”
One flow
What happens, in order, when one thing is done. The most useful diagram to start with, and the easiest to get right.
- “Draw what happens when a user signs up, from the form to the database, as a sequence diagram.”
- “Diagram the checkout flow, including what happens when the payment fails.”
The data
The tables or collections and how they relate, read from the schema or the models.
- “Show the data model as an entity diagram, from the schema in this repo.”
- “Draw which services read and write each table.”
One part, up close
The modules inside one service and what depends on what. Useful before a refactor.
- “Diagram the modules in the billing package and what depends on what.”
- “Before you change it, draw how this module works today so we agree on it.”
3. Check it against the code
The AI draws what it read, and it does not read everything. Three habits catch most mistakes:
- Ask what it read. “Which files did you use, and what did you leave out?” If the queue worker is not on the list, it is not on the diagram.
- Read the arrows, not the boxes. Boxes are usually right. Wrong directions and missing calls are where diagrams lie.
- Correct it in plain words. “The API never talks to the bank directly, it goes through the payments service.” The change is saved at the same link.
4. Share the link and keep it current
An architecture diagram is out of date the week after it is drawn, which is why most teams stop trusting theirs. Put the link in the README or the pull request, and when the code changes, ask for the change: “update the architecture diagram, we added a queue and a worker”. The link stays the same and every earlier version is kept, so you can see how the system looked before.
In a repo, the AI can also add a short file that lists the repo’s diagrams, so the next session, or a teammate’s tool, updates the existing diagram instead of drawing a new one.