# himanishpuri/chime architecture

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

- Interactive diagram: https://gitdiagram.com/himanishpuri/chime
- Repository: https://github.com/himanishpuri/chime

## Overview

##### Project type and purpose
- This is a full-stack, real-time chat application (“Chime”).
- Frontend: React/Vite single-page app.
- Backend: Node.js + Express REST APIs + Socket.io for real-time.
- Database: MongoDB via Mongoose.
- Purpose: allow users to register/login, create/join chat rooms, exchange messages in real-time, view online presence and message history.

##### File structure
- Top level:
- client/ (React app)
- server/ (Express + Socket.io)
- client/src: Pages (Login, Register, ChatPage), Components (Message), Utils (Context for auth and socket state).
- server/src:
- Configurations (db.config.js)
- Models (User, Room, ChatLog)
- Controllers (auth.controller.js, room.controller.js)
- Routes (authRoutes.js, roomRoutes.js)
- Sockets (socket event handlers)
- Config files: .env.example in both client & server, indicating environment variables for API URL, DB URI, JWT secrets.

##### README
- Confirms tech stack: Node.js, Express, Socket.io, MongoDB, Mongoose.
- Describes features: authentication, chat rooms, messaging, presence, history.
- Points out entry points: server/index.js (starts Express & Socket.io), client/main.jsx (mounts React app).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    subgraph "Client (React SPA)" 
        direction TB
        HTML["index.html"]:::client
        Main["main.jsx"]:::client
        CSS["index.css"]:::client
        TailwindCfg["tailwind.config.js"]:::client
        ViteCfg["vite.config.js"]:::client
        subgraph "Pages & Components"
            direction TB
            Login["Login.jsx"]:::client
            Register["Register.jsx"]:::client
            ChatPage["ChatPage.jsx"]:::client
            MessageComp["Message.jsx"]:::client
        end
        Context["Context.jsx"]:::client
    end

    %% Server Layer
    subgraph "Server"
        direction TB
        Entry["index.js"]:::server
        EnvSrv[".env.example"]:::external
        subgraph "Configurations"
            direction TB
            DBConfig["db.config.js"]:::server
        end
        subgraph "REST API"
            direction TB
            subgraph "Routes"
                direction TB
                AuthRoutes["authRoutes.js"]:::server
                RoomRoutes["roomRoutes.js"]:::server
            end
            subgraph "Controllers"
                direction TB
                AuthCtrl["auth.controller.js"]:::server
                RoomCtrl["room.controller.js"]:::server
            end
            subgraph "Models"
                direction TB
                UserModel["user.model.js"]:::server
                RoomModel["room.model.js"]:::server
                ChatLogModel["chatLog.model.js"]:::server
            end
        end
        subgraph "Socket.io Layer"
            direction TB
            Sockets["Sockets"]:::server
        end
    end

    %% Database & External
    DB["MongoDB"]:::db
    EnvClient[".env.example"]:::external

    %% Interactions
    HTML --> Main
    Main -->|imports CSS and Context| CSS
    Main -->|bootstrap| Login
    Main -->|bootstrap| Register
    Main -->|bootstrap| ChatPage
    Main --> Context
    Context -->|provides auth & socket| ChatPage
    ChatPage --> MessageComp

    %% HTTP Flow
    Login -->|HTTP POST /auth/register| AuthRoutes
    Register -->|HTTP POST /auth/login| AuthRoutes
    AuthRoutes --> AuthCtrl
    AuthCtrl --> UserModel
    RoomRoutes --> RoomCtrl
    RoomCtrl --> RoomModel
    AuthCtrl --> DB
    RoomCtrl --> DB

    %% WebSocket Flow
    ChatPage -->|WebSocket connect| Entry
    Entry --> Sockets
    Sockets -->|handle join_room,send_message| RoomCtrl
    Sockets -->|persist chatLog| ChatLogModel
    RoomCtrl --> DB
    ChatPage <-->|broadcast messages| Sockets

    %% Database
    UserModel --> DB
    RoomModel --> DB
    ChatLogModel --> DB

    %% External env
    Main --> EnvClient
    Entry --> EnvSrv

    %% Click Events
    click Main "https://github.com/himanishpuri/chime/blob/main/client/src/main.jsx"
    click HTML "https://github.com/himanishpuri/chime/blob/main/client/index.html"
    click CSS "https://github.com/himanishpuri/chime/blob/main/client/src/index.css"
    click TailwindCfg "https://github.com/himanishpuri/chime/blob/main/client/tailwind.config.js"
    click ViteCfg "https://github.com/himanishpuri/chime/blob/main/client/vite.config.js"
    click Login "https://github.com/himanishpuri/chime/blob/main/client/src/Pages/Login.jsx"
    click Register "https://github.com/himanishpuri/chime/blob/main/client/src/Pages/Register.jsx"
    click ChatPage "https://github.com/himanishpuri/chime/blob/main/client/src/Pages/ChatPage.jsx"
    click MessageComp "https://github.com/himanishpuri/chime/blob/main/client/src/Pages/Components/Message.jsx"
    click Context "https://github.com/himanishpuri/chime/blob/main/client/src/Utils/Context.jsx"
    click Entry "https://github.com/himanishpuri/chime/blob/main/server/index.js"
    click DBConfig "https://github.com/himanishpuri/chime/blob/main/server/src/Configurations/db.config.js"
    click UserModel "https://github.com/himanishpuri/chime/blob/main/server/src/Models/user.model.js"
    click RoomModel "https://github.com/himanishpuri/chime/blob/main/server/src/Models/room.model.js"
    click ChatLogModel "https://github.com/himanishpuri/chime/blob/main/server/src/Models/chatLog.model.js"
    click AuthCtrl "https://github.com/himanishpuri/chime/blob/main/server/src/Controllers/auth.controller.js"
    click RoomCtrl "https://github.com/himanishpuri/chime/blob/main/server/src/Controllers/room.controller.js"
    click AuthRoutes "https://github.com/himanishpuri/chime/blob/main/server/src/Routes/authRoutes.js"
    click RoomRoutes "https://github.com/himanishpuri/chime/blob/main/server/src/Routes/roomRoutes.js"
    click Sockets "https://github.com/himanishpuri/chime/tree/main/server/src/Sockets"
    click EnvSrv "https://github.com/himanishpuri/chime/blob/main/server/.env.example"
    click EnvClient "https://github.com/himanishpuri/chime/blob/main/client/.env.example"

    %% Styles
    classDef client fill:#D0E6A5,stroke:#333,stroke-width:1px
    classDef server fill:#FFDD94,stroke:#333,stroke-width:1px
    classDef db fill:#94DDF4,stroke:#333,stroke-width:1px
    classDef external fill:#F3A6B8,stroke:#333,stroke-width:1px
```
