How stemmlerjs/white-label works
Project Type & Purpose
• This is a Node.js + TypeScript enterprise application built using Domain-Driven Design (DDD). Its purpose is to enable vinyl trading, and its architecture follows the modular and layered patterns DDD encourages.
• The README makes it clear that the design is taken from a DDD course, so the emphasis is on domain encapsulation (entities, value objects, aggregates, events), clean separation of concerns, and modular boundaries.
Recognize the Main Components from the File Structure
• Presentation / API Layer: Look at src/infra/http – files like app.ts and the API route definitions (e.g., src/infra/http/api/v1.ts, users routes in src/modules/users/infra/http/routes).
• Core Domain Layer: Under src/core you have the basic building blocks of the domain (Domain, AggregateRoot, ValueObject, Entity, events, use cases). This layer is language-agnostic and encapsulates key domain logic.
• Infrastructure & ORM: The src/infra/sequelize folder (with models, migrations, hooks, and the Sequelize runner) represents the integration with the relational database.
• Application Utilities & Shared Code: The shared directory and utility files (in src/shared and src/utils) support common functionalities across the application.
Relationships and Interactions
• HTTP Request Flow: Start with the external API clients that interact with the HTTP API layer, which processes requests through controllers (located in the various “useCases” subdirectories and BaseController.ts in src/core/infra).
• Application Service Flow: From the controllers, the requests invoke specific use case services defined in each module (for example, CreateUserUseCase in users module, various vinyl catalog use cases, trading offer use cases).
• Domain Layer: The use cases then work with domain entities/aggregates (see the files in src/core/domain and in each module’s domain folders). Domain events are emitted here (with event handlers/subscribers found in each module’s subscribers or events directories).
• Infrastructure Integration: Notify external systems (e.g., Slack notifications in the notification module) and persist data via repositories. The repositories (in src/modules/*/repos and src/core/infra/Repo.ts) interact with the Sequelize ORM for database operations.
Important Architectural Patterns & Principles
• Domain-Driven Design: Emphasize that the structure is based on domain models, aggregates, domain events, and use cases. Each module represents a distinct bounded context.
• Clean Separation of Concerns: Notice how controllers, domain entities, use cases, and repositories have distinct folders.
• Event Handling: Domain events drive some of the interactions (e.g., AfterUserCreated, AfterVinylCreatedEvent subscribers).
• Infrastructure Abstraction: Use of a “Repo” abstraction enables persistence strategies (here implemented with Sequelize) without polluting domain logic.
Elements
• Begin at the top with “External Clients” or “API Consumers” that send requests.
• “Domain Layer” with core domain constructs (entities, aggregates, value objects) along with domain events. Group the common core (src/core/domain) and each module’s domain logic.
• Event subscribers that respond to domain events and trigger further actions.