Files
Alexander Abakumov 15e744da49 Initial commit: Complete Software Architecture course with 11 modules
- Added comprehensive course structure with 11 modules
- Included theoretical content, practical examples, and tasks
- Multi-language code examples (Java, Rust, Node.js, Python)
- Detailed analysis of architectural approaches and trade-offs
- Complete caching strategies documentation
- Architecture examples from real-world systems (Twitter, Netflix, Uber)
- Structured navigation and learning path
- Ready for educational use
2025-09-09 22:08:07 +03:00

7.1 KiB

C4 Model

Навигация


Что такое C4 Model

C4 Model — методология для документирования архитектуры программного обеспечения через четыре уровня абстракции.

Уровни C4 Model

1. Context (Контекст)

Цель: Показать систему в контексте её окружения.

@startuml
!include https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/master/C4_Context.puml

title System Context diagram for Internet Banking System

Person(customer, "Customer", "A customer of the bank, with personal bank accounts.")
Person(customerService, "Customer Service", "Customer service representative of the bank.")

System(bankingSystem, "Internet Banking System", "Allows customers to view information about their bank accounts, and make payments.")

System_Ext(emailSystem, "E-mail System", "The internal Microsoft Exchange e-mail system.")
System_Ext(mainframeBankingSystem, "Mainframe Banking System", "Stores all of the core banking information about customers, accounts, transactions, etc.")

Rel(customer, bankingSystem, "Uses", "HTTPS")
Rel(customerService, bankingSystem, "Uses", "HTTPS")
Rel(bankingSystem, emailSystem, "Sends e-mails using", "SMTP")
Rel(bankingSystem, mainframeBankingSystem, "Gets account information from, and makes payments using", "XML/HTTPS")

@enduml

2. Container (Контейнеры)

Цель: Показать высокоуровневую форму системы.

@startuml
!include https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/master/C4_Container.puml

title Container diagram for Internet Banking System

Person(customer, "Customer", "A customer of the bank, with personal bank accounts.")
Person(customerService, "Customer Service", "Customer service representative of the bank.")

System_Boundary(c1, "Internet Banking System") {
    Container(webApp, "Web Application", "Java, Spring MVC", "Delivers the static content and the Internet banking single page application.")
    Container(api, "API Application", "Java, Spring Boot", "Provides Internet banking functionality via a JSON/HTTPS API.")
    ContainerDb(database, "Database", "Oracle Database", "Stores user login information, hashed authentication credentials, access logs, etc.")
}

System_Ext(emailSystem, "E-mail System", "The internal Microsoft Exchange e-mail system.")
System_Ext(mainframeBankingSystem, "Mainframe Banking System", "Stores all of the core banking information about customers, accounts, transactions, etc.")

Rel(customer, webApp, "Uses", "HTTPS")
Rel(customerService, webApp, "Uses", "HTTPS")
Rel(webApp, api, "Makes API calls to", "JSON/HTTPS")
Rel(api, database, "Reads from and writes to", "JDBC")
Rel(api, emailSystem, "Sends e-mails using", "SMTP")
Rel(api, mainframeBankingSystem, "Makes API calls to", "XML/HTTPS")

@enduml

3. Component (Компоненты)

Цель: Показать как контейнер состоит из компонентов.

@startuml
!include https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/master/C4_Component.puml

title Component diagram for Internet Banking System - API Application

Container_Boundary(api, "API Application") {
    Component(security, "Security Component", "Spring Security", "Provides authentication and authorisation functionality.")
    Component(controllers, "Controllers", "Spring MVC", "Handles HTTP requests and responses.")
    Component(services, "Services", "Spring", "Contains the business logic.")
    Component(repositories, "Repositories", "Spring Data", "Handles data access.")
}

ContainerDb(database, "Database", "Oracle Database", "Stores user login information, hashed authentication credentials, access logs, etc.")
System_Ext(mainframeBankingSystem, "Mainframe Banking System", "Stores all of the core banking information about customers, accounts, transactions, etc.")

Rel(controllers, security, "Uses")
Rel(controllers, services, "Uses")
Rel(services, repositories, "Uses")
Rel(repositories, database, "Reads from and writes to", "JDBC")
Rel(services, mainframeBankingSystem, "Makes API calls to", "XML/HTTPS")

@enduml

4. Code (Код)

Цель: Показать детали реализации компонентов.

@startuml
!include https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/master/C4_Component.puml

title Component diagram for Internet Banking System - Services

Component_Boundary(services, "Services") {
    Component(accountService, "AccountService", "Java Class", "Provides account related operations.")
    Component(securityService, "SecurityService", "Java Class", "Provides security related operations.")
    Component(emailService, "EmailService", "Java Class", "Provides email related operations.")
}

ComponentDb(database, "Database", "Oracle Database", "Stores user login information, hashed authentication credentials, access logs, etc.")
System_Ext(mainframeBankingSystem, "Mainframe Banking System", "Stores all of the core banking information about customers, accounts, transactions, etc.")

Rel(accountService, database, "Reads from and writes to", "JDBC")
Rel(accountService, mainframeBankingSystem, "Makes API calls to", "XML/HTTPS")
Rel(securityService, database, "Reads from and writes to", "JDBC")
Rel(emailService, mainframeBankingSystem, "Makes API calls to", "XML/HTTPS")

@enduml

Лучшие практики C4 Model

1. Используйте правильный уровень детализации

  • Context: для стейкхолдеров
  • Container: для разработчиков
  • Component: для архитекторов
  • Code: для разработчиков

2. Фокусируйтесь на взаимодействиях

  • Показывайте потоки данных
  • Указывайте протоколы
  • Описывайте интерфейсы

3. Обновляйте документацию

  • Синхронизируйте с кодом
  • Версионируйте изменения
  • Отслеживайте устаревшую документацию

Заключение

C4 Model предоставляет структурированный подход к документированию архитектуры:

  1. Четыре уровня абстракции — от контекста до кода
  2. Аудитория-ориентированность — каждый уровень для своей аудитории
  3. Фокус на взаимодействиях — показывает как компоненты взаимодействуют
  4. Масштабируемость — подходит для систем любого размера

Правильное использование C4 Model значительно улучшает понимание архитектуры системы всеми участниками проекта.