# nhlamdev/social-blog-backend architecture

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

- Interactive diagram: https://gitdiagram.com/nhlamdev/social-blog-backend
- Repository: https://github.com/nhlamdev/social-blog-backend

## Overview

##### Main System Components

a) Core Application Layer:
- NestJS Application Core
- Configuration Management System
- Authentication System
- Database Layer
- WebSocket Gateway
- Helper Services

b) External Services Integration:
- Social Authentication Providers (Discord, GitHub, Google)
- MinIO Storage Service
- Redis Cache
- Email Service
- Queue System

##### Module Organization

Create distinct sections for the business modules:
- Member Management
- Content Management (Questions, Answers, Comments)
- Category Management
- Series Management
- Notification System
- Storage Management
- Session Management
- Contact Management

**┌─ External Services ─┐  ┌─ Authentication ─┐  ┌─ Storage ─┐**
- Google           │  │ - JWT            │  │ - MinIO   │
- GitHub          │  │ - Social Auth    │  └──────────┘
- Discord         │  └─────────────────┘
- ┘

**┌─ API Layer ────────────────────────────────┐**
- Controllers (REST Endpoints)                │
- ┤
- Business Logic (Services)                   │
- ┤
- Data Access Layer (Repositories)            │
- ┘

**┌─ Helper Services ─┐  ┌─ WebSocket ─┐**
- Logger         │  │ Gateway      │
- Mail           │  └─────────────┘
- Configuration  │
- ┘

##### Important Relationships to Highlight

- Authentication flow from social providers through the auth module to the application
- Database interactions with entities
- WebSocket connections for real-time features
- Caching layer interactions
- Demonstrate file storage flow with MinIO

##### Specific Implementation Notes

- How the modular structure is implemented using NestJS modules
- Separation of concerns between controllers, services, and entities
- Demonstrate how the helper services are shared across modules
- Configuration system's role in managing environment-specific settings

Remember to include version information and any significant dependencies that affect the architecture (like TypeORM, Redis, etc.).

This will provide a comprehensive view of the system while maintaining clarity and usefulness for both development and documentation purposes.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph External
        Google["Google Auth"]:::external
        GitHub["GitHub Auth"]:::external
        Discord["Discord Auth"]:::external
        MinIO["MinIO Storage"]:::external
        Redis["Redis Cache"]:::external
        EmailSvc["Email Service"]:::external
    end

    subgraph Core
        AppCore["NestJS App Core"]:::core
        click AppCore "https://github.com/nhlamdev/social-blog-backend/blob/main/src/app.module.ts"
        
        Config["Configuration Management"]:::core
        click Config "https://github.com/nhlamdev/social-blog-backend/blob/main/src/configuration/config.module.ts"
        
        Auth["Authentication System"]:::core
        click Auth "https://github.com/nhlamdev/social-blog-backend/blob/main/src/auth/auth.module.ts"
        
        DB["Database Layer"]:::core
        click DB "https://github.com/nhlamdev/social-blog-backend/blob/main/src/database/database.module.ts"
        
        WSGateway["WebSocket Gateway"]:::core
        click WSGateway "https://github.com/nhlamdev/social-blog-backend/blob/main/src/websocket/websocket.gateway.ts"
        
        Helper["Helper Services"]:::core
        click Helper "https://github.com/nhlamdev/social-blog-backend/blob/main/src/helper/shared.module.ts"
    end

    subgraph BusinessModules
        Member["Member Management"]:::module
        click Member "https://github.com/nhlamdev/social-blog-backend/blob/main/src/module/member/member.module.ts"
        
        Content["Content Management"]:::module
        click Content "https://github.com/nhlamdev/social-blog-backend/blob/main/src/module/content/content.module.ts"
        
        Question["Question Management"]:::module
        click Question "https://github.com/nhlamdev/social-blog-backend/blob/main/src/module/question/question.module.ts"
        
        Answer["Answer Management"]:::module
        click Answer "https://github.com/nhlamdev/social-blog-backend/blob/main/src/module/answer/answer.module.ts"
        
        Comment["Comment Management"]:::module
        click Comment "https://github.com/nhlamdev/social-blog-backend/blob/main/src/module/comment/comment.module.ts"
        
        Category["Category Management"]:::module
        click Category "https://github.com/nhlamdev/social-blog-backend/blob/main/src/module/category/category.module.ts"
        
        Series["Series Management"]:::module
        click Series "https://github.com/nhlamdev/social-blog-backend/blob/main/src/module/series/series.module.ts"
        
        Notification["Notification System"]:::module
        click Notification "https://github.com/nhlamdev/social-blog-backend/blob/main/src/module/notification/notification.module.ts"
        
        Storage["Storage Management"]:::module
        click Storage "https://github.com/nhlamdev/social-blog-backend/blob/main/src/module/storage/storage.module.ts"
        
        Session["Session Management"]:::module
        click Session "https://github.com/nhlamdev/social-blog-backend/blob/main/src/module/session/session.module.ts"
        
        Contact["Contact Management"]:::module
        click Contact "https://github.com/nhlamdev/social-blog-backend/blob/main/src/module/contact/contact.module.ts"
    end

    subgraph AuthStrategies
        DiscordStrat["Discord Strategy"]:::auth
        click DiscordStrat "https://github.com/nhlamdev/social-blog-backend/blob/main/src/auth/strategies/discord.strategy.ts"
        
        GitHubStrat["GitHub Strategy"]:::auth
        click GitHubStrat "https://github.com/nhlamdev/social-blog-backend/blob/main/src/auth/strategies/github.strategy.ts"
        
        GoogleStrat["Google Strategy"]:::auth
        click GoogleStrat "https://github.com/nhlamdev/social-blog-backend/blob/main/src/auth/strategies/google.strategy.ts"
        
        JWTAccess["JWT Access"]:::auth
        click JWTAccess "https://github.com/nhlamdev/social-blog-backend/blob/main/src/auth/strategies/jwt-access.strategy.ts"
        
        JWTRefresh["JWT Refresh"]:::auth
        click JWTRefresh "https://github.com/nhlamdev/social-blog-backend/blob/main/src/auth/strategies/jwt-refresh.strategy.ts"
    end

    subgraph SharedComponents
        BaseEntity["Base Entities"]:::shared
        click BaseEntity "https://github.com/nhlamdev/social-blog-backend/blob/main/src/shared/base/base.entity.ts"
        
        Utils["Utilities"]:::shared
        click Utils "https://github.com/nhlamdev/social-blog-backend/tree/main/src/shared/utils/"
        
        Types["Types"]:::shared
        click Types "https://github.com/nhlamdev/social-blog-backend/tree/main/src/shared/types/"
        
        DTOs["DTOs"]:::shared
        click DTOs "https://github.com/nhlamdev/social-blog-backend/tree/main/src/shared/dto/"
    end

    %% Connections
    Google --> GoogleStrat
    GitHub --> GitHubStrat
    Discord --> DiscordStrat
    GoogleStrat & GitHubStrat & DiscordStrat --> Auth
    Auth --> JWTAccess & JWTRefresh
    MinIO --> Storage
    Redis --> AppCore
    EmailSvc --> Helper
    
    AppCore --> BusinessModules
    Config --> AppCore
    Auth --> AppCore
    DB --> AppCore
    WSGateway --> AppCore
    Helper --> AppCore

    %% Styling
    classDef external fill:#2374ab,color:white
    classDef core fill:#2a9d8f,color:white
    classDef module fill:#e9c46a
    classDef auth fill:#f4a261
    classDef shared fill:#e76f51,color:white

    %% Legend
    subgraph Legend
        L1["External Services"]:::external
        L2["Core Components"]:::core
        L3["Business Modules"]:::module
        L4["Auth Strategies"]:::auth
        L5["Shared Components"]:::shared
    end
```
