# ashuthe1/projecthub architecture

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

- Interactive diagram: https://gitdiagram.com/ashuthe1/projecthub
- Repository: https://github.com/ashuthe1/projecthub

## Overview

##### Project type and purpose
- This is a full-stack web application (“Project Hub”) consisting of:
- A React front-end (client/) with component, feature, and layout layers
- A Node/Express REST API back-end (server/) with controllers, models, routes, middleware
- A separate WebSocket service (websocket/) for real-time messaging
- Redis for caching, rate-limiting, session or OTP storage
- MongoDB (implied by Mongoose models) as the primary database
- External integrations: Stripe (payments), email service (OTP), possible CORS/allowed-origins

##### File structure
- client/: React + Vite + Tailwind + Redux Toolkit (slices + RTK Query)
- src/components/, pages/, features/ (auth, blog, project, user)
- src/redux (store.js, apiSlice.js)
- public/, assets/, hooks/, layouts/
- server/: Node/Express REST API
- config/ (cors, Redis client, roles)
- middleware/ (credentials, rateLimiter, JWT/Otp verification, errorHandler)
- controllers/ (auth, blog, project, subscription, user)
- routes/ (authRoutes, blogRoutes, projectRoutes, subscriptionRoutes, userRoutes)
- models/ (Mongoose schemas)
- utils/ (OTP generator, email sender, Redis key generator)
- websocket/: standalone service for messaging
- socket/socket.js (socket.io setup)
- controllers/messageController.js
- routes/messageRoutes.js
- models (conversation, message)
- shares same Redis and MongoDB patterns

##### Key architecture points from README
- Requires Redis to be running
- Two separate servers (REST + WebSocket)
- Front-end served by Vite dev server, communicates via HTTP REST and WebSocket
- Stripe payment integration lives on front-end and REST endpoints

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Front-end Layer
    subgraph "Front-end (client)" 
        direction TB
        Client["React Client"]:::frontend
        Components["Components Layer"]:::frontend
        Pages["Pages Layer"]:::frontend
        Features["Features (Redux slices & RTK Query)"]:::frontend
        Layouts["Layouts"]:::frontend
        ReduxStore["Redux Store"]:::frontend
        APISlice["API Slice"]:::frontend
        Client --> Components
        Client --> Pages
        Client --> Features
        Client --> Layouts
        Client --> ReduxStore
        Client --> APISlice
    end

    %% Backend Services
    subgraph "REST API Service (server)" 
        direction TB
        RESTRoot["REST API"]:::backend
        Config["Config"]:::backend
        Routes["Routes"]:::backend
        Middleware["Middleware"]:::backend
        Controllers["Controllers"]:::backend
        Models["Models"]:::backend
        Utils["Utils"]:::backend
        RESTRoot --> Config
        RESTRoot --> Routes
        RESTRoot --> Middleware
        RESTRoot --> Controllers
        RESTRoot --> Models
        RESTRoot --> Utils
    end

    subgraph "WebSocket Service (websocket)" 
        direction TB
        WSRoot["WebSocket Service"]:::backend
        WSConfig["Config"]:::backend
        WSRoutes["Routes"]:::backend
        WSControllers["Controllers"]:::backend
        WSModels["Models"]:::backend
        WSSocket["Socket Setup"]:::backend
        WSRoot --> WSConfig
        WSRoot --> WSRoutes
        WSRoot --> WSControllers
        WSRoot --> WSModels
        WSRoot --> WSSocket
    end

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

    %% External Services
    subgraph "External Services"
        direction TB
        Stripe["Stripe"]:::external
        EmailService["Email Service"]:::external
    end

    %% Connections
    Client -->|"HTTP (REST)"| RESTRoot
    Client -.->|"WebSocket"| WSRoot
    RESTRoot -->|"Mongoose"| MongoDB
    RESTRoot -->|"Redis Caching/OTP"| Redis
    WSRoot -->|"Mongoose"| MongoDB
    WSRoot -->|"Redis Caching"| Redis
    RESTRoot -->|"Payment API"| Stripe
    RESTRoot -->|"Send OTP Email"| EmailService

    %% Click Events - Front-end
    click Client "https://github.com/ashuthe1/projecthub/tree/main/client/"
    click Components "https://github.com/ashuthe1/projecthub/tree/main/client/src/components/"
    click Pages "https://github.com/ashuthe1/projecthub/tree/main/client/src/pages/"
    click Features "https://github.com/ashuthe1/projecthub/tree/main/client/src/features/"
    click Layouts "https://github.com/ashuthe1/projecthub/tree/main/client/src/layouts/"
    click ReduxStore "https://github.com/ashuthe1/projecthub/blob/main/client/src/redux/store.js"
    click APISlice "https://github.com/ashuthe1/projecthub/blob/main/client/src/redux/apiSlice.js"

    %% Click Events - REST API Service
    click RESTRoot "https://github.com/ashuthe1/projecthub/tree/main/server/"
    click Config "https://github.com/ashuthe1/projecthub/tree/main/server/config/"
    click Routes "https://github.com/ashuthe1/projecthub/tree/main/server/routes/"
    click Middleware "https://github.com/ashuthe1/projecthub/tree/main/server/middleware/"
    click Controllers "https://github.com/ashuthe1/projecthub/tree/main/server/controllers/"
    click Models "https://github.com/ashuthe1/projecthub/tree/main/server/models/"
    click Utils "https://github.com/ashuthe1/projecthub/tree/main/server/utils/"
    click MongoDB "https://github.com/ashuthe1/projecthub/blob/main/server/database/connection.js"
    click Redis "https://github.com/ashuthe1/projecthub/blob/main/server/config/redisClient.js"
    click Controllers "https://github.com/ashuthe1/projecthub/blob/main/server/controllers/subscriptionController.js" "subscription"
    click Utils "https://github.com/ashuthe1/projecthub/blob/main/server/utils/sendEmail.js"

    %% Click Events - WebSocket Service
    click WSRoot "https://github.com/ashuthe1/projecthub/tree/main/websocket/"
    click WSConfig "https://github.com/ashuthe1/projecthub/tree/main/websocket/config/"
    click WSControllers "https://github.com/ashuthe1/projecthub/blob/main/websocket/controllers/messageController.js"
    click WSRoutes "https://github.com/ashuthe1/projecthub/blob/main/websocket/routes/messageRoutes.js"
    click WSModels "https://github.com/ashuthe1/projecthub/tree/main/websocket/models/"
    click WSSocket "https://github.com/ashuthe1/projecthub/blob/main/websocket/socket/socket.js"
    click MongoDB "https://github.com/ashuthe1/projecthub/blob/main/websocket/database/connection.js"
    click Redis "https://github.com/ashuthe1/projecthub/blob/main/websocket/config/redisClient.js"

    %% Styles
    classDef frontend fill:#FFE5B4,stroke:#FFA500,stroke-width:2px
    classDef backend fill:#D0E7FF,stroke:#1E90FF,stroke-width:2px
    classDef db fill:#DFFFD6,stroke:#008000,stroke-width:2px
    classDef external fill:#F0F0F0,stroke:#808080,stroke-width:2px
```
