# cosmicpython/book architecture

> Architecture diagram of the GitHub repository cosmicpython/book, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/cosmicpython/book
- Repository: https://github.com/cosmicpython/book

## Overview

This repository publishes a book teaching maintainable Python application design. The principal reader journey progresses from domain modeling and repositories through service-layer architecture, units of work, aggregates, and event-driven patterns, then covers commands, integration, CQRS, and dependency injection. The README also identifies appendices on project structure, CSV migration, Django, and validation. The graph represents documented chapter order and capabilities; source excerpts chiefly cover repository-maintenance scripts, so internal book-content relationships beyond the README are not asserted.

Main entry points: [`chapter_01_domain_model.asciidoc`](https://github.com/cosmicpython/book/blob/master/chapter_01_domain_model.asciidoc) (Domain model), [`chapter_02_repository.asciidoc`](https://github.com/cosmicpython/book/blob/master/chapter_02_repository.asciidoc) (Repository), [`chapter_03_abstractions.asciidoc`](https://github.com/cosmicpython/book/blob/master/chapter_03_abstractions.asciidoc) (Abstractions), [`chapter_04_service_layer.asciidoc`](https://github.com/cosmicpython/book/blob/master/chapter_04_service_layer.asciidoc) (Service layer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_foundations["Domain foundations"]
  node_domain["Domain model"]
  node_repository["Repository"]
  node_abstractions["Abstractions"]
end

subgraph group_architecture["Application architecture"]
  node_service["Service layer"]
  node_testing["Testing gears"]
  node_uow["Unit of work"]
  node_aggregate["Aggregates"]
end

subgraph group_messaging["Messaging patterns"]
  node_events["Domain events"]
  node_messagebus["Message bus"]
  node_commands["Commands"]
  node_external["External events"]
  node_cqrs["CQRS"]
  node_di["Dependency injection"]
end

subgraph group_appendices["Practical appendices"]
  node_project["Project structure"]
  node_csv["CSV migration"]
  node_django["Django integration"]
  node_validation["Validation"]
end

node_reader(("Reader"))

node_reader -->|"starts with"| node_domain
node_domain -->|"continues to"| node_repository
node_repository -->|"continues to"| node_abstractions
node_abstractions -->|"continues to"| node_service
node_service -->|"continues to"| node_testing
node_testing -->|"continues to"| node_uow
node_uow -->|"continues to"| node_aggregate
node_aggregate -->|"continues to"| node_events
node_events -->|"continues to"| node_messagebus
node_messagebus -->|"continues to"| node_commands
node_commands -->|"continues to"| node_external
node_external -->|"continues to"| node_cqrs
node_cqrs -->|"continues to"| node_di
node_reader -->|"also covers"| node_project
node_reader -->|"also covers"| node_csv
node_reader -->|"also covers"| node_django
node_reader -->|"also covers"| node_validation

click node_domain "https://github.com/cosmicpython/book/blob/master/chapter_01_domain_model.asciidoc"
click node_repository "https://github.com/cosmicpython/book/blob/master/chapter_02_repository.asciidoc"
click node_abstractions "https://github.com/cosmicpython/book/blob/master/chapter_03_abstractions.asciidoc"
click node_service "https://github.com/cosmicpython/book/blob/master/chapter_04_service_layer.asciidoc"
click node_testing "https://github.com/cosmicpython/book/blob/master/chapter_05_high_gear_low_gear.asciidoc"
click node_uow "https://github.com/cosmicpython/book/blob/master/chapter_06_uow.asciidoc"
click node_aggregate "https://github.com/cosmicpython/book/blob/master/chapter_07_aggregate.asciidoc"
click node_events "https://github.com/cosmicpython/book/blob/master/chapter_08_events_and_message_bus.asciidoc"
click node_messagebus "https://github.com/cosmicpython/book/blob/master/chapter_09_all_messagebus.asciidoc"
click node_commands "https://github.com/cosmicpython/book/blob/master/chapter_10_commands.asciidoc"
click node_external "https://github.com/cosmicpython/book/blob/master/chapter_11_external_events.asciidoc"
click node_cqrs "https://github.com/cosmicpython/book/blob/master/chapter_12_cqrs.asciidoc"
click node_di "https://github.com/cosmicpython/book/blob/master/chapter_13_dependency_injection.asciidoc"
click node_project "https://github.com/cosmicpython/book/blob/master/appendix_project_structure.asciidoc"
click node_csv "https://github.com/cosmicpython/book/blob/master/appendix_csvs.asciidoc"
click node_django "https://github.com/cosmicpython/book/blob/master/appendix_django.asciidoc"
click node_validation "https://github.com/cosmicpython/book/blob/master/appendix_validation.asciidoc"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_domain,node_repository,node_abstractions toneBlue
class node_service,node_testing,node_uow,node_aggregate toneAmber
class node_events,node_messagebus,node_commands,node_external,node_cqrs,node_di toneMint
class node_project,node_csv,node_django,node_validation toneRose
class node_reader toneIndigo
```

## Components

### Domain foundations

- [Domain model](https://github.com/cosmicpython/book/blob/master/chapter_01_domain_model.asciidoc): `chapter_01_domain_model.asciidoc`
- [Repository](https://github.com/cosmicpython/book/blob/master/chapter_02_repository.asciidoc): `chapter_02_repository.asciidoc`
- [Abstractions](https://github.com/cosmicpython/book/blob/master/chapter_03_abstractions.asciidoc): `chapter_03_abstractions.asciidoc`

### Application architecture

- [Service layer](https://github.com/cosmicpython/book/blob/master/chapter_04_service_layer.asciidoc): `chapter_04_service_layer.asciidoc`
- [Testing gears](https://github.com/cosmicpython/book/blob/master/chapter_05_high_gear_low_gear.asciidoc): `chapter_05_high_gear_low_gear.asciidoc`
- [Unit of work](https://github.com/cosmicpython/book/blob/master/chapter_06_uow.asciidoc): `chapter_06_uow.asciidoc`
- [Aggregates](https://github.com/cosmicpython/book/blob/master/chapter_07_aggregate.asciidoc): `chapter_07_aggregate.asciidoc`

### Messaging patterns

- [Domain events](https://github.com/cosmicpython/book/blob/master/chapter_08_events_and_message_bus.asciidoc): `chapter_08_events_and_message_bus.asciidoc`
- [Message bus](https://github.com/cosmicpython/book/blob/master/chapter_09_all_messagebus.asciidoc): `chapter_09_all_messagebus.asciidoc`
- [Commands](https://github.com/cosmicpython/book/blob/master/chapter_10_commands.asciidoc): `chapter_10_commands.asciidoc`
- [External events](https://github.com/cosmicpython/book/blob/master/chapter_11_external_events.asciidoc): `chapter_11_external_events.asciidoc`
- [CQRS](https://github.com/cosmicpython/book/blob/master/chapter_12_cqrs.asciidoc): `chapter_12_cqrs.asciidoc`
- [Dependency injection](https://github.com/cosmicpython/book/blob/master/chapter_13_dependency_injection.asciidoc): `chapter_13_dependency_injection.asciidoc`

### Practical appendices

- [Project structure](https://github.com/cosmicpython/book/blob/master/appendix_project_structure.asciidoc): `appendix_project_structure.asciidoc`
- [CSV migration](https://github.com/cosmicpython/book/blob/master/appendix_csvs.asciidoc): `appendix_csvs.asciidoc`
- [Django integration](https://github.com/cosmicpython/book/blob/master/appendix_django.asciidoc): `appendix_django.asciidoc`
- [Validation](https://github.com/cosmicpython/book/blob/master/appendix_validation.asciidoc): `appendix_validation.asciidoc`

### Other components

- **Reader**

## Connections

- Reader → Domain model: starts with (evidence: `Readme.md`)
- Domain model → Repository: continues to (evidence: `Readme.md`)
- Repository → Abstractions: continues to (evidence: `Readme.md`)
- Abstractions → Service layer: continues to (evidence: `Readme.md`)
- Service layer → Testing gears: continues to (evidence: `Readme.md`)
- Testing gears → Unit of work: continues to (evidence: `Readme.md`)
- Unit of work → Aggregates: continues to (evidence: `Readme.md`)
- Aggregates → Domain events: continues to (evidence: `Readme.md`)
- Domain events → Message bus: continues to (evidence: `Readme.md`)
- Message bus → Commands: continues to (evidence: `Readme.md`)
- Commands → External events: continues to (evidence: `Readme.md`)
- External events → CQRS: continues to (evidence: `Readme.md`)
- CQRS → Dependency injection: continues to (evidence: `Readme.md`)
- Reader → Project structure: also covers (evidence: `Readme.md`)
- Reader → CSV migration: also covers (evidence: `Readme.md`)
- Reader → Django integration: also covers (evidence: `Readme.md`)
- Reader → Validation: also covers (evidence: `Readme.md`)
