# ekas-7/chat-app architecture

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

- Interactive diagram: https://gitdiagram.com/ekas-7/chat-app
- Repository: https://github.com/ekas-7/chat-app

## Overview

##### Project type and purpose
- This is a full-stack, real-time chat application.
- Purpose: allow multiple users to exchange messages, share files, manage chat rooms, track presence and read receipts.

##### File structure
- Top level: `.env.example`, `docker-compose.yml`, `start.sh`, three main folders: `frontend`, `server`, `socket`.
- frontend: React/Vite app (components, context, service wrappers).
- server: Express.js API (models, controllers, routes, MongoDB connection, file uploads).
- socket: Socket.IO WebSocket server for real-time events.
- Infrastructure files: Dockerfiles in each folder, Compose orchestration.

##### Key insights from the README
- Frontend uses React 18, TailwindCSS, Material UI, Socket.IO client, Google OAuth.
- Backend: Express, Mongoose, Multer, CORS.
- Socket server: Socket.IO, user presence tracking, message delivery.
- Orchestrated via Docker Compose, exposes ports: 5173 (UI), 3000 (API), 8080 (WS), 27017 (MongoDB).

##### Main components
a. Frontend UI layer
- React app container
- Context provider for auth and messaging state
- Service module for HTTP calls
- Socket.IO client for real-time events
b. Backend API
- Express.js server
- Controllers (convo, users, messages, images)
- Mongoose models (User, Message, Convo, File)
- Multer-based upload utility
c. Socket Server
- Socket.IO server entry point
- Event handlers for connection, join room, message, presence
d. Database
- MongoDB instance (collections: users, messages, convos, files)
e. External services
- Google OAuth provider
- (Optional) Cloud storage if file uploads go beyond local FS
f. DevOps / Orchestration
- Docker Compose network connecting all containers
- Environment variables via `.env`

##### Relationships and interactions
- Frontend → HTTP REST → Backend API (auth, CRUD chat rooms, file upload).
- Frontend ↔ WebSocket → Socket Server (real-time message broadcast, presence updates).
- Backend API ↔ MongoDB (read/write data models).
- Frontend uses Google OAuth (redirect→token→API/Socket auth).

##### Architectural patterns and principles
- Separation of concerns: UI, API, real-time layer, data persistence.
- MVC-style in the API (models/controllers/routes).
- Pub/Sub pattern in Socket.IO for event distribution.
- Context API for global state management in React.
- Containerization for environment parity (Docker).

##### Technologies and frameworks to label
- React 18, Vite, TailwindCSS, Material UI, Socket.IO client.
- Node.js, Express.js, Mongoose, Multer, CORS.
- Socket.IO server.
- MongoDB.
- Google OAuth.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interface Layer
    subgraph "User Interface Layer"
        direction TB
        ReactApp["React App Container"]:::frontend
        ContextProvider["Context Provider (Auth & Messaging)"]:::frontend
        ServiceModule["Service Module (HTTP calls)"]:::frontend
        SocketClient["Socket.IO Client"]:::frontend
    end

    %% Application Layer
    subgraph "Application Layer"
        direction TB
        subgraph "Backend API" 
            direction TB
            ExpressServer["Express.js Server"]:::api
            DBConnection["MongoDB Connection Module"]:::api
            Controllers["Controllers\n(convo, users, messages, images)"]:::api
            Models["Mongoose Models\n(User, Message, Convo, File)"]:::api
            UploadUtil["Multer Upload Utility"]:::api
            Routes["API Routes"]:::api
        end
        subgraph "Socket Server"
            direction TB
            SocketServer["Socket.IO Server\nEvent Handlers"]:::realTime
        end
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        MongoDB["MongoDB"]:::database
    end

    %% External Services Layer
    subgraph "External Services"
        direction TB
        GoogleOAuth["Google OAuth Provider"]:::external
    end

    %% Infrastructure Layer
    subgraph "Infrastructure"
        direction TB
        DockerCompose["Docker Compose Network"]:::infra
        StartupScript["Startup Script"]:::infra
        FW_Dockerfile["frontend/Dockerfile"]:::infra
        API_Dockerfile["server/Dockerfile"]:::infra
        Socket_Dockerfile["socket/Dockerfile"]:::infra
    end

    %% Connections
    ReactApp -->|"HTTP REST (5173→3000)"| ExpressServer
    ContextProvider --> ReactApp
    ServiceModule --> ExpressServer
    ReactApp -->|"WS (8080)"| SocketServer
    SocketClient --> SocketServer
    ExpressServer -->|"Reads/Writes"| MongoDB
    SocketServer -.->|"Optional Persist"| ExpressServer
    SocketServer -->|"Reads/Writes"| MongoDB
    ReactApp -->|"OAuth Redirect"| GoogleOAuth
    GoogleOAuth -->|"Token"| ExpressServer
    GoogleOAuth -->|"Token"| SocketServer

    DockerCompose --> ReactApp
    DockerCompose --> ExpressServer
    DockerCompose --> SocketServer
    DockerCompose --> MongoDB

    StartupScript --> DockerCompose
    FW_Dockerfile --> DockerCompose
    API_Dockerfile --> DockerCompose
    Socket_Dockerfile --> DockerCompose

    %% Click Events
    click ReactApp "https://github.com/ekas-7/chat-app/blob/main/frontend/src/App.jsx"
    click ContextProvider "https://github.com/ekas-7/chat-app/blob/main/frontend/src/context/AccountProvider.jsx"
    click ServiceModule "https://github.com/ekas-7/chat-app/blob/main/frontend/src/service/service.js"
    click SocketClient "https://github.com/ekas-7/chat-app/blob/main/frontend/src/main.jsx"
    click ExpressServer "https://github.com/ekas-7/chat-app/blob/main/server/server.js"
    click DBConnection "https://github.com/ekas-7/chat-app/blob/main/server/database/db.js"
    click Controllers "https://github.com/ekas-7/chat-app/blob/main/server/controllers/convoControllers.js"
    click Controllers "https://github.com/ekas-7/chat-app/blob/main/server/controllers/getusersControllers.js"
    click Controllers "https://github.com/ekas-7/chat-app/blob/main/server/controllers/imageControllers.js"
    click Controllers "https://github.com/ekas-7/chat-app/blob/main/server/controllers/messageContollers.js"
    click Models "https://github.com/ekas-7/chat-app/blob/main/server/models/User.js"
    click Models "https://github.com/ekas-7/chat-app/blob/main/server/models/Message.js"
    click Models "https://github.com/ekas-7/chat-app/blob/main/server/models/Convo.js"
    click Models "https://github.com/ekas-7/chat-app/blob/main/server/models/File.js"
    click UploadUtil "https://github.com/ekas-7/chat-app/blob/main/server/utils/upload.js"
    click Routes "https://github.com/ekas-7/chat-app/blob/main/server/routes/getUsersRouter.js"
    click SocketServer "https://github.com/ekas-7/chat-app/blob/main/socket/index.js"
    click DockerCompose "https://github.com/ekas-7/chat-app/blob/main/docker-compose.yml"
    click StartupScript "https://github.com/ekas-7/chat-app/blob/main/start.sh"
    click FW_Dockerfile "https://github.com/ekas-7/chat-app/tree/main/frontend/Dockerfile"
    click API_Dockerfile "https://github.com/ekas-7/chat-app/tree/main/server/Dockerfile"
    click Socket_Dockerfile "https://github.com/ekas-7/chat-app/tree/main/socket/Dockerfile"

    %% Styles
    classDef frontend fill:#cfe2ff,stroke:#0275d8,color:#0275d8
    classDef api fill:#d4edda,stroke:#28a745,color:#155724
    classDef realTime fill:#fff3cd,stroke:#ffc107,color:#856404
    classDef database fill:#e2e3e5,stroke:#6c757d,color:#383d41
    classDef external fill:#e2eaff,stroke:#6f42c1,color:#392085
    classDef infra fill:#f8f9fa,stroke:#adb5bd,color:#495057
```
