C4 diagrams

From lexler/skill-factory · View interactive version

C4 diagrams is an AI agent skill from the GitHub repository lexler/skill-factory. Creates C4 architecture diagrams for designing, documenting, or understanding software architecture. Use when working through system design, mapping existing codebases, or visualizing structure at any level from system landscape down to code.

How to use this skill

Skill file

STARTER_CHARACTER = 🏗️

C4 Model

C4 is a hierarchical approach to diagramming software architecture. Four core levels of zoom, each showing more detail:

System Context (one system + its users and external dependencies)
  └── Container (deployable units inside the system)
        └── Component (logical groupings inside a container)
              └── Code (classes, interfaces, functions inside a component)

Three supplementary diagram types complement this hierarchy:

Core Abstractions

Choosing the Diagram Type

Pick the level that matches the conversation. Load the reference for the type you're creating.

Static structure (the zoom hierarchy):

Wider or orthogonal views:

Most teams need only System Context + Container. Add others when they earn their place.

Choosing the Output Format

Ask the user which format they prefer. If no preference stated, choose based on context:

Notation Rules

Every diagram must have:

Every element must have:

Every container and component must also have:

Every relationship must:

Descriptions and legends are format-dependent:

Review Checklist

After creating any diagram, verify:

Anti-Patterns

One giant diagram — if a Container diagram has 20+ containers, split into focused views by domain area or user journey. Each view should tell one story.

Mixing abstraction levels — don't show components and software systems on the same diagram. Each diagram operates at one zoom level.

Missing technology labels — "Web App" tells the reader nothing. "React SPA" or "Spring Boot API" tells them what stack they're looking at.

Vague relationship labels — "Uses" between every element makes the diagram useless. Be specific: "Authenticates via", "Publishes events to", "Reads from".

Deployment details in Container diagrams — clustering, load balancers, replication belong in Deployment diagrams, not Container diagrams.

Workflows

From Existing Code

When analyzing a codebase to generate diagrams:

  1. Explore the codebase to identify the system boundary, external dependencies, and internal structure
  2. Start at System Context level — identify users and external systems
  3. Zoom into Container level — identify deployable units, data stores, and inter-container communication
  4. Ask the user if deeper levels (Component, Code) are needed before going further
  5. For large systems, create multiple focused views by domain area or user journey rather than one giant diagram
  6. Verify the diagram against actual code — don't guess at relationships

Recognizing C4 elements in code:

From Designs Being Planned

When the user wants to work through architecture for a system that doesn't exist yet — or only partially exists — first figure out where they are in the design process:

  1. Look for existing design artifacts before asking. Check docs/, architecture/, design/, ADRs, RFCs, README files, anywhere design might already be captured. If you find them, read them and base the diagrams on what's there.
  2. If partial designs exist, draft diagrams from them and ask the user only about gaps.
  3. If no design exists, interview the user: what is the system, who uses it, what does it integrate with, what are the major moving parts.
  4. Draft a System Context diagram and validate with the user before going deeper
  5. Discuss containers — what tech, what responsibilities, how they communicate
  6. Draft a Container diagram
  7. Go deeper only if the user wants to explore a specific container's internals

The diagrams are a tool for thinking, not just documentation. Surface architectural decisions as you draft — "I'm assuming the queue decouples ingestion from processing — is that intentional?" — rather than just transcribing what the user said.

After the First Draft

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.