# nguyenbrandon327/r-mart architecture

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

- Interactive diagram: https://gitdiagram.com/nguyenbrandon327/r-mart
- Repository: https://github.com/nguyenbrandon327/r-mart

## Overview

R-Mart is a UCR-student marketplace. Students browse and search listings, create or manage products, and can message sellers; the frontend is a Next.js app and the backend is an Express API backed by PostgreSQL. The tree and excerpts also show accounts, saved/recent products, real-time messaging, and an AI assistant. Several frontend-to-API links and unsampled feature internals are not shown, so those relationships are left unverified rather than asserted.

Main entry points: [`backend/controllers/productController.ts`](https://github.com/nguyenbrandon327/r-mart/blob/main/backend/controllers/productController.ts) (Product workflows), [`backend/langchain/services/chatbotService.ts`](https://github.com/nguyenbrandon327/r-mart/blob/main/backend/langchain/services/chatbotService.ts) (Agent orchestration), [`backend/controllers/messageController.ts`](https://github.com/nguyenbrandon327/r-mart/blob/main/backend/controllers/messageController.ts) (Messaging workflows), [`backend/server.ts`](https://github.com/nguyenbrandon327/r-mart/blob/main/backend/server.ts) (Express API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["Marketplace experience"]
  node_browse["Browse listings<br/>[page.tsx]"]
  node_search_ui["Search listings<br/>[page.tsx]"]
  node_listing_ui["Create listing<br/>[page.tsx]"]
  node_auth_ui["Account onboarding<br/>[page.tsx]"]
  node_product_ui["Product details<br/>[page.tsx]"]
  node_inbox_ui["Buyer-seller inbox<br/>[page.tsx]"]
  node_saved_ui["Saved products<br/>[page.tsx]"]
end

subgraph group_client_state["Client state"]
  node_client_state["Redux state<br/>[productSlice.ts]"]
  node_search_state["Search state<br/>[searchSlice.ts]"]
  node_auth_state["Auth state<br/>[authSlice.ts]"]
end

subgraph group_api["API and domain services"]
  node_server["Express API<br/>[server.ts]"]
  node_product_api["Product workflows"]
  node_search_api["Search service"]
  node_account_api["Account workflows<br/>[userController.ts]"]
  node_messages_api["Messaging workflows"]
  node_auth_api["Authentication<br/>[authController.ts]"]
end

subgraph group_data["Persistence and integrations"]
  node_db[("PostgreSQL<br/>[db.ts]")]
  node_meili[("Meilisearch<br/>[meilisearch.ts]")]
  node_s3["Image storage<br/>[s3.ts]"]
  node_socket["Live messaging<br/>[socket.ts]"]
end

subgraph group_assistant["AI assistant"]
  node_chat_routes["Chatbot endpoints<br/>[chatbotRoutes.ts]"]
  node_chat_controller["Chatbot controller"]
  node_chat_service["Agent orchestration<br/>[chatbotService.ts]"]
  node_router_agent["Intent router<br/>[routerAgent.ts]"]
  node_buyer_agent["Buyer assistant<br/>[buyerAgent.ts]"]
  node_seller_agent["Seller copilot<br/>[sellerAgent.ts]"]
  node_support_agent["Support and safety<br/>[supportAgent.ts]"]
end

node_student(("UCR student"))

node_student -->|"browses"| node_browse
node_student -->|"searches"| node_search_ui
node_student -->|"posts listings"| node_listing_ui
node_student -.->|"messages sellers"| node_inbox_ui
node_browse -->|"uses state"| node_client_state
node_search_ui -->|"dispatches search"| node_search_state
node_listing_ui -->|"dispatches product"| node_client_state
node_auth_ui -->|"dispatches auth"| node_auth_state
node_browse -.->|"fetches listings"| node_product_api
node_search_ui -.->|"queries catalog"| node_search_api
node_listing_ui -.->|"submits listing"| node_product_api
node_auth_ui -.->|"submits account"| node_auth_api
node_inbox_ui -.->|"loads conversations"| node_messages_api
node_server -->|"routes products"| node_product_api
node_server -->|"routes auth"| node_auth_api
node_server -->|"routes messages"| node_messages_api
node_server -->|"mounts chatbot"| node_chat_routes
node_chat_routes -->|"dispatches requests"| node_chat_controller
node_product_api -->|"reads and writes"| node_db
node_product_api -->|"indexes products"| node_search_api
node_product_api -->|"manages images"| node_s3
node_search_api -->|"searches index"| node_meili
node_account_api -->|"reads and writes"| node_db
node_account_api -->|"manages profile images"| node_s3
node_auth_api -->|"reads and writes"| node_db
node_messages_api -->|"stores messages"| node_db
node_messages_api -->|"emits messages"| node_socket
node_messages_api -->|"uploads images"| node_s3
node_chat_controller -.->|"uses assistant"| node_chat_service
node_chat_service -->|"routes intent"| node_router_agent
node_chat_service -->|"dispatches buyer"| node_buyer_agent
node_chat_service -->|"dispatches seller"| node_seller_agent
node_chat_service -->|"dispatches support"| node_support_agent
node_router_agent -.->|"selects agent"| node_buyer_agent
node_router_agent -.->|"selects agent"| node_seller_agent
node_router_agent -.->|"selects agent"| node_support_agent

click node_browse "https://github.com/nguyenbrandon327/r-mart/blob/main/frontend/app/all-listings/page.tsx"
click node_search_ui "https://github.com/nguyenbrandon327/r-mart/blob/main/frontend/app/search/page.tsx"
click node_listing_ui "https://github.com/nguyenbrandon327/r-mart/blob/main/frontend/app/add-listing/page.tsx"
click node_auth_ui "https://github.com/nguyenbrandon327/r-mart/blob/main/frontend/app/auth/onboarding/page.tsx"
click node_product_ui "https://github.com/nguyenbrandon327/r-mart/blob/main/frontend/app/product/%5Bslug%5D/page.tsx"
click node_inbox_ui "https://github.com/nguyenbrandon327/r-mart/blob/main/frontend/app/inbox/%5BchatId%5D/page.tsx"
click node_saved_ui "https://github.com/nguyenbrandon327/r-mart/blob/main/frontend/app/saved/page.tsx"
click node_client_state "https://github.com/nguyenbrandon327/r-mart/blob/main/frontend/store/slices/productSlice.ts"
click node_search_state "https://github.com/nguyenbrandon327/r-mart/blob/main/frontend/store/slices/searchSlice.ts"
click node_auth_state "https://github.com/nguyenbrandon327/r-mart/blob/main/frontend/store/slices/authSlice.ts"
click node_server "https://github.com/nguyenbrandon327/r-mart/blob/main/backend/server.ts"
click node_product_api "https://github.com/nguyenbrandon327/r-mart/blob/main/backend/controllers/productController.ts"
click node_search_api "https://github.com/nguyenbrandon327/r-mart/blob/main/backend/controllers/searchController.ts"
click node_account_api "https://github.com/nguyenbrandon327/r-mart/blob/main/backend/controllers/userController.ts"
click node_messages_api "https://github.com/nguyenbrandon327/r-mart/blob/main/backend/controllers/messageController.ts"
click node_auth_api "https://github.com/nguyenbrandon327/r-mart/blob/main/backend/controllers/authController.ts"
click node_db "https://github.com/nguyenbrandon327/r-mart/blob/main/backend/config/db.ts"
click node_meili "https://github.com/nguyenbrandon327/r-mart/blob/main/backend/config/meilisearch.ts"
click node_s3 "https://github.com/nguyenbrandon327/r-mart/blob/main/backend/utils/s3.ts"
click node_socket "https://github.com/nguyenbrandon327/r-mart/blob/main/backend/socket/socket.ts"
click node_chat_routes "https://github.com/nguyenbrandon327/r-mart/blob/main/backend/routes/chatbotRoutes.ts"
click node_chat_controller "https://github.com/nguyenbrandon327/r-mart/blob/main/backend/controllers/chatbotController.ts"
click node_chat_service "https://github.com/nguyenbrandon327/r-mart/blob/main/backend/langchain/services/chatbotService.ts"
click node_router_agent "https://github.com/nguyenbrandon327/r-mart/blob/main/backend/langchain/agents/routerAgent.ts"
click node_buyer_agent "https://github.com/nguyenbrandon327/r-mart/blob/main/backend/langchain/agents/buyerAgent.ts"
click node_seller_agent "https://github.com/nguyenbrandon327/r-mart/blob/main/backend/langchain/agents/sellerAgent.ts"
click node_support_agent "https://github.com/nguyenbrandon327/r-mart/blob/main/backend/langchain/agents/supportAgent.ts"

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_browse,node_search_ui,node_listing_ui,node_auth_ui,node_product_ui,node_inbox_ui,node_saved_ui toneBlue
class node_client_state,node_search_state,node_auth_state toneAmber
class node_server,node_product_api,node_search_api,node_account_api,node_messages_api,node_auth_api toneMint
class node_db,node_meili,node_s3,node_socket toneRose
class node_chat_routes,node_chat_controller,node_chat_service,node_router_agent,node_buyer_agent,node_seller_agent,node_support_agent,node_student toneIndigo
```

## Components

### Marketplace experience

- [Browse listings](https://github.com/nguyenbrandon327/r-mart/blob/main/frontend/app/all-listings/page.tsx): `frontend/app/all-listings/page.tsx`
- [Search listings](https://github.com/nguyenbrandon327/r-mart/blob/main/frontend/app/search/page.tsx): `frontend/app/search/page.tsx`
- [Create listing](https://github.com/nguyenbrandon327/r-mart/blob/main/frontend/app/add-listing/page.tsx): `frontend/app/add-listing/page.tsx`
- [Account onboarding](https://github.com/nguyenbrandon327/r-mart/blob/main/frontend/app/auth/onboarding/page.tsx): `frontend/app/auth/onboarding/page.tsx`
- [Product details](https://github.com/nguyenbrandon327/r-mart/blob/main/frontend/app/product/%5Bslug%5D/page.tsx): `frontend/app/product/[slug]/page.tsx`
- [Buyer-seller inbox](https://github.com/nguyenbrandon327/r-mart/blob/main/frontend/app/inbox/%5BchatId%5D/page.tsx): `frontend/app/inbox/[chatId]/page.tsx`
- [Saved products](https://github.com/nguyenbrandon327/r-mart/blob/main/frontend/app/saved/page.tsx): `frontend/app/saved/page.tsx`

### Client state

- [Redux state](https://github.com/nguyenbrandon327/r-mart/blob/main/frontend/store/slices/productSlice.ts): `frontend/store/slices/productSlice.ts`
- [Search state](https://github.com/nguyenbrandon327/r-mart/blob/main/frontend/store/slices/searchSlice.ts): `frontend/store/slices/searchSlice.ts`
- [Auth state](https://github.com/nguyenbrandon327/r-mart/blob/main/frontend/store/slices/authSlice.ts): `frontend/store/slices/authSlice.ts`

### API and domain services

- [Express API](https://github.com/nguyenbrandon327/r-mart/blob/main/backend/server.ts): `backend/server.ts`
- [Product workflows](https://github.com/nguyenbrandon327/r-mart/blob/main/backend/controllers/productController.ts): `backend/controllers/productController.ts`
- [Search service](https://github.com/nguyenbrandon327/r-mart/blob/main/backend/controllers/searchController.ts): `backend/controllers/searchController.ts`
- [Account workflows](https://github.com/nguyenbrandon327/r-mart/blob/main/backend/controllers/userController.ts): `backend/controllers/userController.ts`
- [Messaging workflows](https://github.com/nguyenbrandon327/r-mart/blob/main/backend/controllers/messageController.ts): `backend/controllers/messageController.ts`
- [Authentication](https://github.com/nguyenbrandon327/r-mart/blob/main/backend/controllers/authController.ts): `backend/controllers/authController.ts`

### Persistence and integrations

- [PostgreSQL](https://github.com/nguyenbrandon327/r-mart/blob/main/backend/config/db.ts): `backend/config/db.ts`
- [Meilisearch](https://github.com/nguyenbrandon327/r-mart/blob/main/backend/config/meilisearch.ts): `backend/config/meilisearch.ts`
- [Image storage](https://github.com/nguyenbrandon327/r-mart/blob/main/backend/utils/s3.ts): `backend/utils/s3.ts`
- [Live messaging](https://github.com/nguyenbrandon327/r-mart/blob/main/backend/socket/socket.ts): `backend/socket/socket.ts`

### AI assistant

- [Chatbot endpoints](https://github.com/nguyenbrandon327/r-mart/blob/main/backend/routes/chatbotRoutes.ts): `backend/routes/chatbotRoutes.ts`
- [Chatbot controller](https://github.com/nguyenbrandon327/r-mart/blob/main/backend/controllers/chatbotController.ts): `backend/controllers/chatbotController.ts`
- [Agent orchestration](https://github.com/nguyenbrandon327/r-mart/blob/main/backend/langchain/services/chatbotService.ts): `backend/langchain/services/chatbotService.ts`
- [Intent router](https://github.com/nguyenbrandon327/r-mart/blob/main/backend/langchain/agents/routerAgent.ts): `backend/langchain/agents/routerAgent.ts`
- [Buyer assistant](https://github.com/nguyenbrandon327/r-mart/blob/main/backend/langchain/agents/buyerAgent.ts): `backend/langchain/agents/buyerAgent.ts`
- [Seller copilot](https://github.com/nguyenbrandon327/r-mart/blob/main/backend/langchain/agents/sellerAgent.ts): `backend/langchain/agents/sellerAgent.ts`
- [Support and safety](https://github.com/nguyenbrandon327/r-mart/blob/main/backend/langchain/agents/supportAgent.ts): `backend/langchain/agents/supportAgent.ts`

### Other components

- **UCR student**

## Connections

- UCR student → Browse listings: browses
- UCR student → Search listings: searches
- UCR student → Create listing: posts listings
- UCR student → Buyer-seller inbox: messages sellers
- Browse listings → Redux state: uses state (evidence: `frontend/app/all-listings/page.tsx`)
- Search listings → Search state: dispatches search (evidence: `frontend/app/search/page.tsx`)
- Create listing → Redux state: dispatches product (evidence: `frontend/app/add-listing/page.tsx`)
- Account onboarding → Auth state: dispatches auth (evidence: `frontend/app/auth/onboarding/page.tsx`)
- Browse listings → Product workflows: fetches listings
- Search listings → Search service: queries catalog
- Create listing → Product workflows: submits listing
- Account onboarding → Authentication: submits account
- Buyer-seller inbox → Messaging workflows: loads conversations
- Express API → Product workflows: routes products (evidence: `backend/server.ts`)
- Express API → Authentication: routes auth (evidence: `backend/server.ts`)
- Express API → Messaging workflows: routes messages (evidence: `backend/server.ts`)
- Express API → Chatbot endpoints: mounts chatbot (evidence: `backend/server.ts`)
- Chatbot endpoints → Chatbot controller: dispatches requests (evidence: `backend/routes/chatbotRoutes.ts`)
- Product workflows → PostgreSQL: reads and writes (evidence: `backend/controllers/productController.ts`)
- Product workflows → Search service: indexes products (evidence: `backend/controllers/productController.ts`)
- Product workflows → Image storage: manages images (evidence: `backend/controllers/productController.ts`)
- Search service → Meilisearch: searches index (evidence: `backend/controllers/searchController.ts`)
- Account workflows → PostgreSQL: reads and writes (evidence: `backend/controllers/userController.ts`)
- Account workflows → Image storage: manages profile images (evidence: `backend/controllers/userController.ts`)
- Authentication → PostgreSQL: reads and writes (evidence: `backend/controllers/authController.ts`)
- Messaging workflows → PostgreSQL: stores messages (evidence: `backend/controllers/messageController.ts`)
- Messaging workflows → Live messaging: emits messages (evidence: `backend/controllers/messageController.ts`)
- Messaging workflows → Image storage: uploads images (evidence: `backend/controllers/messageController.ts`)
- Chatbot controller → Agent orchestration: uses assistant
- Agent orchestration → Intent router: routes intent (evidence: `backend/langchain/services/chatbotService.ts`)
- Agent orchestration → Buyer assistant: dispatches buyer (evidence: `backend/langchain/services/chatbotService.ts`)
- Agent orchestration → Seller copilot: dispatches seller (evidence: `backend/langchain/services/chatbotService.ts`)
- Agent orchestration → Support and safety: dispatches support (evidence: `backend/langchain/services/chatbotService.ts`)
- Intent router → Buyer assistant: selects agent
- Intent router → Seller copilot: selects agent
- Intent router → Support and safety: selects agent
