# suunidhi/campuschain_v2 architecture

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

- Interactive diagram: https://gitdiagram.com/suunidhi/campuschain_v2
- Repository: https://github.com/suunidhi/campuschain_v2

## Overview

1. **Overall shape**: This repository is split into two independently packaged apps: a Node/Express backend in `backend/` and a React/Vite single-page frontend in `frontend/`. The architecture is a standard client–server split with the frontend consuming HTTP APIs from the backend.

2. **Backend runtime and entrypoint**: `backend/server.js` is the backend bootstrap point. It is responsible for wiring the Express app together with database connectivity, authentication setup, and route registration.

3. **Backend data layer**: `backend/models/User.js` and `backend/models/Product.js` define the core persisted entities. Their presence, together with `backend/config/db.js`, indicates a model-driven persistence layer, very likely backed by MongoDB/Mongoose-style document storage.

4. **Backend authentication**: Authentication is centralized through `backend/config/passport.js` and `backend/middleware/auth.js`. Passport config suggests strategy-based login handling, while the auth middleware is the boundary that protects private API routes and enforces session/token checks.

5. **Backend API surface**: The API is organized by resource in `backend/routes/authRoutes.js`, `backend/routes/userRoutes.js`, and `backend/routes/productRoutes.js`. This suggests separate concerns for login/registration, user profile or account operations, and product/item CRUD.

6. **Backend request flow**: Requests enter the Express server, pass through auth middleware where needed, then reach route handlers, which read/write the User/Product models and return JSON responses. Protected endpoints likely depend on Passport-derived identity or request context.

7. **Frontend application shell**: The frontend is a React SPA bootstrapped from `frontend/src/main.jsx` and composed in `frontend/src/App.jsx`. It uses page-level components under `frontend/src/pages/` and shared UI in `frontend/src/components/`.

8. **Frontend navigation and screens**: The main user flows are represented by `Home`, `Login`, `Register`, `Dashboard`, `Marketplace`, `ListItem`, and `AuthCallback`. This implies the app supports onboarding/authentication, a user dashboard, a marketplace browsing experience, and a flow for creating listings.

9. **Frontend API boundary**: `frontend/src/api/axios.js` is the shared HTTP client layer, so all backend communication is funneled through a centralized Axios configuration. `frontend/src/config.js` likely holds runtime values such as backend base URLs or environment-specific settings.

10. **Client-side state and auth support**: `frontend/src/utils/storage.js` abstracts browser storage for session/auth data, and `frontend/src/utils/wallet.js` suggests wallet-related interaction or identity handling on the client. `AuthCallback.jsx` indicates the app may complete an external auth redirect or wallet-auth handshake before entering the main UI.

11. **Shared UI and presentation**: `Navbar`, `Footer`, and `PolygonBg` are reusable UI elements that frame the pages and provide consistent styling/navigation. CSS is split between global styles (`index.css`, `App.css`) and component-specific styles (`navbar.css`).

12. **Important architectural boundary**: The repo keeps backend logic, persistence, and auth enforcement entirely in `backend/`, while the React app remains a thin client concerned with routing, UI state, and calling APIs. Any architecture diagram should show the frontend talking only to the backend API, with the backend owning authorization and data access.

Main entry points: [`frontend/src/App.jsx`](https://github.com/suunidhi/campuschain_v2/blob/main/frontend/src/App.jsx) (App Shell), [`backend/server.js`](https://github.com/suunidhi/campuschain_v2/blob/main/backend/server.js) (Server), [`backend/routes/authRoutes.js`](https://github.com/suunidhi/campuschain_v2/blob/main/backend/routes/authRoutes.js) (Auth API), [`backend/routes/userRoutes.js`](https://github.com/suunidhi/campuschain_v2/blob/main/backend/routes/userRoutes.js) (User API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_backend["Backend"]
  node_backend_server["Server<br/>Express bootstrap<br/>[server.js]"]
  node_backend_db[("DB Config<br/>mongoose connect<br/>[db.js]")]
  node_backend_passport["Passport<br/>auth strategies<br/>[passport.js]"]
  node_backend_auth_mw{{"Auth MW<br/>route guard<br/>[auth.js]"}}
  node_backend_user_model["User<br/>model<br/>[User.js]"]
  node_backend_product_model["Product<br/>model<br/>[Product.js]"]
  node_backend_auth_routes["Auth API<br/>routes<br/>[authRoutes.js]"]
  node_backend_user_routes["User API<br/>routes<br/>[userRoutes.js]"]
  node_backend_product_routes["Product API<br/>routes<br/>[productRoutes.js]"]
end

subgraph group_frontend["Frontend"]
  node_frontend_main["Main<br/>React entry<br/>[main.jsx]"]
  node_frontend_app["App Shell<br/>React shell<br/>[App.jsx]"]
  node_frontend_api["API Client<br/>axios client<br/>[axios.js]"]
  node_frontend_config["Config<br/>[config.js]"]
  node_frontend_storage["Storage<br/>client state<br/>[storage.js]"]
  node_frontend_wallet["Wallet<br/>client auth<br/>[wallet.js]"]
  node_frontend_navbar["Navbar<br/>ui component<br/>[Navbar.jsx]"]
  node_frontend_footer["Footer<br/>ui component<br/>[Footer.jsx]"]
  node_frontend_bg["Bg<br/>ui component<br/>[PolygonBg.jsx]"]
  node_frontend_home["Home<br/>page<br/>[Home.jsx]"]
  node_frontend_login["Login<br/>page<br/>[Login.jsx]"]
  node_frontend_register["Register<br/>page<br/>[Register.jsx]"]
  node_frontend_dashboard["Dashboard<br/>page<br/>[Dashboard.jsx]"]
  node_frontend_marketplace["Marketplace<br/>page<br/>[Marketplace.jsx]"]
  node_frontend_listitem["List Item<br/>page<br/>[ListItem.jsx]"]
  node_frontend_callback["Auth Callback<br/>page<br/>[AuthCallback.jsx]"]
end

node_backend_server -->|"connects"| node_backend_db
node_backend_server -->|"configures"| node_backend_passport
node_backend_server -->|"mounts"| node_backend_auth_routes
node_backend_server -->|"mounts"| node_backend_user_routes
node_backend_server -->|"mounts"| node_backend_product_routes
node_backend_auth_routes -->|"uses"| node_backend_passport
node_backend_user_routes -->|"protects"| node_backend_auth_mw
node_backend_product_routes -->|"protects"| node_backend_auth_mw
node_backend_auth_routes -->|"reads/writes"| node_backend_user_model
node_backend_user_routes -->|"reads/writes"| node_backend_user_model
node_backend_product_routes -->|"reads/writes"| node_backend_product_model
node_backend_user_model -->|"persists via"| node_backend_db
node_backend_product_model -->|"persists via"| node_backend_db
node_frontend_main -->|"renders"| node_frontend_app
node_frontend_app -->|"calls"| node_frontend_api
node_frontend_app -->|"reads"| node_frontend_config
node_frontend_app -->|"uses"| node_frontend_storage
node_frontend_app -->|"uses"| node_frontend_wallet
node_frontend_app -->|"composes"| node_frontend_navbar
node_frontend_app -->|"composes"| node_frontend_footer
node_frontend_app -->|"composes"| node_frontend_bg
node_frontend_app -->|"routes to"| node_frontend_home
node_frontend_app -->|"routes to"| node_frontend_login
node_frontend_app -->|"routes to"| node_frontend_register
node_frontend_app -->|"routes to"| node_frontend_dashboard
node_frontend_app -->|"routes to"| node_frontend_marketplace
node_frontend_app -->|"routes to"| node_frontend_listitem
node_frontend_app -->|"routes to"| node_frontend_callback
node_frontend_api -->|"HTTP API"| node_backend_server
node_frontend_callback -->|"stores"| node_frontend_storage

click node_backend_server "https://github.com/suunidhi/campuschain_v2/blob/main/backend/server.js"
click node_backend_db "https://github.com/suunidhi/campuschain_v2/blob/main/backend/config/db.js"
click node_backend_passport "https://github.com/suunidhi/campuschain_v2/blob/main/backend/config/passport.js"
click node_backend_auth_mw "https://github.com/suunidhi/campuschain_v2/blob/main/backend/middleware/auth.js"
click node_backend_user_model "https://github.com/suunidhi/campuschain_v2/blob/main/backend/models/User.js"
click node_backend_product_model "https://github.com/suunidhi/campuschain_v2/blob/main/backend/models/Product.js"
click node_backend_auth_routes "https://github.com/suunidhi/campuschain_v2/blob/main/backend/routes/authRoutes.js"
click node_backend_user_routes "https://github.com/suunidhi/campuschain_v2/blob/main/backend/routes/userRoutes.js"
click node_backend_product_routes "https://github.com/suunidhi/campuschain_v2/blob/main/backend/routes/productRoutes.js"
click node_frontend_main "https://github.com/suunidhi/campuschain_v2/blob/main/frontend/src/main.jsx"
click node_frontend_app "https://github.com/suunidhi/campuschain_v2/blob/main/frontend/src/App.jsx"
click node_frontend_api "https://github.com/suunidhi/campuschain_v2/blob/main/frontend/src/api/axios.js"
click node_frontend_config "https://github.com/suunidhi/campuschain_v2/blob/main/frontend/src/config.js"
click node_frontend_storage "https://github.com/suunidhi/campuschain_v2/blob/main/frontend/src/utils/storage.js"
click node_frontend_wallet "https://github.com/suunidhi/campuschain_v2/blob/main/frontend/src/utils/wallet.js"
click node_frontend_navbar "https://github.com/suunidhi/campuschain_v2/blob/main/frontend/src/components/Navbar.jsx"
click node_frontend_footer "https://github.com/suunidhi/campuschain_v2/blob/main/frontend/src/components/Footer.jsx"
click node_frontend_bg "https://github.com/suunidhi/campuschain_v2/blob/main/frontend/src/components/PolygonBg.jsx"
click node_frontend_home "https://github.com/suunidhi/campuschain_v2/blob/main/frontend/src/pages/Home.jsx"
click node_frontend_login "https://github.com/suunidhi/campuschain_v2/blob/main/frontend/src/pages/Login.jsx"
click node_frontend_register "https://github.com/suunidhi/campuschain_v2/blob/main/frontend/src/pages/Register.jsx"
click node_frontend_dashboard "https://github.com/suunidhi/campuschain_v2/blob/main/frontend/src/pages/Dashboard.jsx"
click node_frontend_marketplace "https://github.com/suunidhi/campuschain_v2/blob/main/frontend/src/pages/Marketplace.jsx"
click node_frontend_listitem "https://github.com/suunidhi/campuschain_v2/blob/main/frontend/src/pages/ListItem.jsx"
click node_frontend_callback "https://github.com/suunidhi/campuschain_v2/blob/main/frontend/src/pages/AuthCallback.jsx"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_backend_server,node_backend_db,node_backend_passport,node_backend_auth_mw,node_backend_user_model,node_backend_product_model,node_backend_auth_routes,node_backend_user_routes,node_backend_product_routes toneBlue
class node_frontend_main,node_frontend_app,node_frontend_api,node_frontend_config,node_frontend_storage,node_frontend_wallet,node_frontend_navbar,node_frontend_footer,node_frontend_bg,node_frontend_home,node_frontend_login,node_frontend_register,node_frontend_dashboard,node_frontend_marketplace,node_frontend_listitem,node_frontend_callback toneAmber
```

## Components

### Backend

Express API, auth, and persistence

- [Server](https://github.com/suunidhi/campuschain_v2/blob/main/backend/server.js): Express bootstrap · Wires middleware, auth, database, and routes. · `backend/server.js`
- [DB Config](https://github.com/suunidhi/campuschain_v2/blob/main/backend/config/db.js): mongoose connect · Database connection setup for the backend. · `backend/config/db.js`
- [Passport](https://github.com/suunidhi/campuschain_v2/blob/main/backend/config/passport.js): auth strategies · Configures authentication strategy handling. · `backend/config/passport.js`
- [Auth MW](https://github.com/suunidhi/campuschain_v2/blob/main/backend/middleware/auth.js): route guard · Protects private routes and checks identity. · `backend/middleware/auth.js`
- [User](https://github.com/suunidhi/campuschain_v2/blob/main/backend/models/User.js): model · Persistent user/account entity. · `backend/models/User.js`
- [Product](https://github.com/suunidhi/campuschain_v2/blob/main/backend/models/Product.js): model · Persistent product/listing entity. · `backend/models/Product.js`
- [Auth API](https://github.com/suunidhi/campuschain_v2/blob/main/backend/routes/authRoutes.js): routes · Login and registration endpoints. · `backend/routes/authRoutes.js`
- [User API](https://github.com/suunidhi/campuschain_v2/blob/main/backend/routes/userRoutes.js): routes · User/account endpoints. · `backend/routes/userRoutes.js`
- [Product API](https://github.com/suunidhi/campuschain_v2/blob/main/backend/routes/productRoutes.js): routes · Product CRUD and listing endpoints. · `backend/routes/productRoutes.js`

### Frontend

React SPA and client-side flows

- [Main](https://github.com/suunidhi/campuschain_v2/blob/main/frontend/src/main.jsx): React entry · Bootstraps the SPA. · `frontend/src/main.jsx`
- [App Shell](https://github.com/suunidhi/campuschain_v2/blob/main/frontend/src/App.jsx): React shell · Top-level routing and composition. · `frontend/src/App.jsx`
- [API Client](https://github.com/suunidhi/campuschain_v2/blob/main/frontend/src/api/axios.js): axios client · Shared HTTP client for backend requests. · `frontend/src/api/axios.js`
- [Config](https://github.com/suunidhi/campuschain_v2/blob/main/frontend/src/config.js): runtime config · Frontend runtime settings and base values. · `frontend/src/config.js`
- [Storage](https://github.com/suunidhi/campuschain_v2/blob/main/frontend/src/utils/storage.js): client state · Browser storage abstraction for auth/session data. · `frontend/src/utils/storage.js`
- [Wallet](https://github.com/suunidhi/campuschain_v2/blob/main/frontend/src/utils/wallet.js): client auth · Wallet or identity interaction helpers. · `frontend/src/utils/wallet.js`
- [Navbar](https://github.com/suunidhi/campuschain_v2/blob/main/frontend/src/components/Navbar.jsx): ui component · Primary navigation bar. · `frontend/src/components/Navbar.jsx`
- [Footer](https://github.com/suunidhi/campuschain_v2/blob/main/frontend/src/components/Footer.jsx): ui component · Page footer component. · `frontend/src/components/Footer.jsx`
- [Bg](https://github.com/suunidhi/campuschain_v2/blob/main/frontend/src/components/PolygonBg.jsx): ui component · Decorative background component. · `frontend/src/components/PolygonBg.jsx`
- [Home](https://github.com/suunidhi/campuschain_v2/blob/main/frontend/src/pages/Home.jsx): page · Landing page. · `frontend/src/pages/Home.jsx`
- [Login](https://github.com/suunidhi/campuschain_v2/blob/main/frontend/src/pages/Login.jsx): page · Sign-in flow. · `frontend/src/pages/Login.jsx`
- [Register](https://github.com/suunidhi/campuschain_v2/blob/main/frontend/src/pages/Register.jsx): page · Account creation flow. · `frontend/src/pages/Register.jsx`
- [Dashboard](https://github.com/suunidhi/campuschain_v2/blob/main/frontend/src/pages/Dashboard.jsx): page · Authenticated user workspace. · `frontend/src/pages/Dashboard.jsx`
- [Marketplace](https://github.com/suunidhi/campuschain_v2/blob/main/frontend/src/pages/Marketplace.jsx): page · Browse listings and products. · `frontend/src/pages/Marketplace.jsx`
- [List Item](https://github.com/suunidhi/campuschain_v2/blob/main/frontend/src/pages/ListItem.jsx): page · Create a new listing. · `frontend/src/pages/ListItem.jsx`
- [Auth Callback](https://github.com/suunidhi/campuschain_v2/blob/main/frontend/src/pages/AuthCallback.jsx): page · Completes redirect-based auth or handshake. · `frontend/src/pages/AuthCallback.jsx`

## Connections

- Server → DB Config: connects · Initializes persistence before serving requests.
- Server → Passport: configures · Registers authentication strategy setup.
- Server → Auth API: mounts · Exposes auth endpoints.
- Server → User API: mounts · Exposes user endpoints.
- Server → Product API: mounts · Exposes product endpoints.
- Auth API → Passport: uses · Delegates login/auth flow handling.
- User API → Auth MW: protects · Applies request guards to private user routes.
- Product API → Auth MW: protects · Applies request guards to private product routes.
- Auth API → User: reads/writes · Creates and validates user records.
- User API → User: reads/writes · Loads and updates account data.
- Product API → Product: reads/writes · Creates and queries product data.
- User → DB Config: persists via · Stored through the configured database layer.
- Product → DB Config: persists via · Stored through the configured database layer.
- Main → App Shell: renders · Starts the application shell.
- App Shell → API Client: calls · Uses shared API client for backend communication.
- App Shell → Config: reads · Consumes runtime configuration.
- App Shell → Storage: uses · Loads and stores session/auth data.
- App Shell → Wallet: uses · Supports wallet or external identity flows.
- App Shell → Navbar: composes · Includes shared navigation.
- App Shell → Footer: composes · Includes shared footer.
- App Shell → Bg: composes · Includes decorative background.
- App Shell → Home: routes to · Hosts the landing screen.
- App Shell → Login: routes to · Hosts sign-in flow.
- App Shell → Register: routes to · Hosts registration flow.
- App Shell → Dashboard: routes to · Hosts authenticated workspace.
- App Shell → Marketplace: routes to · Hosts marketplace browsing.
- App Shell → List Item: routes to · Hosts listing creation.
- App Shell → Auth Callback: routes to · Completes redirect-based auth flow.
- API Client → Server: HTTP API · Frontend talks to backend over HTTP.
- Auth Callback → Storage: stores · Persists auth/session result after callback.
