C4 model diagrams with AI
The C4 model describes software at four levels: the system in its context, the containers inside it (apps, APIs, databases), the components inside one container, and, rarely, the code. An AI coding tool can read your repo and draw the first three, one level per diagram, with the people, systems and protocols labelled the C4 way. Ask for one level at a time and check the boundaries.
1. Open your AI tool
It works out the containers and components from the code, so use a tool that works inside the repo:
Each guide has the one-minute setup. Once Diagram is connected, every diagram the AI draws is saved at a link instead of staying in the chat.
2. Ask for it
Say what you want to see in plain words. These requests work, and each is one message:
Level 1: system context
The system as one box, the people who use it, and the outside systems it talks to. For people who don’t read code.
- “Draw a C4 system context diagram for this repo: the system as one box, the people who use it, and the outside systems it depends on.”
Level 2: containers
The apps, APIs, workers, databases and queues inside the system, and how they talk. The level most teams want.
- “Draw a C4 container diagram of this repo. Label each container with its technology, and each arrow with what it sends and how (HTTPS, SQL, a queue).”
- “Add a legend that explains the C4 shapes.”
Level 3: components
Inside one container: its main modules and what depends on what.
- “Draw a C4 component diagram of the API container: its main modules, what each does, and which other containers they call.”
An example
3. Check it
The AI draws what it read or was told. These habits catch most mistakes:
- One level per diagram. The point of C4 is that each level is readable on its own. Ask for them separately and link them.
- Label every arrow. C4 arrows say what is sent and how: “reads and writes orders [SQL]”. An unlabelled arrow is the most common mistake.
- Say the technology. Containers carry their type and technology, such as “API [Container: Node.js]”. Ask the AI to read it from the code rather than guess.
- Draw the boundary. Make it clear what is inside your system and what isn’t. The AI sometimes draws a third-party API as one of your containers.
4. Share the link and keep it current
Put the link in the README, the pull request or the doc. When things change, ask for the change in plain words. It’s saved at the same link and every earlier version is kept, so nobody is looking at an old picture.
Questions
- Can AI make C4 diagrams?
- Yes. A coding tool that reads the repo can draw the context, container and component levels. Ask for one level at a time, in C4 notation, with labelled arrows.
- Do I need Structurizr or C4-PlantUML?
- No. The AI draws the diagram directly. If your team keeps C4 as code, it can also write Structurizr DSL or C4-PlantUML for you.
- Which level should I start with?
- Containers (level 2). It is the one most people mean by “architecture diagram”, and the context and component levels are easy to add once it is right.
- How do I keep the levels in step?
- Keep them in one Diagram project and ask the AI to update all three when a container is added. Each keeps its link and its earlier versions.