# shivamthakurxcode/dynexia-client-portal architecture

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

- Interactive diagram: https://gitdiagram.com/shivamthakurxcode/dynexia-client-portal
- Repository: https://github.com/shivamthakurxcode/dynexia-client-portal

## Overview

##### Project Type and Purpose
- This is a full-stack, monorepo MERN-style application combining:
- A Next.js 13 “app” folder front-end (React + Tailwind + shadcn/ui + NextAuth)
- An Express.js REST API back-end (in “backend/”)
- A legacy-style Create-React-App front-end (in “frontend/”)—likely for transitional or standalone use
- Shared libraries and hooks under “lib/” and “hooks/”
- Purpose: a client portal supporting user auth, project/document/invoice management, messaging, and onboarding.

##### File-Structure Analysis
- Top-level:
- Dockerfiles and docker-compose configs (local + prod)
- nginx reverse-proxy config
- prisma schema (though MongoDB is primary—prisma may be for local schemas or future SQL)
- Next.js project (app/, components/, lib/) with serverless API routes for auth, upload, webhook
- Separate Express backend (backend/) exposing /api/auth, /api/projects, /api/documents, etc.
- A standalone React app (frontend/) using React Router and Axios
- Patterns:
- Next.js handles SSR/SSG and NextAuth under “app/api/auth”
- Express uses MVC structure: controllers/, models/, routes/
- Shared authentication logic: JWT in Express, NextAuth in Next.js
- Cloudinary as file-storage service, Google OAuth as external identity provider
- Deployment: containerized services orchestrated via Docker Compose, with Nginx for SSL/HTTP routing.

a. Main Components
1. User’s Browser (React SPA or Next.js pages)
2. Next.js Front-End Server
3. Express.js API Server
4. MongoDB Database
5. Cloudinary (file storage)
6. External OAuth Provider (Google)
7. Nginx Reverse Proxy (in prod)
8. (Optional) CRA Front-End Service
b. Relationships & Data Flows
- Browser ↔ Next.js Server: page requests, form submissions, NextAuth flows
- Next.js Server ↔ Express API: REST calls for projects, docs, messages, invoices
- Express API ↔ MongoDB: Mongoose CRUD operations
- Express API ↔ Cloudinary: upload/download via cloudinary.js util
- Next.js Server ↔ Google OAuth: OAuth handshake via NextAuth
- Nginx ↔ (Next.js / Express) containers: SSL termination and path-based routing
- (If used) Browser ↔ CRA Front-End Service → Express API (similar calls)
c. Architectural Patterns
- Monorepo with multiple sub-projects
- Separation of concerns: SSR/SSG front-end vs. dedicated data API
- MVC in Express backend; App Router pattern in Next.js front-end
- Serverless functions (Next.js app/api) for auth and file-upload webhook
- Containerized micro-services behind Nginx gateway
d. Key Technologies
- Next.js 13 (React + App Router + NextAuth + Tailwind + shadcn/ui)
- Express.js + Node.js + Mongoose + JWT
- MongoDB Atlas (or local)
- Cloudinary for media storage
- Docker, Docker Compose, Nginx
- Prisma (for schema if used), Google OAuth
- Legacy React SPA (CRA with React Router + Axios)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Browser
    Browser["User's Browser"]:::external

    %% Infrastructure Layer
    subgraph "Infrastructure & Orchestration"
        Nginx["Nginx Reverse Proxy"]:::gateway
        DockerCompose["Docker Compose"]:::infra
        Prisma["Prisma Schema"]:::db
        Public["Public Assets"]:::infra
        Styles["Global Styles & Tailwind Config"]:::infra
    end

    %% Frontend Layer
    subgraph "Front-End Layer"
        NextJS["Next.js Front-End Server<br/>(3000)"]:::service
        CRA["Legacy CRA Front-End Service<br/>(3001)"]:::service
    end

    %% Next.js Serverless API Routes
    subgraph "Next.js Serverless API Routes"
        NextAuth["NextAuth Authentication"]:::function
        Upload["File Upload Endpoint"]:::function
        Webhook["Webhook Endpoint"]:::function
    end

    %% Backend Layer
    subgraph "Back-End Layer"
        Express["Express.js REST API Server<br/>(5000)"]:::service
        subgraph "Express MVC Structure"
            Controllers["Controllers"]:::component
            Models["Models"]:::component
            Routes["Routes"]:::component
            Middleware["Middleware"]:::component
            Utils["Utils"]:::component
        end
    end

    %% Shared Code
    subgraph "Shared Hooks"
        UseMobile["use-mobile"]:::hook
        UseToast["use-toast"]:::hook
    end

    subgraph "Shared Libraries"
        LibAuth["lib/auth.ts"]:::lib
        LibDB["lib/db.ts"]:::lib
        LibUtils["lib/utils.ts"]:::lib
        LibActions["lib/actions"]:::lib
    end

    %% External Services
    Cloudinary["Cloudinary"]:::db
    GoogleOAuth["Google OAuth"]:::external

    %% Connections
    Browser -->|"HTTP/HTTPS"| Nginx
    Nginx -->|"/" Proxy| NextJS
    Nginx -->|"/api/backend" Proxy| Express
    Nginx -->|"/legacy" Proxy| CRA

    Browser -->|"React SPA"| CRA
    Browser -->|"SSR/SSG"| NextJS

    NextJS -->|"OAuth Handshake"| GoogleOAuth
    NextJS -->|"Calls REST API"| Express
    NextJS -->|"Invokes"| NextAuth
    NextJS -->|"Invokes"| Upload
    NextJS -->|"Invokes"| Webhook

    CRA -->|"REST Calls"| Express

    Express -->|"CRUD Queries"| MongoDB
    Express -->|"Uploads/Downloads"| Cloudinary

    Upload -->|"Uploads"| Cloudinary
    Webhook -->|"Webhook Stream"| Cloudinary

    Express --> Controllers
    Express --> Models
    Express --> Routes
    Express --> Middleware
    Express --> Utils

    %% Shared usage
    NextJS --> UseMobile
    NextJS --> UseToast
    NextJS --> LibAuth
    NextJS --> LibDB
    NextJS --> LibUtils
    NextJS --> LibActions

    Express --> LibDB
    Express --> LibUtils

    %% Databases
    subgraph "Database Services"
        MongoDB["MongoDB"]:::db
    end

    Express --> MongoDB

    %% Click Events
    click NextJS "https://github.com/shivamthakurxcode/dynexia-client-portal/tree/main/app/"
    click NextJS "https://github.com/shivamthakurxcode/dynexia-client-portal/tree/main/components/"
    click NextJS "https://github.com/shivamthakurxcode/dynexia-client-portal/tree/main/lib/"
    click NextJS "https://github.com/shivamthakurxcode/dynexia-client-portal/blob/main/middleware.ts"
    click NextJS "https://github.com/shivamthakurxcode/dynexia-client-portal/blob/main/next.config.mjs"
    click NextJS "https://github.com/shivamthakurxcode/dynexia-client-portal/blob/main/tsconfig.json"
    click NextAuth "https://github.com/shivamthakurxcode/dynexia-client-portal/blob/main/app/api/auth/[...nextauth]/route.ts"
    click Upload "https://github.com/shivamthakurxcode/dynexia-client-portal/blob/main/app/api/upload/route.ts"
    click Webhook "https://github.com/shivamthakurxcode/dynexia-client-portal/blob/main/app/api/webhook/route.ts"
    click Express "https://github.com/shivamthakurxcode/dynexia-client-portal/blob/main/backend/server.js"
    click Controllers "https://github.com/shivamthakurxcode/dynexia-client-portal/tree/main/backend/controllers/"
    click Models "https://github.com/shivamthakurxcode/dynexia-client-portal/tree/main/backend/models/"
    click Routes "https://github.com/shivamthakurxcode/dynexia-client-portal/tree/main/backend/routes/"
    click Middleware "https://github.com/shivamthakurxcode/dynexia-client-portal/tree/main/backend/middleware/"
    click Utils "https://github.com/shivamthakurxcode/dynexia-client-portal/tree/main/backend/utils/"
    click Express "https://github.com/shivamthakurxcode/dynexia-client-portal/blob/main/backend/config/db.js"
    click Express "https://github.com/shivamthakurxcode/dynexia-client-portal/blob/main/backend/config/config.env.example"
    click Express "https://github.com/shivamthakurxcode/dynexia-client-portal/blob/main/Dockerfile.backend"
    click CRA "https://github.com/shivamthakurxcode/dynexia-client-portal/blob/main/frontend/src/App.js"
    click CRA "https://github.com/shivamthakurxcode/dynexia-client-portal/blob/main/frontend/src/pages/ProjectsPage.js"
    click CRA "https://github.com/shivamthakurxcode/dynexia-client-portal/tree/main/frontend/src/components/"
    click CRA "https://github.com/shivamthakurxcode/dynexia-client-portal/blob/main/frontend/src/contexts/AuthContext.js"
    click CRA "https://github.com/shivamthakurxcode/dynexia-client-portal/blob/main/frontend/src/services/api.js"
    click CRA "https://github.com/shivamthakurxcode/dynexia-client-portal/blob/main/frontend/src/utils/helpers.js"
    click CRA "https://github.com/shivamthakurxcode/dynexia-client-portal/blob/main/Dockerfile.frontend"
    click UseMobile "https://github.com/shivamthakurxcode/dynexia-client-portal/blob/main/hooks/use-mobile.tsx"
    click UseToast "https://github.com/shivamthakurxcode/dynexia-client-portal/blob/main/hooks/use-toast.ts"
    click LibAuth "https://github.com/shivamthakurxcode/dynexia-client-portal/blob/main/lib/auth.ts"
    click LibDB "https://github.com/shivamthakurxcode/dynexia-client-portal/blob/main/lib/db.ts"
    click LibUtils "https://github.com/shivamthakurxcode/dynexia-client-portal/blob/main/lib/utils.ts"
    click LibActions "https://github.com/shivamthakurxcode/dynexia-client-portal/tree/main/lib/actions/"
    click DockerCompose "https://github.com/shivamthakurxcode/dynexia-client-portal/blob/main/docker-compose.yml"
    click DockerCompose "https://github.com/shivamthakurxcode/dynexia-client-portal/blob/main/docker-compose.prod.yml"
    click Nginx "https://github.com/shivamthakurxcode/dynexia-client-portal/blob/main/nginx/nginx.conf"
    click Prisma "https://github.com/shivamthakurxcode/dynexia-client-portal/blob/main/prisma/schema.prisma"
    click Styles "https://github.com/shivamthakurxcode/dynexia-client-portal/blob/main/styles/globals.css"
    click Styles "https://github.com/shivamthakurxcode/dynexia-client-portal/blob/main/postcss.config.mjs"
    click Styles "https://github.com/shivamthakurxcode/dynexia-client-portal/blob/main/tailwind.config.ts"
    click Public "https://github.com/shivamthakurxcode/dynexia-client-portal/tree/main/public/"

    %% Styles
    classDef service fill:#D6EAF8,stroke:#2874A6,color:#1B2631
    classDef component fill:#EBF5FB,stroke:#5499C7,color:#1B2631
    classDef hook fill:#E8F8F5,stroke:#1ABC9C,color:#1B2631
    classDef lib fill:#F5EEF8,stroke:#AF7AC5,color:#1B2631
    classDef function fill:#FEF9E7,stroke:#F1C40F,color:#1B2631
    classDef db fill:#E9F7EF,stroke:#27AE60,color:#1B2631
    classDef external fill:#FADBD8,stroke:#C0392B,color:#1B2631
    classDef gateway fill:#FDEDEC,stroke:#D35400,color:#1B2631
    classDef infra fill:#F4F6F6,stroke:#85929E,color:#1B2631
```
