# stemmlerjs/ddd-forum architecture

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

- Interactive diagram: https://gitdiagram.com/stemmlerjs/ddd-forum
- Repository: https://github.com/stemmlerjs/ddd-forum

## Overview

##### Main Components
- Frontend Client: Represented by the “public/app” folder. This React.js application uses Redux for state management and Sass for styling. It interacts with the backend via API calls and may include routing (with components like AuthenticatedRoute/UnauthenticatedRoute).
- Backend Server: The backend code lives predominantly under “src” as well as additional modules under “public” (if any are meant to support server side rendering or API endpoints). This portion is subdivided by subdomains:
- Forum Subdomain: Contains the “forum” module with its own domain (models like Post, Comment, Member, Votes), use cases (createPost, upvotePost, replyToComment, etc.), repositories (both interface definitions and Sequelize implementations), DTOs, mappers, and subscriptions.
- Users Subdomain: Covers all user-related functionality (authentication, user creation, login, logout, token refreshing). It has similar layers: domain objects (User, EmailVerificationToken, events), use cases (createUser, login, logout, refreshAccessToken), and adapter/infrastructure components (including Redis based token management).
- Shared/Infrastructure Components: Under directories like “src/shared” (including core utilities, HTTP setup, database configuration, and Redux store configuration), plus Docker configurations (Dockerfile and docker-compose.yml) that orchestrate container-based deployment.

##### Relationships and Interactions
- The Frontend communicates with the Backend through REST APIs (and possibly GraphQL endpoints defined under “src/shared/infra/http/graphql”).
- The backend follows Clean Architecture: the outer layers (infrastructure and adapter) call into the inner application (use cases) and domain layers, while the domain remains ignorant of the implementation details.
- Within each subdomain, use cases coordinate domain logic using domain objects; they depend on abstract repository interfaces (or “ports”), with concrete implementations provided by the infrastructure (e.g., SequelizeRepo implementations).
- Shared utilities and configurations (from “src/shared”) provide cross-cutting concerns like error handling, middleware, and database configuration.
- Communication flows (e.g., user actions from the frontend trigger API calls to backend controllers that invoke respective use cases).

##### Architectural Patterns and Design Principles
- Clean Architecture: Separate layers where the domain (business logic) does not depend directly on the infrastructure. Show how application use cases in the “forum” and “users” subdomains are isolated from the specifics of Express, Sequelize, or Redis.
- Domain-Driven Design: Emphasize two main subdomains (“forum” and “users”), each with its own domain objects, events, and business rules.
- Repository Pattern: Illustrate interfaces like IUserRepo, ICommentRepo, and their concrete implementations in the infrastructure layer.
- SOLID Principles: Point out how single-responsibility is enforced in controllers, domain models, mappers, and utility classes.

##### Relevant Technologies and Frameworks
- Frontend: React, Redux, Sass.
- Backend: Express.js, Sequelize for ORM, Docker (using Dockerfile and docker-compose.yml), Redis for token management.
- Development/Testing Tools: Jest (as seen in jest.config.js), nodemon for development, CircleCI for CI/CD workflows.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Section
    subgraph "Client"
        FE("React Frontend\n(Redux, Sass, Routing)"):::frontend
    end

    %% Backend Server Section
    subgraph "Backend Server"
        %% Presentation Layer
        subgraph "Presentation Layer"
            FController("Forum HTTP Controllers/Routes"):::presentation
            UController("Users HTTP Controllers/Routes"):::presentation
        end

        %% Application Layer
        subgraph "Application Layer"
            FUseCases("Forum Use Cases"):::application
            UUseCases("Users Use Cases"):::application
        end

        %% Domain Layer
        subgraph "Domain Layer"
            FDomain("Forum Domain Models & Events"):::domain
            UDomain("Users Domain Models & Events"):::domain
        end

        %% Infrastructure/Adapters Layer
        subgraph "Infrastructure/Adapters"
            %% Forum Subdomain Infrastructure
            FRepoInt("Forum Repo Interfaces"):::infra
            FRepoImpl("Forum Repo Implementations"):::infra
            FDTO("Forum DTOs"):::infra
            FMappers("Forum Mappers"):::infra
            FSub("Forum Subscriptions"):::infra

            %% Users Subdomain Infrastructure
            URepoInt("Users Repo Interfaces"):::infra
            URepoImpl("Users Repo Implementations"):::infra
            UServices("Users Services"):::infra
            URedis("Users Redis Integration"):::infra

            %% Shared Infrastructure
            Shared("Shared Infrastructure"):::shared
        end
    end

    %% External Services Section
    subgraph "External Services"
        DB("SQL Database (Sequelize)"):::external
        Redis("Redis Cache"):::external
    end

    %% Docker & Deployment Section
    subgraph "Docker & Deployment"
        Dockerfile("Dockerfile"):::deploy
        DockerCompose("docker-compose.yml"):::deploy
    end

    %% Connections for Client -> Backend
    FE -->|"API_Calls"| FController
    FE -->|"API_Calls"| UController

    %% Connections within Forum Subdomain
    FController -->|"Invokes"| FUseCases
    FUseCases -->|"Executes"| FDomain
    FUseCases -->|"Calls"| FRepoInt
    FUseCases -->|"Maps"| FDTO
    FController -->|"Triggers"| FSub

    %% Connections within Users Subdomain
    UController -->|"Invokes"| UUseCases
    UUseCases -->|"Executes"| UDomain
    UUseCases -->|"Calls"| URepoInt
    UUseCases -->|"Utilizes"| UServices

    %% Infrastructure Relationships
    FRepoInt ---|"Impl"| FRepoImpl
    URepoInt ---|"Impl"| URepoImpl
    UServices ---|"Uses"| URedis

    %% Shared Infrastructure Connections
    FRepoInt -->|"Uses"| Shared
    FRepoImpl -->|"Uses"| Shared
    URepoInt -->|"Uses"| Shared

    %% External Services Connections
    Shared -->|"Configures"| DB
    UServices -->|"Manages"| Redis

    %% Cross-Domain Interaction (if any)
    FUseCases ---|"Interacts"| UUseCases

    %% Docker Deployment Connections
    Dockerfile -->|"Deploys_to"| FE
    DockerCompose -->|"Deploys"| Shared

    %% Click Events for Component Mappings
    click FE "https://github.com/stemmlerjs/ddd-forum/tree/master/public/app"
    click FController "https://github.com/stemmlerjs/ddd-forum/tree/master/src/modules/forum/infra/http/routes"
    click UController "https://github.com/stemmlerjs/ddd-forum/tree/master/src/modules/users/infra/http/routes"
    click FUseCases "https://github.com/stemmlerjs/ddd-forum/tree/master/src/modules/forum/useCases"
    click UUseCases "https://github.com/stemmlerjs/ddd-forum/tree/master/src/modules/users/useCases"
    click FDomain "https://github.com/stemmlerjs/ddd-forum/tree/master/src/modules/forum/domain"
    click UDomain "https://github.com/stemmlerjs/ddd-forum/tree/master/src/modules/users/domain"
    click FRepoInt "https://github.com/stemmlerjs/ddd-forum/tree/master/src/modules/forum/repos"
    click FRepoImpl "https://github.com/stemmlerjs/ddd-forum/tree/master/src/modules/forum/repos/implementations"
    click FDTO "https://github.com/stemmlerjs/ddd-forum/tree/master/src/modules/forum/dtos"
    click FMappers "https://github.com/stemmlerjs/ddd-forum/tree/master/src/modules/forum/mappers"
    click FSub "https://github.com/stemmlerjs/ddd-forum/tree/master/src/modules/forum/subscriptions"
    click URepoInt "https://github.com/stemmlerjs/ddd-forum/tree/master/src/modules/users/repos"
    click URepoImpl "https://github.com/stemmlerjs/ddd-forum/tree/master/src/modules/users/repos/implementations"
    click UServices "https://github.com/stemmlerjs/ddd-forum/tree/master/src/modules/users/services"
    click URedis "https://github.com/stemmlerjs/ddd-forum/tree/master/src/modules/users/services/redis"
    click Shared "https://github.com/stemmlerjs/ddd-forum/tree/master/src/shared"
    click Dockerfile "https://github.com/stemmlerjs/ddd-forum/tree/master/Dockerfile"
    click DockerCompose "https://github.com/stemmlerjs/ddd-forum/blob/master/docker-compose.yml"

    %% Styles
    classDef frontend fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
    classDef presentation fill:#FAD7A0,stroke:#D35400,stroke-width:2px;
    classDef application fill:#A9DFBF,stroke:#28B463,stroke-width:2px;
    classDef domain fill:#F5B7B1,stroke:#C0392B,stroke-width:2px;
    classDef infra fill:#D2B4DE,stroke:#8E44AD,stroke-width:2px;
    classDef shared fill:#F9E79F,stroke:#F1C40F,stroke-width:2px;
    classDef external fill:#FADBD8,stroke:#E74C3C,stroke-width:2px;
    classDef deploy fill:#D5F5E3,stroke:#27AE60,stroke-width:2px;
```
