Ecommerce example
The examples/ecommerce directory shows a full composition: DomainModule, EventBus, Outbox, Discovery and RPC.
Minimal run (orders only)
run_minimal.py — Application + orders DomainModule + OpenAPI:
from urich import Application
from orders.module import orders_module
app = Application()
app.register(orders_module)
app.openapi(title="Ecommerce API", version="0.1.0")
Run: uvicorn run_minimal:app --reload, then open /docs.
Full composition (main.py)
main.py composes:
- Orders DomainModule — Commands/queries and domain events for orders.
- EventBusModule — Custom adapter (e.g. Redis) for publishing domain events.
- OutboxModule — Storage and publisher (e.g. Postgres + Kafka) for transactional outbox.
- DiscoveryModule — Static map of service names to URLs.
- RpcModule — Server at
/rpcand client with custom transport.
Order of registration: discovery and event bus first, then domain modules, then RPC (client may need ServiceDiscovery from the container).
Orders context structure
| File | Purpose |
|---|---|
| domain.py | Order (AggregateRoot), OrderCreated (DomainEvent). |
| application.py | CreateOrder, GetOrder (Command/Query), handlers with repo + EventBus injection. |
| infrastructure.py | IOrderRepository, in-memory OrderRepositoryImpl. |
| module.py | DomainModule("orders").aggregate(...).repository(...).command(...).query(...).on_event(...). |
This is the same structure the CLI generates with add-context and add-aggregate.