# khu-khlug/sight-backend architecture

> Architecture diagram of the GitHub repository khu-khlug/sight-backend, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/khu-khlug/sight-backend
- Repository: https://github.com/khu-khlug/sight-backend

## Overview

##### Main Components

a. Core Layer:
- Authentication System (auth folder)
- Configuration Management (config folder)
- Persistence Layer (persistence folder)
- Transaction Management (transaction folder)

b. Domain Layer:
- Domain
- User Domain
- Interest Domain
- Seminar Domain
- Cache Domain
- Message Domain

c. Application Layer:
- Command Handlers
- Query Handlers
- Event Handlers

d. Interface Layer:
- REST Controllers
- DTOs

e. Infrastructure Layer:
- Database (MySQL)
- Logger
- External Services

##### Architectural Patterns to Highlight

- CQRS (Command Query Responsibility Segregation) - evident from the command/query separation
- Domain-Driven Design - clear from the domain organization
- Event-Driven Architecture - presence of event handlers
- Repository Pattern - visible in domain repositories
- Factory Pattern - used in domain object creation

**[External Clients] → [Interface Layer (Controllers)]**
- ↓
**[Application Layer] → [Commands/Queries/Events]**
- ↓
**[Domain Layer] → [Domain Models/Services/Repositories]**
- ↓
**[Infrastructure Layer] → [Database/External Services]**

##### Important Relationships

a. Data Flow:
- Client requests → Controllers → Command/Query Handlers → Domain Services → Repositories → Database
- Event flows from Domain Events → Event Handlers → External Services

b. Dependencies:
- How the auth guard protects routes
- Transaction boundaries
- Event publishing/handling paths

##### Special Components to Highlight

- Authentication/Authorization flow
- Transaction management system
- Management functionality
- User management system
- Point system
- Door lock password management (InfraBlue)

##### Technical Stack Elements

- NestJS Framework
- MySQL Database
- Docker Container
- MikroORM (based on configuration file)

##### Implementation Details

- Core Business Logic (Group, User, Interest domains)
- Infrastructure Services (Logger, Database)
- Cross-cutting Concerns (Auth, Configuration)
- External Integrations (Slack, InfraBlue)

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        EC[External Clients]:::client
    end

    subgraph Interface
        REST[REST Controllers]:::interface
        DTO[DTOs]:::interface
    end

    subgraph Application
        CH[Command Handlers]:::application
        QH[Query Handlers]:::application
        EH[Event Handlers]:::application
    end

    subgraph Domain
        GD[Group Domain]:::domain
        UD[User Domain]:::domain
        ID[Interest Domain]:::domain
        SD[Seminar Domain]:::domain
        CD[Cache Domain]:::domain
        MD[Message Domain]:::domain
        PS[Point System]:::domain
    end

    subgraph Core
        Auth[Authentication System]:::core
        Config[Configuration Management]:::core
        PL[Persistence Layer]:::core
        TM[Transaction Management]:::core
    end

    subgraph Infrastructure
        DB[(MySQL Database)]:::infra
        Logger[Logger System]:::infra
        ES[External Services]:::infra
        DLP[Door Lock Password]:::infra
        Slack[Slack Integration]:::infra
    end

    EC --> REST
    REST --> CH
    REST --> QH
    CH --> GD
    CH --> UD
    QH --> GD
    QH --> UD
    GD --> EH
    UD --> EH
    EH --> ES
    GD --> PL
    UD --> PL
    ID --> PL
    SD --> PL
    CD --> PL
    MD --> PL
    PL --> DB
    Auth -.-> REST
    Config -.-> PL
    TM -.-> PL
    ES --> Slack
    ES --> DLP
    UD --> PS

    %% Click events for component mapping
    click Auth "https://github.com/khu-khlug/sight-backend/tree/main/src/core/auth/"
    click Config "https://github.com/khu-khlug/sight-backend/tree/main/src/core/config/"
    click PL "https://github.com/khu-khlug/sight-backend/tree/main/src/core/persistence/"
    click TM "https://github.com/khu-khlug/sight-backend/tree/main/src/core/persistence/transaction/"
    click GD "https://github.com/khu-khlug/sight-backend/tree/main/src/app/domain/group/"
    click UD "https://github.com/khu-khlug/sight-backend/tree/main/src/app/domain/user/"
    click ID "https://github.com/khu-khlug/sight-backend/tree/main/src/app/domain/interest/"
    click SD "https://github.com/khu-khlug/sight-backend/tree/main/src/app/domain/seminar/"
    click CD "https://github.com/khu-khlug/sight-backend/tree/main/src/app/domain/cache/"
    click MD "https://github.com/khu-khlug/sight-backend/tree/main/src/app/domain/message/"
    click CH "https://github.com/khu-khlug/sight-backend/tree/main/src/app/application/group/command/"
    click QH "https://github.com/khu-khlug/sight-backend/tree/main/src/app/application/group/query/"
    click EH "https://github.com/khu-khlug/sight-backend/tree/main/src/app/application/group/eventHandler/"
    click REST "https://github.com/khu-khlug/sight-backend/tree/main/src/app/interface/"
    click DTO "https://github.com/khu-khlug/sight-backend/tree/main/src/app/interface/user/manager/dto/"
    click Logger "https://github.com/khu-khlug/sight-backend/tree/main/src/app/infra/logger/"
    click Slack "https://github.com/khu-khlug/sight-backend/blob/main/src/app/domain/adapter/ISlackSender.ts"
    click DLP "https://github.com/khu-khlug/sight-backend/tree/main/src/app/application/infraBlue/"
    click PS "https://github.com/khu-khlug/sight-backend/blob/main/src/app/domain/user/service/PointGrantService.ts"

    classDef client fill:#e1e1e1,stroke:#333,stroke-width:2px
    classDef interface fill:#2196F3,stroke:#333,stroke-width:2px
    classDef application fill:#4CAF50,stroke:#333,stroke-width:2px
    classDef domain fill:#FFC107,stroke:#333,stroke-width:2px
    classDef core fill:#9C27B0,stroke:#333,stroke-width:2px
    classDef infra fill:#607D8B,stroke:#333,stroke-width:2px

    %% Legend
    subgraph Legend
        L1[Client Layer]:::client
        L2[Interface Layer]:::interface
        L3[Application Layer]:::application
        L4[Domain Layer]:::domain
        L5[Core Layer]:::core
        L6[Infrastructure Layer]:::infra
    end
```
