# vanchung369/chat-service architecture

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

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

## Overview

##### Project type and purpose
- This is a backend API server built with NestJS (Node.js + TypeScript).
- It exposes both HTTP endpoints (via controllers) and a WebSocket gateway for real-time communication.
- It includes a “base” layer for common concerns (error handling, logging, validation, repository patterns) and integrates with external services (e.g., Firebase).

##### File structure
- Top-level files:
- package.json / tsconfig.json / nest-cli.json → build and runtime configuration
- docker-compose.yml → container orchestration
- .env.example → environment variables
- src/main.ts: application entrypoint (starts Nest application)
- src/app.module.ts: root module that imports feature modules
- src/app.controller.ts / src/app.service.ts: simple example controller + service
- src/base: cross-cutting concerns
- api.ts: shared API utilities
- exception.filter.ts: global exception handling
- logging.interceptor.ts: request/response logging
- validation.pipe.ts: global input validation
- firebase.util.ts + config.ts: Firebase integration
- repositories/: generic repository base classes/interfaces
- src/providers/gateway: WebSocket gateway module + gateway implementation

##### README
- Confirms it is the NestJS starter template.
- No custom application-domain details, but implies a modular, scalable, server-side application.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Clients
    HTTPClient["HTTP Client"]:::client
    WSClient["WebSocket Client"]:::client

    %% Docker Compose Network
    subgraph "Docker Compose Network" 
        direction TB
        subgraph "NestJS App Container" 
            direction TB
            Entry["Entry Point: main.ts"]:::app
            click Entry "https://github.com/vanchung369/chat-service/blob/develop/src/main.ts"

            AppModule["Root Module: app.module.ts"]:::app
            click AppModule "https://github.com/vanchung369/chat-service/blob/develop/src/app.module.ts"

            subgraph "HTTP Module"
                direction TB
                Controller["Controller: app.controller.ts"]:::app
                click Controller "https://github.com/vanchung369/chat-service/blob/develop/src/app.controller.ts"
                Service["Service: app.service.ts"]:::app
                click Service "https://github.com/vanchung369/chat-service/blob/develop/src/app.service.ts"
            end

            subgraph "Gateway Module"
                direction TB
                GatewayMod["Gateway Module: gateway.module.ts"]:::app
                click GatewayMod "https://github.com/vanchung369/chat-service/blob/develop/src/providers/gateway/gateway.module.ts"
                GatewayImpl["Gateway: gateway.websocket.ts"]:::app
                click GatewayImpl "https://github.com/vanchung369/chat-service/blob/develop/src/providers/gateway/gateway.websocket.ts"
            end

            subgraph "Base Module"
                direction TB
                APIUtil["API Utilities: api.ts"]:::app
                click APIUtil "https://github.com/vanchung369/chat-service/blob/develop/src/base/api.ts"
                Exception["Exception Filter: exception.filter.ts"]:::app
                click Exception "https://github.com/vanchung369/chat-service/blob/develop/src/base/exception/exception.filter.ts"
                Logging["Logging Interceptor: logging.interceptor.ts"]:::app
                click Logging "https://github.com/vanchung369/chat-service/blob/develop/src/base/interceptor/logging.interceptor.ts"
                Validation["Validation Pipe: validation.pipe.ts"]:::app
                click Validation "https://github.com/vanchung369/chat-service/blob/develop/src/base/validation/validation.pipe.ts"
                FirebaseCfg["Firebase Config: config.ts"]:::app
                click FirebaseCfg "https://github.com/vanchung369/chat-service/blob/develop/src/base/firebase/config.ts"
                FirebaseUtil["Firebase Util: firebase.util.ts"]:::app
                click FirebaseUtil "https://github.com/vanchung369/chat-service/blob/develop/src/base/firebase/firebase.util.ts"
                RepoIntf["Repository Interface: interface.repository.ts"]:::app
                click RepoIntf "https://github.com/vanchung369/chat-service/blob/develop/src/base/repositories/interface.repository.ts"
                RepoEntity["Repository Entity: repository.entity.ts"]:::app
                click RepoEntity "https://github.com/vanchung369/chat-service/blob/develop/src/base/repositories/repository.entity.ts"
                RepoBase["Repository Base: repository.ts"]:::app
                click RepoBase "https://github.com/vanchung369/chat-service/blob/develop/src/base/repositories/repository.ts"
            end
        end

        DB["Database"]:::db
    end

    FirebaseExt["Firebase Service"]:::external

    %% Infrastructure files
    DockerCompose["docker-compose.yml"]:::infra
    click DockerCompose "https://github.com/vanchung369/chat-service/blob/develop/docker-compose.yml"
    NestCLI["nest-cli.json"]:::infra
    click NestCLI "https://github.com/vanchung369/chat-service/blob/develop/nest-cli.json"
    TSConfig["tsconfig.json / tsconfig.build.json"]:::infra
    click TSConfig "https://github.com/vanchung369/chat-service/blob/develop/tsconfig.json / tsconfig.build.json"
    Package["package.json / package-lock.json"]:::infra
    click Package "https://github.com/vanchung369/chat-service/blob/develop/package.json / package-lock.json"

    %% Relationships
    HTTPClient -->|"HTTP/REST"| Controller
    WSClient -->|"WebSocket"| GatewayImpl
    Controller -->|"calls"| Service
    Service -->|"uses Repository"| RepoBase
    GatewayImpl -->|"calls Service"| Service
    RepoBase -->|"reads/writes"| DB
    Entry -->|"bootstraps"| AppModule
    AppModule -->|"imports"| Controller
    AppModule -->|"imports"| GatewayMod
    AppModule -->|"imports"| APIUtil
    AppModule -->|"imports"| RepoBase
    APIUtil -->|"global utility"| Controller
    Exception -->|"handles errors for"| Controller
    Logging -->|"intercepts"| Controller
    Validation -->|"validates for"| Controller
    AllModules["All Modules"] -.->|"integrates"| FirebaseUtil
    FirebaseUtil -->|"calls External API"| FirebaseExt
    DB -.->|"network link"| DockerCompose
    Entry -.->|"runs in"| DockerCompose

    classDef app fill:#D6EFFF,stroke:#0B6E99,color:#000
    classDef db fill:#D4F8D4,stroke:#3A8A00,color:#000
    classDef external fill:#FFD8A8,stroke:#DA8C00,color:#000
    classDef infra fill:#E8E8E8,stroke:#999,color:#000
    classDef client fill:#FFE5E5,stroke:#CC0000,color:#000
```
