What you'll learn: which diagram answers which design-review question, using one teaching system drawn at every level (context, container, component, sequence, deployment, state, data model, trust boundary), and a checklist you can apply to any diagram.
At a glance
Figure 1. One system, many views, one checklist
How to read this: pick the branch that matches the question being asked, and note that every branch ends in the same two gates, shared names and the checklist.
- A diagram answers one question for one audience. Choose the type from the question.
- Structure views (context, container, component) say what exists. They say nothing about order.
- Sequence and state diagrams say what happens: decisions, retries, exits. Draw the failure paths, not only the happy path.
- Mark trust boundaries and name the control at each crossing. Model output and retrieved text count as untrusted.
- About 15 nodes is the limit for one view. Keep diagrams as text next to the code.
The real-world problem
Composite scenario, not a real company. A team presents a customer-facing assistant that answers from policy documents and can open a support ticket, on one slide with eleven boxes, three arrow styles and a legend nobody can find. Reviewers ask four questions it cannot answer:
- Where does the customer's identity go after the gateway?
- What happens if the search step returns nothing?
- Who retries when the ticket service is slow?
- Which parts run in the same network as the documents?
The slide mixes structure, runtime order and deployment in one picture. The fix is a small set of diagrams, each answering one question, drawn from the same component names.
After this page you will be able to
- Choose the diagram type that answers a given design-review question.
- Draw C4-style context, container and component views as architecture diagrams, with consistent names.
- Draw a sequence diagram for a normal request and for two failure paths.
- Mark trust boundaries and name the control where a data flow crosses one.
- Apply the diagram checklist and reject a diagram that fails it.
Prerequisites and cross-links
Read the AI architect mindset first: each diagram question comes from requirements and constraints. Background:
- RAG systems explained: the Retriever, Vector index and Document store.
- Securing LLM apps with guardrails: the attacks trust boundaries contain.
- AI system resilience: timeouts, retries and fallbacks.
- MCP versus function calling: how a Tool server is reached.
Terms used on this page: C4 model, trust boundary, sequence diagram, idempotency key and data flow diagram.
Core concepts
One system, drawn at every level
Every diagram here shows the same invented policy Q&A assistant. A customer asks about a policy (a returns or warranty policy, say). The assistant answers only from approved policy documents, cites the passages it used, and can create a support ticket on request. It is not a real product and every number attached to it is illustrative.
The course uses fixed component names so diagrams on different pages can be read against each other.
| Name | What it does in the teaching system |
|---|---|
| Client app | The web or mobile front end |
| API gateway | Authenticates, rate-limits, forwards with a verified identity |
| Orchestrator | Runs the agent loop: builds the prompt, calls the model, decides about tool calls, checks the output |
| Model gateway | The single path to model providers: keys, provider-side retries, token accounting |
| LLM provider | An external service that generates text |
| Retriever | Turns the question into a search and returns the allowed passages |
| Vector index | Embeddings of policy passages for similarity search |
| Document store | The approved policy documents and their versions |
| Tool server | Exposes the ticket-creation tool |
| Policy engine | Allow or deny for a tool call, for a given user |
| Event bus | Carries audit and trace events asynchronously |
| Worker | Consumes events and writes them to storage |
| Trace store | Keeps traces and audit events |
| Eval service | Replays saved cases against a new prompt or model version |
How to read this: use the left column's name in every diagram and in the prose; a renamed box looks like a new component.
The course-wide Approval service is absent: a ticket created on the customer's own behalf is reversible and customer-initiated, so a Policy engine decision is enough here. A refund would add it. The ticketing system and identity provider are external.
C4 in one page
The C4 model, created by Simon Brown and documented at c4model.com, describes software at four zoom levels: system context, containers, components and code. The site calls it "an easy to learn, developer friendly approach to software architecture diagramming". You do not need all four levels, "only those that add value"; context and container diagrams are named as sufficient for most teams.
| Level | Scope | Primary elements | What the C4 site says |
|---|---|---|---|
| System context | One software system | The system, with people and external systems around it | For everybody; recommended for all teams |
| Container | One software system | The containers inside it | For technical people; says very little about deployment |
| Component | One container | The components inside it | For architects and developers; only if they add value |
| Deployment | One or more systems in a single environment | Deployment nodes and the instances on them | One diagram per environment; icons must be in the key |
How to read this: each row zooms in one step, and deployment is a separate lens on the same containers.
- A container is "an application or a data store" that "needs to be running in order for the overall software system to work". It is not about Docker, so a client library inside the Orchestrator is not a container.
- A component is "a grouping of related functionality encapsulated behind a well-defined interface."
Notation rules worth adopting even without C4 tooling:
- Every diagram has a title that says its type and scope, and a key or legend.
- Each diagram stands alone and is mostly understood without a narrative.
- Every element carries a type and a short description.
- Every line is labelled and runs one way. Lines between containers name a technology or protocol.
Here the C4-style views use the site's architecture diagram format (a text spec with zones and labelled arrows): they follow the C4 abstractions but are not C4 tool output. Mermaid's own C4 type is, in its documentation's words, "an experimental diagram for now" whose syntax and properties can change in future releases. A text spec is editable in a pull request. The cost: nothing enforces C4 discipline, which is what the checklist below is for.
The context view
The context view shows the system in the middle and only the people and external systems around it.
Figure 2. Context view of the policy Q&A assistant
How to read this: person icons are people, the shaded box groups the external systems the team does not run, and each arrow is one direction with a label saying what travels.
It leaves out databases, queues and the model gateway on purpose. One decision is already exposed: customer question text leaves the system for an LLM provider. A privacy reviewer needs that on the first diagram, not the tenth.
The container view
The container view zooms into the system. Draw the containers that fail, scale and get secured differently, including the asynchronous audit path.
Figure 3. Container view of the policy Q&A assistant
How to read this: solid arrows are synchronous calls that the customer waits for, dashed arrows are asynchronous, database icons are stores, and the large box is the system boundary.
- The Orchestrator is the only container that talks to the Retriever, Model gateway, Policy engine and Tool server, so the next view zooms into it.
- The audit path is asynchronous. What happens when the Event bus is down belongs in a failure sequence, not here.
- Left out to stay near the node limit: the identity provider and the ingestion path that fills the Document store and Vector index. A real view would show both.
The component view
A component view decomposes one container, and only when it adds value. For the Orchestrator it does: the agent loop holds most AI-specific decisions.
Figure 4. Component view of the Orchestrator
How to read this: the large box is one container, the boxes inside it are components with one responsibility each, dashed arrows are asynchronous events, and everything outside the box is another container from Figure 3.
| Component | One responsibility | The rule that lives here |
|---|---|---|
| Input checks | Reject oversize or malformed requests | Before any model spend |
| Context builder | Choose which passages and conversation parts go in the prompt | What the model sees |
| Agent loop | Own the step budget | How many tool rounds |
| Tool dispatcher | The only code that may call the Tool server | The Policy engine check, in one place |
| Output checks | Verify, for example, that every citation was retrieved | What reaches the customer |
| Audit emitter | Written once, used by the others | No path forgets to log |
How to read this: each row is a box in Figure 4, and the last column is why that box exists.
Sequence diagrams for runtime behaviour
Structure diagrams do not say what happens in what order. A sequence diagram shows participants as vertical lifelines and messages as arrows read top to bottom. The C4 site's dynamic diagram shows "how elements in the static model collaborate at runtime to implement a user story, use case, feature", in either collaboration or sequence style.
| You want | Mermaid syntax |
|---|---|
| A short name for a lifeline | participant X as Name |
| Request and reply | ->> and -->> |
| An asynchronous message | -) |
| A decision at a point in time | Note over A,B: text |
| Alternatives, optional steps, repeats, parallel work | alt / else, opt, loop, par |
| Numbered steps | autonumber |
How to read this: the left column is the need, the right column is the syntax this page's figures use.
Mermaid's documentation warns that the word "end" can break a diagram, that a semicolon acts as a line break and that # needs an entity code, so avoid them in message text. Draw one sequence per scenario, with at most about eight participants, and put each decision in a note where the system makes it.
Figure 5. Normal question, answered from the policy documents
How to read this: time runs downward, solid arrows are requests, dotted arrows are replies, the open-headed arrow is asynchronous, and the note marks a decision the Orchestrator makes.
The happy path is the least informative diagram you can draw. The next two show what the design does when things go wrong.
Figure 6. Failure path: the retrieval step returns nothing or times out
How to read this: the alt block shows two alternatives that end in the same customer message, and the notes mark the decisions.
With no evidence, the Orchestrator does not call the model at all. A model asked a policy question with no passages can still produce a fluent answer from its training data, which the system promised not to do. Retrying the Retriever once is a design choice; if you make it, the diagram must show it and the timeout budget must pay for it.