# mourya2044/indipostcollectv2 architecture

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

- Interactive diagram: https://gitdiagram.com/mourya2044/indipostcollectv2
- Repository: https://github.com/mourya2044/indipostcollectv2

## Overview

1. **Overall shape**
   - This is a two-tier monorepo: a **React/Vite frontend** in `frontend/` and an **Express/Node backend** in `backend/`.
   - The frontend is a thin presentation layer; most business rules, persistence, auth, AI calls, payments, and media handling happen in the backend.

2. **Frontend application boundary**
   - The frontend is organized around route-level pages in `src/pages/` and reusable UI in `src/components/`.
   - `AppRoutes.jsx` and `main.jsx` define the client-side navigation shell.
   - `src/lib/axios.js`, `src/queries/`, and `src/store/useAuthStore.js` show the main client data layer: Axios for API calls, React Query for server state, and Zustand for auth/session state.

3. **Backend API structure**
   - The backend follows a classic modular MVC-ish split:
     - `routes/` exposes HTTP endpoints,
     - `controllers/` handle request/response logic,
     - `services/` contain business logic,
     - `models/` define Mongoose schemas,
     - `lib/` holds shared initializers and third-party clients,
     - `middlewares/` enforce request guards.
   - `src/index.js` is the server entry point and likely wires Express, logging, middleware, routes, and DB startup together.

4. **Persistence and domain model**
   - MongoDB is the primary datastore via Mongoose (`lib/db.js`).
   - The model set shows the core business domains:
     - identity/auth: `user`, `token`, `verification`
     - catalog/commerce: `stamp`, `order`, `cart`-related flow
     - content/community: `post`, `comment`
     - events: `event`, `eventRegistration`
     - AI chat history: `aichatsession`, `archieved_messaged`
   - This suggests the backend is stateful across users, collectibles, orders, and AI conversations.

5. **Authentication and account lifecycle**
   - Auth is a dedicated subsystem with `auth.routes.js`, `auth.controller.js`, and `auth.middleware.js`.
   - The README indicates JWT-based auth with secure cookies, plus email verification and reset flows.
   - Supporting utilities like `sendEmail.js` and `sendResetEmail.js`, along with `token` and `verification` models, imply OTP/verification and password recovery are first-class workflows.

6. **Media and profile assets**
   - `lib/cloudinary.js` indicates Cloudinary is the external storage boundary for uploaded images.
   - This likely covers user avatars and stamp images, which are central to the product.
   - The frontend has a `ProfilePhotoSelector` and pages that depend on image-centric workflows, reinforcing Cloudinary as the media pipeline.

7. **AI subsystem**
   - AI is isolated into its own route/controller/service stack: `ai.routes.js`, `ai.controller.js`, `ai.service.js`, and `lib/ai.js`.
   - The tests (`aichat.test.js`, `funcalling.test.js`, `multimodal.test.js`, `systemconfig.test.js`) show three AI capabilities:
     - conversational chat,
     - function/tool calling,
     - multimodal image understanding.
   - The README and file names indicate LangChain/OpenRouter-backed LLM orchestration, with schema validation for structured outputs.

8. **AI stamp recognition flow**
   - The main AI product feature is stamp recognition from uploaded images with optional text clues.
   - The likely data path is: frontend upload/input → backend AI endpoint → vision model inference → structured stamp metadata/story returned to the client.
   - The returned data includes catalog-like fields such as title, country, year, condition, thematic tags, and narrative text, which feeds the collector experience and possibly stamp detail pages.

9. **Marketplace, cart, order, and Stripe**
   - Commerce is split across `cart`, `order`, and `stripe` routes/controllers.
   - Stripe is the payment boundary; backend handles checkout/payment lifecycle, while the frontend has dedicated `CartPage`, `CheckoutPage`, and payment outcome pages.
   - `order.model.js` suggests server-side order persistence and post-payment tracking rather than a purely client-managed cart.

10. **Community, posts, and social content**
   - The community subsystem uses `post`, `comment`, and frontend community components/pages.
   - This likely supports a social feed for collectors, post creation, and discussion around stamps or collection items.
   - `src/queries/postsQuery.js` suggests server state for posts is normalized and fetched through a dedicated API slice.

11. **Events and admin management**
   - Events are a separate domain with `event.routes.js`, `event.controller.js`, `event.model.js`, and `eventRegistration.model.js`.
   - The frontend has `EventsPage` plus admin-oriented components for `EventManagement`.
   - There is also `StampsManagement` in the admin UI, implying privileged CRUD views for catalog and event operations.

12. **User dashboard and profile surfaces**
   - `ProfilePage` is composed from dedicated subviews for posts, orders, and events.
   - This shows the user dashboard is an aggregation layer over multiple backend domains rather than a standalone data source.
   - The frontend also includes layout components like `AuthLayout` and `ProfileLayout`, which separate public, auth, and account-management navigation.

13. **Operational and deployment boundaries**
   - `nginx.conf` suggests production traffic may be served through Nginx as a reverse proxy and/or SPA host.
   - `.github/workflows/deploy.yml` indicates CI/CD automation, and `frontend/vercel.json` shows the frontend has explicit Vercel deployment configuration.
   - The deployment boundary therefore spans at least frontend hosting plus backend API hosting, with environment variables required for MongoDB, JWT, Cloudinary, OpenRouter, Stripe, and email.

14. **What an architecture diagram should emphasize**
   - Draw the system as a **React client** calling an **Express API**.
   - Inside the backend, show distinct service lines for **auth**, **AI**, **commerce/payment**, **community/posts**, **events**, and **profile/media**.
   - Show MongoDB as the central persistence layer, Cloudinary as the image asset store, Stripe as the payment processor, and the LLM provider/OpenRouter as the AI external dependency.

Main entry points: [`backend/src/routes`](https://github.com/mourya2044/indipostcollectv2/tree/main/backend/src/routes) (API routes), [`frontend/src/pages`](https://github.com/mourya2044/indipostcollectv2/tree/main/frontend/src/pages) (Pages), [`backend/src/models`](https://github.com/mourya2044/indipostcollectv2/tree/main/backend/src/models) (Mongo models), [`backend/src/lib`](https://github.com/mourya2044/indipostcollectv2/tree/main/backend/src/lib) (Backend lib)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_frontend_shell["App shell<br/>React router shell<br/>[main.jsx]"]
  node_frontend_routes["Routes<br/>page routing<br/>[AppRoutes.jsx]"]
  node_frontend_pages["Pages<br/>route views"]
  node_frontend_ui["UI components<br/>shared UI"]
  node_frontend_data["Client data<br/>API state<br/>[axios.js]"]
end

subgraph group_backend["Backend"]
  node_backend_entry["Server entry<br/>Express bootstrap<br/>[index.js]"]
  node_backend_routes["API routes<br/>HTTP layer"]
  node_backend_auth["Auth stack<br/>identity flow<br/>[auth.routes.js]"]
  node_backend_ai["AI stack<br/>LLM orchestration<br/>[ai.routes.js]"]
  node_backend_commerce["Commerce<br/>cart/order/payment<br/>[cart.routes.js]"]
  node_backend_content["Content<br/>community domain<br/>[post.routes.js]"]
  node_backend_events["Events<br/>[event.routes.js]"]
  node_backend_models[("Mongo models<br/>Mongoose schemas")]
  node_backend_services["Core services<br/>business logic<br/>[ai.service.js]"]
  node_backend_lib["Backend lib<br/>integrations"]
  node_backend_middlewares["Middleware<br/>request guards<br/>[auth.middleware.js]"]
  node_backend_utils["Email utils<br/>account workflows<br/>[sendEmail.js]"]
end

subgraph group_external["External services"]
  node_mongo[("MongoDB<br/>database")]
  node_cloudinary[("Cloudinary<br/>media storage")]
  node_stripe["Stripe<br/>payments"]
  node_llm{{"LLM provider<br/>OpenRouter/LangChain"}}
  node_email["Email service<br/>SMTP/email"]
end

node_frontend_shell -->|"mounts"| node_frontend_routes
node_frontend_routes -->|"renders"| node_frontend_pages
node_frontend_pages -->|"composes"| node_frontend_ui
node_frontend_pages -->|"fetches via"| node_frontend_data
node_frontend_data -->|"calls API"| node_backend_entry
node_backend_entry -->|"registers"| node_backend_routes
node_backend_routes -->|"exposes"| node_backend_auth
node_backend_routes -->|"exposes"| node_backend_ai
node_backend_routes -->|"exposes"| node_backend_commerce
node_backend_routes -->|"exposes"| node_backend_content
node_backend_routes -->|"exposes"| node_backend_events
node_backend_routes -.->|"protects with"| node_backend_middlewares
node_backend_auth -->|"reads/writes"| node_backend_models
node_backend_auth -->|"sends emails"| node_backend_utils
node_backend_ai -->|"delegates to"| node_backend_services
node_backend_ai -->|"stores chats"| node_backend_models
node_backend_commerce -->|"reads/writes"| node_backend_models
node_backend_commerce -->|"charges via"| node_stripe
node_backend_content -->|"reads/writes"| node_backend_models
node_backend_events -->|"reads/writes"| node_backend_models
node_backend_lib -->|"connects to"| node_mongo
node_backend_lib -->|"uploads to"| node_cloudinary
node_backend_lib -->|"integrates with"| node_llm
node_backend_utils -->|"delivers via"| node_email
node_backend_models -->|"persists in"| node_mongo
node_frontend_pages -.->|"uploads images"| node_cloudinary
node_frontend_pages -.->|"checkout redirect"| node_stripe
node_frontend_pages -.->|"AI results"| node_llm

click node_frontend_shell "https://github.com/mourya2044/indipostcollectv2/blob/main/frontend/src/main.jsx"
click node_frontend_routes "https://github.com/mourya2044/indipostcollectv2/blob/main/frontend/src/AppRoutes.jsx"
click node_frontend_pages "https://github.com/mourya2044/indipostcollectv2/tree/main/frontend/src/pages"
click node_frontend_ui "https://github.com/mourya2044/indipostcollectv2/tree/main/frontend/src/components"
click node_frontend_data "https://github.com/mourya2044/indipostcollectv2/blob/main/frontend/src/lib/axios.js"
click node_backend_entry "https://github.com/mourya2044/indipostcollectv2/blob/main/backend/src/index.js"
click node_backend_routes "https://github.com/mourya2044/indipostcollectv2/tree/main/backend/src/routes"
click node_backend_auth "https://github.com/mourya2044/indipostcollectv2/blob/main/backend/src/routes/auth.routes.js"
click node_backend_ai "https://github.com/mourya2044/indipostcollectv2/blob/main/backend/src/routes/ai.routes.js"
click node_backend_commerce "https://github.com/mourya2044/indipostcollectv2/blob/main/backend/src/routes/cart.routes.js"
click node_backend_content "https://github.com/mourya2044/indipostcollectv2/blob/main/backend/src/routes/post.routes.js"
click node_backend_events "https://github.com/mourya2044/indipostcollectv2/blob/main/backend/src/routes/event.routes.js"
click node_backend_models "https://github.com/mourya2044/indipostcollectv2/tree/main/backend/src/models"
click node_backend_services "https://github.com/mourya2044/indipostcollectv2/blob/main/backend/src/services/ai.service.js"
click node_backend_lib "https://github.com/mourya2044/indipostcollectv2/tree/main/backend/src/lib"
click node_backend_middlewares "https://github.com/mourya2044/indipostcollectv2/blob/main/backend/src/middlewares/auth.middleware.js"
click node_backend_utils "https://github.com/mourya2044/indipostcollectv2/blob/main/backend/src/utils/sendEmail.js"

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_frontend_shell,node_frontend_routes,node_frontend_pages,node_frontend_ui,node_frontend_data toneBlue
class node_backend_entry,node_backend_routes,node_backend_auth,node_backend_ai,node_backend_commerce,node_backend_content,node_backend_events,node_backend_models,node_backend_services,node_backend_lib,node_backend_middlewares,node_backend_utils toneAmber
class node_mongo,node_cloudinary,node_stripe,node_llm,node_email toneMint
```

## Components

### Frontend

React/Vite client and presentation layer

- [App shell](https://github.com/mourya2044/indipostcollectv2/blob/main/frontend/src/main.jsx): React router shell · Bootstraps the SPA and client-side navigation · `frontend/src/main.jsx`
- [Routes](https://github.com/mourya2044/indipostcollectv2/blob/main/frontend/src/AppRoutes.jsx): page routing · Defines top-level client routes and layout composition · `frontend/src/AppRoutes.jsx`
- [Pages](https://github.com/mourya2044/indipostcollectv2/tree/main/frontend/src/pages): route views · Home, marketplace, community, profile, auth, events, AI, and payment screens · `frontend/src/pages`
- [UI components](https://github.com/mourya2044/indipostcollectv2/tree/main/frontend/src/components): shared UI · Reusable components for navigation, community, stamps, profile, admin, and forms · `frontend/src/components`
- [Client data](https://github.com/mourya2044/indipostcollectv2/blob/main/frontend/src/lib/axios.js): API state · Axios client, query layer, and auth/session store · `frontend/src/lib/axios.js`

### Backend

Express API, business logic, and persistence

- [Server entry](https://github.com/mourya2044/indipostcollectv2/blob/main/backend/src/index.js): Express bootstrap · Starts the API server and wires middleware, routes, and startup initialization · `backend/src/index.js`
- [API routes](https://github.com/mourya2044/indipostcollectv2/tree/main/backend/src/routes): HTTP layer · Public endpoint boundaries for auth, AI, stamps, posts, cart, orders, events, and payments · `backend/src/routes`
- [Auth stack](https://github.com/mourya2044/indipostcollectv2/blob/main/backend/src/routes/auth.routes.js): identity flow · Login, signup, verification, reset, and session protection · `backend/src/routes/auth.routes.js`
- [AI stack](https://github.com/mourya2044/indipostcollectv2/blob/main/backend/src/routes/ai.routes.js): LLM orchestration · Chat, tool calling, multimodal stamp recognition, and structured AI responses · `backend/src/routes/ai.routes.js`
- [Commerce](https://github.com/mourya2044/indipostcollectv2/blob/main/backend/src/routes/cart.routes.js): cart/order/payment · Cart, order persistence, and Stripe-backed checkout flow · `backend/src/routes/cart.routes.js`
- [Content](https://github.com/mourya2044/indipostcollectv2/blob/main/backend/src/routes/post.routes.js): community domain · Posts, comments, and stamp catalog endpoints · `backend/src/routes/post.routes.js`
- [Events](https://github.com/mourya2044/indipostcollectv2/blob/main/backend/src/routes/event.routes.js): events domain · Event CRUD and registration management · `backend/src/routes/event.routes.js`
- [Mongo models](https://github.com/mourya2044/indipostcollectv2/tree/main/backend/src/models): Mongoose schemas · Users, tokens, verification, stamps, posts, comments, orders, events, registrations, and AI chat history · `backend/src/models`
- [Core services](https://github.com/mourya2044/indipostcollectv2/blob/main/backend/src/services/ai.service.js): business logic · Reusable service layer, especially AI inference and response shaping · `backend/src/services/ai.service.js`
- [Backend lib](https://github.com/mourya2044/indipostcollectv2/tree/main/backend/src/lib): integrations · MongoDB, Cloudinary, and AI client initialization · `backend/src/lib`
- [Middleware](https://github.com/mourya2044/indipostcollectv2/blob/main/backend/src/middlewares/auth.middleware.js): request guards · Auth and request protection for protected endpoints · `backend/src/middlewares/auth.middleware.js`
- [Email utils](https://github.com/mourya2044/indipostcollectv2/blob/main/backend/src/utils/sendEmail.js): account workflows · Verification and password reset email helpers · `backend/src/utils/sendEmail.js`

### External services

Third-party systems used by the app

- **MongoDB**: database · Primary persistence for users, content, commerce, events, and AI chats
- **Cloudinary**: media storage · Image upload and profile/stamp asset storage
- **Stripe**: payments · Checkout and payment processing boundary
- **LLM provider**: OpenRouter/LangChain · External model access for chat and stamp recognition
- **Email service**: SMTP/email · Sends verification and reset messages

## Connections

- App shell → Routes: mounts · SPA bootstrap hands off to route configuration
- Routes → Pages: renders · Routes select the active page view
- Pages → UI components: composes · Pages reuse shared interface components
- Pages → Client data: fetches via · Pages load and mutate server state through client data helpers
- Client data → Server entry: calls API · Client issues HTTP requests to the Express backend
- Server entry → API routes: registers · Server mounts the route modules
- API routes → Auth stack: exposes · Auth endpoints are one major API surface
- API routes → AI stack: exposes · AI endpoints handle chat and stamp recognition
- API routes → Commerce: exposes · Cart, order, and payment endpoints
- API routes → Content: exposes · Posts, comments, and stamp catalog endpoints
- API routes → Events: exposes · Event and registration endpoints
- API routes → Middleware: protects with · Protected routes apply auth guards
- Auth stack → Mongo models: reads/writes · User, token, and verification persistence
- Auth stack → Email utils: sends emails · Verification and reset flows trigger outbound email helpers
- AI stack → Core services: delegates to · AI route/controller logic uses the AI service layer
- AI stack → Mongo models: stores chats · Conversation sessions and archived messages are persisted
- Commerce → Mongo models: reads/writes · Cart and order state is stored server-side
- Commerce → Stripe: charges via · Payments are processed through Stripe
- Content → Mongo models: reads/writes · Posts, comments, and stamps persist in MongoDB schemas
- Events → Mongo models: reads/writes · Events and registrations are persisted
- Backend lib → MongoDB: connects to · Database initializer connects the API to MongoDB
- Backend lib → Cloudinary: uploads to · Image assets are stored in Cloudinary
- Backend lib → LLM provider: integrates with · AI client wraps the external model provider
- Email utils → Email service: delivers via · Account lifecycle emails go through the mail provider
- Mongo models → MongoDB: persists in · All core domain data lives in MongoDB
- Pages → Cloudinary: uploads images · Profile/photo and stamp image workflows depend on media storage
- Pages → Stripe: checkout redirect · Payment pages coordinate with the Stripe checkout flow
- Pages → LLM provider: AI results · AI assistant and stamp recognition consume AI-backed responses
