How devswork-hub/storex-api-nestjs-orders works
Project type and purpose
• This is a NestJS-based backend “microservice” (monolith with microservice patterns) implementing a single Bounded Context (“Order”) with a GraphQL API.
• It follows Domain-Driven Design (DDD), Clean Architecture, CQRS, Event-Driven and Outbox patterns to handle commands, publish events, manage read models, and integrate with external systems (Kafka, RabbitMQ, mail, payments).
a. API Layer
• GraphQL Server (NestJS GraphQL module)
• Interceptors (logging, timeout) and custom error handlers
b. Application Layer
• CQRS Command Handlers and Query Handlers
• Domain Sagas/Choreography
• Event Handlers (to react to domain events)
c. Domain Layer (core)
• Aggregates, Entities, Value Objects, Domain Events
• Shared Domain Library (@storex-domain and src/shared/domain)
d. Persistence Layer – Command Side
• PostgreSQL (with Outbox table for local transactional outbox)
• TypeORM or Sequelize modules, transaction interceptor, UoW service
e. Persistence Layer – Query Side
• MongoDB (read models, projections)
• Redis (read-through cache and hot-data caching)
• Outbox-relay service or cron job that reads from Outbox table and writes to MongoDB or publishes to brokers
f. Messaging Layer
• Internal Domain Event Bus (in-memory or NestJS pub/sub adapter)
• External brokers:
– RabbitMQ module (publisher, consumer, DLQ, retry strategies)
– Kafka module (CDC events, thombstone interceptor)
g. Integrations
• Mail integration (queue, sender, processor)
• Payments integration service
h. Infrastructure & DevOps
• Docker & docker-compose files (per component: PG, Mongo, Redis, Kafka, RabbitMQ, ELK, Keycloak)
• Kubernetes manifests (.k8s folder)
• CI/CD workflows (GitHub Actions)
• Monitoring stack: ELK (Filebeat, Logstash, Elasticsearch, Kibana)
Relationships and data-flows
1. Client → GraphQL API
2. API → Command Handlers → Domain Model → Transaction committed in Postgres + Outbox insert
3. Outbox Relay (cron or CDC) reads Outbox → publishes Domain Events to RabbitMQ/Kafka
4. Event Consumers (in same service or external) handle events → update MongoDB read models → populate Redis cache
5. Client queries GraphQL → Query Handlers read from Redis/MongoDB
6. For long-running processes or sagas, commands emit events → other modules react (choreography)
Highlighted architectural patterns
• CQRS: separate Command Handlers vs. Query Handlers
• Outbox: transactional outbox in Postgres, relay to brokers
• Event-Driven / Choreography: domain events propagate changes
• DDD: modules per Bounded Context, vertical slice design
• Caching: Redis as read-through cache for high-frequency queries
• Shared libraries: core domain/common code extracted under lib/@storex-domain and src/shared
Essential details to capture
• Boundaries between Command/Query sides
• Location of Outbox table and relay mechanisms
• All messaging paths (internal event bus → external brokers → internal consumers)
• Integration points to mail and payment services
• Use of shared libraries for domain abstractions
• Deployment artifacts (Docker containers, Kubernetes namespaces)