Diagram library
AI engineering, drawn as systems
Every diagram in this wiki uses one visual language: the same shapes, colors, and line styles mean the same thing everywhere. Hover or tap any component for an explanation, highlight a flow, or open a diagram fullscreen to zoom in. Each one also has a full text description.
Shapes
- Rounded rectangle: Service or code you run
- Cylinder: Database or storage
- Hexagon: LLM or other model
- Circle: User or actor
- Page: File or document
Colors
- AI / LLM
- Backend
- Frontend
- Data / storage
- Security / risk
- External
Lines
- Request or data
- Async job or event
- Streaming response
- Trust boundary
The learning roadmap
Nine stages take you from web foundations to a job-ready portfolio. Each stage depends on the ones before it, which is why the wiki is ordered this way.
- Start Here2 weeksbeginner Understand the role and pick a study plan.
- Foundations4 weeksbeginner TypeScript, Node.js, React, databases, APIs, and DevOps.
- LLM Fundamentals2 weeksbeginner Tokens, context windows, choosing models, keys and billing.
- LLM App Engineering5 weeksintermediate Streaming, structured outputs, tool use, RAG, and caching.
- Agents & Orchestration5 weeksadvanced Agent loops, multi-agent systems, MCP, durable execution.
- Production AI2 weeksadvanced Evals, tracing, reliability, security, and cost.
- AI-Assisted Development1 weekintermediate Build, review, test, and debug with coding agents.
- Projects3 weeksadvanced Six builds, ending with a production SaaS assistant.
- Career2 weeksintermediate Portfolio, writing, and AI system design interviews.
Show text descriptionHide text description
The roadmap is an ordered path of 9 stages. Each stage builds on the ones before it. Durations follow the 6-month standard plan; the 3-month plan compresses them and the 12-month plan expands the foundations.
- Start Here (2 weeks, beginner): Understand the role and pick a study plan.
- Foundations (4 weeks, beginner): TypeScript, Node.js, React, databases, APIs, and DevOps.
- LLM Fundamentals (2 weeks, beginner): Tokens, context windows, choosing models, keys and billing.
- LLM App Engineering (5 weeks, intermediate): Streaming, structured outputs, tool use, RAG, and caching.
- Agents & Orchestration (5 weeks, advanced): Agent loops, multi-agent systems, MCP, durable execution.
- Production AI (2 weeks, advanced): Evals, tracing, reliability, security, and cost.
- AI-Assisted Development (1 week, intermediate): Build, review, test, and debug with coding agents.
- Projects (3 weeks, advanced): Six builds, ending with a production SaaS assistant.
- Career (2 weeks, intermediate): Portfolio, writing, and AI system design interviews.
Architecture of an AI application
A production AI feature is mostly ordinary full-stack engineering. The model is one component behind your API, surrounded by auth, storage, background jobs, and observability. Use the flow buttons to trace a chat request, document indexing, or telemetry.
Hover or tap a component to see what it does.
Show text descriptionHide text description
The diagram shows a production AI web application as boxes inside two trust zones: your own infrastructure, and third-party model APIs. Solid arrows are requests, dashed arrows are asynchronous jobs and telemetry, and arrows with moving dots are streamed responses.
- User: The person using your product in a browser or mobile app.
- React UI: Renders the chat or feature UI, sends requests to your API, and renders streamed tokens as they arrive. Never holds model API keys.
- API layer: The only place that talks to model providers. Validates input, checks auth and rate limits, assembles context, calls the model, and streams the answer back over Server-Sent Events.
- Auth: Identifies the user and decides what data and tools they may access. Every model call and tool call inherits these permissions.
- Redis: Fast key-value store for per-user rate limits, response caching, and short-lived session state.
- Postgres: The system of record: users, conversations, and documents. The pgvector extension stores embeddings so the same database answers similarity searches for RAG.
- Job queue: Holds slow work (document indexing, long agent runs, batch jobs) so API requests return quickly. Jobs survive restarts and can be retried.
- Workers: Node.js processes that pull jobs from the queue: chunk documents, request embeddings, write vectors to Postgres, and run long tasks with retries.
- Observability: Collects a trace for every request and job, with prompts, token counts, latency, and cost, so you can debug bad answers and run evals on real traffic.
- Model APIs: Hosted models reached over HTTPS: an LLM for generation and tool use, and an embedding model for vector search. Stateless: every request must carry its full context.
Chat request. The UI posts the message to your API, which verifies the session, checks the rate limit in Redis, retrieves context from Postgres, calls the model, and streams tokens back to the browser over SSE.
Document indexing. An upload is acknowledged immediately and queued. A worker chunks the document, requests embeddings from the model API, and writes the vectors to pgvector.
Observability. The API and workers emit a trace for every request and job, with token counts, latency, and cost. Traces feed dashboards, alerts, and evals on real traffic.
The tool-use loop
Tool use (also called function calling) lets a model request actions, but your code always executes them. Step through one full loop, including the exact JSON that crosses each arrow.
Step 1 of 7
The user asks a question
The answer depends on live data the model has never seen, so a plain model call would guess. Your app receives the message like any other request.
User message
"Where is my order #4821?"Show text descriptionHide text description
The diagram shows five parts: the user, your app (a Node.js server), the LLM behind the Messages API, your tool code, and your database. The model never executes tools itself; your app runs the loop.
- The user asks a question. The answer depends on live data the model has never seen, so a plain model call would guess. Your app receives the message like any other request.
- Your app calls the model with tool definitions. Alongside the conversation, you describe each tool: a name, a description the model reads to decide when to use it, and a JSON Schema for its input.
- The model asks you to run a tool. The model cannot execute code. It stops with stop_reason "tool_use" and returns a tool_use block naming the tool and the arguments it chose.
- Your code executes the tool. Validate the input, check that this user may see this order, then run the function. Your data never leaves your control unless you return it.
- Send the tool result back. The API is stateless: append the assistant turn exactly as received, then a user turn containing a tool_result that references the tool_use id, and call the model again.
- The model writes the final answer. With the result in context, the model answers and stops with stop_reason "end_turn". If it needs more data, it returns tool_use again and the loop repeats from step 3.
- Stream the answer to the user. Show the final text in the UI. In production, cap the loop (for example at 10 iterations), log every tool call, and treat tool results as untrusted input.
Retrieval-augmented generation (RAG)
RAG grounds answers in your own documents. The work splits into an offline indexing path and an online query path that meet at the vector database.
Hover or tap a component to see what it does.
Show text descriptionHide text description
Retrieval-augmented generation has two paths that meet at the vector database.
Indexing path. Runs offline whenever documents change: load each document, split it into chunks, embed every chunk, and store the vectors with their text and metadata.
Query path. Runs on every request: embed the question, retrieve the nearest chunks, rerank them, and give the best few to the LLM, which answers with citations.
- Documents: Your source of truth: help-center articles, internal docs, tickets, PDFs. Keep each document's URL and title for citations.
- Chunk: Split documents into passages of a few hundred tokens, ideally on headings or paragraphs, with a small overlap. Attach the source, title, and section to each chunk.
- Embedding model: Turns each chunk into a vector: a list of numbers where similar meanings end up close together. Use the same embedding model for indexing and querying.
- Vector DB: Stores each chunk's text, metadata, and vector, with an index (such as HNSW) for fast nearest-neighbor search.
- Question: The user's question, for example: "How do I rotate an API key?"
- Embedding model: Embeds the question with the same model used for the documents, so the question and the chunks live in the same vector space.
- Vector search: Finds the chunks whose vectors are closest to the question's vector, usually 20 to 50 candidates. Combine with keyword search for exact terms (hybrid search).
- Reranker: A model that reads the question and each candidate together and scores relevance more precisely than vector similarity. Keep only the best few chunks.
- LLM: Receives the question plus the selected chunks, with instructions to answer only from them and cite the sources it used.
- Answer: The response shown to the user, with links to the source documents so they can verify it.
The numbers on the arrows are typical starting points, not rules: retrieve around 20 candidates, then keep the best 5 after reranking. Tune both with evals.
Agent design patterns
Most useful "agents" are simpler workflows. These six patterns go from the most predictable to the most autonomous; start at the top and move down only when the task demands it.
Prompt chaining
Tap a step for details.
Show text descriptionHide text description
Input flows through LLM call 1, a code gate that can exit early, LLM call 2, and LLM call 3 to the output.
Use it when: The task splits cleanly into ordered subtasks and you want each call to be simpler and more accurate.
Example: Write an outline, check it covers required points, draft the article, then polish the tone.
Routing
Tap a step for details.
Show text descriptionHide text description
A router LLM classifies the input and sends it to one of three specialized handlers, whose result becomes the output.
Use it when: Inputs fall into distinct categories that are better handled separately, including routing easy requests to a smaller, cheaper model.
Example: Send billing questions, technical issues, and general questions to different prompts and models.
Parallelization
Tap a step for details.
Show text descriptionHide text description
The input fans out to three concurrent LLM calls checking accuracy, tone, and safety; code aggregates the results into the output.
Use it when: Subtasks are independent and can run concurrently for speed, or you want several independent checks or votes for confidence.
Example: Run accuracy, tone, and safety checks on a draft in parallel, then combine the verdicts.
Orchestrator-workers
Tap a step for details.
Show text descriptionHide text description
An orchestrator LLM plans subtasks and dispatches them to worker LLM calls; a synthesizer LLM combines their results into the output.
Use it when: You cannot predict the subtasks in advance, for example how many files a code change touches or which sources a question needs.
Example: Plan which files to edit for a feature, have a worker propose each file's change, then merge them into one patch.
Evaluator-optimizer
Tap a step for details.
Show text descriptionHide text description
A generator LLM writes a draft; an evaluator LLM scores it and either sends feedback back to the generator or accepts it as the output.
Use it when: You have clear evaluation criteria and iterative refinement measurably improves the result.
Example: Translate a document, have an evaluator flag mistranslated terms, and revise until no issues remain or a round limit is hit.
Autonomous agent
Tap a step for details.
Show text descriptionHide text description
A human gives the LLM agent a task; the agent repeatedly takes actions in its environment and reads the feedback, checks in with the human when needed, and stops when done.
Use it when: The task is open-ended, the number of steps cannot be predicted, and you can afford the cost and verify the outcome.
Example: Fix a failing test: read the code, run the tests, edit files, re-run, and stop when the suite passes.