marcosvs98 / cqrs-architecture-with-python

Applying CQRS pattern with Python Fastapi.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

cqrs-architecture-with-python

Applying pattern Ports and Adapters + CQRS with Python Fastapi.

Bounded Contexts

Domain: Ordering
Concepts: Domain Driven Design (Subdomains, Bounded Contexts, Ubiquitous Language, Aggregates, Value Objects)
Architecture style: Event Driven Microservices
Architectural patterns: Event Sourcing, Hexagonal Architecture and CQRS
Technology: Python with (FastAPI), MongoDB and Redis

Domain

Customers use the website application(s) to place orders. Application coordinates order preparation and delivery.

Sub-domains

  • Order: This domain is responsible for managing and processing orders placed by customers, including product selection, pricing, and payment completion.
  • Product: This domain is responsible for managing and providing information about the products available for sale, including descriptions, prices and images.
  • Delivery: This domain is responsible for managing and tracking deliveries, including scheduling deliveries, tracking carrier location, and processing returns.
  • Maps: This domain is responsible for providing geographic information including delivery routes, delivery locations and estimated travel time.
  • Payment: This domain is responsible for processing payments, including credit card authorizations, balance checks and payment confirmations

Domain model

Sub-domain software programing models:

Domain model is mainly a software programing model which is applied to a specific sub-domain. It defines the vocabulary and acts as a communication tool for everyone involved (business and IT), deriving a Ubiquitous Language.

Bounded Context

Each of this group of applications/services belongs to a specific bounded context:

  • ordering - Order bounded context, with messages serialized to JSON

A goal is to develop a Ubiquitous Language as our domain (sub-domain) model within an explicitly Bounded Context. Therefore, there are a number of rules for Models and Contexts

  • Explicitly define the context within which a model applies
  • Ideally, keep one sub-domain model per one Bounded Context
  • Explicitly set boundaries in terms of team organization, usage within specific parts of the application, and physical manifestations such as code bases and database schemas

Technologies and patterns used

  • Python 3.10
  • FastAPI (Rest API)
  • MongoDB
  • Pydantic 2.5
  • Redis
  • CQRS
  • Ports & Adapters
  • Event Sourcing

In addition to others, the main pattern that guides this project is the Ports & Adapter + CQRS. In summary, this pattern provides a way to organize code so that business logic is encapsulated, but separated from the underlying delivery mechanism. This allows for better maintenance and fewer dependencies.

With CQRS, we have a clear separation of concerns, making the codebase easier to understand and maintain.Developers can more easily reason about how changes to the codebase will affect the overall system. Additionally, its use allows each model to evolve independently since they are not strongly coupled. This means changes to one model can be made without affecting the other model.


Running the project

Option 1 - Via Docker Compose

Run docker-compose

Finally, run the project and its dependencies in the background using the command

docker-compose up -d

References

About

Applying CQRS pattern with Python Fastapi.

License:GNU General Public License v3.0


Languages

Language:Python 96.4%Language:Dockerfile 2.1%Language:Shell 1.3%Language:Makefile 0.3%