# lamdx4/chat-chit-server architecture

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

- Interactive diagram: https://gitdiagram.com/lamdx4/chat-chit-server
- Repository: https://github.com/lamdx4/chat-chit-server

## Overview

##### Project type and purpose
- Chat-Chit Server is a backend for a real-time chat application built in Node.js/TypeScript.
- It exposes REST endpoints (Express) and WebSocket channels (Socket.IO) supporting group chats, 1:1 messaging, stories, friend management, file uploads, reactions, polls, read receipts, notifications, etc.
- Data is persisted in MySQL via TypeORM; caching/realtime scaling via Redis; file storage in AWS S3; authentication via JWT + Google OAuth.

##### File structure
- Entry point: index.ts initializes Express, Socket.IO, middleware, routes, infra (DB, Redis, S3).
- Layered architecture under src/:
- web/ → Presentation layer: Express controllers, routes, request DTOs & validators, middlewares, Socket.IO handlers.
- application/ → Business logic services (auth, user, group, story) and DTOs.
- core/ → Domain model: TypeORM entities (User, Message, GroupChat, Story, etc.), value objects (role priority).
- infras/ → Infrastructure services:
– infras/data → DataSource + repositories implement persistence
– infras/jwt → JWT provider & payload definitions
– infras/aws-s3 → S3 file storage service
– infras/google-auth → Google OAuth helper
– infras/redis → Redis client for caching & Socket.IO adapter
- shared-kernel/ → Cross-cutting utilities: config service, logger, decorators, shared types.
- Docker and GitHub Actions configs for containerization & CI/CD.

##### README for architectural insights
- Technology stack listing matches layers.
- Feature list highlights key subsystems: Authentication, Messaging (HTTP + WS), File Upload, Caching, External Integrations.
- Database schema shows core entities and relationships.

## Diagram (Mermaid)

```mermaid
flowchart TB
  %% External Clients
  subgraph "Clients" 
    direction TB
    WebClient["Web Client"]:::external
    MobileClient["Mobile Client"]:::external
  end

  %% Presentation Layer
  subgraph "Presentation Layer" 
    direction TB
    APIGateway["API Gateway / HTTP Server"]:::presentation
    ExpressRoutes["Express Routes"]:::presentation
    HTTPControllers["HTTP Controllers"]:::presentation
    DTOsValidators["Request DTOs & Validators"]:::presentation
    Middlewares["Middlewares"]:::presentation
    SocketServer["WebSocket Server (Socket.IO)"]:::presentation
    SocketHandlers["WebSocket Handlers"]:::presentation
    SocketConstants["Socket Event Constants"]:::presentation
  end

  %% Application Services Layer
  subgraph "Application Services" 
    direction TB
    AuthService["AuthService"]:::application
    UserService["UserService"]:::application
    GroupService["GroupService"]:::application
    MessageService["MessageService"]:::application
    StoryService["StoryService"]:::application
    AppDTOs["Application DTOs & Utils"]:::application
  end

  %% Domain Model
  subgraph "Domain Model" 
    direction TB
    Entities["Domain Entities"]:::domain
    ValueObjects["Value Objects"]:::domain
  end

  %% Infrastructure Layer
  subgraph "Infrastructure" 
    direction TB
    DataSource["TypeORM DataSource"]:::infrastructure
    Repositories["Repositories"]:::infrastructure
    SeedScripts["Seed Scripts"]:::infrastructure
    RedisClient["Redis Client & Adapter"]:::infrastructure
    S3Service["AWS S3 File Storage Service"]:::infrastructure
    GoogleOAuth["Google OAuth Helper"]:::infrastructure
    JWTProvider["JWT Provider & Payloads"]:::infrastructure
    InfraInit["Infrastructure Initialization"]:::infrastructure
  end

  %% Shared Utilities
  subgraph "Shared Utilities" 
    direction TB
    ConfigService["Configuration Service"]:::shared
    Logger["Logger Utility"]:::shared
    SharedTypes["Shared Types & Decorators"]:::shared
  end

  %% External Systems
  subgraph "External Integrations"
    direction TB
    MySQL["MySQL Database"]:::external
    RedisCache["Redis (Cache & Pub/Sub)"]:::external
    AWSS3Ext["AWS S3"]:::external
    GoogleExt["Google OAuth"]:::external
  end

  %% Relationships
  WebClient -->|HTTP/WS| APIGateway
  MobileClient -->|HTTP/WS| APIGateway

  APIGateway -->|uses| ExpressRoutes
  ExpressRoutes -->|calls| HTTPControllers
  HTTPControllers -->|validates| DTOsValidators
  HTTPControllers -->|uses| Middlewares
  HTTPControllers -->|invokes| AuthService
  HTTPControllers -->|invokes| UserService
  HTTPControllers -->|invokes| GroupService
  HTTPControllers -->|invokes| StoryService
  HTTPControllers -->|invokes| MessageService

  APIGateway -->|upgrades| SocketServer
  SocketServer -->|handles| SocketHandlers
  SocketHandlers -->|emits/subscribes| SocketConstants
  SocketHandlers -->|invokes| AuthService
  SocketHandlers -->|invokes| MessageService
  SocketHandlers -->|invokes| GroupService

  AuthService -->|operates on| Entities
  UserService -->|operates on| Entities
  GroupService -->|operates on| Entities
  MessageService -->|operates on| Entities
  StoryService -->|operates on| Entities
  AppDTOs -->|transfers| Entities

  AuthService -->|caches| RedisClient
  UserService -->|caches| RedisClient
  GroupService -->|caches| RedisClient
  MessageService -->|pubsub| RedisClient

  AuthService -->|stores files| S3Service
  StoryService -->|stores files| S3Service

  AuthService -->|calls| GoogleOAuth
  HTTPControllers -->|validates token| JWTProvider
  AuthService -->|generates token| JWTProvider

  Entities -->|persist via| Repositories
  Repositories -->|connect| DataSource
  DataSource -->|SQL| MySQL

  SeedScripts -->|loads data| DataSource

  RedisClient -->|pub/sub| RedisCache
  RedisClient -->|adapter| SocketServer

  S3Service -->|API| AWSS3Ext
  GoogleOAuth -->|API| GoogleExt

  InfraInit -->|initializes| DataSource
  InfraInit -->|initializes| RedisClient
  InfraInit -->|initializes| S3Service
  InfraInit -->|initializes| JWTProvider
  InfraInit -->|initializes| GoogleOAuth

  ConfigService -->|provides| InfraInit
  Logger -->|logs| InfraInit
  SharedTypes -->|used by| HTTPControllers

  %% Click Events
  click APIGateway "https://github.com/lamdx4/chat-chit-server/blob/main/index.ts"
  click ExpressRoutes "https://github.com/lamdx4/chat-chit-server/blob/main/src/web/routers/common-router.ts"
  click HTTPControllers "https://github.com/lamdx4/chat-chit-server/tree/main/src/web/controllers"
  click DTOsValidators "https://github.com/lamdx4/chat-chit-server/tree/main/src/web/controllers/**/reqs"
  click DTOsValidators "https://github.com/lamdx4/chat-chit-server/tree/main/src/web/controllers/**/validators"
  click Middlewares "https://github.com/lamdx4/chat-chit-server/tree/main/src/web/middlewares"
  click SocketServer "https://github.com/lamdx4/chat-chit-server/blob/main/src/web/socketio/socket-io.ts"
  click SocketHandlers "https://github.com/lamdx4/chat-chit-server/blob/main/src/web/socketio/io.handler.ts"
  click SocketConstants "https://github.com/lamdx4/chat-chit-server/blob/main/src/web/socketio/event.constant.ts"
  click AuthService "https://github.com/lamdx4/chat-chit-server/blob/main/src/application/auth/auth.service.ts"
  click UserService "https://github.com/lamdx4/chat-chit-server/blob/main/src/application/user/user.service.ts"
  click GroupService "https://github.com/lamdx4/chat-chit-server/blob/main/src/application/group/group.service.ts"
  click MessageService "https://github.com/lamdx4/chat-chit-server/blob/main/src/application/group/message.service.ts"
  click StoryService "https://github.com/lamdx4/chat-chit-server/blob/main/src/application/story/story.service.ts"
  click AppDTOs "https://github.com/lamdx4/chat-chit-server/tree/main/src/application/**/dtos"
  click AppDTOs "https://github.com/lamdx4/chat-chit-server/tree/main/src/application/utils"
  click Entities "https://github.com/lamdx4/chat-chit-server/tree/main/src/core/entities"
  click ValueObjects "https://github.com/lamdx4/chat-chit-server/blob/main/src/core/value-objects/role-priority.ts"
  click DataSource "https://github.com/lamdx4/chat-chit-server/blob/main/src/infras/data/data-source/data-source.ts"
  click Repositories "https://github.com/lamdx4/chat-chit-server/blob/main/src/infras/data/repository/*.repository.ts"
  click SeedScripts "https://github.com/lamdx4/chat-chit-server/tree/main/src/infras/data/seed-data"
  click RedisClient "https://github.com/lamdx4/chat-chit-server/blob/main/src/infras/redis/redis.ts"
  click S3Service "https://github.com/lamdx4/chat-chit-server/blob/main/src/infras/aws-s3/aws-s3.service.ts"
  click GoogleOAuth "https://github.com/lamdx4/chat-chit-server/blob/main/src/infras/google-auth/google-oauth-helper.ts"
  click JWTProvider "https://github.com/lamdx4/chat-chit-server/blob/main/src/infras/jwt/jwt-provider.ts"
  click JWTProvider "https://github.com/lamdx4/chat-chit-server/tree/main/src/infras/jwt/payload"
  click InfraInit "https://github.com/lamdx4/chat-chit-server/blob/main/src/infras/init-infras.ts"
  click ConfigService "https://github.com/lamdx4/chat-chit-server/blob/main/src/shared-kernel/env/config-service.ts"
  click Logger "https://github.com/lamdx4/chat-chit-server/blob/main/src/shared-kernel/logger/logger.ts"
  click SharedTypes "https://github.com/lamdx4/chat-chit-server/tree/main/src/shared-kernel/types"
  click SharedTypes "https://github.com/lamdx4/chat-chit-server/tree/main/src/shared-kernel/decorators"

  %% Styles
  classDef presentation fill:#D0E8FF,stroke:#0366D6,color:#0366D6
  classDef application fill:#DFF5D4,stroke:#228B22,color:#228B22
  classDef domain fill:#FFF4C1,stroke:#DAA520,color:#DAA520
  classDef infrastructure fill:#FFE4C4,stroke:#CD853F,color:#CD853F
  classDef shared fill:#E8E8E8,stroke:#696969,color:#696969
  classDef external fill:#F0F0F0,stroke:#A9A9A9,color:#A9A9A9,stroke-dasharray: 5 5
```
