# tranminhhieu20/timphongtro architecture

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

- Interactive diagram: https://gitdiagram.com/tranminhhieu20/timphongtro
- Repository: https://github.com/tranminhhieu20/timphongtro

## Overview

This is a room-listing and rental-lead platform with user accounts, favorites, admin listing imports, lead management, and user–admin chat. Visitors browse and search rooms, view details, and submit leads; administrators manage listings, leads, and conversations. The frontend routes these experiences through shared API services to an Express backend, MongoDB models, and realtime Socket.IO events. Edges are limited to relationships shown in excerpts, the source index, or route definitions; unsampled subsystems are included where the tree identifies them, without guessing their internal calls.

Main entry points: [`frontend/src/services/api.js`](https://github.com/tranminhhieu20/timphongtro/blob/main/frontend/src/services/api.js) (API services), [`frontend/src/App.jsx`](https://github.com/tranminhhieu20/timphongtro/blob/main/frontend/src/App.jsx) (App routes), [`backend/src/controllers/chat.controller.js`](https://github.com/tranminhhieu20/timphongtro/blob/main/backend/src/controllers/chat.controller.js) (Chat operations), [`backend/src/modules/User.js`](https://github.com/tranminhhieu20/timphongtro/blob/main/backend/src/modules/User.js) (User records)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web experience"]
  node_app["App routes<br/>[App.jsx]"]
  node_home["Room browsing<br/>[HomePage.jsx]"]
  node_roomdetail["Room details<br/>[RoomDetail.jsx]"]
  node_roomcard["Room card<br/>[RoomCard.jsx]"]
  node_adminrooms["Admin listings<br/>[AdminRooms.jsx]"]
  node_adminimport["Listing imports<br/>[AdminImport.jsx]"]
  node_adminleads["Lead console<br/>[AdminLeads.jsx]"]
  node_favorites["Favorites<br/>[FavoritesPage.jsx]"]
  node_api["API services<br/>[api.js]"]
end

subgraph group_listing["Listings and leads"]
  node_roomroutes["Room routes<br/>[room.routes.js]"]
  node_roomcontroller["Room management<br/>[room.controller.js]"]
  node_roommodel["Room records<br/>[Room.js]"]
  node_leadpage["Lead workflow<br/>[AdminLeads.jsx]"]
  node_leadroutes["Lead routes<br/>[lead.routes.js]"]
  node_leadcontroller["Lead management<br/>[lead.controller.js]"]
  node_leadmodel["Lead records<br/>[Lead.js]"]
end

subgraph group_identity["Accounts and access"]
  node_authcontext["Auth context<br/>[AuthContext.jsx]"]
  node_login["Login and signup<br/>[LoginPage.jsx]"]
  node_register["Registration<br/>[RegisterPage.jsx]"]
  node_authroutes["Auth routes<br/>[auth.routes.js]"]
  node_authcontroller["Auth operations<br/>[auth.controller.js]"]
  node_usercontroller["User operations<br/>[user.controller.js]"]
  node_usermodel["User records<br/>[User.js]"]
  node_protect["Session protection<br/>[authProtect.js]"]
end

subgraph group_messaging["Chat and realtime"]
  node_chatbox["Chat interface<br/>[ChatBox.jsx]"]
  node_adminchat["Admin chat<br/>[AdminChat.jsx]"]
  node_chatroutes["Chat routes<br/>[chat.routes.js]"]
  node_chatcontroller["Chat operations<br/>[chat.controller.js]"]
  node_conversation["Conversations<br/>[Conversation.js]"]
  node_message["Messages<br/>[Message.js]"]
end

subgraph group_backend["Backend services"]
  node_server["HTTP and sockets<br/>[server.js]"]
  node_db["Database connector<br/>[db.js]"]
end

node_visitor(("Visitor"))
node_admin(("Administrator"))

node_visitor -.->|"opens"| node_app
node_admin -.->|"opens"| node_app
node_app -->|"routes to"| node_home
node_app -->|"routes to"| node_roomdetail
node_app -->|"routes to"| node_adminrooms
node_app -->|"routes to"| node_adminimport
node_app -->|"routes to"| node_adminleads
node_app -->|"routes to"| node_adminchat
node_app -->|"provides auth"| node_authcontext
node_home -->|"renders"| node_roomcard
node_home -->|"requests listings"| node_api
node_roomdetail -->|"requests room"| node_api
node_roomdetail -->|"renders"| node_roomcard
node_adminrooms -->|"manages listings"| node_api
node_adminimport -->|"uploads imports"| node_api
node_adminleads -->|"manages leads"| node_api
node_favorites -.->|"loads favorites"| node_api
node_login -.->|"uses auth"| node_authcontext
node_register -.->|"uses auth"| node_authcontext
node_authcontext -->|"calls auth service"| node_api
node_api -->|"HTTP requests"| node_roomroutes
node_api -->|"HTTP requests"| node_leadroutes
node_api -->|"HTTP requests"| node_authroutes
node_api -->|"HTTP requests"| node_chatroutes
node_roomroutes -->|"dispatches"| node_roomcontroller
node_roomcontroller -->|"reads and writes"| node_roommodel
node_roomcontroller -->|"emits room event"| node_server
node_roomcontroller -.->|"returns listings"| node_visitor
node_leadroutes -->|"dispatches"| node_leadcontroller
node_leadcontroller -->|"reads and writes"| node_leadmodel
node_leadcontroller -->|"references rooms"| node_roommodel
node_leadcontroller -->|"references users"| node_usermodel
node_authroutes -->|"dispatches"| node_authcontroller
node_authcontroller -->|"reads and writes"| node_usermodel
node_authcontroller -->|"broadcasts signup"| node_server
node_authcontroller -.->|"sends reset email"| node_admin
node_usercontroller -->|"reads and writes"| node_usermodel
node_protect -->|"loads session user"| node_usermodel
node_roomroutes -->|"guards writes"| node_protect
node_leadroutes -->|"guards user routes"| node_protect
node_chatbox -->|"uses chat service"| node_api
node_adminchat -->|"uses chat service"| node_api
node_chatroutes -->|"dispatches"| node_chatcontroller
node_chatcontroller -->|"reads and writes"| node_conversation
node_chatcontroller -->|"reads and writes"| node_message
node_chatcontroller -->|"looks up users"| node_usermodel
node_chatcontroller -->|"sends socket events"| node_server
node_server -->|"mounts routes"| node_authroutes

click node_app "https://github.com/tranminhhieu20/timphongtro/blob/main/frontend/src/App.jsx"
click node_home "https://github.com/tranminhhieu20/timphongtro/blob/main/frontend/src/pages/HomePage.jsx"
click node_roomdetail "https://github.com/tranminhhieu20/timphongtro/blob/main/frontend/src/pages/RoomDetail.jsx"
click node_roomcard "https://github.com/tranminhhieu20/timphongtro/blob/main/frontend/src/components/RoomCard.jsx"
click node_adminrooms "https://github.com/tranminhhieu20/timphongtro/blob/main/frontend/src/pages/AdminRooms.jsx"
click node_adminimport "https://github.com/tranminhhieu20/timphongtro/blob/main/frontend/src/pages/AdminImport.jsx"
click node_adminleads "https://github.com/tranminhhieu20/timphongtro/blob/main/frontend/src/pages/AdminLeads.jsx"
click node_favorites "https://github.com/tranminhhieu20/timphongtro/blob/main/frontend/src/pages/FavoritesPage.jsx"
click node_api "https://github.com/tranminhhieu20/timphongtro/blob/main/frontend/src/services/api.js"
click node_authcontext "https://github.com/tranminhhieu20/timphongtro/blob/main/frontend/src/context/AuthContext.jsx"
click node_login "https://github.com/tranminhhieu20/timphongtro/blob/main/frontend/src/pages/LoginPage.jsx"
click node_register "https://github.com/tranminhhieu20/timphongtro/blob/main/frontend/src/pages/RegisterPage.jsx"
click node_roomroutes "https://github.com/tranminhhieu20/timphongtro/blob/main/backend/src/routes/room.routes.js"
click node_roomcontroller "https://github.com/tranminhhieu20/timphongtro/blob/main/backend/src/controllers/room.controller.js"
click node_roommodel "https://github.com/tranminhhieu20/timphongtro/blob/main/backend/src/modules/Room.js"
click node_leadpage "https://github.com/tranminhhieu20/timphongtro/blob/main/frontend/src/pages/AdminLeads.jsx"
click node_leadroutes "https://github.com/tranminhhieu20/timphongtro/blob/main/backend/src/routes/lead.routes.js"
click node_leadcontroller "https://github.com/tranminhhieu20/timphongtro/blob/main/backend/src/controllers/lead.controller.js"
click node_leadmodel "https://github.com/tranminhhieu20/timphongtro/blob/main/backend/src/modules/Lead.js"
click node_authroutes "https://github.com/tranminhhieu20/timphongtro/blob/main/backend/src/routes/auth.routes.js"
click node_authcontroller "https://github.com/tranminhhieu20/timphongtro/blob/main/backend/src/controllers/auth.controller.js"
click node_usercontroller "https://github.com/tranminhhieu20/timphongtro/blob/main/backend/src/controllers/user.controller.js"
click node_usermodel "https://github.com/tranminhhieu20/timphongtro/blob/main/backend/src/modules/User.js"
click node_protect "https://github.com/tranminhhieu20/timphongtro/blob/main/backend/src/middlewares/authProtect.js"
click node_chatbox "https://github.com/tranminhhieu20/timphongtro/blob/main/frontend/src/components/ChatBox.jsx"
click node_adminchat "https://github.com/tranminhhieu20/timphongtro/blob/main/frontend/src/pages/AdminChat.jsx"
click node_chatroutes "https://github.com/tranminhhieu20/timphongtro/blob/main/backend/src/routes/chat.routes.js"
click node_chatcontroller "https://github.com/tranminhhieu20/timphongtro/blob/main/backend/src/controllers/chat.controller.js"
click node_conversation "https://github.com/tranminhhieu20/timphongtro/blob/main/backend/src/modules/Conversation.js"
click node_message "https://github.com/tranminhhieu20/timphongtro/blob/main/backend/src/modules/Message.js"
click node_server "https://github.com/tranminhhieu20/timphongtro/blob/main/backend/src/server.js"
click node_db "https://github.com/tranminhhieu20/timphongtro/blob/main/backend/src/lib/db.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_app,node_home,node_roomdetail,node_roomcard,node_adminrooms,node_adminimport,node_adminleads,node_favorites,node_api toneBlue
class node_roomroutes,node_roomcontroller,node_roommodel,node_leadpage,node_leadroutes,node_leadcontroller,node_leadmodel toneAmber
class node_authcontext,node_login,node_register,node_authroutes,node_authcontroller,node_usercontroller,node_usermodel,node_protect toneMint
class node_chatbox,node_adminchat,node_chatroutes,node_chatcontroller,node_conversation,node_message toneRose
class node_server,node_db,node_visitor,node_admin toneIndigo
```

## Components

### Web experience

- [App routes](https://github.com/tranminhhieu20/timphongtro/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`
- [Room browsing](https://github.com/tranminhhieu20/timphongtro/blob/main/frontend/src/pages/HomePage.jsx): `frontend/src/pages/HomePage.jsx`
- [Room details](https://github.com/tranminhhieu20/timphongtro/blob/main/frontend/src/pages/RoomDetail.jsx): `frontend/src/pages/RoomDetail.jsx`
- [Room card](https://github.com/tranminhhieu20/timphongtro/blob/main/frontend/src/components/RoomCard.jsx): `frontend/src/components/RoomCard.jsx`
- [Admin listings](https://github.com/tranminhhieu20/timphongtro/blob/main/frontend/src/pages/AdminRooms.jsx): `frontend/src/pages/AdminRooms.jsx`
- [Listing imports](https://github.com/tranminhhieu20/timphongtro/blob/main/frontend/src/pages/AdminImport.jsx): `frontend/src/pages/AdminImport.jsx`
- [Lead console](https://github.com/tranminhhieu20/timphongtro/blob/main/frontend/src/pages/AdminLeads.jsx): `frontend/src/pages/AdminLeads.jsx`
- [Favorites](https://github.com/tranminhhieu20/timphongtro/blob/main/frontend/src/pages/FavoritesPage.jsx): `frontend/src/pages/FavoritesPage.jsx`
- [API services](https://github.com/tranminhhieu20/timphongtro/blob/main/frontend/src/services/api.js): `frontend/src/services/api.js`

### Listings and leads

- [Room routes](https://github.com/tranminhhieu20/timphongtro/blob/main/backend/src/routes/room.routes.js): `backend/src/routes/room.routes.js`
- [Room management](https://github.com/tranminhhieu20/timphongtro/blob/main/backend/src/controllers/room.controller.js): `backend/src/controllers/room.controller.js`
- [Room records](https://github.com/tranminhhieu20/timphongtro/blob/main/backend/src/modules/Room.js): `backend/src/modules/Room.js`
- [Lead workflow](https://github.com/tranminhhieu20/timphongtro/blob/main/frontend/src/pages/AdminLeads.jsx): `frontend/src/pages/AdminLeads.jsx`
- [Lead routes](https://github.com/tranminhhieu20/timphongtro/blob/main/backend/src/routes/lead.routes.js): `backend/src/routes/lead.routes.js`
- [Lead management](https://github.com/tranminhhieu20/timphongtro/blob/main/backend/src/controllers/lead.controller.js): `backend/src/controllers/lead.controller.js`
- [Lead records](https://github.com/tranminhhieu20/timphongtro/blob/main/backend/src/modules/Lead.js): `backend/src/modules/Lead.js`

### Accounts and access

- [Auth context](https://github.com/tranminhhieu20/timphongtro/blob/main/frontend/src/context/AuthContext.jsx): `frontend/src/context/AuthContext.jsx`
- [Login and signup](https://github.com/tranminhhieu20/timphongtro/blob/main/frontend/src/pages/LoginPage.jsx): `frontend/src/pages/LoginPage.jsx`
- [Registration](https://github.com/tranminhhieu20/timphongtro/blob/main/frontend/src/pages/RegisterPage.jsx): `frontend/src/pages/RegisterPage.jsx`
- [Auth routes](https://github.com/tranminhhieu20/timphongtro/blob/main/backend/src/routes/auth.routes.js): `backend/src/routes/auth.routes.js`
- [Auth operations](https://github.com/tranminhhieu20/timphongtro/blob/main/backend/src/controllers/auth.controller.js): `backend/src/controllers/auth.controller.js`
- [User operations](https://github.com/tranminhhieu20/timphongtro/blob/main/backend/src/controllers/user.controller.js): `backend/src/controllers/user.controller.js`
- [User records](https://github.com/tranminhhieu20/timphongtro/blob/main/backend/src/modules/User.js): `backend/src/modules/User.js`
- [Session protection](https://github.com/tranminhhieu20/timphongtro/blob/main/backend/src/middlewares/authProtect.js): `backend/src/middlewares/authProtect.js`

### Chat and realtime

- [Chat interface](https://github.com/tranminhhieu20/timphongtro/blob/main/frontend/src/components/ChatBox.jsx): `frontend/src/components/ChatBox.jsx`
- [Admin chat](https://github.com/tranminhhieu20/timphongtro/blob/main/frontend/src/pages/AdminChat.jsx): `frontend/src/pages/AdminChat.jsx`
- [Chat routes](https://github.com/tranminhhieu20/timphongtro/blob/main/backend/src/routes/chat.routes.js): `backend/src/routes/chat.routes.js`
- [Chat operations](https://github.com/tranminhhieu20/timphongtro/blob/main/backend/src/controllers/chat.controller.js): `backend/src/controllers/chat.controller.js`
- [Conversations](https://github.com/tranminhhieu20/timphongtro/blob/main/backend/src/modules/Conversation.js): `backend/src/modules/Conversation.js`
- [Messages](https://github.com/tranminhhieu20/timphongtro/blob/main/backend/src/modules/Message.js): `backend/src/modules/Message.js`

### Backend services

- [HTTP and sockets](https://github.com/tranminhhieu20/timphongtro/blob/main/backend/src/server.js): `backend/src/server.js`
- [Database connector](https://github.com/tranminhhieu20/timphongtro/blob/main/backend/src/lib/db.js): `backend/src/lib/db.js`

### Other components

- **Visitor**
- **Administrator**

## Connections

- Visitor → App routes: opens
- Administrator → App routes: opens
- App routes → Room browsing: routes to (evidence: `frontend/src/App.jsx`)
- App routes → Room details: routes to (evidence: `frontend/src/App.jsx`)
- App routes → Admin listings: routes to (evidence: `frontend/src/App.jsx`)
- App routes → Listing imports: routes to (evidence: `frontend/src/App.jsx`)
- App routes → Lead console: routes to (evidence: `frontend/src/App.jsx`)
- App routes → Admin chat: routes to (evidence: `frontend/src/App.jsx`)
- App routes → Auth context: provides auth (evidence: `frontend/src/App.jsx`)
- Room browsing → Room card: renders (evidence: `frontend/src/pages/HomePage.jsx`)
- Room browsing → API services: requests listings (evidence: `frontend/src/pages/HomePage.jsx`)
- Room details → API services: requests room (evidence: `frontend/src/pages/RoomDetail.jsx`)
- Room details → Room card: renders (evidence: `frontend/src/pages/RoomDetail.jsx`)
- Admin listings → API services: manages listings (evidence: `frontend/src/pages/AdminRooms.jsx`)
- Listing imports → API services: uploads imports (evidence: `frontend/src/pages/AdminImport.jsx`)
- Lead console → API services: manages leads (evidence: `frontend/src/pages/AdminLeads.jsx`)
- Favorites → API services: loads favorites
- Login and signup → Auth context: uses auth
- Registration → Auth context: uses auth
- Auth context → API services: calls auth service (evidence: `frontend/src/context/AuthContext.jsx`)
- API services → Room routes: HTTP requests (evidence: `frontend/src/services/api.js`)
- API services → Lead routes: HTTP requests (evidence: `frontend/src/services/api.js`)
- API services → Auth routes: HTTP requests (evidence: `frontend/src/services/api.js`)
- API services → Chat routes: HTTP requests (evidence: `frontend/src/services/api.js`)
- Room routes → Room management: dispatches (evidence: `backend/src/routes/room.routes.js`)
- Room management → Room records: reads and writes (evidence: `backend/src/controllers/room.controller.js`)
- Room management → HTTP and sockets: emits room event (evidence: `backend/src/controllers/room.controller.js`)
- Room management → Visitor: returns listings
- Lead routes → Lead management: dispatches (evidence: `backend/src/routes/lead.routes.js`)
- Lead management → Lead records: reads and writes (evidence: `backend/src/controllers/lead.controller.js`)
- Lead management → Room records: references rooms (evidence: `backend/src/controllers/lead.controller.js`)
- Lead management → User records: references users (evidence: `backend/src/controllers/lead.controller.js`)
- Auth routes → Auth operations: dispatches (evidence: `backend/src/routes/auth.routes.js`)
- Auth operations → User records: reads and writes (evidence: `backend/src/controllers/auth.controller.js`)
- Auth operations → HTTP and sockets: broadcasts signup (evidence: `backend/src/controllers/auth.controller.js`)
- Auth operations → Administrator: sends reset email
- User operations → User records: reads and writes (evidence: `backend/src/controllers/user.controller.js`)
- Session protection → User records: loads session user (evidence: `backend/src/middlewares/authProtect.js`)
- Room routes → Session protection: guards writes (evidence: `backend/src/routes/room.routes.js`)
- Lead routes → Session protection: guards user routes (evidence: `backend/src/routes/lead.routes.js`)
- Chat interface → API services: uses chat service (evidence: `frontend/src/components/ChatBox.jsx`)
- Admin chat → API services: uses chat service (evidence: `frontend/src/pages/AdminChat.jsx`)
- Chat routes → Chat operations: dispatches (evidence: `backend/src/routes/chat.routes.js`)
- Chat operations → Conversations: reads and writes (evidence: `backend/src/controllers/chat.controller.js`)
- Chat operations → Messages: reads and writes (evidence: `backend/src/controllers/chat.controller.js`)
- Chat operations → User records: looks up users (evidence: `backend/src/controllers/chat.controller.js`)
- Chat operations → HTTP and sockets: sends socket events (evidence: `backend/src/controllers/chat.controller.js`)
- HTTP and sockets → Auth routes: mounts routes (evidence: `backend/src/server.js`)
