# stemmlerjs/white-label architecture

> Architecture diagram of the GitHub repository stemmlerjs/white-label, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/stemmlerjs/white-label
- Repository: https://github.com/stemmlerjs/white-label

## Overview

##### 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.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Layer
    EC("External Clients"):::http

    %% HTTP API Layer
    subgraph "HTTP API Layer"
        API_App("Express App (app.ts)"):::http
        API_v1("API v1 (api/v1.ts)"):::http
        Users_API_Routes("Users API Routes"):::http
    end

    %% Users Module
    subgraph "Users Module"
        U1("Users UseCases & Controllers"):::module
        U2("Users Domain Logic"):::module
        U3("Users Subscribers"):::module
        U4("Users Repositories"):::module
        U5("Users Mappers"):::module
        U1 --> U2
        U1 --> U4
        U1 --> U5
        U2 --> U3
    end

    %% Vinyl Module
    subgraph "Vinyl Module"
        V1("Vinyl UseCases"):::module
        V2("Vinyl Domain Logic"):::module
        V3("Vinyl Subscribers"):::module
        V4("Vinyl Repositories"):::module
        V5("Vinyl Mappers"):::module
        V1 --> V2
        V1 --> V4
        V1 --> V5
        V2 --> V3
    end

    %% Trading Module
    subgraph "Trading Module"
        T1("Trading UseCases"):::module
        T2("Trading Domain Logic"):::module
        T1 --> T2
    end

    %% Notification Module
    subgraph "Notification Module"
        N1("Notification UseCases"):::module
        N2("Notification Domain Logic"):::module
        N3("Notification Subscribers"):::module
        N4("Notification Services"):::module
        N1 --> N2
        N1 --> N3
        N1 --> N4
    end

    %% Billing Module
    subgraph "Billing Module"
        B1("Billing Module Entry"):::module
    end

    %% Core Domain Layer
    subgraph "Core Domain"
        C1("Domain Fundamentals"):::domain
        C2("Domain Events"):::domain
        C1 --> C2
    end

    %% Infrastructure & ORM
    subgraph "Infrastructure & ORM"
        I1("Database Integration (Sequelize)"):::infra
        I2("Sequelize Models"):::infra
        I1 --> I2
    end

    %% Application Utilities & Shared Code
    subgraph "Application Utilities"
        S("Shared Functionality"):::utils
        U("Utility Scripts"):::utils
        S --> U
    end

    %% Connections from External to HTTP API Layer
    EC --> API_App
    API_App --> U1
    API_App --> V1
    API_App --> T1
    API_App --> N1
    API_App --> B1
    API_v1 --> U1
    API_v1 --> V1
    API_v1 --> T1
    API_v1 --> N1
    API_v1 --> B1
    Users_API_Routes --> U1

    %% Connections from Module Domain Logic to Core Domain
    U2 --> C1
    V2 --> C1
    T2 --> C1
    N2 --> C1

    %% Connections from Module Repositories to Infrastructure
    U4 --> I1
    V4 --> I1

    %% Styles
    classDef http fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef domain fill:#90EE90,stroke:#000,stroke-width:1px;
    classDef module fill:#FFDAB9,stroke:#000,stroke-width:1px;
    classDef infra fill:#F08080,stroke:#000,stroke-width:1px;
    classDef utils fill:#D3D3D3,stroke:#000,stroke-width:1px;

    %% Click Events
    click API_App "https://github.com/stemmlerjs/white-label/blob/master/src/infra/http/app.ts"
    click API_v1 "https://github.com/stemmlerjs/white-label/blob/master/src/infra/http/api/v1.ts"
    click Users_API_Routes "https://github.com/stemmlerjs/white-label/blob/master/src/modules/users/infra/http/routes/index.ts"

    click C1 "https://github.com/stemmlerjs/white-label/tree/master/src/core/domain"
    click C2 "https://github.com/stemmlerjs/white-label/tree/master/src/core/domain/events"

    click U2 "https://github.com/stemmlerjs/white-label/tree/master/src/modules/users/domain"
    click U1 "https://github.com/stemmlerjs/white-label/tree/master/src/modules/users/useCases"
    click U3 "https://github.com/stemmlerjs/white-label/tree/master/src/modules/users/subscribers"
    click U4 "https://github.com/stemmlerjs/white-label/tree/master/src/modules/users/repos"
    click U5 "https://github.com/stemmlerjs/white-label/tree/master/src/modules/users/mappers"

    click V2 "https://github.com/stemmlerjs/white-label/tree/master/src/modules/vinyl/domain"
    click V1 "https://github.com/stemmlerjs/white-label/tree/master/src/modules/vinyl/useCases/catalog"
    click V3 "https://github.com/stemmlerjs/white-label/tree/master/src/modules/vinyl/subscribers"
    click V4 "https://github.com/stemmlerjs/white-label/tree/master/src/modules/vinyl/repos"
    click V5 "https://github.com/stemmlerjs/white-label/tree/master/src/modules/vinyl/mappers"

    click T2 "https://github.com/stemmlerjs/white-label/tree/master/src/modules/trading/domain"
    click T1 "https://github.com/stemmlerjs/white-label/tree/master/src/modules/trading/useCases"

    click N2 "https://github.com/stemmlerjs/white-label/tree/master/src/modules/notification/domain"
    click N1 "https://github.com/stemmlerjs/white-label/tree/master/src/modules/notification/useCases"
    click N3 "https://github.com/stemmlerjs/white-label/tree/master/src/modules/notification/subscribers"
    click N4 "https://github.com/stemmlerjs/white-label/tree/master/src/modules/notification/services"

    click B1 "https://github.com/stemmlerjs/white-label/tree/master/src/modules/billing"

    click I1 "https://github.com/stemmlerjs/white-label/tree/master/src/infra/sequelize"
    click I2 "https://github.com/stemmlerjs/white-label/tree/master/src/infra/sequelize/models"

    click S "https://github.com/stemmlerjs/white-label/tree/master/src/shared"
    click U "https://github.com/stemmlerjs/white-label/tree/master/src/utils"
```
