# psyho-pw/sayhobot architecture

> Architecture diagram of the GitHub repository psyho-pw/sayhobot, 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/psyho-pw/sayhobot
- Repository: https://github.com/psyho-pw/sayhobot

## Overview

##### Main Components Identification

a) Core Application Layer:
- NestJS Application Core
- Configuration Module
- Common Infrastructure Layer

b) Feature Modules:
- Discord Integration Module
- Song Module
- Database Layer (TypeORM)

##### Architectural Patterns to Highlight

The project follows several important patterns that should be represented:

- Modular Architecture (NestJS modules)
- Repository Pattern (for data access)
- Middleware Pipeline
- Exception Handling Framework
- Transaction Management

##### Component Relationships

Use the following connections:

- Double lines for HTTP/REST communications

##### Special Elements

a) Cross-Cutting Concerns:
- Error Interceptor
- Transaction Interceptor
- Logger Middleware
- Custom Decorators

b) Configuration:
- Environment Configuration
- TypeORM Configuration
- Winston Logger Configuration

##### Detailed Component Breakdown

Discord Integration:
**DiscordModule**
- DiscordClientService
- DiscordCommandService
- DiscordEventService
- DiscordNotificationService
- DiscordService

Song Management:
**SongModule**
- SongController
- SongService
- SongEntity

##### Implementation Details to Note

- How the AbstractEntity is extended by concrete entities
- How the custom decorators are applied
- Demonstrate the transaction management flow
- Error handling hierarchy

Remember to use standardized UML or C4 model notation where appropriate, but feel free to customize the representation to best convey the specific architecture of this application.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Client Layer"
        HTTP[HTTP Clients]
        Discord[Discord Bot Interface]
    end

    subgraph "Entry Points"
        SongCtrl["Song Controller"]:::controller
        DiscordEventH["Discord Event Handlers"]:::discord
        DiscordCmdH["Discord Command Handlers"]:::discord
        click SongCtrl "https://github.com/psyho-pw/sayhoBot/blob/develop/src/song/song.controller.ts"
    end

    subgraph "Core Services"
        DiscordSvc["Discord Service"]:::discord
        SongSvc["Song Service"]:::service
        ConfigSvc["Configuration Service"]:::config
        click DiscordSvc "https://github.com/psyho-pw/sayhoBot/blob/develop/src/discord/discord.service.ts"
        click SongSvc "https://github.com/psyho-pw/sayhoBot/blob/develop/src/song/song.service.ts"
        click ConfigSvc "https://github.com/psyho-pw/sayhoBot/blob/develop/src/config/config.service.ts"

        subgraph "Discord Services"
            DiscordClientSvc["Discord Client Service"]:::discord
            DiscordCmdSvc["Discord Command Service"]:::discord
            DiscordEventSvc["Discord Event Service"]:::discord
            DiscordNotifSvc["Discord Notification Service"]:::discord
            click DiscordClientSvc "https://github.com/psyho-pw/sayhoBot/blob/develop/src/discord/discord.client.service.ts"
            click DiscordCmdSvc "https://github.com/psyho-pw/sayhoBot/blob/develop/src/discord/discord.command.service.ts"
            click DiscordEventSvc "https://github.com/psyho-pw/sayhoBot/blob/develop/src/discord/discord.event.service.ts"
            click DiscordNotifSvc "https://github.com/psyho-pw/sayhoBot/blob/develop/src/discord/discord.notification.service.ts"
        end
    end

    subgraph "Infrastructure Layer"
        DB[(TypeORM Database)]:::database
        Logger["Winston Logger"]:::logger
        TransactionMgr["Transaction Manager"]:::infrastructure
        click Logger "https://github.com/psyho-pw/sayhoBot/blob/develop/src/common/configServices/winston.config.service.ts"
    end

    subgraph "Cross-Cutting Concerns"
        ErrorInt["Error Interceptor"]:::error
        TransactionInt["Transaction Interceptor"]:::infrastructure
        LoggerMW["Logger Middleware"]:::logger
        click ErrorInt "https://github.com/psyho-pw/sayhoBot/blob/develop/src/common/interceptors/error.interceptor.ts"
        click TransactionInt "https://github.com/psyho-pw/sayhoBot/blob/develop/src/common/interceptors/transaction.interceptor.ts"
        click LoggerMW "https://github.com/psyho-pw/sayhoBot/blob/develop/src/common/middlewares/logger.middleware.ts"
    end

    subgraph "Exception Handling"
        BaseDiscordEx["Base Discord Exception"]:::error
        ClientEx["Client Exception"]:::error
        CommandEx["Command Exception"]:::error
        EventEx["Event Exception"]:::error
        NotificationEx["Notification Exception"]:::error
        GeneralEx["General Exception"]:::error
        click BaseDiscordEx "https://github.com/psyho-pw/sayhoBot/blob/develop/src/common/exceptions/discord/discord.exception.ts"
        click ClientEx "https://github.com/psyho-pw/sayhoBot/blob/develop/src/common/exceptions/discord/discord.client.exception.ts"
        click CommandEx "https://github.com/psyho-pw/sayhoBot/blob/develop/src/common/exceptions/discord/discord.command.exception.ts"
        click EventEx "https://github.com/psyho-pw/sayhoBot/blob/develop/src/common/exceptions/discord/discord.event.exception.ts"
        click NotificationEx "https://github.com/psyho-pw/sayhoBot/blob/develop/src/common/exceptions/discord/discord.notification.exception.ts"
        click GeneralEx "https://github.com/psyho-pw/sayhoBot/blob/develop/src/common/exceptions/general.exception.ts"
    end

    %% Connections
    HTTP --> SongCtrl
    Discord --> DiscordEventH
    Discord --> DiscordCmdH
    
    SongCtrl --> SongSvc
    DiscordEventH --> DiscordSvc
    DiscordCmdH --> DiscordSvc
    
    DiscordSvc --> DiscordClientSvc
    DiscordSvc --> DiscordCmdSvc
    DiscordSvc --> DiscordEventSvc
    DiscordSvc --> DiscordNotifSvc
    
    SongSvc --> DB
    DiscordSvc -.-> Logger
    
    ErrorInt -.-> BaseDiscordEx
    BaseDiscordEx --> ClientEx
    BaseDiscordEx --> CommandEx
    BaseDiscordEx --> EventEx
    BaseDiscordEx --> NotificationEx
    BaseDiscordEx --> GeneralEx

    %% Styles
    classDef controller fill:#2196F3,stroke:#1565C0,color:white
    classDef service fill:#4CAF50,stroke:#2E7D32,color:white
    classDef discord fill:#7289DA,stroke:#5B6EAE,color:white
    classDef database fill:#FFC107,stroke:#FFA000,color:black
    classDef config fill:#9C27B0,stroke:#7B1FA2,color:white
    classDef infrastructure fill:#795548,stroke:#5D4037,color:white
    classDef error fill:#F44336,stroke:#C62828,color:white
    classDef logger fill:#607D8B,stroke:#455A64,color:white
```
