c4-level4-code
C4 Level 4: Code Diagram
The Code diagram is the lowest level of detail, showing how a single component is implemented. It's often used for complex components or database schemas.
Core Principles (MANDATORY)
- Optionality: Level 4 is usually optional. Only use it when the internal implementation is too complex to understand without a visual map.
- Specific Implementation: Use standard UML class diagram notation or ER diagrams (Entity Relationship Diagrams) for data models.
- Keep it Focused: Don't diagram the entire codebase. Focus on the core classes or tables that provide the component's value.
Elements Used
- Class: Classes, interfaces, types.
- Table: Database tables, columns, relationships (Primary/Foreign keys).
- Relationship: Inheritance, composition, aggregation, or data associations.
Mermaid Templates
UML Class Diagram Template
classDiagram
class User {
+int id
+string username
+string password
+save()
}
class AuthService {
+authenticate(username, password)
}
AuthService --> User : Uses
ER Diagram (Database) Template
erDiagram
USER ||--o{ ORDER : places
USER {
int id PK
string username
string email
}
ORDER {
int id PK
int user_id FK
datetime created_at
}
Level 4 Review Checklist
- Is this diagram necessary for understanding the component?
- Are relationships (inheritance, association) correctly labeled?
- Is the diagram focused on only the most important parts?
- Does it correctly reflect the actual codebase structure?
More from kinhluan/skills
scheduling-algorithms
Job scheduling algorithms for parallel and distributed systems
5ddd-core
Professional Strategic Domain-Driven Design (DDD) Hub. Use this skill for Event Storming, identifying Subdomains, defining Bounded Contexts, and mapping Domain Models to the heart of your architecture.
4c4-model
Professional C4 model architecture hub for "Design-to-Code Sync". Use this skill to navigate the C4 hierarchy, map diagrams to stakeholders, avoid architectural anti-patterns, and choose the right level for designing or documenting existing codebases.
4ddd-tactical
Tactical Domain-Driven Design (DDD) with Scoring Rubric. Use this skill when designing internal domain models or performing architectural reviews to ensure domain logic is isolated and rich.
4ddd-patterns
Advanced Domain-Driven Design (DDD) Integration Patterns. Use this skill for implementing CQRS, Event Sourcing, the Outbox Pattern, and Anti-Corruption Layers (ACL) in distributed systems.
4c4-level2-container
Specialized in Container diagrams (Level 2) with Infrastructure mapping. Use this skill when the user requests decomposing systems into separately deployable units, identifying the tech stack, and mapping infrastructure components (Docker, K8s).
4