# m10maeda/itddd architecture

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

- Interactive diagram: https://gitdiagram.com/m10maeda/itddd
- Repository: https://github.com/m10maeda/itddd

## Overview

##### Main components
a. Frontend: apps/web (Next.js)
b. Backend services (NestJS):
- Circles service (apps/circles)
- Profiles service (apps/profiles)
c. Shared packages (code generators, ESLint/TS configs)
d. CI/CD & orchestration: .circleci config, docker-compose

##### Relationships & data flows
- User ↔ Web UI (HTTP in browser)
- Web UI → Data‐access layer → API clients (generated by circles-api / profiles-api)
- API clients → REST endpoints on Circles service and Profiles service
- Each service → Domain layer → Application layer (Use Cases) → Infrastructure layer (in‐memory persistence, event‐bus, messenger)
- Domain events published internally → event‐bus → subscribers or external messenger
- Docker Compose wires together web (port 3000), circles (e.g. 3001), profiles (e.g. 3002)

##### Architectural patterns
- DDD layering in each NestJS service:
– Presentation (Controllers, DTOs)
– Application (Interactors / Use Cases)
– Domain (Entities, Value Objects, Policies, Repositories)
– Infrastructure (in‐memory stores, event‐bus, messenger modules)
- Monorepo with Turborepo + PNPM workspaces
- Code‐generation packages to produce type‐safe API clients
- In‐memory event sourcing for demos

##### Essential details checklist
[ ] Layer labels (Presentation, Application, Domain, Infrastructure)
[ ] CI/CD process at top/bottom to show build/test pipeline

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% CI/CD Pipeline
    CI["CI/CD (.circleci/config.yml)"]:::ci
    CI -->|"build & test"| Web
    CI -->|"build & test"| Circles
    CI -->|"build & test"| Profiles

    %% Web Frontend
    subgraph "Web Frontend (Next.js)" 
        direction TB
        Web["apps/web<br/>port 3000"]:::frontend
        UI["User Browser UI"]:::frontend
        subgraph "Data Access"
            direction TB
            CirclesClient["Circles API Client"]:::frontend
            ProfilesClient["Profiles API Client"]:::frontend
        end
    end

    %% Circles Service
    subgraph "Circles Service (NestJS)" 
        direction TB
        Circles["apps/circles<br/>port 3001"]:::circles
        subgraph "Presentation Layer"
            direction TB
            CircleController["Circle Controller<br/>DTOs, Filters"]:::circles
            HealthController["Health Controller"]:::circles
        end
        subgraph "Application Layer"
            direction TB
            CirclesUseCase["Use Case Interactors"]:::circles
        end
        subgraph "Domain Layer"
            direction TB
            CircleEntity["Entities & Value Objects"]:::circles
            CircleEvents["Domain Events"]:::circles
        end
        subgraph "Infrastructure Layer"
            direction TB
            CirclesStore["In-Memory Persistence"]:::circles
            CirclesEventBus["Event Bus"]:::circles
            CirclesQuery["Query Service"]:::circles
        end
    end

    %% Profiles Service
    subgraph "Profiles Service (NestJS)" 
        direction TB
        Profiles["apps/profiles<br/>port 3002"]:::profiles
        subgraph "Presentation Layer"
            direction TB
            ProfileController["Profile Controller<br/>DTOs, Filters"]:::profiles
            ProfilesHealth["Health Controller"]:::profiles
        end
        subgraph "Application Layer"
            direction TB
            ProfilesUseCase["Application Services"]:::profiles
        end
        subgraph "Domain Layer"
            direction TB
            ProfileEntity["Entities & Value Objects"]:::profiles
            ProfileEvents["Domain Events"]:::profiles
        end
        subgraph "Infrastructure Layer"
            direction TB
            ProfilesStore["In-Memory Persistence"]:::profiles
            ProfilesEventBus["Event Bus"]:::profiles
            Messenger["External Messenger"]:::profiles
        end
    end

    %% Shared Packages
    subgraph "Developer Tools (Shared Packages)"
        direction TB
        CirclesAPI["packages/circles-api"]:::shared
        ProfilesAPI["packages/profiles-api"]:::shared
        ESLintConfig["packages/eslint-config"]:::shared
        TSConfig["packages/typescript-config"]:::shared
    end

    %% Docker Compose Orchestration
    DockerCompose["Docker Compose<br/>(docker-compose.yaml)"]:::orchestration
    DockerCompose -->|wires| Web
    DockerCompose -->|wires| Circles
    DockerCompose -->|wires| Profiles

    %% Data Flows
    UI -->|"calls"| CirclesClient
    UI -->|"calls"| ProfilesClient
    CirclesClient -->|"HTTP"| CircleController
    ProfilesClient -->|"HTTP"| ProfileController

    %% Circles Internal Flow
    CircleController -->|invoke| CirclesUseCase
    CirclesUseCase -->|operate on| CircleEntity
    CircleEntity -->|persist| CirclesStore
    CirclesUseCase -->|publish| CirclesEventBus
    CirclesEventBus -->|subscribe| CirclesQuery

    %% Profiles Internal Flow
    ProfileController -->|invoke| ProfilesUseCase
    ProfilesUseCase -->|operate on| ProfileEntity
    ProfileEntity -->|persist| ProfilesStore
    ProfilesUseCase -->|publish| ProfilesEventBus
    ProfilesEventBus -->|deliver| Messenger

    %% Click Events
    click Web "https://github.com/m10maeda/itddd/tree/main/apps/web"
    click UI "https://github.com/m10maeda/itddd/tree/main/apps/web/src/app"
    click CirclesClient "https://github.com/m10maeda/itddd/tree/main/apps/web/src/data-access"
    click ProfilesClient "https://github.com/m10maeda/itddd/tree/main/apps/web/src/data-access"
    click Web "https://github.com/m10maeda/itddd/tree/main/apps/web/Dockerfile"

    click Circles "https://github.com/m10maeda/itddd/tree/main/apps/circles"
    click CircleController "https://github.com/m10maeda/itddd/tree/main/apps/circles/src/presentation"
    click HealthController "https://github.com/m10maeda/itddd/tree/main/apps/circles/src/presentation"
    click CirclesUseCase "https://github.com/m10maeda/itddd/tree/main/apps/circles/src/application"
    click CircleEntity "https://github.com/m10maeda/itddd/tree/main/apps/circles/src/domain"
    click CircleEvents "https://github.com/m10maeda/itddd/tree/main/apps/circles/src/domain"
    click CirclesStore "https://github.com/m10maeda/itddd/tree/main/apps/circles/src/infrastructure"
    click CirclesEventBus "https://github.com/m10maeda/itddd/tree/main/apps/circles/src/infrastructure"
    click CirclesQuery "https://github.com/m10maeda/itddd/tree/main/apps/circles/src/infrastructure"
    click Circles "https://github.com/m10maeda/itddd/tree/main/apps/circles/Dockerfile"

    click Profiles "https://github.com/m10maeda/itddd/tree/main/apps/profiles"
    click ProfileController "https://github.com/m10maeda/itddd/tree/main/apps/profiles/src/presentation"
    click ProfilesHealth "https://github.com/m10maeda/itddd/tree/main/apps/profiles/src/presentation"
    click ProfilesUseCase "https://github.com/m10maeda/itddd/tree/main/apps/profiles/src/application"
    click ProfileEntity "https://github.com/m10maeda/itddd/tree/main/apps/profiles/src/domain"
    click ProfileEvents "https://github.com/m10maeda/itddd/tree/main/apps/profiles/src/domain"
    click ProfilesStore "https://github.com/m10maeda/itddd/tree/main/apps/profiles/src/infrastructure"
    click ProfilesEventBus "https://github.com/m10maeda/itddd/tree/main/apps/profiles/src/infrastructure"
    click Messenger "https://github.com/m10maeda/itddd/tree/main/apps/profiles/src/infrastructure"
    click Profiles "https://github.com/m10maeda/itddd/tree/main/apps/profiles/Dockerfile"

    click CirclesAPI "https://github.com/m10maeda/itddd/tree/main/packages/circles-api"
    click ProfilesAPI "https://github.com/m10maeda/itddd/tree/main/packages/profiles-api"
    click ESLintConfig "https://github.com/m10maeda/itddd/tree/main/packages/eslint-config"
    click TSConfig "https://github.com/m10maeda/itddd/tree/main/packages/typescript-config"

    click CI "https://github.com/m10maeda/itddd/blob/main/.circleci/config.yml"
    click DockerCompose "https://github.com/m10maeda/itddd/blob/main/docker-compose.yaml"

    %% Styles
    classDef frontend fill:#e0f7fa,stroke:#006064,color:#004d40
    classDef circles fill:#fff3e0,stroke:#e65100,color:#bf360c
    classDef profiles fill:#e8f5e9,stroke:#2e7d32,color:#1b5e20
    classDef shared fill:#f5f5f5,stroke:#9e9e9e,color:#424242
    classDef ci fill:#424242,stroke:#212121,color:#fafafa
    classDef orchestration fill:#37474f,stroke:#263238,color:#eceff1
```
