How marcosvs98/cqrs-architecture-with-python works
Project type and purpose
• This is a backend service built in Python 3.10 on FastAPI, implementing Hexagonal Architecture (Ports & Adapters), CQRS, and Event Sourcing in an event-driven microservices style.
• Its primary bounded context is “Ordering,” with sub-domains for Order, Product, Delivery, Maps, and Payment. The service exposes a REST API to place orders, orchestrates domain logic, stores and publishes events, and interacts with external systems (MongoDB, Redis, Kafka, Google Maps API, PayPal).
File structure
• Top-level: configuration files (Dockerfile, docker-compose.yaml, Makefile, pyproject.toml, mypy.ini), scripts for installation and pre-commit, start-up scripts.
• src/app.py and src/bootstrap.py: entry points that wire adapters to ports and launch the FastAPI server.
• src/adapters: concrete implementations of outbound ports (Redis cache, MongoDB, Kafka publisher, Google Maps, PayPal, cost-calculator).
• src/domain: hexagonal core organized by sub-domains (order, product, delivery, maps, payment). Each sub-domain has:
• ports (interfaces for inbound/outbound)
• adapters directory (if any)
• models, entities, value objects, events, exceptions, DTOs
• services (e.g. order_command, order_query, order_mediator)
• repositories and controllers under order.
• src/ports: generic interfaces shared across domains (e.g., cache_interface).
• Infrastructure births in adapters and docker-compose: MongoDB, Redis, Kafka, external APIs.
Extract architectural insights from the README
• Pattern: Ports & Adapters (Hexagonal) + CQRS + Event Sourcing
• Bounded Context: Ordering, with domain model defining Ubiquitous Language
• Tech Stack: FastAPI (REST), MongoDB (event store and query store), Redis (cache), Kafka (event bus), external services (Google Maps, PayPal).
Final advice
• Be exhaustive but clear: show each sub-domain’s ports and adapters if space allows.
• Essential flows: HTTP → Domain → Persistence → Messaging → External APIs → Cache.
• Iterate: start with high-level blocks (API, Domain, Infra), then drill into details of CQRS and adapters.