# henriqueweiand/nestjs-real-time-chat architecture

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

- Interactive diagram: https://gitdiagram.com/henriqueweiand/nestjs-real-time-chat
- Repository: https://github.com/henriqueweiand/nestjs-real-time-chat

## Overview

##### Project type and purpose
- This is a real‑time chat application backend built with NestJS, exposing Socket.IO channels to React‑based micro frontends. Its purpose is to handle WebSocket connections, route incoming/outgoing chat messages, and integrate with frontends for a multi‑tenant or micro‑frontend chat UI.

##### File structure
- Top‑level files:
- nest-cli.json, tsconfig*.json, package.json, .eslintrc.js, .prettierrc, .gitignore
- README.md describes the stack.
- src/
- main.ts — bootstrapper for the Nest application
- app.module.ts — root module
- app.controller.ts / app.service.ts — sample health‑check endpoints
- chat/
– chat.module.ts — encapsulates chat functionality
– chat-gateway.ts — Socket.IO Gateway that handles events and pushes updates
- test/ contains end‑to‑end and unit test configurations.

##### README
- Confirms use of NestJS, React micro frontends, and Socket.IO.
- No database in code; likely ephemeral in‐memory broadcast (or storage handled elsewhere).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend layer
    subgraph "React Micro Frontends"
        style React1 fill:#cce5ff,stroke:#004085
        style React2 fill:#cce5ff,stroke:#004085
        React1["React Micro Frontend #1"]:::frontend
        React2["React Micro Frontend #2"]:::frontend
    end

    %% Backend layer
    subgraph "NestJS Application"
        style Backend fill:none,stroke:#28a745,stroke-width:2px
        Main["main.ts\n(NestJS Bootstrapper)"]:::backend
        AppModule["app.module.ts\n(Root Module)"]:::backend
        Controller["app.controller.ts\n(HTTP Controller)"]:::controller
        Service["app.service.ts\n(AppService)"]:::service
        ChatModule["chat.module.ts\n(Chat Module)"]:::module
        Gateway["chat-gateway.ts\n(Chat Gateway)"]:::gateway
        ChatService["ChatService\n(Business Logic)"]:::service
    end

    %% Data store placeholder
    DataStore["Data Store / Cache"]:::datastore

    %% Connections
    React1 -->|"connect WS"| Gateway
    React2 -->|"connect WS"| Gateway
    React1 -->|"HTTP GET /health"| Controller
    React2 -->|"HTTP GET /health"| Controller

    Controller -->|"getStatus()"| Service
    Main -->|"bootstraps"| AppModule
    AppModule -->|"imports"| Controller
    AppModule -->|"imports"| Service
    AppModule -->|"imports"| ChatModule
    ChatModule -->|"provides"| Gateway
    ChatModule -->|"provides"| ChatService

    Gateway -->|"sendMessage"| ChatService
    ChatService -->|"broadcast"| Gateway
    Gateway -->|"ws event broadcast"| React1
    Gateway -->|"ws event broadcast"| React2

    ChatService -->|"optional persistence"| DataStore
    DataStore -->|"optional read"| ChatService

    %% Click Events
    click Main "https://github.com/henriqueweiand/nestjs-real-time-chat/blob/master/src/main.ts"
    click AppModule "https://github.com/henriqueweiand/nestjs-real-time-chat/blob/master/src/app.module.ts"
    click Controller "https://github.com/henriqueweiand/nestjs-real-time-chat/blob/master/src/app.controller.ts"
    click Service "https://github.com/henriqueweiand/nestjs-real-time-chat/blob/master/src/app.service.ts"
    click ChatModule "https://github.com/henriqueweiand/nestjs-real-time-chat/blob/master/src/chat/chat.module.ts"
    click Gateway "https://github.com/henriqueweiand/nestjs-real-time-chat/blob/master/src/chat/chat-gateway.ts"
    click DataStore "https://github.com/henriqueweiand/nestjs-real-time-chat/blob/master/test/app.e2e-spec.ts"
    click Controller "https://github.com/henriqueweiand/nestjs-real-time-chat/blob/master/src/app.controller.spec.ts"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085,color:#004085;
    classDef backend fill:#d4edda,stroke:#155724,color:#155724;
    classDef controller fill:#d4edda,stroke:#155724,color:#155724;
    classDef service fill:#d4edda,stroke:#155724,color:#155724;
    classDef module fill:#d4edda,stroke:#155724,color:#155724;
    classDef gateway fill:#d4edda,stroke:#155724,color:#155724;
    classDef datastore fill:#ffe5b4,stroke:#ff851b,color:#ff851b;
```
