# ijas9118/nexus architecture

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

- Interactive diagram: https://gitdiagram.com/ijas9118/nexus
- Repository: https://github.com/ijas9118/nexus

## Overview

##### Project Type and Purpose
- Nexus is a full-stack web application for tech-focused blogging, squads (topic groups), real-time chat, video mentorship, and subscription payments.
- The frontend is a React/TypeScript SPA built with Vite, Redux, TanStack Query, Shadcn UI, Tailwind CSS, Socket.IO & WebRTC.
- The backend is a Node.js/Express REST API using Inversify for DI, layered by Controllers → Services → Repositories, persisting data in MongoDB and caching in Redis. It also integrates with Stripe, Cloudinary, SMTP, JWT auth, Socket.IO, WebRTC, and auto-documents via Swagger.

##### File Structure Analysis
- Top-level: `frontend/`, `backend/`, CI/CD workflows, Docker and docker-compose files.
- Frontend: organized by components (atoms → molecules → organisms), features, services, routes, context, store (Redux slices), utils.
- Backend: layered by `src/routes` → `src/controllers` → `src/services` → `src/repositories`, with shared types, DTOs, DI container, models, middlewares, utils, jobs.
- Infra config: Dockerfiles, Nginx config for FE, CI/CD pipeline.

##### Key Architectural Patterns
- Frontend: Component-driven UI, client-side routing, centralized state (Redux), query caching, real-time sockets.
- Backend: Repository pattern, dependency injection (Inversify), layered architecture (controllers, services, repositories), REST + WebSocket endpoints, background jobs, third-party integrations.

##### Main Components
a. User Device / Browser (React SPA)
b. Frontend Server (optional: Nginx container)
c. Backend API Server (Express + Inversify)
d. Real-time Socket Server (Socket.IO)
e. MongoDB (primary datastore)
f. Redis (caching, session management)
g. External Services:
- Stripe (payments)
- Cloudinary (image uploads)
- SMTP/email provider
- Google OAuth
h. WebRTC signaling (could be on backend or separate signaling server)
i. CI/CD pipeline / Docker registry (optional infra layer)

##### Relationships and Data Flows
- Browser ↔ API Server (REST calls over HTTPS via Axios)
- Browser ↔ Socket.IO Server (WebSocket for chat, notifications)
- Browser ↔ WebRTC peer connections (video calls)
- API Server ↔ MongoDB (CRUD via Mongoose)
- API Server ↔ Redis (cache reads/writes, session store)
- API Server ↔ Stripe API (payment intents, webhooks)
- API Server ↔ Cloudinary API (upload, fetch URLs)
- API Server ↔ SMTP/email (nodemailerTransporter)
- CI/CD ↔ Docker Registry → deploy FE & BE containers

## Diagram (Mermaid)

```mermaid
flowchart TB
    CI["CI/CD Pipeline"]:::infra
    CI -->|"build & deploy"| DockerCompose

    subgraph "Docker Compose"
        direction TB
        Nginx["Nginx / Frontend Server"]:::frontend
        subgraph "Backend Container"
            direction TB
            API["Express API Server"]:::backend
            SIO["Socket.IO Server"]:::backend
            Signal["WebRTC Signaling\n(Socket.IO + TURN/STUN)"]:::backend
        end
    end

    Browser["User Browser / React SPA"]:::frontend

    Browser -->|HTTPS REST| Nginx
    Browser -->|WebSocket| SIO
    Browser -->|"WebRTC Peer Connection"| WebRTCPeer["WebRTC Peer Connection"]:::frontend
    WebRTCPeer -.->|signaling| Signal
    Signal -.->|ICE negotiation| WebRTCPeer

    Nginx -->|proxy REST| API

    API -->|CRUD| MongoDB["MongoDB"]:::datastore
    API -->|cache| Redis["Redis"]:::datastore
    API -.->|payment intents/webhooks| Stripe["Stripe"]:::external
    API -.->|image uploads| Cloudinary["Cloudinary"]:::external
    API -.->|send emails| SMTP["SMTP / Email Provider"]:::external
    API -.->|OAuth login| GoogleOAuth["Google OAuth"]:::external

    subgraph "React SPA Internals"
        direction TB
        Pages["Pages & Routes"]:::frontend
        Components["Components\n(Atoms → Molecules → Organisms)"]:::frontend
        Store["Redux Store & Slices"]:::frontend
        DataFetch["TanStack Query & Axios Services"]:::frontend
        Context["Context Providers\n(SocketContext, DialogContext)"]:::frontend
        RealTime["Socket.IO Client"]:::frontend
        VideoComp["VideoCall Features"]:::frontend

        Browser --> Pages
        Pages --> Components
        Components --> Store
        Store --> DataFetch
        DataFetch --> Context
        Context --> RealTime
        RealTime --> VideoComp
    end

    subgraph "Express API Internals"
        direction TB
        Controllers["Controllers\n(src/controllers)"]:::backend
        Services["Services\n(src/services)"]:::backend
        Repositories["Repositories\n(src/repositories)"]:::backend
        DI["Inversify DI Container\n(src/inversify.config.ts)"]:::backend
        Middlewares["Middlewares\n(src/middlewares)"]:::backend
        Jobs["Jobs & Schedulers\n(src/jobs)"]:::backend
        Swagger["Swagger Docs\n(/api/docs)"]:::backend

        API --> Controllers
        Controllers --> Services
        Services --> Repositories
        DI --> Controllers
        Middlewares --> API
        Jobs --> API
        Swagger --> API
    end

    classDef frontend fill:#D0E8FF,stroke:#0366D6,stroke-width:2px
    classDef backend fill:#DFFFD0,stroke:#22863A,stroke-width:2px
    classDef datastore fill:#FFE8D0,stroke:#D73A49,stroke-width:2px
    classDef external fill:#F0F0F0,stroke:#6A737D,stroke-width:2px,stroke-dasharray:5 5
    classDef infra fill:#EDEDED,stroke:#444444,stroke-width:2px

    click Browser "https://github.com/ijas9118/nexus/tree/master/frontend/src/"
    click Nginx "https://github.com/ijas9118/nexus/blob/master/frontend/nginx.conf"
    click Nginx "https://github.com/ijas9118/nexus/tree/master/frontend/Dockerfile"
    click Nginx "https://github.com/ijas9118/nexus/blob/master/frontend/Dockerfile.prod"
    click API "https://github.com/ijas9118/nexus/blob/master/backend/src/app.ts"
    click API "https://github.com/ijas9118/nexus/blob/master/backend/src/server.ts"
    click API "https://github.com/ijas9118/nexus/tree/master/backend/Dockerfile"
    click API "https://github.com/ijas9118/nexus/blob/master/backend/Dockerfile.prod"
    click SIO "https://github.com/ijas9118/nexus/blob/master/backend/src/socket/socket.ts"
    click Controllers "https://github.com/ijas9118/nexus/blob/master/backend/src/controllers/socket.controller.ts"
    click SIO "https://github.com/ijas9118/nexus/blob/master/backend/src/routes/chat.routes.ts"
    click MongoDB "https://github.com/ijas9118/nexus/blob/master/backend/src/config/database.config.ts"
    click Repositories "https://github.com/ijas9118/nexus/tree/master/backend/src/repositories/"
    click Redis "https://github.com/ijas9118/nexus/blob/master/backend/src/config/redisClient.config.ts"
    click Stripe "https://github.com/ijas9118/nexus/blob/master/backend/src/config/stripe.cofig.ts"
    click Stripe "https://github.com/ijas9118/nexus/blob/master/backend/src/controllers/payment.controller.ts"
    click Stripe "https://github.com/ijas9118/nexus/blob/master/backend/src/routes/webhook.routes.ts"
    click Stripe "https://github.com/ijas9118/nexus/blob/master/backend/src/services/payment.service.ts"
    click Cloudinary "https://github.com/ijas9118/nexus/blob/master/backend/src/config/cloudinary.ts"
    click Cloudinary "https://github.com/ijas9118/nexus/blob/master/backend/src/utils/cloudinaryUtils.ts"
    click SMTP "https://github.com/ijas9118/nexus/blob/master/backend/src/utils/nodemailerTransporter.ts"
    click SMTP "https://github.com/ijas9118/nexus/blob/master/backend/src/services/auth/email.service.ts"
    click GoogleOAuth "https://github.com/ijas9118/nexus/blob/master/backend/src/config/passport.ts"
    click Signal "https://github.com/ijas9118/nexus/blob/master/frontend/src/features/videoCall/VideoCallPage.tsx"
    click Signal "https://github.com/ijas9118/nexus/blob/master/frontend/src/features/videoCall/useVideoCall.ts"
    click Signal "https://github.com/ijas9118/nexus/blob/master/frontend/src/features/videoCall/components/CallControls.tsx"
    click Signal "https://github.com/ijas9118/nexus/blob/master/frontend/src/features/videoCall/VideoPlayer.tsx"
    click CI "https://github.com/ijas9118/nexus/blob/master/.github/workflows/ci-cd.yml"
    click CI "https://github.com/ijas9118/nexus/blob/master/docker-compose.yml"
    click CI "https://github.com/ijas9118/nexus/blob/master/docker-compose-prod.yml"
```
