Architecture as Code
C4 diagrams generated from source code, updated on every commit. PlantUML and Mermaid rendered in CI/CD and deployed to GitHub Pages.
Why Architecture as Code?
Diagrams live in your codebase, version-controlled and auto-generated. They evolve with your system instead of rotting in outdated PowerPoints.
-
- Updated on every commit -
npm run docs:archregenerates C4 diagrams from source - - Version controlled - Track architecture changes in Git, see diffs in PRs
- - Reviewed like code - Architecture changes go through pull requests with team visibility
- - Published in CI/CD - Diagrams render and deploy automatically (this site uses GitHub Actions)
C4 Model: 4 Levels of Architecture Diagrams
Progressive zoom from system context down to code level. Each level can be automatically generated from your infrastructure and application code.
Level 1: System Context
SystemBig picture: your system, users, and external dependencies
Web App -> Payment API
Web App -> Email Service
Parse deployment pipelines and infrastructure configs to extract external systems
Parse .github/workflows/cd.yml to extract Cloudflare Pages, deployment triggers, and external services
Level 2: Container
ContainerApplications, databases, microservices, file systems
Node.js API
Redis Cache
PostgreSQL DB
Parse Infrastructure as Code to extract resources and dependencies
inframap generate terraform/ generates PlantUML from Terraform state, or parse package.json dependencies
Level 3: Component
ComponentServices, controllers, repositories within a container
OrderController
PaymentGateway
DatabaseRepository
Scan source code directory structure and module organization
Recursively scan src/services/, src/components/ directories and parse index.ts exports
Level 4: Code
CodeClasses, methods, functions, interfaces
getUser(id)
updateUser(id, data)
deleteUser(id)
}
Use AST parsers to extract class structures, method signatures, and dependencies
Use acorn or @babel/parser to parse TypeScript files and extract class methods, or use typedoc for full API docs
This Portfolio: All 4 C4 levels are auto-generated from code using
npm run docs:arch
Level 1 System Context Example
High-level view of this portfolio site and its external dependencies, auto-generated from GitHub Actions workflows.
.github/workflows/cd.yml and ci.yml Level 2 Container Example: Microservices Architecture
Event-driven microservices with Kafka showing containers (services, databases, message queues) and their interactions.
docs/architecture/examples/microservices.mmd Level 2 Container Example: Data Pipeline Architecture
Real-time and batch data processing containers showing data flow from ingestion through transformation to consumption.
docs/architecture/examples/data-pipeline.mmd Level 3 Component Example: Order Service
Zooming into the Order Service container to show its internal components, controllers, and repositories.
docs/architecture/examples/order-service.puml Level 4 Code Example: ThemeManager Class
Zooming into a component to show class structure and method signatures, auto-generated from TypeScript source code. Note: Level 4 diagrams are optional. They're great for critical algorithms, security components, or complex business logic that needs detailed documentation. But avoid generating them for entire systems - they quickly become overwhelming and unmaintainable at scale.
src/services/ThemeManager.ts using AST parsing
Want This for Your Systems?
Architecture that lives with code. Documentation that evolves with your team.
Let's Talk