# shiksha-nath02/echoverse architecture

> Architecture diagram of the GitHub repository shiksha-nath02/echoverse, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-02-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/shiksha-nath02/echoverse
- Repository: https://github.com/shiksha-nath02/echoverse

## Overview

EchoVerse is a **full-stack web application**:

- **Client**: React + Vite SPA (`client/`) that renders pages/components and calls a REST API via Axios.
- **Server**: Node.js + Express REST API (`backend/`) implementing authentication + posts (and likely comments, per README).
- **Data layer**: PostgreSQL accessed through **Prisma ORM** (`backend/prisma/schema.prisma`, `migrations/`).
- **Auth**: **JWT-based** auth with an Express middleware (`backend/middleware/auth.js`).

##### Frontend (client/)
- `client/src/main.jsx` + `App.jsx`: SPA bootstrap + top-level routing layout
- `client/src/pages/*`: route-level screens (Login, Signup, Dashboard, AdminPortal, ShowPost, NewPost, Logout)
- `client/src/Components/*`: shared UI + routing guards
- `PrivateRoute.jsx` / `PublicRoute.jsx`: **important**—they indicate the client enforces auth gating in the UI
- `client/src/Services/api.js` and `client/src/api/*` (auth.js, posts.js): **API client layer** (Axios wrapper + endpoint-specific functions)
- `client/src/store/store.js`: global state (auth/user state is likely stored here)

- “Routing + Pages”
- “Auth Guards (PrivateRoute/PublicRoute)”
- “API Client (Axios)”
- “State Store”

##### Backend (backend/)
Key nodes:
- `backend/index.js`: Express app entrypoint; likely mounts routes and middleware
- `backend/routes/auth.js`, `backend/routes/posts.js`: route modules
- `backend/controllers/authcontroller.js`, `backend/controllers/postCtrl.js`: request handlers / business logic
- `backend/middleware/auth.js`: JWT verification / protection of routes
- `backend/prisma/schema.prisma` + `migrations/*`: data model + schema evolution

- “Routes”
- “Middleware (JWT auth)”
- “Controllers / Services (business logic)”
- “Prisma Client (ORM)”
- “PostgreSQL DB”

##### Database layer
From README Prisma schema:
- Entities: `User`, `Post`, `Comment`
- Relations: User→Posts, Post→Comments, User→Comments

##### Signup/Login
- Browser (Login/Signup page) → Axios (`client/src/api/auth.js`) → Express `/api/auth/*`
- Express routes → `authcontroller.js`
- `authcontroller.js` → Prisma → Postgres (create/find user)
- Response returns **JWT** (and possibly user payload)

##### Authenticated session
- Browser stores JWT (likely in store/local storage; not shown but implied)
- Subsequent API calls include JWT in `Authorization: Bearer <token>` (usually done in `Services/api.js`)
- Express `middleware/auth.js` validates JWT and attaches user context to request

##### Read posts
- Dashboard/Home → `client/src/api/posts.js` → GET `/api/post`
- Express `routes/posts.js` → `postCtrl.js` → Prisma → Postgres
##### Create post
- NewPost page → POST `/api/post`
- Protected by `middleware/auth.js` (very important to show)

##### Comments (README mentions it, repo doesn’t show route file)
- “Comments API” component (even if route file is not visible) OR
- As “planned/expected endpoint per README”

- **SPA + REST**: React SPA consumes REST endpoints from Express.
- **Route → Controller** separation on backend: `routes/` delegates to `controllers/`.
- **Middleware-based security**: `middleware/auth.js` acts as a gatekeeper for protected routes.
- **Data access via ORM**: Prisma is the only component that talks to Postgres.
- **Shared domain model**: Prisma schema defines the domain entities (User, Post, Comment).

##### Level 0: System Context (1 slide)
- Actors: “User (Browser)”
- Systems: “EchoVerse Web App (React SPA)”, “EchoVerse API (Express)”, “PostgreSQL”
- External: none obvious (no S3, no email provider, etc.)
- Browser ↔ React SPA (static assets)
- React SPA ↔ Express API (JSON/HTTPS)
- Express API ↔ Postgres (SQL via Prisma)

## Diagram (Mermaid)

```mermaid
flowchart TD
  %% ========== Level 0: System Context ==========
  subgraph "Level 0 — System Context"
    U["User (Browser)"]:::external

    subgraph "EchoVerse"
      FE0["Web Client (React + Vite SPA)"]:::frontend
      BE0["REST API (Node.js + Express)"]:::backend
      DB0[("PostgreSQL DB\n(User, Post, Comment)")]:::data
    end

    U -->|"Uses"| FE0
    FE0 -->|"HTTPS/JSON\nJWT over HTTPS"| BE0
    BE0 -->|"SQL via Prisma ORM"| DB0
  end

  TB["Trust Boundary\nInternet ↔ API\n(JWT over HTTPS)"]:::boundary
  FE0 --> TB --> BE0

  %% ========== Level 1: Container Diagram ==========
  subgraph "Level 1 — Containers"
    direction TB

    subgraph "Client Container (client/)"
      direction TB
      FE_BOOT["SPA Bootstrap (main.jsx)"]:::frontend
      FE_APP["App Shell + Routing (App.jsx)"]:::frontend

      subgraph "Routing + Pages (client/src/pages/)"
        direction TB
        P_LOGIN["Login Page"]:::frontend
        P_SIGNUP["Signup Page"]:::frontend
        P_DASH["Dashboard Page"]:::frontend
        P_ADMIN["Admin Portal Page"]:::frontend
        P_NEWPOST["New Post Page"]:::frontend
        P_SHOWPOST["Show Post Page"]:::frontend
        P_LOGOUT["Logout Page"]:::frontend
      end

      subgraph "UI + Route Guards (client/src/Components/)"
        direction TB
        C_NAV["Navbar"]:::frontend
        C_PRIV["PrivateRoute (Auth Guard)"]:::frontend
        C_PUB["PublicRoute (Auth Guard)"]:::frontend
      end

      subgraph "API Client Layer"
        direction TB
        S_AXIOS["Axios Base Client (Services/api.js)"]:::frontend
        API_AUTH["Auth API (api/auth.js)"]:::frontend
        API_POSTS["Posts API (api/posts.js)"]:::frontend
        API_COMMENTS["Comments API (/api/comment)\n(documented/expected)"]:::planned
      end

      STORE["Global State Store (store.js)\n(auth/user + JWT)"]:::frontend
    end

    subgraph "Server Container (backend/)"
      direction TB
      BE_ENTRY["Express Entrypoint (index.js)"]:::backend

      subgraph "HTTP Layer"
        direction TB
        R_AUTH["Auth Routes (routes/auth.js)"]:::backend
        R_POSTS["Posts Routes (routes/posts.js)"]:::backend
        R_COMMENTS["Comments Routes\n(documented/expected)"]:::planned
      end

      MW_JWT["JWT Auth Middleware (middleware/auth.js)\n(verify token, attach user)"]:::security

      subgraph "Controllers / Business Logic"
        direction TB
        CTRL_AUTH["Auth Controller (controllers/authcontroller.js)"]:::backend
        CTRL_POSTS["Posts Controller (controllers/postCtrl.js)"]:::backend
        CTRL_COMMENTS["Comments Controller\n(documented/expected)"]:::planned
      end

      subgraph "Data Access (Prisma ORM)"
        direction TB
        PRISMA["Prisma Client"]:::data
        SCHEMA["Prisma Schema (schema.prisma)\nUser↔Posts; Post↔Comments; User↔Comments"]:::data
        MIGR["Migrations (migrations/*)"]:::data
        MIG1["Migration SQL (init)"]:::data
        MIG2["Migration SQL (initialising)"]:::data
      end

      DB1[("PostgreSQL\nTables: User, Post, Comment")]:::data
    end
  end

  %% ========== Frontend internal wiring ==========
  FE_BOOT -->|"Bootstraps"| FE_APP
  FE_APP -->|"Renders"| C_NAV
  FE_APP -->|"RoutesTo"| P_LOGIN
  FE_APP -->|"RoutesTo"| P_SIGNUP
  FE_APP -->|"RoutesTo"| P_DASH
  FE_APP -->|"RoutesTo"| P_ADMIN
  FE_APP -->|"RoutesTo"| P_NEWPOST
  FE_APP -->|"RoutesTo"| P_SHOWPOST
  FE_APP -->|"RoutesTo"| P_LOGOUT

  P_DASH -->|"GuardedBy"| C_PRIV
  P_ADMIN -->|"GuardedBy"| C_PRIV
  P_NEWPOST -->|"GuardedBy"| C_PRIV
  P_SHOWPOST -->|"GuardedBy"| C_PRIV
  P_LOGIN -->|"GuardedBy"| C_PUB
  P_SIGNUP -->|"GuardedBy"| C_PUB

  STORE -->|"ProvidesAuthState"| C_PRIV
  STORE -->|"ProvidesAuthState"| C_PUB

  API_AUTH -->|"Uses"| S_AXIOS
  API_POSTS -->|"Uses"| S_AXIOS
  API_COMMENTS -.->|"WouldUse"| S_AXIOS

  STORE -->|"StoresJWT/User"| S_AXIOS

  %% ========== Backend internal wiring ==========
  BE_ENTRY -->|"Mounts"| R_AUTH
  BE_ENTRY -->|"Mounts"| R_POSTS
  BE_ENTRY -.->|"MayMount"| R_COMMENTS

  R_AUTH -->|"Calls"| CTRL_AUTH
  R_POSTS -->|"Calls"| CTRL_POSTS
  R_COMMENTS -.->|"Calls"| CTRL_COMMENTS

  R_POSTS -->|"ProtectedBy"| MW_JWT
  R_COMMENTS -.->|"ProtectedBy"| MW_JWT

  MW_JWT -->|"OnSuccess adds req.user"| CTRL_POSTS
  MW_JWT -.->|"OnSuccess adds req.user"| CTRL_COMMENTS

  CTRL_AUTH -->|"Reads/Writes"| PRISMA
  CTRL_POSTS -->|"Reads/Writes"| PRISMA
  CTRL_COMMENTS -.->|"Reads/Writes"| PRISMA

  SCHEMA -->|"DefinesModels"| PRISMA
  MIGR -->|"EvolvesSchema"| SCHEMA
  MIG1 -->|"SQL"| MIGR
  MIG2 -->|"SQL"| MIGR

  PRISMA -->|"SQL"| DB1

  %% ========== Cross-boundary API flows ==========
  P_SIGNUP -->|"POST /api/auth/signup\nHTTPS/JSON"| R_AUTH
  P_LOGIN -->|"POST /api/auth/login\nHTTPS/JSON"| R_AUTH
  R_AUTH -->|"Returns JWT + user payload"| P_LOGIN
  R_AUTH -->|"Returns JWT + user payload"| P_SIGNUP

  P_DASH -->|"GET /api/post\nAuthorization: Bearer JWT"| R_POSTS
  P_NEWPOST -->|"POST /api/post\nAuthorization: Bearer JWT"| R_POSTS
  P_SHOWPOST -->|"GET /api/post/:id\nAuthorization: Bearer JWT"| R_POSTS

  %% Optional/expected per README
  FE_APP -.->|"(/api/comment) expected\nAuthorization: Bearer JWT"| R_COMMENTS

  %% ========== Click Events (from component_mapping) ==========
  click FE_BOOT "https://github.com/shiksha-nath02/echoverse/blob/main/client/src/main.jsx"
  click FE_APP "https://github.com/shiksha-nath02/echoverse/blob/main/client/src/App.jsx"
  click P_LOGIN "https://github.com/shiksha-nath02/echoverse/blob/main/client/src/pages/Login.jsx"
  click P_SIGNUP "https://github.com/shiksha-nath02/echoverse/blob/main/client/src/pages/Signup.jsx"
  click P_DASH "https://github.com/shiksha-nath02/echoverse/blob/main/client/src/pages/Dashboard.jsx"
  click P_ADMIN "https://github.com/shiksha-nath02/echoverse/blob/main/client/src/pages/AdminPortal.jsx"
  click P_NEWPOST "https://github.com/shiksha-nath02/echoverse/blob/main/client/src/pages/NewPost.jsx"
  click P_SHOWPOST "https://github.com/shiksha-nath02/echoverse/blob/main/client/src/pages/ShowPost.jsx"
  click P_LOGOUT "https://github.com/shiksha-nath02/echoverse/blob/main/client/src/pages/Logout.jsx"
  click C_NAV "https://github.com/shiksha-nath02/echoverse/blob/main/client/src/Components/Navbar.jsx"
  click C_PRIV "https://github.com/shiksha-nath02/echoverse/blob/main/client/src/Components/PrivateRoute.jsx"
  click C_PUB "https://github.com/shiksha-nath02/echoverse/blob/main/client/src/Components/PublicRoute.jsx"
  click S_AXIOS "https://github.com/shiksha-nath02/echoverse/blob/main/client/src/Services/api.js"
  click API_AUTH "https://github.com/shiksha-nath02/echoverse/blob/main/client/src/api/auth.js"
  click API_POSTS "https://github.com/shiksha-nath02/echoverse/blob/main/client/src/api/posts.js"
  click STORE "https://github.com/shiksha-nath02/echoverse/blob/main/client/src/store/store.js"

  click BE_ENTRY "https://github.com/shiksha-nath02/echoverse/blob/main/backend/index.js"
  click R_AUTH "https://github.com/shiksha-nath02/echoverse/blob/main/backend/routes/auth.js"
  click R_POSTS "https://github.com/shiksha-nath02/echoverse/blob/main/backend/routes/posts.js"
  click CTRL_AUTH "https://github.com/shiksha-nath02/echoverse/blob/main/backend/controllers/authcontroller.js"
  click CTRL_POSTS "https://github.com/shiksha-nath02/echoverse/blob/main/backend/controllers/postCtrl.js"
  click MW_JWT "https://github.com/shiksha-nath02/echoverse/blob/main/backend/middleware/auth.js"
  click SCHEMA "https://github.com/shiksha-nath02/echoverse/blob/main/backend/prisma/schema.prisma"
  click MIGR "https://github.com/shiksha-nath02/echoverse/tree/main/backend/prisma/migrations/"
  click MIG1 "https://github.com/shiksha-nath02/echoverse/blob/main/backend/prisma/migrations/20251124100816_init/migration.sql"
  click MIG2 "https://github.com/shiksha-nath02/echoverse/blob/main/backend/prisma/migrations/20251214051356_initialising/migration.sql"

  %% ========== Styles ==========
  classDef external fill:#f3f4f6,stroke:#6b7280,color:#111827,stroke-width:1px
  classDef frontend fill:#dbeafe,stroke:#1d4ed8,color:#0b1b4a,stroke-width:1px
  classDef backend fill:#dcfce7,stroke:#16a34a,color:#052e12,stroke-width:1px
  classDef security fill:#fee2e2,stroke:#dc2626,color:#450a0a,stroke-width:1px
  classDef data fill:#ffedd5,stroke:#f97316,color:#431407,stroke-width:1px
  classDef planned fill:#e5e7eb,stroke:#6b7280,color:#111827,stroke-width:1px,stroke-dasharray: 5 5
  classDef boundary fill:#ffffff,stroke:#111827,color:#111827,stroke-width:2px,stroke-dasharray: 6 4
```
