|
|
@@ -1,30 +1,162 @@
|
|
|
## Instructions
|
|
|
|
|
|
-C4 diagrams model software architecture at different levels of abstraction, from system context to component details.
|
|
|
+C4 diagrams model software architecture at different levels of abstraction, from system context to component details. Mermaid's C4 diagram syntax is compatible with plantUML. C4 diagrams are used to visualize software architecture at different levels: System Context, Container, Component, Dynamic, and Deployment.
|
|
|
+
|
|
|
+**Note**: This is an experimental diagram type. The syntax and properties can change in future releases. Proper documentation will be provided when the syntax is stable.
|
|
|
|
|
|
### Syntax
|
|
|
|
|
|
-- Use `C4Context`, `C4Container`, `C4Component`, or `C4Dynamic` keywords
|
|
|
-- Title: `title Diagram Title`
|
|
|
-- Person: `Person(alias, "Label", "Description")`
|
|
|
-- System: `System(alias, "Label", "Description")`
|
|
|
-- SystemDb: `SystemDb(alias, "Label", "Description")`
|
|
|
-- Boundary: `Enterprise_Boundary(alias, "Label") { }`
|
|
|
-- Relationships: `Rel(from, to, "Label", "Technology")`
|
|
|
-- BiRel: `BiRel(from, to, "Label", "Technology")`
|
|
|
+- Use `C4Context`, `C4Container`, `C4Component`, `C4Dynamic`, or `C4Deployment` keywords
|
|
|
+- Title: `title Diagram Title` (optional)
|
|
|
+- Elements:
|
|
|
+ - Person: `Person(alias, "Label", "Description")`
|
|
|
+ - System: `System(alias, "Label", "Description")`
|
|
|
+ - SystemDb: `SystemDb(alias, "Label", "Description")`
|
|
|
+ - SystemQueue: `SystemQueue(alias, "Label", "Description")`
|
|
|
+ - System_Ext: `System_Ext(alias, "Label", "Description")`
|
|
|
+ - Container: `Container(alias, "Label", "Technology", "Description")`
|
|
|
+ - Component: `Component(alias, "Label", "Technology", "Description")`
|
|
|
+ - Deployment_Node: `Deployment_Node(alias, "Label", "Type", "Description")`
|
|
|
+- Boundaries: `Enterprise_Boundary(alias, "Label") { }` or `System_Boundary(alias, "Label") { }`
|
|
|
+- Relationships: `Rel(from, to, "Label", "Technology")` or `BiRel(from, to, "Label", "Technology")`
|
|
|
+- Directional relationships: `Rel_U`, `Rel_D`, `Rel_L`, `Rel_R` (Up, Down, Left, Right)
|
|
|
+
|
|
|
+Reference: [Mermaid C4 Diagram Documentation](https://mermaid.ai/open-source/syntax/c4.html)
|
|
|
|
|
|
-### Example
|
|
|
+### Example (C4Context - System Context Diagram)
|
|
|
|
|
|
```mermaid
|
|
|
C4Context
|
|
|
title System Context Diagram
|
|
|
-
|
|
|
+
|
|
|
Person(customer, "Customer", "A customer of the system")
|
|
|
System(webapp, "Web Application", "Provides web interface")
|
|
|
System_Ext(email, "Email System", "Sends email notifications")
|
|
|
SystemDb(database, "Database", "Stores application data")
|
|
|
-
|
|
|
+
|
|
|
Rel(customer, webapp, "Uses")
|
|
|
Rel(webapp, database, "Reads from and writes to")
|
|
|
Rel(webapp, email, "Sends emails via")
|
|
|
```
|
|
|
+
|
|
|
+### Example (C4Container - Container Diagram)
|
|
|
+
|
|
|
+```mermaid
|
|
|
+C4Container
|
|
|
+ title Container Diagram
|
|
|
+
|
|
|
+ Person(user, "User", "A user of the system")
|
|
|
+ System_Boundary(c1, "Web Application") {
|
|
|
+ Container(web, "Web Server", "Java/Spring", "Delivers web content")
|
|
|
+ Container(api, "API Application", "Java/Spring", "Provides API endpoints")
|
|
|
+ }
|
|
|
+ SystemDb(database, "Database", "PostgreSQL", "Stores data")
|
|
|
+
|
|
|
+ Rel(user, web, "Uses", "HTTPS")
|
|
|
+ Rel(web, api, "Uses", "HTTPS")
|
|
|
+ Rel(api, database, "Reads from and writes to", "JDBC")
|
|
|
+```
|
|
|
+
|
|
|
+### Example (C4Component - Component Diagram)
|
|
|
+
|
|
|
+```mermaid
|
|
|
+C4Component
|
|
|
+ title Component Diagram
|
|
|
+
|
|
|
+ Container(webapp, "Web Application", "Java/Spring", "Web application")
|
|
|
+ System_Boundary(c1, "Web Application") {
|
|
|
+ Component(controller, "UserController", "Spring MVC", "Handles HTTP requests")
|
|
|
+ Component(service, "UserService", "Spring", "Business logic")
|
|
|
+ Component(repository, "UserRepository", "Spring Data", "Data access")
|
|
|
+ }
|
|
|
+ SystemDb(database, "Database", "PostgreSQL", "Stores data")
|
|
|
+
|
|
|
+ Rel(webapp, controller, "Uses")
|
|
|
+ Rel(controller, service, "Uses")
|
|
|
+ Rel(service, repository, "Uses")
|
|
|
+ Rel(repository, database, "Reads from and writes to")
|
|
|
+```
|
|
|
+
|
|
|
+### Example (C4Dynamic - Dynamic Diagram)
|
|
|
+
|
|
|
+```mermaid
|
|
|
+C4Dynamic
|
|
|
+ title Dynamic Diagram
|
|
|
+
|
|
|
+ Person(user, "User", "A user")
|
|
|
+ System(webapp, "Web Application", "Web app")
|
|
|
+ SystemDb(database, "Database", "Database")
|
|
|
+
|
|
|
+ RelIndex(1, user, webapp, "1. Login request")
|
|
|
+ RelIndex(2, webapp, database, "2. Query user")
|
|
|
+ RelIndex(3, database, webapp, "3. Return user data")
|
|
|
+ RelIndex(4, webapp, user, "4. Return login result")
|
|
|
+```
|
|
|
+
|
|
|
+### Example (C4Deployment - Deployment Diagram)
|
|
|
+
|
|
|
+```mermaid
|
|
|
+C4Deployment
|
|
|
+ title Deployment Diagram
|
|
|
+
|
|
|
+ Deployment_Node(web, "Web Server", "Linux", "Apache Tomcat"){
|
|
|
+ Container(webapp, "Web Application", "Java", "Web application")
|
|
|
+ }
|
|
|
+ Deployment_Node(app, "Application Server", "Linux", "Java Runtime"){
|
|
|
+ Container(appserver, "App Server", "Java", "Application server")
|
|
|
+ }
|
|
|
+ Deployment_Node(db, "Database Server", "Linux", "PostgreSQL"){
|
|
|
+ ContainerDb(database, "Database", "PostgreSQL", "Database")
|
|
|
+ }
|
|
|
+
|
|
|
+ Rel(webapp, appserver, "Deploys")
|
|
|
+ Rel(appserver, database, "Connects to")
|
|
|
+```
|
|
|
+
|
|
|
+### Example (With Enterprise Boundary)
|
|
|
+
|
|
|
+```mermaid
|
|
|
+C4Context
|
|
|
+ title System Context with Boundaries
|
|
|
+
|
|
|
+ Person(customer, "Customer", "A customer")
|
|
|
+ Enterprise_Boundary(c1, "Customer Enterprise") {
|
|
|
+ System(crm, "CRM System", "Customer management")
|
|
|
+ }
|
|
|
+ Enterprise_Boundary(c2, "Provider Enterprise") {
|
|
|
+ System(webapp, "Web Application", "Main application")
|
|
|
+ SystemDb(database, "Database", "Data storage")
|
|
|
+ }
|
|
|
+
|
|
|
+ Rel(customer, crm, "Uses")
|
|
|
+ Rel(crm, webapp, "Sends data to")
|
|
|
+ Rel(webapp, database, "Uses")
|
|
|
+```
|
|
|
+
|
|
|
+### Example (With Bidirectional Relationship)
|
|
|
+
|
|
|
+```mermaid
|
|
|
+C4Context
|
|
|
+ title System Context with BiRel
|
|
|
+
|
|
|
+ System(systemA, "System A", "First system")
|
|
|
+ System(systemB, "System B", "Second system")
|
|
|
+
|
|
|
+ BiRel(systemA, systemB, "Communicates with", "REST API")
|
|
|
+```
|
|
|
+
|
|
|
+### Alternative (Flowchart - compatible with all Mermaid versions)
|
|
|
+
|
|
|
+If C4 diagrams are not supported, use this flowchart alternative:
|
|
|
+
|
|
|
+```mermaid
|
|
|
+flowchart TD
|
|
|
+ Customer[Customer]
|
|
|
+ WebApp[Web Application]
|
|
|
+ Database[(Database)]
|
|
|
+ Email[Email System]
|
|
|
+
|
|
|
+ Customer -->|Uses| WebApp
|
|
|
+ WebApp -->|Reads/Writes| Database
|
|
|
+ WebApp -->|Sends| Email
|
|
|
+```
|