# princerahul1/venomai-chat-app architecture

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

- Interactive diagram: https://gitdiagram.com/princerahul1/venomai-chat-app
- Repository: https://github.com/princerahul1/venomai-chat-app

## Overview

##### Project Type and Purpose
- Full-stack web application
- Real-time chat, collaborative coding, code execution in browser, AI chatbot assistance

##### High-Level File Structure Analysis
A. Backend (Node.js + Express)
- server.js, app.js: entry points
- /controllers: ai.controller, project.controller, user.controller (MVC controllers)
- /services: ai.service, project.service, user.service, redis.service (business logic & external integrations)
- /models: user.model (Mongo schema), project.model
- /routes: ai.routes, project.routes, user.routes (REST & WebSocket endpoints)
- /db/db.js: MongoDB connection
- /middleware/auth.middleware.js: JWT auth guard

B. Frontend (React + Vite)
- public/index.html, src/main.jsx: app initialization
- src/App.jsx, src/routes/AppRoutes.jsx: route definitions
- src/screens: Login, Register, Home, Project
- src/auth/UserAuth.jsx, src/context/user.context.jsx: authentication & global state
- src/config: axios (HTTP client), socket (WebSocket client), webContainer (in-browser code runner)
- assets, styles, tailwind.config

##### Key Architectural Patterns & Principles
- Separation of Concerns:
– Backend uses MVC (models, controllers, services)
– Frontend uses component-based UI + context for global state
- Layered Architecture:
– Presentation (React UI)
– API & Real-time layer (Express endpoints + WebSocket)
– Business logic (services)
– Data (MongoDB, Redis cache)
– External integrations (Google Gemini AI, Web Container)
- Stateless API with JWT for auth and Redis for session/cache

##### Main Components
1. Client Browser
- React App (Vite)
- WebSocket client
- Web Container iframe
2. API Server (Express)
- HTTP REST endpoints (/api/users, /api/projects, /api/ai)
- WebSocket server for real-time chat & code collaboration
- Auth middleware (JWT)
3. Business Services
- UserService, ProjectService, AIService, RedisService
4. Data Stores
- MongoDB (primary persistence)
- Redis (caching, session store)
5. External Services
- Google Gemini API (AI chatbot)
- Web Container Environment (in-browser code execution)
6. Deployment Targets
- Frontend on Vercel
- Backend on Render (or similar)

##### Relationships & Data Flows
- User ↔ Browser: UI interactions
- Browser → API (HTTP): user auth, project CRUD, file history
- Browser ↔ WebSocket: real-time messaging, collaborative code editing events
- API → MongoDB: read/write user & project documents
- API ↔ Redis: caching project sessions & auth tokens
- API → Google Gemini: send user prompt, receive AI response
- Browser → Web Container: send code, receive execution output

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    subgraph "Client (React)" 
        direction TB
        MainJS["src/main.jsx"]:::frontend
        AppJS["src/App.jsx"]:::frontend
        RoutesJS["src/routes/AppRoutes.jsx"]:::frontend
        SocketCfg["src/config/socket.js"]:::frontend
        WebContainerCfg["src/config/webContainer.js"]:::frontend
    end

    %% Backend Layer
    subgraph "API Server (Express)"
        direction TB
        ServerJS["server.js"]:::backend
        AppJS_Back["app.js"]:::backend

        subgraph "Routes"
            direction TB
            UserRoutes["user.routes.js"]:::backend
            ProjectRoutes["project.routes.js"]:::backend
            AIRoutes["ai.routes.js"]:::backend
        end

        AuthMW["auth.middleware.js"]:::backend

        subgraph "Controllers"
            direction TB
            UserCtrl["user.controller.js"]:::backend
            ProjectCtrl["project.controller.js"]:::backend
            AICtrl["ai.controller.js"]:::backend
        end

        subgraph "Services"
            direction TB
            UserSvc["user.service.js"]:::backend
            ProjectSvc["project.service.js"]:::backend
            AISvc["ai.service.js"]:::backend
            RedisSvc["redis.service.js"]:::backend
        end
    end

    %% Data Stores
    subgraph "Data Stores"
        direction TB
        MongoDB["MongoDB"]:::datastore
        RedisDB["Redis"]:::datastore
    end

    %% External Services
    subgraph "External Services"
        direction TB
        GeminiAPI["Google Gemini API"]:::external
        WebContainerEnv["Web Container Env"]:::external
    end

    %% Connections Client -> API
    MainJS -->|imports| AppJS
    AppJS -->|renders routes| RoutesJS
    AppJS -->|HTTP requests| UserRoutes
    AppJS -->|HTTP requests| ProjectRoutes
    AppJS -->|HTTP requests| AIRoutes
    SocketCfg -->|WebSocket| UserRoutes
    SocketCfg -->|WebSocket| ProjectRoutes
    WebContainerCfg -->|executes code| WebContainerEnv

    %% API Server connections
    ServerJS -->|bootstraps| AppJS_Back
    AppJS_Back -->|uses| AuthMW
    AppJS_Back -->|registers| UserRoutes
    AppJS_Back -->|registers| ProjectRoutes
    AppJS_Back -->|registers| AIRoutes

    UserRoutes -->|uses| AuthMW
    ProjectRoutes -->|uses| AuthMW
    AIRoutes -->|uses| AuthMW

    UserRoutes -->|calls| UserCtrl
    ProjectRoutes -->|calls| ProjectCtrl
    AIRoutes -->|calls| AICtrl

    UserCtrl -->|invokes| UserSvc
    ProjectCtrl -->|invokes| ProjectSvc
    AICtrl -->|invokes| AISvc

    UserSvc -->|reads/writes| MongoDB
    ProjectSvc -->|reads/writes| MongoDB
    UserSvc -->|caches| RedisDB
    ProjectSvc -->|caches| RedisDB
    RedisSvc -->|manages| RedisDB

    AISvc -->|calls| GeminiAPI

    %% Client code execution
    RoutesJS -->|triggers code| WebContainerCfg

    %% Click Events
    click MainJS "https://github.com/princerahul1/venomai-chat-app/blob/main/Frontend/src/main.jsx"
    click AppJS "https://github.com/princerahul1/venomai-chat-app/blob/main/Frontend/src/App.jsx"
    click RoutesJS "https://github.com/princerahul1/venomai-chat-app/blob/main/Frontend/src/routes/AppRoutes.jsx"
    click SocketCfg "https://github.com/princerahul1/venomai-chat-app/blob/main/Frontend/src/config/socket.js"
    click WebContainerCfg "https://github.com/princerahul1/venomai-chat-app/blob/main/Frontend/src/config/webContainer.js"
    click ServerJS "https://github.com/princerahul1/venomai-chat-app/blob/main/Backend/server.js"
    click AppJS_Back "https://github.com/princerahul1/venomai-chat-app/blob/main/Backend/app.js"
    click UserRoutes "https://github.com/princerahul1/venomai-chat-app/blob/main/Backend/routes/user.routes.js"
    click ProjectRoutes "https://github.com/princerahul1/venomai-chat-app/blob/main/Backend/routes/project.routes.js"
    click AIRoutes "https://github.com/princerahul1/venomai-chat-app/blob/main/Backend/routes/ai.routes.js"
    click AuthMW "https://github.com/princerahul1/venomai-chat-app/blob/main/Backend/middleware/auth.middleware.js"
    click UserCtrl "https://github.com/princerahul1/venomai-chat-app/blob/main/Backend/controllers/user.controller.js"
    click ProjectCtrl "https://github.com/princerahul1/venomai-chat-app/blob/main/Backend/controllers/project.controller.js"
    click AICtrl "https://github.com/princerahul1/venomai-chat-app/blob/main/Backend/controllers/ai.controller.js"
    click UserSvc "https://github.com/princerahul1/venomai-chat-app/blob/main/Backend/services/user.service.js"
    click ProjectSvc "https://github.com/princerahul1/venomai-chat-app/blob/main/Backend/services/project.service.js"
    click AISvc "https://github.com/princerahul1/venomai-chat-app/blob/main/Backend/services/ai.service.js"
    click RedisSvc "https://github.com/princerahul1/venomai-chat-app/blob/main/Backend/services/redis.service.js"

    %% Styles
    classDef frontend fill:#E0F7FA,stroke:#006064,stroke-width:1px
    classDef backend fill:#E8F5E9,stroke:#1B5E20,stroke-width:1px
    classDef datastore fill:#FFF3E0,stroke:#E65100,stroke-width:1px
    classDef external fill:#F3E5F5,stroke:#4A148C,stroke-width:1px
```
