# aryansrivastava1709/whispr architecture

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

- Interactive diagram: https://gitdiagram.com/aryansrivastava1709/whispr
- Repository: https://github.com/aryansrivastava1709/whispr

## Overview

a. Frontend (Client):
- Components:
- React application
- Main entry (client/src/main.jsx)
- App structure in App.jsx and other components like ChatWindow, Login, and SignUp.
- Utility libraries (e.g., messageStore.js, userStore.js)
- Technology Stack: React, Vite, Tailwind CSS, ESLint.
b. Backend (Server):
- Controllers: Handles business logic (messageController.js, userController.js)
- Models: Data schemas for User and Message (Mongoose-based, from models folder)
- Routes: API endpoints organized under userRoutes.js and messageRoutes.js that facilitate user registration, login, and chat operations.
- Utilities:
- auth.js for handling JWT-based authentication,
- socket.js for managing real-time Socket.IO connections,
- languageModel.js for interfacing with the Google Gemini LLM.
- Technology Stack: Node.js, Express, Mongoose, Socket.IO.
c. Database (Implicit):
- Although not explicitly shown, the use of Mongoose schemas implies integration with a MongoDB database.
d. External Services:
- Google Gemini LLM API for language generation.
- Possible authentication integrations via tokens (JWT).

##### Relationships and Interactions
- The Backend interacts with the Database when handling persistent data such as user credentials and message history.

##### Architectural Patterns and Design Principles
- Separation of concerns:
- Frontend (presentation and state management)
- Backend (API, authentication, real-time messaging, and business logic)
- Persistence layer (database operations via Mongoose)
- Modularity—in the backend, controllers handle logic separate from models and routes, while utilities encapsulate authentication and socket management.
- Event-driven, reactive nature introduced by Socket.IO for real-time communication.

##### Relevant Technologies
- Client: React, Vite, Tailwind, ESLint
- Server: Node.js, Express, Mongoose, Socket.IO
- External: Google Gemini LLM API and implicitly, a MongoDB instance.
- Other: JWT for authentication, with environment variables for configuration.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Frontend (Client Application)"
        FE1["React App"]:::frontend
        FE2["Main Entry"]:::frontend
        FE3["App Structure"]:::frontend
        FE4["ChatWindow Component"]:::frontend
        FE5["Login Component"]:::frontend
        FE6["SignUp Component"]:::frontend
        FE7["Message Store Utility"]:::frontend
        FE8["User Store Utility"]:::frontend
    end

    subgraph "Backend (Express Server)"
        BE1["Express Server Entry Point"]:::backend
        subgraph "Controllers"
            BE2["Message Controller"]:::backend
            BE3["User Controller"]:::backend
        end
        subgraph "Models"
            BE4["Message Model"]:::backend
            BE5["User Model"]:::backend
        end
        subgraph "Routes"
            BE6["Message Routes"]:::backend
            BE7["User Routes"]:::backend
        end
        subgraph "Utilities"
            BE8["Authentication Utility"]:::backend
            BE9["Socket.IO Module"]:::backend
            BE10["Language Model Utility"]:::backend
        end
    end

    DB["MongoDB Database"]:::database
    ES["Google Gemini LLM API"]:::external

    %% Interactions between Frontend and Backend
    FE1 -->|"HTTP"| BE6
    FE1 -->|"HTTP"| BE7
    FE1 <==>|"SocketIO"| BE9

    %% Backend internal flow
    BE6 -->|"invokes"| BE2
    BE7 -->|"invokes"| BE3
    BE2 -->|"uses"| BE4
    BE3 -->|"uses"| BE5
    BE8 -.->|"secures"| BE2
    BE8 -.->|"secures"| BE3

    %% Models interact with Database
    BE4 -->|"persists to"| DB
    BE5 -->|"persists to"| DB

    %% Language model utility interaction
    BE10 -->|"calls"| ES

    %% Click Events for Frontend Components
    click FE1 "https://github.com/aryansrivastava1709/whispr/tree/main/client/"
    click FE2 "https://github.com/aryansrivastava1709/whispr/blob/main/client/src/main.jsx"
    click FE3 "https://github.com/aryansrivastava1709/whispr/blob/main/client/src/App.jsx"
    click FE4 "https://github.com/aryansrivastava1709/whispr/blob/main/client/src/components/ChatWIndow.jsx"
    click FE5 "https://github.com/aryansrivastava1709/whispr/blob/main/client/src/components/login/Login.jsx"
    click FE6 "https://github.com/aryansrivastava1709/whispr/blob/main/client/src/components/signup/SignUp.jsx"
    click FE7 "https://github.com/aryansrivastava1709/whispr/blob/main/client/src/lib/messageStore.js"
    click FE8 "https://github.com/aryansrivastava1709/whispr/blob/main/client/src/lib/userStore.js"

    %% Click Events for Backend Components
    click BE1 "https://github.com/aryansrivastava1709/whispr/blob/main/server/index.js"
    click BE2 "https://github.com/aryansrivastava1709/whispr/blob/main/server/controllers/messageController.js"
    click BE3 "https://github.com/aryansrivastava1709/whispr/blob/main/server/controllers/userController.js"
    click BE4 "https://github.com/aryansrivastava1709/whispr/blob/main/server/models/Message.js"
    click BE5 "https://github.com/aryansrivastava1709/whispr/blob/main/server/models/User.js"
    click BE6 "https://github.com/aryansrivastava1709/whispr/blob/main/server/routes/messageRoutes.js"
    click BE7 "https://github.com/aryansrivastava1709/whispr/blob/main/server/routes/userRoutes.js"
    click BE8 "https://github.com/aryansrivastava1709/whispr/blob/main/server/utils/auth.js"
    click BE9 "https://github.com/aryansrivastava1709/whispr/blob/main/server/utils/socket.js"
    click BE10 "https://github.com/aryansrivastava1709/whispr/blob/main/server/utils/languageModel.js"

    %% Styles
    classDef frontend fill:#fefbcd,stroke:#e2b007,stroke-width:2px;
    classDef backend fill:#d0e6f7,stroke:#3f7fbf,stroke-width:2px;
    classDef database fill:#ffe6e6,stroke:#cc0000,stroke-width:2px;
    classDef external fill:#e6ffe6,stroke:#2ca02c,stroke-width:2px;
```
