How jaimeirazabal1/event-sourcing-app works
Main Components
• • API/Server Layer: The entry point for requests (src/server.ts) which sets up an Express API.
• • Command Component: Located in src/commands (e.g., task.commands.ts) – responsible for handling write operations (commands) such as creating or updating tasks.
• • Query Component: Found in src/queries (e.g., task.queries.ts) – used exclusively for read operations to retrieve data.
• • Event Store: In src/events (with event.store.ts) – the core element that captures and saves events, including metadata like type and payload.
• • Event Emitter: Located in src/infrastructure (event.emitter.ts) – which notifies other components of new events.
• • Projector Component: In src/projectors (e.g., task.projector.ts) – listens for events (like TASK_CREATED) and updates the read models (e.g., tasks table) accordingly.
• • Infrastructure Layer: In src/infrastructure (database.ts, event.emitter.ts) – handles dependencies such as database connections and event emission mechanisms.
• • Configuration/Deployment Components: Dockerfile, docker-compose.yml, .env which are used for containerization and deployment.
Relationships and Interactions
• Commands (write operations) trigger the Event Store to persist an event (e.g., TASK_CREATED) and then immediately use an Event Emitter to notify subscribers.
• The Projector subscribes to specific events and updates the database (read models) accordingly.
• Queries then pull data from the updated database, ensuring a clear separation from the write model.
• The server (API layer) routes incoming HTTP requests to the proper command or query handlers.
• All components communicate in an event-driven manner that underpins the CQRS model.
Architectural Patterns and Design Principles
• Event Sourcing: Indicate that every change is captured as an immutable event stored in a dedicated Event Store.
• Separation of Concerns: Attest to how command handling, query retrieval, event storage, and projecting changes are organized into distinct modules.
Relevant Technologies and Tools
• Node.js/Express (for the API/server in src/server.ts).
• TypeScript (as indicated by .ts files and tsconfig.json).
• Database integration (abstracted through src/infrastructure/database.ts, possibly using an ORM).
• Event Emitter pattern (src/infrastructure/event.emitter.ts) that notifies projectors of changes.
• Containerization (Dockerfile and docker-compose.yml) to manage deployments.