# an525ish/whisper-wave architecture

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

- Interactive diagram: https://gitdiagram.com/an525ish/whisper-wave
- Repository: https://github.com/an525ish/whisper-wave

## Overview

##### And Name the Main Components
- Client Application (Frontend)
- Built with React, Redux Toolkit, and React Router.
- Located in the “client” folder with clear separation into assets, components, hooks, pages, shared UI elements, and configuration files (Tailwind, Vite).
- Server Application (Backend)
- Built with Node.js and Express.js.
- Handles REST API routes, WebSocket/Socket.IO for real-time messaging (also includes controllers, routes, models, middlewares, seeders, and utility functions).
- Database
- MongoDB serves as the persistent storage, managing collections for users, chats, messages, friend requests, etc.
- Real-time Communication Service
- Socket.IO for bi-directional real-time communication between the frontend and backend.

##### Relationships and Data Flow Between Components
- Client ↔ Server:
- HTTP/REST API calls for authentication (JWT-based login, registration) and other CRUD operations.
- WebSocket connections (via Socket.IO) for real-time events such as messaging, notifications, and friend requests.
- Server ↔ Database:
- CRUD operations performed by server controllers interacting with MongoDB through defined models.
- Server Internal Flow:
- Incoming API requests are processed through middleware (authentication, error handling) and routed to appropriate controllers.
- Controllers use utilities and services (e.g., file processing with Jimp/FFmpeg) to handle business logic.
- Client Internal Flow:
- React components (pages and shared components like chat panels, friend request dialogs, notification dialogs, etc.) interact with Redux for state management and trigger API calls and WebSocket events.

##### Architectural Patterns & Design Principles
- Separation of Concerns:
- Clear division between the presentation layer (React components) and the service layer (Node/Express API and business logic).
- MVC-Like Pattern on the Server:
- Routes, controllers, models, and middlewares are separated, facilitating maintainability.
- Real-time Data Flow:
- Integration of Socket.IO to complement typical HTTP-based interactions.
- Modular and Reusable UI Components:

##### Technologies & Frameworks to Annotate
- Frontend: React, Redux, React Router, TailwindCSS.
- Backend: Node.js, Express.js, Socket.IO.
- Database: MongoDB.
- Additional Libraries: JWT for authentication, bcrypt for password hashing, Jimp and FFmpeg for file processing.

##### Final Touches
- Component is clearly labeled.
- Use multiple layers if needed:
- For instance, separate the UI tier from the business logic tier on the server side.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Frontend Subgraph
    subgraph "Frontend"
        FApp("Client Application"):::frontend
        FSrc("React App (client/src)"):::frontend
        FConfig("Configurations (Vite & Tailwind)"):::frontend
        FSocket("Socket.IO Client"):::frontend
    end

    %% Backend Subgraph
    subgraph "Backend"
        BApp("Server Application"):::backend
        BIndex("Entry Point (index.js)"):::backend
        BRoutes("Routes"):::backend
        BMiddle("Middlewares"):::backend
        BControllers("Controllers"):::backend
        BModels("Models"):::backend
        BSeeders("Seeders"):::backend
        BUtils("Utilities"):::backend
        BSocket("Socket.IO Server"):::backend
    end

    %% Database Node
    DB("Database (MongoDB)"):::database

    %% Connections between Frontend and Backend
    FApp -->|"HTTP/REST(JWT)"| BApp
    FApp ---|"Socket.IO"| FSocket
    FSocket ---|"Socket.IO"| BSocket

    %% Internal Frontend Flow
    FApp --> FSrc
    FApp --> FConfig

    %% Internal Backend Flow
    BApp --> BIndex
    BIndex --> BRoutes
    BRoutes -->|"use"| BMiddle
    BRoutes -->|"forwards"| BControllers
    BControllers -->|"accesses"| BModels
    BControllers -->|"calls"| BUtils
    BModels --> DB
    BApp --> BSeeders

    %% Class Definitions for Colors
    classDef frontend fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef backend fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef database fill:#fff3cd,stroke:#856404,stroke-width:2px;

    %% Click Events for Frontend Components
    click FApp "https://github.com/an525ish/whisper-wave/tree/master/client/"
    click FSrc "https://github.com/an525ish/whisper-wave/tree/master/client/src"
    click FConfig "https://github.com/an525ish/whisper-wave/blob/master/client/vite.config.js"
    click FSocket "https://github.com/an525ish/whisper-wave/blob/master/client/src/lib/socketConstants.js"

    %% Click Events for Backend Components
    click BApp "https://github.com/an525ish/whisper-wave/tree/master/server/"
    click BIndex "https://github.com/an525ish/whisper-wave/blob/master/server/index.js"
    click BRoutes "https://github.com/an525ish/whisper-wave/tree/master/server/routes"
    click BMiddle "https://github.com/an525ish/whisper-wave/tree/master/server/middlewares"
    click BControllers "https://github.com/an525ish/whisper-wave/tree/master/server/controllers"
    click BModels "https://github.com/an525ish/whisper-wave/tree/master/server/models"
    click BSeeders "https://github.com/an525ish/whisper-wave/tree/master/server/seeders"
    click BUtils "https://github.com/an525ish/whisper-wave/tree/master/server/utils"
    click BSocket "https://github.com/an525ish/whisper-wave/blob/master/server/constants/socket-events.js"

    %% Click Event for Database (Models Directory)
    click DB "https://github.com/an525ish/whisper-wave/tree/master/server/models/"
```
