# bukguide/bukguide-service architecture

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

- Interactive diagram: https://gitdiagram.com/bukguide/bukguide-service
- Repository: https://github.com/bukguide/bukguide-service

## Overview

##### Core System Modules and Components
- Fact that the project is organized into individual modules – the “domain” areas. For example, you have modules for:
- Blog (src/blog)
- Categories – which are further subdivided into expertise, language, location, permission, tag, and type tour (see src/categories/*).
- Chat (includes a controller, service, and a gateway for real-time communications – src/chat)
- Users (managing user resources – src/users)
- Upload (handling file upload logic – src/upload)
- Additional support modules and services:
- Email Service (src/email) with email templates (Handlebars templates)
- Discord integration (src/discord)
- Security via JWT strategy (src/strategy/jwt.strategy.ts)
- Utility services (src/ultiService)
- Configuration and response handling (src/config/respone.service.ts)

##### Module Relationships and Data Flow
- A “Controller” (handling requests) that calls its related “Service.”
- The service then interacts with the database layer via Prisma.
- In the case of the chat module, include a connection from the chat gateway to the service layer to illustrate the real-time messaging flow.
- That the email service and Discord service are triggered from business logic when needed (for example, after certain user actions or notifications).

##### Architectural Patterns
- Modular Design: Emphasize that each domain (blog, categories, chat, users, etc.) is encapsulated as a separate module.
- MVC-like pattern: Controllers serve as the entry point for HTTP requests, services handle business logic, and Prisma (Repository) acts as the persistence layer.

##### Final Arrangement and Detailing
- Related modules together where applicable within a “Module” container (for example, inside a larger “Categories” block, show sub-modules like expertise, language, etc.).
- Key architectural patterns or critical interactions (e.g., the JWT authentication flow from incoming requests to controller-to-service calls, and the subsequent security checks).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Layer 1: Client/Application
    subgraph "Layer 1: Client/Application"
        client["Client/Application"]:::clientStyle
    end

    %% Layer 2: API Gateway / Controllers
    subgraph "Layer 2: API Gateway / Controllers"
        blogC["Blog Controller"]:::controller
        expC["Expertise Controller"]:::controller
        langC["Language Controller"]:::controller
        locC["Location Controller"]:::controller
        permC["Permission Controller"]:::controller
        tagC["Tag Controller"]:::controller
        typeTourC["Type Tour Controller"]:::controller
        chatC["Chat Controller"]:::controller
        usersC["Users Controller"]:::controller
        uploadC["Upload Controller"]:::controller
        chatG["Chat Gateway"]:::gateway
    end

    %% Layer 3: Business Logic / Services
    subgraph "Layer 3: Business Logic / Services"
        blogS["Blog Service"]:::service
        expS["Expertise Service"]:::service
        langS["Language Service"]:::service
        locS["Location Service"]:::service
        permS["Permission Service"]:::service
        tagS["Tag Service"]:::service
        typeTourS["Type Tour Service"]:::service
        chatS["Chat Service"]:::service
        usersS["Users Service"]:::service
        uploadS["Upload Service"]:::service
        utilS["Utility Service"]:::service
        configS["Configuration Service"]:::service
    end

    %% Layer 4: Persistence
    subgraph "Layer 4: Persistence"
        prisma["Prisma ORM"]:::db
    end

    %% External Services
    subgraph "External Services"
        email["Email Service"]:::external
        discord["Discord Integration"]:::external
    end

    %% Security
    subgraph "Security"
        jwt["JWT Strategy"]:::security
    end

    %% Deployment & Environment Configuration
    subgraph "Deployment & Environment"
        deployment["Deployment/Env Config"]:::deployment
    end

    %% Data Flow - Client to API Gateway / Controllers
    client -->|"sends_request"| blogC
    client -->|"sends_request"| expC
    client -->|"sends_request"| langC
    client -->|"sends_request"| locC
    client -->|"sends_request"| permC
    client -->|"sends_request"| tagC
    client -->|"sends_request"| typeTourC
    client -->|"sends_request"| chatC
    client -->|"sends_request"| usersC
    client -->|"sends_request"| uploadC
    client -->|"connects"| chatG

    %% Controllers calling corresponding Services
    blogC -->|"calls"| blogS
    expC -->|"calls"| expS
    langC -->|"calls"| langS
    locC -->|"calls"| locS
    permC -->|"calls"| permS
    tagC -->|"calls"| tagS
    typeTourC -->|"calls"| typeTourS
    chatC -->|"calls"| chatS
    usersC -->|"calls"| usersS
    uploadC -->|"calls"| uploadS

    %% Chat Gateway routing to Chat Service
    chatG -->|"routes_message"| chatS

    %% Services querying the Persistence Layer (Prisma)
    blogS -->|"db_query"| prisma
    expS -->|"db_query"| prisma
    langS -->|"db_query"| prisma
    locS -->|"db_query"| prisma
    permS -->|"db_query"| prisma
    tagS -->|"db_query"| prisma
    typeTourS -->|"db_query"| prisma
    chatS -->|"db_query"| prisma
    usersS -->|"db_query"| prisma
    uploadS -->|"db_query"| prisma

    %% Services triggering External Services
    blogS -->|"triggers"| email
    chatS -->|"triggers"| email
    usersS -->|"triggers"| email

    blogS -->|"notifies"| discord
    chatS -->|"notifies"| discord
    usersS -->|"notifies"| discord

    %% Controllers performing authentication via JWT Strategy
    blogC -->|"auth_check"| jwt
    expC -->|"auth_check"| jwt
    langC -->|"auth_check"| jwt
    locC -->|"auth_check"| jwt
    permC -->|"auth_check"| jwt
    tagC -->|"auth_check"| jwt
    typeTourC -->|"auth_check"| jwt
    chatC -->|"auth_check"| jwt
    usersC -->|"auth_check"| jwt
    uploadC -->|"auth_check"| jwt

    %% Services utilizing Utility and Configuration Services
    blogS -->|"uses"| utilS
    blogS -->|"uses"| configS
    expS -->|"uses"| utilS
    expS -->|"uses"| configS
    langS -->|"uses"| utilS
    langS -->|"uses"| configS
    locS -->|"uses"| utilS
    locS -->|"uses"| configS
    permS -->|"uses"| utilS
    permS -->|"uses"| configS
    tagS -->|"uses"| utilS
    tagS -->|"uses"| configS
    typeTourS -->|"uses"| utilS
    typeTourS -->|"uses"| configS
    chatS -->|"uses"| utilS
    chatS -->|"uses"| configS
    usersS -->|"uses"| utilS
    usersS -->|"uses"| configS
    uploadS -->|"uses"| utilS
    uploadS -->|"uses"| configS

    %% Prisma connected to Deployment / Environment (containerized deployment)
    prisma -->|"deployed_on"| deployment

    %% Click Events for Component Mapping
    click blogC "https://github.com/bukguide/bukguide-service/tree/main/src/blog"
    click blogS "https://github.com/bukguide/bukguide-service/tree/main/src/blog"

    click expC "https://github.com/bukguide/bukguide-service/tree/main/src/categories/expertise"
    click expS "https://github.com/bukguide/bukguide-service/tree/main/src/categories/expertise"

    click langC "https://github.com/bukguide/bukguide-service/tree/main/src/categories/language"
    click langS "https://github.com/bukguide/bukguide-service/tree/main/src/categories/language"

    click locC "https://github.com/bukguide/bukguide-service/tree/main/src/categories/location"
    click locS "https://github.com/bukguide/bukguide-service/tree/main/src/categories/location"

    click permC "https://github.com/bukguide/bukguide-service/tree/main/src/categories/permission"
    click permS "https://github.com/bukguide/bukguide-service/tree/main/src/categories/permission"

    click tagC "https://github.com/bukguide/bukguide-service/tree/main/src/categories/tag"
    click tagS "https://github.com/bukguide/bukguide-service/tree/main/src/categories/tag"

    click typeTourC "https://github.com/bukguide/bukguide-service/tree/main/src/categories/type-toure"
    click typeTourS "https://github.com/bukguide/bukguide-service/tree/main/src/categories/type-toure"

    click chatC "https://github.com/bukguide/bukguide-service/tree/main/src/chat"
    click chatS "https://github.com/bukguide/bukguide-service/tree/main/src/chat"
    click chatG "https://github.com/bukguide/bukguide-service/tree/main/src/chat"

    click usersC "https://github.com/bukguide/bukguide-service/tree/main/src/users"
    click usersS "https://github.com/bukguide/bukguide-service/tree/main/src/users"

    click uploadC "https://github.com/bukguide/bukguide-service/tree/main/src/upload"
    click uploadS "https://github.com/bukguide/bukguide-service/tree/main/src/upload"

    click email "https://github.com/bukguide/bukguide-service/tree/main/src/email"
    
    click discord "https://github.com/bukguide/bukguide-service/blob/main/src/discord/discordService.ts"
    
    click jwt "https://github.com/bukguide/bukguide-service/blob/main/src/strategy/jwt.strategy.ts"
    
    click utilS "https://github.com/bukguide/bukguide-service/blob/main/src/ultiService/ultiService.ts"
    
    click configS "https://github.com/bukguide/bukguide-service/blob/main/src/config/respone.service.ts"
    
    click prisma "https://github.com/bukguide/bukguide-service/tree/main/prisma"
    
    click deployment "https://github.com/bukguide/bukguide-service/blob/main/docker-compose.yml"

    %% Styling Definitions
    classDef clientStyle fill:#D0E8F2,stroke:#333,stroke-width:2px;
    classDef controller fill:#AEE1F9,stroke:#000,stroke-width:2px;
    classDef service fill:#C5F7C3,stroke:#000,stroke-width:2px;
    classDef gateway fill:#F9D1A9,stroke:#000,stroke-width:2px;
    classDef db fill:#F5D0A9,stroke:#000,stroke-width:2px;
    classDef external fill:#F9A9A9,stroke:#000,stroke-width:2px;
    classDef security fill:#D1A9F9,stroke:#000,stroke-width:2px;
    classDef deployment fill:#EAD1F9,stroke:#000,stroke-width:2px;
```
