Back to Architecture & Design Patterns

c4-architecture

c4 modelarchitecturemermaiddocumentationdiagramssoftware designsystem visualizationcoding assistant
⭐ 2.0kπŸ“„ MITπŸ•’ 2026-03-05Source β†—

Install this skill

npx skills add softaworks/agent-toolkit

Works across Claude Code, Cursor, Codex, Copilot & Antigravity

The c4-architecture skill provides a structured method for documenting software designs using Mermaid.js C4 syntax. It translates high-level system concepts into standard visual representations, including Context, Container, Component, and Deployment levels. By adopting this model, developers can standardize documentation, ensuring that both technical stakeholders and external collaborators share a consistent understanding of system boundaries and internal interactions. The skill automates the boilerplate syntax required for C4 diagrams, allowing you to focus on mapping relationships and infrastructure nodes rather than manual diagramming. It is particularly effective for teams transitioning from ambiguous whiteboard sketches to formal, version-controlled architecture documentation. The approach enforces logical abstraction, preventing cluttered diagrams by guiding you to choose the appropriate level of detail based on the specific audience and project goals.

When to Use This Skill

  • β€’Documenting new feature integrations during sprint planning
  • β€’Onboarding developers to existing microservices architectures
  • β€’Visualizing cloud deployment strategies for production systems
  • β€’Mapping request-response lifecycles for troubleshooting distributed logic

How to Invoke This Skill

Example prompts that trigger this skill in Claude Code, Cursor, or Antigravity:

  • β€œGenerate a C4 container diagram for my system
  • β€œHow should I model my backend architecture using Mermaid?
  • β€œCreate a system context diagram for this codebase
  • β€œWrite a C4 component diagram for the authentication module
  • β€œVisualize the deployment architecture for my microservices
  • β€œExplain my current architecture using C4 levels

Pro Tips

  • πŸ’‘Specify the exact C4 level (e.g., 'Generate a C4 Context diagram for...') to ensure the output is tailored to your audience's needs.
  • πŸ’‘Provide a concise description of key components, their responsibilities, and main interactions for more accurate and detailed diagrams.
  • πŸ’‘After generation, use online Mermaid editors or IDE extensions to quickly preview and fine-tune the diagrams before embedding them in your documentation.

What this skill does

  • β€’Generates standardized Mermaid C4 diagram syntax
  • β€’Maps system context with actors and external dependencies
  • β€’Defines container boundaries for applications and data storage
  • β€’Visualizes component interactions and specific technology stacks
  • β€’Models deployment environments including cloud nodes and infrastructure
  • β€’Creates numbered dynamic flows for complex request sequences

When not to use it

  • βœ•Simple CRUD applications with no significant architectural complexity
  • βœ•When you require pixel-perfect graphic design for marketing presentations

Example workflow

  1. Analyze the codebase to determine the scope of the system boundaries.
  2. Define the target audience to select the appropriate C4 level.
  3. Draft the system context, identifying external actors and main modules.
  4. Detail the containers or internal components and their specific technology stacks.
  5. Establish relationships and data flows between components.
  6. Review the rendered diagram against the current source code for accuracy.

Prerequisites

  • –Knowledge of Mermaid.js syntax
  • –Clear understanding of current system architecture

Pitfalls & limitations

  • !Creating diagrams that are too granular, reducing readability
  • !Failing to update diagrams when the underlying code changes
  • !Over-using Dynamic diagrams where static ones would suffice

FAQ

Which C4 level is most important?
The Context and Container levels are usually sufficient for most development tasks as they define scope and system interactions.
When should I use a Dynamic diagram?
Use Dynamic diagrams when you need to illustrate the sequence of calls or logic flows during a specific request process.
Can I use this for non-cloud infrastructure?
Yes, the deployment level is flexible enough to model physical hardware, local containers, or any infrastructure node arrangement.
Do I need to generate all levels?
No, you should only generate levels that add genuine value for the specific audience viewing the documentation.

How it compares

Unlike generic diagrams, this skill strictly enforces C4 abstraction levels, ensuring documentation remains readable and follows industry-standard design conventions.

Source & trust

⭐ 2.0k starsπŸ“„ MITπŸ•’ Updated 2026-03-05
πŸ“„ Full skill instructions β€” original source: softaworks/agent-toolkit
# C4 Architecture Documentation

Generate software architecture documentation using C4 model diagrams in Mermaid syntax.

## Workflow

1. **Understand scope** - Determine which C4 level(s) are needed based on audience
2. **Analyze codebase** - Explore the system to identify components, containers, and relationships
3. **Generate diagrams** - Create Mermaid C4 diagrams at appropriate abstraction levels
4. **Document** - Write diagrams to markdown files with explanatory context

## C4 Diagram Levels

Select the appropriate level based on the documentation need:

| Level | Diagram Type | Audience | Shows | When to Create |
|-------|-------------|----------|-------|----------------|
| 1 | **C4Context** | Everyone | System + external actors | Always (required) |
| 2 | **C4Container** | Technical | Apps, databases, services | Always (required) |
| 3 | **C4Component** | Developers | Internal components | Only if adds value |
| 4 | **C4Deployment** | DevOps | Infrastructure nodes | For production systems |
| - | **C4Dynamic** | Technical | Request flows (numbered) | For complex workflows |

**Key Insight:** "Context + Container diagrams are sufficient for most software development teams." Only create Component/Code diagrams when they genuinely add value.

## Quick Start Examples

### System Context (Level 1)
C4Context
title System Context - Workout Tracker

Person(user, "User", "Tracks workouts and exercises")
System(app, "Workout Tracker", "Vue PWA for tracking strength and CrossFit workouts")
System_Ext(browser, "Web Browser", "Stores data in IndexedDB")

Rel(user, app, "Uses")
Rel(app, browser, "Persists data to", "IndexedDB")


### Container Diagram (Level 2)
C4Container
title Container Diagram - Workout Tracker

Person(user, "User", "Tracks workouts")

Container_Boundary(app, "Workout Tracker PWA") {
Container(spa, "SPA", "Vue 3, TypeScript", "Single-page application")
Container(pinia, "State Management", "Pinia", "Manages application state")
ContainerDb(indexeddb, "IndexedDB", "Dexie", "Local workout storage")
}

Rel(user, spa, "Uses")
Rel(spa, pinia, "Reads/writes state")
Rel(pinia, indexeddb, "Persists", "Dexie ORM")


### Component Diagram (Level 3)
C4Component
title Component Diagram - Workout Feature

Container(views, "Views", "Vue Router pages")

Container_Boundary(workout, "Workout Feature") {
Component(useWorkout, "useWorkout", "Composable", "Workout execution state")
Component(useTimer, "useTimer", "Composable", "Timer state machine")
Component(workoutRepo, "WorkoutRepository", "Dexie", "Workout persistence")
}

Rel(views, useWorkout, "Uses")
Rel(useWorkout, useTimer, "Controls")
Rel(useWorkout, workoutRepo, "Saves to")


### Dynamic Diagram (Request Flow)
C4Dynamic
title Dynamic Diagram - User Sign In Flow

ContainerDb(db, "Database", "PostgreSQL", "User credentials")
Container(spa, "Single-Page App", "React", "Banking UI")

Container_Boundary(api, "API Application") {
Component(signIn, "Sign In Controller", "Express", "Auth endpoint")
Component(security, "Security Service", "JWT", "Validates credentials")
}

Rel(spa, signIn, "1. Submit credentials", "JSON/HTTPS")
Rel(signIn, security, "2. Validate")
Rel(security, db, "3. Query user", "SQL")

UpdateRelStyle(spa, signIn, $textColor="blue", $offsetY="-30")


### Deployment Diagram
C4Deployment
title Deployment Diagram - Production

Deployment_Node(browser, "Customer Browser", "Chrome/Firefox") {
Container(spa, "SPA", "React", "Web application")
}

Deployment_Node(aws, "AWS Cloud", "us-east-1") {
Deployment_Node(ecs, "ECS Cluster", "Fargate") {
Container(api, "API Service", "Node.js", "REST API")
}
Deployment_Node(rds, "RDS", "db.r5.large") {
ContainerDb(db, "Database", "PostgreSQL", "Application data")
}
}

Rel(spa, api, "API calls", "HTTPS")
Rel(api, db, "Reads/writes", "JDBC")


## Element Syntax

### People and Systems
Person(alias, "Label", "Description")
Person_Ext(alias, "Label", "Description") # External person
System(alias, "Label", "Description")
System_Ext(alias, "Label", "Description") # External system
SystemDb(alias, "Label", "Description") # Database system
SystemQueue(alias, "Label", "Description") # Queue system


### Containers
Container(alias, "Label", "Technology", "Description")
Container_Ext(alias, "Label", "Technology", "Description")
ContainerDb(alias, "Label", "Technology", "Description")
ContainerQueue(alias, "Label", "Technology", "Description")


### Components
Component(alias, "Label", "Technology", "Description")
Component_Ext(alias, "Label", "Technology", "Description")
ComponentDb(alias, "Label", "Technology", "Description")


### Boundaries
Enterprise_Boundary(alias, "Label") { ... }
System_Boundary(alias, "Label") { ... }
Container_Boundary(alias, "Label") { ... }
Boundary(alias, "Label", "type") { ... }


### Relationships
Rel(from, to, "Label")
Rel(from, to, "Label", "Technology")
BiRel(from, to, "Label") # Bidirectional
Rel_U(from, to, "Label") # Upward
Rel_D(from, to, "Label") # Downward
Rel_L(from, to, "Label") # Leftward
Rel_R(from, to, "Label") # Rightward


### Deployment Nodes
Deployment_Node(alias, "Label", "Type", "Description") { ... }
Node(alias, "Label", "Type", "Description") { ... } # Shorthand


## Styling and Layout

### Layout Configuration
UpdateLayoutConfig($c4ShapeInRow="3", $c4BoundaryInRow="1")

- $c4ShapeInRow - Number of shapes per row (default: 4)
- $c4BoundaryInRow - Number of boundaries per row (default: 2)

### Element Styling
UpdateElementStyle(alias, $fontColor="red", $bgColor="grey", $borderColor="red")


### Relationship Styling
UpdateRelStyle(from, to, $textColor="blue", $lineColor="blue", $offsetX="5", $offsetY="-10")

Use $offsetX and $offsetY to fix overlapping relationship labels.

## Best Practices

### Essential Rules

1. **Every element must have**: Name, Type, Technology (where applicable), and Description
2. **Use unidirectional arrows only** - Bidirectional arrows create ambiguity
3. **Label arrows with action verbs** - "Sends email using", "Reads from", not just "uses"
4. **Include technology labels** - "JSON/HTTPS", "JDBC", "gRPC"
5. **Stay under 20 elements per diagram** - Split complex systems into multiple diagrams

### Clarity Guidelines

1. **Start at Level 1** - Context diagrams help frame the system scope
2. **One diagram per file** - Keep diagrams focused on a single abstraction level
3. **Meaningful aliases** - Use descriptive aliases (e.g., orderService not s1)
4. **Concise descriptions** - Keep descriptions under 50 characters when possible
5. **Always include a title** - "System Context diagram for [System Name]"

### What to Avoid

See [references/common-mistakes.md](references/common-mistakes.md) for detailed anti-patterns:
- Confusing containers (deployable) vs components (non-deployable)
- Modeling shared libraries as containers
- Showing message brokers as single containers instead of individual topics
- Adding undefined abstraction levels like "subcomponents"
- Removing type labels to "simplify" diagrams

## Microservices Guidelines

### Single Team Ownership
Model each microservice as a **container** (or container group):
C4Container
title Microservices - Single Team

System_Boundary(platform, "E-commerce Platform") {
Container(orderApi, "Order Service", "Spring Boot", "Order processing")
ContainerDb(orderDb, "Order DB", "PostgreSQL", "Order data")
Container(inventoryApi, "Inventory Service", "Node.js", "Stock management")
ContainerDb(inventoryDb, "Inventory DB", "MongoDB", "Stock data")
}


### Multi-Team Ownership
Promote microservices to **software systems** when owned by separate teams:
C4Context
title Microservices - Multi-Team

Person(customer, "Customer", "Places orders")
System(orderSystem, "Order System", "Team Alpha")
System(inventorySystem, "Inventory System", "Team Beta")
System(paymentSystem, "Payment System", "Team Gamma")

Rel(customer, orderSystem, "Places orders")
Rel(orderSystem, inventorySystem, "Checks stock")
Rel(orderSystem, paymentSystem, "Processes payment")


### Event-Driven Architecture
Show individual topics/queues as containers, NOT a single "Kafka" box:
C4Container
title Event-Driven Architecture

Container(orderService, "Order Service", "Java", "Creates orders")
Container(stockService, "Stock Service", "Java", "Manages inventory")
ContainerQueue(orderTopic, "order.created", "Kafka", "Order events")
ContainerQueue(stockTopic, "stock.reserved", "Kafka", "Stock events")

Rel(orderService, orderTopic, "Publishes to")
Rel(stockService, orderTopic, "Subscribes to")
Rel(stockService, stockTopic, "Publishes to")
Rel(orderService, stockTopic, "Subscribes to")


## Output Location

Write architecture documentation to docs/architecture/ with naming convention:
- c4-context.md - System context diagram
- c4-containers.md - Container diagram
- c4-components-{feature}.md - Component diagrams per feature
- c4-deployment.md - Deployment diagram
- c4-dynamic-{flow}.md - Dynamic diagrams for specific flows

## Audience-Appropriate Detail

| Audience | Recommended Diagrams |
|----------|---------------------|
| Executives | System Context only |
| Product Managers | Context + Container |
| Architects | Context + Container + key Components |
| Developers | All levels as needed |
| DevOps | Container + Deployment |

## References

- [references/c4-syntax.md](references/c4-syntax.md) - Complete Mermaid C4 syntax
- [references/common-mistakes.md](references/common-mistakes.md) - Anti-patterns to avoid
- [references/advanced-patterns.md](references/advanced-patterns.md) - Microservices, event-driven, deployment

How to Use This Skill Unit

Option A: Project-Specific (Recommended)

  1. Click "Download" above
  2. In your project, create the directory: .agent/skills/c4-architecture/
  3. Save the file as SKILL.md
  4. The agent will automatically discover the skill based on its description.

Option B: Global Installation (All Agents)

Save the file to these locations to make it available across all projects:

  • Claude Code: ~/.claude/skills/softaworks/agent-toolkit/c4-architecture/SKILL.md
  • Cursor: ~/.cursor/skills/softaworks/agent-toolkit/c4-architecture/SKILL.md
  • Antigravity: ~/.gemini/antigravity/skills/softaworks/agent-toolkit/c4-architecture/SKILL.md

πŸš€ Install with CLI:
npx skills add softaworks/agent-toolkit

Read the Master Guide: Mastering Agent Skills β†’

Recommended Rules

View more rules β†’

Recommended Workflows

View more workflows β†’

Recommended MCP Servers

View more MCP servers β†’

Take It Further

Maximize your productivity with these powerful resources

πŸ“‹

Define Your Standards

Set up coding standards to ensure this workflow produces consistent, high-quality results.

Browse Rules Library
πŸ“–

Master Workflows

Learn how to create custom workflows, use Turbo Mode, and build your automation library.

Complete Guide

How to use this Skill in Claude Code & Cursor

For Claude Code (CLI)

To use this skill in Claude Code, copy the rule content into your project's custom instructions or follow our Add-Skill CLI guide. This ensures Claude follows your standards during every code generation.

For Cursor & Windsurf

For Cursor or Windsurf, individual skills are best used in the "Rules for AI" section. This specific unit helps the agent avoid architecture & design patterns issues, leading to cleaner, more efficient code.

Why the skill format matters: the standardized Agent Skills format lets your AI agent load detailed instructions only when they are relevant, keeping your prompt clean while improving results.

Source & attribution

This skill is categorized under Architecture & Design Patterns and is published by Softaworks, maintained in softaworks/agent-toolkit.

← Browse All Agent Skills
Sponsored AI assistant. Recommendations may be paid.