Generate C4 Diagrams from Code or External Data
Generate C4 Diagrams from Code or External Data
Overview
Use EA automation, import facilities, APIs, or scripts to create or update C4-level model elements from source code, repositories, service catalogs, CMDBs, or architecture data. The resulting diagrams can use standard UML, a UML Profile, or a custom C4 MDG Technology.
How to implement
- Choose the authoritative source for each data category.
- Define mappings from source records to C4 elements:
- Service catalog entry -> Software System or Container
- Deployable application -> Container
- Module/package -> Component
- Source class -> Code element
- API dependency -> Relationship
- Establish stable external identifiers to prevent duplicates.
- Write an import or synchronization process using EA automation/API capabilities available in the environment.
- Apply stereotypes, tagged values, notes, and relationship labels during import.
- Generate or update diagrams at the appropriate C4 level.
- Mark generated content clearly and define which fields are editable in EA.
- Schedule synchronization and review exceptions rather than blindly overwriting manual changes.
Example mapping
CMDB application: Customer Portal
-> C4 Software System: Customer Portal
Deployment service: Portal API
-> C4 Container: Portal API
Repository module: authentication
-> C4 Component: Authentication Module
Dependency: Portal API calls Identity Service
-> Relationship label: calls
Advantages
- Reduces manual duplication of existing architecture data.
- Keeps C4 views closer to operational reality.
- Enables repeatable documentation and dashboards.
- Can combine high-level C4 views with detailed code or deployment information.
Disadvantages
- Requires integration development and maintenance.
- Source data may be incomplete, inconsistent, or incorrectly classified.
- Automatically generated diagrams can become crowded.
- Synchronization ownership and conflict rules must be explicit.
- EA upgrades and source-system changes require testing.
Recommended practice
Automate inventory and dependency data, but retain architectural review for boundaries, purposes, abstractions, and stakeholder-facing descriptions. Treat generated diagrams as a maintained product, not an unquestioned export.