# nishant28-sh/tradetogether architecture

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

- Interactive diagram: https://gitdiagram.com/nishant28-sh/tradetogether
- Repository: https://github.com/nishant28-sh/tradetogether

## Overview

1. **Overall shape**
   TradeTogether is a split full-stack MERN application: a React SPA in `Frontend/my-app` talks to a Node.js/Express API in `backend`, with MongoDB as the primary persistence layer. The frontend and backend are deployed separately on Render and connected through an environment-configured API URL.

2. **Frontend application boundary**
   The UI is organized as a single-page app with `src/index.js` and `src/App.js` as the entry points. `src/api.js` centralizes backend calls, and `UserContext.js` carries logged-in user state across the app. Presentation is split into feature-oriented component folders rather than a single monolithic pages directory.

3. **Frontend feature subsystems**
   The React side is divided by domain: authentication (`Auth`), product browsing (`Product`), trading (`Trade`), chat (`Chat`), community (`Community`), gamification (`Gamification`), mentorship (`Mentorship`), user profiles (`User`), and admin UI (`AdminDashboard`). The app also has page-level entry points under `src/Pages` such as `Shop`, `TradePage`, `Challenges`, and community creation/detail screens.

4. **Authentication and session flow**
   Login and registration are handled in the frontend via `AuthBox`, `Login`, and `Register`, then validated by the backend through the user API and JWT-based auth. The backend’s `middleware/auth.js` acts as the protected-route boundary, so authenticated requests are separated from public browsing and signup flows.

5. **Commerce/catalog subsystem**
   Products are modeled, routed, and controlled on the backend through `Product` model, `productRoutes`, and `productController`. On the frontend, `ProductList`, `ProductDetail`, `CreativeTreasures`, and `Shop` provide browse/search/detail screens. This is the main read-heavy flow: UI → product API → MongoDB → rendered catalog.

6. **Barter and trade workflow**
   Trading is a distinct first-class subsystem rather than a feature layered onto products. `TradeDashboard`, `TradePage`, `tradeRoutes`, `tradeController`, and the `Trade` model suggest a proposal/negotiation flow centered on product-for-product exchanges. The presence of `Wishlist` in the community area also supports trade intent and item tracking.

7. **Community, events, and announcements**
   Community interaction is modeled separately with `Community`, `Event`, `Announcement`, and corresponding controllers/routes. Frontend screens like `CommunityShowcase`, `CommunityWelcome`, `CommunityDetail`, `CreateCommunity`, and `CreateEvent` indicate users can join or browse communities and participate in event/announcement-driven engagement.

8. **Realtime chat subsystem**
   Chat is the main realtime boundary in the app. The frontend `ChatPage` connects to a Socket.io-backed server module in `backend/socket/chat.js`, while chat messages are persisted via the `ChatMessage` model. The `notification-18-270129.mp3` asset suggests the UI provides audible message notification feedback.

9. **Gamification and engagement**
   Engagement mechanics are isolated in the `GamificationHub` and `Challenges` screens, backed by the `Challenge` model and `challengeRoutes`/`challengeController`. This subsystem likely awards points/badges or tracks challenge completion, and it is separate from core commerce so it can evolve independently.

10. **Mentorship and profile layer**
   User identity is not just basic auth; there are dedicated profile views (`Profile`, `ArtisanProfile`) and a mentorship hub (`MentorshipHub`). These screens sit on top of the user data model and provide the social/mentor-facing layer of the platform.

11. **Admin, moderation, and operational tooling**
   `AdminDashboard` is the main control surface for platform management, supported by `reportController`, `Report` model, `userController`, and utility scripts like `createAdminUser.js` and `deleteTestUsers.js`. This suggests a separation between normal user flows and privileged moderation/maintenance flows.

12. **Persistence, uploads, and data seeding**
   MongoDB stores the domain entities: users, products, communities, trades, chat messages, events, challenges, reports, announcements, and wishlists. File uploads are handled through `middleware/upload.js` and stored under `backend/uploads/profilePhotos`, which makes profile/media handling a separate storage concern from normal document data. Seed scripts (`seedUsersAndProducts.js`, `seedCommunities.js`, `seedCommunityData.js`) indicate the app can be bootstrapped with demo content.

13. **Deployment and hosting boundaries**
   The frontend is configured for static hosting with `public/_redirects`, while the backend runs as an API service. Environment variables wire the services together (`CLIENT_URL` on the backend and `REACT_APP_API_URL` on the frontend), which is important for diagramming the cross-service dependency between the browser, API, and realtime socket layer.

Main entry points: [`Frontend/my-app/src/App.js`](https://github.com/nishant28-sh/tradetogether/blob/main/Frontend/my-app/src/App.js) (Main app), [`backend/server.js`](https://github.com/nishant28-sh/tradetogether/blob/main/backend/server.js) (API server), [`Frontend/my-app/src/api.js`](https://github.com/nishant28-sh/tradetogether/blob/main/Frontend/my-app/src/api.js) (API client), [`backend/middleware/upload.js`](https://github.com/nishant28-sh/tradetogether/blob/main/backend/middleware/upload.js) (Upload middleware)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend SPA"]
  node_fe_entry["App shell<br/>React entry<br/>[index.js]"]
  node_fe_app["Main app<br/>React shell<br/>[App.js]"]
  node_fe_api["API client<br/>HTTP client<br/>[api.js]"]
  node_fe_userctx(("User context<br/>state context<br/>[UserContext.js]"))
  node_fe_auth["Auth flow<br/>auth UI<br/>[AuthBox.jsx]"]
  node_fe_shop["Catalog UI<br/>browse UI<br/>[ProductList.jsx]"]
  node_fe_trade["Trade UI<br/>exchange UI<br/>[TradeDashboard.jsx]"]
  node_fe_community["Community UI"]
  node_fe_chat["Chat page<br/>realtime UI<br/>[ChatPage.jsx]"]
  node_fe_gamify["Challenges<br/>engagement UI"]
  node_fe_mentorship["Mentorship hub<br/>mentor UI<br/>[MentorshipHub.jsx]"]
  node_fe_admin["Admin dashboard<br/>admin UI<br/>[AdminDashboard.jsx]"]
end

subgraph group_backend["Backend API"]
  node_be_server["API server<br/>Express app<br/>[server.js]"]
  node_be_auth{{"Auth middleware<br/>route guard<br/>[auth.js]"}}
  node_be_upload{{"Upload middleware<br/>file upload<br/>[upload.js]"}}
  node_be_users["Users<br/>user API<br/>[userController.js]"]
  node_be_products["Products<br/>catalog API"]
  node_be_trades["Trades<br/>exchange API<br/>[tradeController.js]"]
  node_be_community["Community"]
  node_be_chat{{"Chat socket<br/>socket.io<br/>[chat.js]"}}
  node_be_challenges["Challenges<br/>gamification API"]
  node_be_reports["Moderation<br/>admin API"]
end

subgraph group_runtime["Runtime & Deployment"]
  node_data_store[("MongoDB<br/>document store")]
  node_file_store["Uploads<br/>asset storage"]
  node_deploy(("Render deploy<br/>hosting"))
end

node_fe_entry -->|"boots"| node_fe_app
node_fe_app -->|"uses"| node_fe_api
node_fe_app -->|"shares state"| node_fe_userctx
node_fe_app -->|"renders"| node_fe_auth
node_fe_app -->|"renders"| node_fe_shop
node_fe_app -->|"renders"| node_fe_trade
node_fe_app -->|"renders"| node_fe_community
node_fe_app -->|"renders"| node_fe_chat
node_fe_app -->|"renders"| node_fe_gamify
node_fe_app -->|"renders"| node_fe_mentorship
node_fe_app -->|"renders"| node_fe_admin
node_fe_api -->|"HTTP"| node_be_server
node_be_server -->|"protects"| node_be_auth
node_be_server -->|"routes"| node_be_users
node_be_server -->|"routes"| node_be_products
node_be_server -->|"routes"| node_be_trades
node_be_server -->|"routes"| node_be_community
node_be_server -->|"routes"| node_be_challenges
node_be_server -->|"routes"| node_be_reports
node_be_server -->|"uses"| node_be_upload
node_be_server -->|"hosts"| node_be_chat
node_be_users -->|"persists"| node_data_store
node_be_products -->|"persists"| node_data_store
node_be_trades -->|"persists"| node_data_store
node_be_community -->|"persists"| node_data_store
node_be_challenges -->|"persists"| node_data_store
node_be_reports -->|"persists"| node_data_store
node_be_chat -->|"persists"| node_data_store
node_be_upload -->|"writes"| node_file_store
node_deploy -->|"hosts"| node_fe_app
node_deploy -->|"hosts"| node_be_server

click node_fe_entry "https://github.com/nishant28-sh/tradetogether/blob/main/Frontend/my-app/src/index.js"
click node_fe_app "https://github.com/nishant28-sh/tradetogether/blob/main/Frontend/my-app/src/App.js"
click node_fe_api "https://github.com/nishant28-sh/tradetogether/blob/main/Frontend/my-app/src/api.js"
click node_fe_userctx "https://github.com/nishant28-sh/tradetogether/blob/main/Frontend/my-app/src/UserContext.js"
click node_fe_auth "https://github.com/nishant28-sh/tradetogether/blob/main/Frontend/my-app/src/Components/Auth/AuthBox.jsx"
click node_fe_shop "https://github.com/nishant28-sh/tradetogether/blob/main/Frontend/my-app/src/Components/Product/ProductList.jsx"
click node_fe_trade "https://github.com/nishant28-sh/tradetogether/blob/main/Frontend/my-app/src/Components/Trade/TradeDashboard.jsx"
click node_fe_community "https://github.com/nishant28-sh/tradetogether/blob/main/Frontend/my-app/src/Components/Community/CommunityShowcase.jsx"
click node_fe_chat "https://github.com/nishant28-sh/tradetogether/blob/main/Frontend/my-app/src/Components/Chat/ChatPage.jsx"
click node_fe_gamify "https://github.com/nishant28-sh/tradetogether/blob/main/Frontend/my-app/src/Components/Gamification/GamificationHub.jsx"
click node_fe_mentorship "https://github.com/nishant28-sh/tradetogether/blob/main/Frontend/my-app/src/Components/Mentorship/MentorshipHub.jsx"
click node_fe_admin "https://github.com/nishant28-sh/tradetogether/blob/main/Frontend/my-app/src/Components/AdminDashboard.jsx"
click node_be_server "https://github.com/nishant28-sh/tradetogether/blob/main/backend/server.js"
click node_be_auth "https://github.com/nishant28-sh/tradetogether/blob/main/backend/middleware/auth.js"
click node_be_upload "https://github.com/nishant28-sh/tradetogether/blob/main/backend/middleware/upload.js"
click node_be_users "https://github.com/nishant28-sh/tradetogether/blob/main/backend/controllers/userController.js"
click node_be_products "https://github.com/nishant28-sh/tradetogether/blob/main/backend/controllers/productController.js"
click node_be_trades "https://github.com/nishant28-sh/tradetogether/blob/main/backend/controllers/tradeController.js"
click node_be_community "https://github.com/nishant28-sh/tradetogether/blob/main/backend/controllers/communityController.js"
click node_be_chat "https://github.com/nishant28-sh/tradetogether/blob/main/backend/socket/chat.js"
click node_be_challenges "https://github.com/nishant28-sh/tradetogether/blob/main/backend/controllers/challengeController.js"
click node_be_reports "https://github.com/nishant28-sh/tradetogether/blob/main/backend/controllers/reportController.js"
click node_file_store "https://github.com/nishant28-sh/tradetogether/tree/main/backend/uploads/profilePhotos"

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_fe_entry,node_fe_app,node_fe_api,node_fe_userctx,node_fe_auth,node_fe_shop,node_fe_trade,node_fe_community,node_fe_chat,node_fe_gamify,node_fe_mentorship,node_fe_admin toneBlue
class node_be_server,node_be_auth,node_be_upload,node_be_users,node_be_products,node_be_trades,node_be_community,node_be_chat,node_be_challenges,node_be_reports toneAmber
class node_data_store,node_file_store,node_deploy toneMint
```

## Components

### Frontend SPA

React single-page app in Frontend/my-app

- [App shell](https://github.com/nishant28-sh/tradetogether/blob/main/Frontend/my-app/src/index.js): React entry · Bootstraps the SPA and top-level routing · `Frontend/my-app/src/index.js`
- [Main app](https://github.com/nishant28-sh/tradetogether/blob/main/Frontend/my-app/src/App.js): React shell · Global app composition and screen orchestration · `Frontend/my-app/src/App.js`
- [API client](https://github.com/nishant28-sh/tradetogether/blob/main/Frontend/my-app/src/api.js): HTTP client · Centralized frontend calls into the backend · `Frontend/my-app/src/api.js`
- [User context](https://github.com/nishant28-sh/tradetogether/blob/main/Frontend/my-app/src/UserContext.js): state context · Carries authenticated user state across the UI · `Frontend/my-app/src/UserContext.js`
- [Auth flow](https://github.com/nishant28-sh/tradetogether/blob/main/Frontend/my-app/src/Components/Auth/AuthBox.jsx): auth UI · Login and registration entry points · `Frontend/my-app/src/Components/Auth/AuthBox.jsx`
- [Catalog UI](https://github.com/nishant28-sh/tradetogether/blob/main/Frontend/my-app/src/Components/Product/ProductList.jsx): browse UI · Product browsing, detail, and shop screens · `Frontend/my-app/src/Components/Product/ProductList.jsx`
- [Trade UI](https://github.com/nishant28-sh/tradetogether/blob/main/Frontend/my-app/src/Components/Trade/TradeDashboard.jsx): exchange UI · Trade dashboard and trade page surfaces · `Frontend/my-app/src/Components/Trade/TradeDashboard.jsx`
- [Community UI](https://github.com/nishant28-sh/tradetogether/blob/main/Frontend/my-app/src/Components/Community/CommunityShowcase.jsx): community UI · Community browsing, creation, wishlist, and detail screens · `Frontend/my-app/src/Components/Community/CommunityShowcase.jsx`
- [Chat page](https://github.com/nishant28-sh/tradetogether/blob/main/Frontend/my-app/src/Components/Chat/ChatPage.jsx): realtime UI · Socket-backed messaging interface · `Frontend/my-app/src/Components/Chat/ChatPage.jsx`
- [Challenges](https://github.com/nishant28-sh/tradetogether/blob/main/Frontend/my-app/src/Components/Gamification/GamificationHub.jsx): engagement UI · Gamification hub and challenge screens · `Frontend/my-app/src/Components/Gamification/GamificationHub.jsx`
- [Mentorship hub](https://github.com/nishant28-sh/tradetogether/blob/main/Frontend/my-app/src/Components/Mentorship/MentorshipHub.jsx): mentor UI · Mentorship and profile-oriented experience · `Frontend/my-app/src/Components/Mentorship/MentorshipHub.jsx`
- [Admin dashboard](https://github.com/nishant28-sh/tradetogether/blob/main/Frontend/my-app/src/Components/AdminDashboard.jsx): admin UI · Privileged moderation and operational control surface · `Frontend/my-app/src/Components/AdminDashboard.jsx`

### Backend API

Node.js/Express service in backend

- [API server](https://github.com/nishant28-sh/tradetogether/blob/main/backend/server.js): Express app · HTTP server, routing, and service composition · `backend/server.js`
- [Auth middleware](https://github.com/nishant28-sh/tradetogether/blob/main/backend/middleware/auth.js): route guard · Protected-route boundary for authenticated requests · `backend/middleware/auth.js`
- [Upload middleware](https://github.com/nishant28-sh/tradetogether/blob/main/backend/middleware/upload.js): file upload · Handles media and profile photo uploads · `backend/middleware/upload.js`
- [Users](https://github.com/nishant28-sh/tradetogether/blob/main/backend/controllers/userController.js): user API · User profiles, auth, and account operations · `backend/controllers/userController.js`
- [Products](https://github.com/nishant28-sh/tradetogether/blob/main/backend/controllers/productController.js): catalog API · Product model access and catalog operations · `backend/controllers/productController.js`
- [Trades](https://github.com/nishant28-sh/tradetogether/blob/main/backend/controllers/tradeController.js): exchange API · Trade proposal and negotiation operations · `backend/controllers/tradeController.js`
- [Community](https://github.com/nishant28-sh/tradetogether/blob/main/backend/controllers/communityController.js): community API · Communities, events, announcements, and feed-related operations · `backend/controllers/communityController.js`
- [Chat socket](https://github.com/nishant28-sh/tradetogether/blob/main/backend/socket/chat.js): socket.io · Realtime chat server module · `backend/socket/chat.js`
- [Challenges](https://github.com/nishant28-sh/tradetogether/blob/main/backend/controllers/challengeController.js): gamification API · Challenge lifecycle and progress operations · `backend/controllers/challengeController.js`
- [Moderation](https://github.com/nishant28-sh/tradetogether/blob/main/backend/controllers/reportController.js): admin API · Reports and admin moderation operations · `backend/controllers/reportController.js`

### Runtime & Deployment

Cross-cutting runtime, realtime, storage, and hosting boundaries

- **MongoDB**: document store · Primary persistence for users, products, trades, communities, chat, and reports
- [Uploads](https://github.com/nishant28-sh/tradetogether/tree/main/backend/uploads/profilePhotos): asset storage · Stored media files and profile photos · `backend/uploads/profilePhotos`
- **Render deploy**: hosting · Separate frontend and backend deployment boundary

## Connections

- App shell → Main app: boots · Entry loads the application shell
- Main app → API client: uses · App components call the centralized API client
- Main app → User context: shares state · Application state is propagated through user context
- Main app → Auth flow: renders · App exposes login and registration flow
- Main app → Catalog UI: renders · App exposes catalog browsing screens
- Main app → Trade UI: renders · App exposes trading screens
- Main app → Community UI: renders · App exposes community screens
- Main app → Chat page: renders · App exposes chat interface
- Main app → Challenges: renders · App exposes challenge and engagement screens
- Main app → Mentorship hub: renders · App exposes mentorship and profiles
- Main app → Admin dashboard: renders · App exposes admin dashboard
- API client → API server: HTTP · Frontend API client calls the backend service
- API server → Auth middleware: protects · Server applies auth middleware to private routes
- API server → Users: routes · Server exposes user operations
- API server → Products: routes · Server exposes catalog operations
- API server → Trades: routes · Server exposes trade operations
- API server → Community: routes · Server exposes community-related operations
- API server → Challenges: routes · Server exposes challenge operations
- API server → Moderation: routes · Server exposes moderation operations
- API server → Upload middleware: uses · Server accepts uploads through middleware
- API server → Chat socket: hosts · Server hosts the realtime chat module
- Users → MongoDB: persists · User data is stored in MongoDB
- Products → MongoDB: persists · Products are stored in MongoDB
- Trades → MongoDB: persists · Trade records are stored in MongoDB
- Community → MongoDB: persists · Communities, events, announcements, and feeds are stored in MongoDB
- Challenges → MongoDB: persists · Challenge data is stored in MongoDB
- Moderation → MongoDB: persists · Reports are stored in MongoDB
- Chat socket → MongoDB: persists · Chat messages are stored in MongoDB
- Upload middleware → Uploads: writes · Uploads are written to profile-photo storage
- Render deploy → Main app: hosts · Frontend is deployed as a separate SPA service
- Render deploy → API server: hosts · Backend is deployed as a separate API service
