# aakash070802/brick-nest-estate architecture

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

- Interactive diagram: https://gitdiagram.com/aakash070802/brick-nest-estate
- Repository: https://github.com/aakash070802/brick-nest-estate

## Overview

1. **Overall shape**
   - BrickNest is a two-tier full-stack app: an **Express/MongoDB backend** and a **React/Vite frontend**.
   - The backend owns authentication, persistence, file uploads, email, and business rules.
   - The frontend is a feature-based SPA that talks to the backend through a small API/service layer.

2. **Backend entrypoint and request pipeline**
   - `backend/server.js` boots the Node process and starts the Express app from `src/app.js`.
   - Requests flow through middleware, then into route modules, then controllers, then Mongoose models/services.
   - Cross-cutting concerns are centralized in `src/middleware` and `src/utils`, especially auth checks, error handling, and upload handling.

3. **Backend domain boundaries**
   - The code is split by business area rather than by technical layer:
     - `auth.controller.js` and `auth.route.js`
     - `user.controller.js` and `user.route.js`
     - `listing.controller.js` and `listing.route.js`
     - `favorite.controller.js` and `favorite.route.js`
   - This makes the main architecture easy to diagram as domain modules hanging off a shared Express core.

4. **Persistence layer**
   - MongoDB is the system of record via Mongoose models in `src/models`.
   - Main collections include:
     - `user` for profile, favorites, and account state
     - `listing` for property records
     - `session` for refresh-token-backed device sessions
     - `otp` for password reset / account restoration flows
     - `activity` for audit logging
   - `src/config/database.js` handles the MongoDB connection, while `config.js` centralizes env-driven settings.

5. **Authentication and session architecture**
   - Authentication is JWT-based with **access + refresh tokens**.
   - Tokens are stored in **HTTP-only cookies**, not in browser local storage.
   - Refresh tokens are tied to **database-backed sessions** for rotation, device tracking, and revocation.
   - `auth.middleware.js` gates protected routes, while `utils/session.js` and `models/session.model.js` support validation/invalidation flows.
   - The README indicates support for logout, logout-all-devices, and token rotation, so the auth boundary is not stateless.

6. **OTP and email flow**
   - OTPs are generated and hashed before storage using `utils/otp.js` and `models/otp.model.js`.
   - `services/email.service.js` sends OTP emails through Nodemailer with Gmail OAuth2.
   - The OTP subsystem is rate-limited and expiry-based, so it acts as a controlled side channel for account recovery rather than a generic notification system.

7. **User management and audit logging**
   - User routes handle profile reads/updates, password changes, avatar uploads, deactivation, and restoration.
   - `activity.model.js` records important security/account events such as login, logout, password changes, profile updates, and token refreshes.
   - This creates a clear audit trail around identity-related actions, separate from the main business data.

8. **Listing and media handling**
   - Listings are managed through `listing.controller.js` and persisted in `listing.model.js`.
   - The app supports create/update/delete, ownership checks, filtering, and multi-image uploads.
   - `multer.middleware.js` handles temporary local uploads, then `utils/cloudinary.js` pushes files to Cloudinary.
   - The listing subsystem therefore has a two-step media flow: upload in transit, external storage at rest.

9. **Favorites subsystem**
   - Favorites are user-scoped and stored in the user document rather than as a standalone top-level feature store.
   - The dedicated favorite route/controller keeps toggle/add/remove behavior isolated, but the data remains bound to the user model.
   - This is a small but important boundary: favorites are an extension of identity, not a separate domain aggregate.

10. **Search and filtering**
   - The backend supports regular query-based listing search with pagination, sorting, and filters.
   - The README also describes AI-powered semantic search: a natural-language query is parsed into structured filters, then translated into MongoDB execution.
   - Architecturally, this is a hybrid path: text intent parsing first, database query second.

11. **Frontend app structure**
   - The frontend is a Vite React SPA with feature-oriented folders under `src/components` and `src/containers`.
   - `src/routes/routesConfig.jsx` centralizes routing, while `Layout.jsx` and `Header.jsx` provide the shared shell.
   - `PrivateRoute.jsx` enforces authenticated navigation on the client side, mirroring backend protection.

12. **Frontend state and API boundaries**
   - Redux Toolkit manages global auth/user state in `redux/features/userSlice.js`.
   - `redux/persist.js` indicates persisted client state for session continuity across reloads.
   - API access is abstracted behind `services/api.js` plus domain services like `authService.js`, `listingService.js`, and `userService.js`.
   - That keeps UI components thin: components call services, services call the backend.

13. **Frontend feature composition**
   - The UI is split by business area: auth forms, property cards, filters, listing CRUD modals/forms, profile screens, and favorites pages.
   - Shared primitives like loaders, modals, and skeletons support the asynchronous data flow from the backend.
   - Theme support is handled separately via `useTheme.js` and theme CSS, so presentation state is isolated from business state.

14. **External services and operational dependencies**
   - **MongoDB** is the primary datastore.
   - **Cloudinary** is the media storage backend for avatars and listing images.
   - **Nodemailer/Gmail OAuth2** is used for OTP delivery and account recovery emails.
   - The backend `.env.sample` shows these are first-class runtime dependencies, not optional add-ons.

15. **End-to-end data flow to keep in the diagram**
   - User actions start in React components, go through the frontend service layer, hit Express routes, pass middleware checks, and then reach controllers/models.
   - Responses come back through standardized response/error utilities (`ApiResponse`, `ApiError`) and drive Redux/UI updates.
   - The most important cross-cutting loops are: auth/session validation, media upload to Cloudinary, OTP email delivery, and activity/session logging.

Main entry points: [`backend/src/routes/auth.route.js`](https://github.com/aakash070802/brick-nest-estate/blob/main/backend/src/routes/auth.route.js) (Routes), [`frontend/src/services/api.js`](https://github.com/aakash070802/brick-nest-estate/blob/main/frontend/src/services/api.js) (API Layer), [`backend/src/app.js`](https://github.com/aakash070802/brick-nest-estate/blob/main/backend/src/app.js) (Express App), [`frontend/src/routes/routesConfig.jsx`](https://github.com/aakash070802/brick-nest-estate/blob/main/frontend/src/routes/routesConfig.jsx) (Routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_backend["Backend"]
  node_backend_server["Server<br/>Node entrypoint<br/>[server.js]"]
  node_backend_app["Express App<br/>HTTP app<br/>[app.js]"]
  node_backend_config["Config<br/>[config.js]"]
  node_backend_db[("Database<br/>Mongo connector<br/>[database.js]")]
  node_backend_auth_ctrl["Auth<br/>[auth.controller.js]"]
  node_backend_user_ctrl["User<br/>[user.controller.js]"]
  node_backend_listing_ctrl["Listing"]
  node_backend_favorite_ctrl["Favorites<br/>Favorite controller"]
  node_backend_routes["Routes<br/>Route modules<br/>[auth.route.js]"]
  node_backend_middleware["Middleware<br/>Request guard<br/>[auth.middleware.js]"]
  node_backend_models[("Models<br/>[user.model.js]")]
  node_backend_utils["Utils<br/>[ApiResponse.js]"]
  node_backend_email["Email Service<br/>Nodemailer service<br/>[email.service.js]"]
end

subgraph group_frontend["Frontend"]
  node_frontend_app["App<br/>React shell<br/>[App.jsx]"]
  node_frontend_routes["Routes<br/>Route config<br/>[routesConfig.jsx]"]
  node_frontend_layout["Layout<br/>Shell components<br/>[Layout.jsx]"]
  node_frontend_state["Redux<br/>Client state<br/>[userSlice.js]"]
  node_frontend_api["API Layer<br/>Service layer<br/>[api.js]"]
  node_frontend_auth_ui["Auth UI<br/>Auth screens<br/>[Login.jsx]"]
  node_frontend_listing_ui["Listings UI<br/>Listing screens<br/>[Home.jsx]"]
  node_frontend_profile_ui["Profile UI<br/>Profile screens<br/>[Profile.jsx]"]
end

subgraph group_external["External"]
  node_external_mongo[("MongoDB<br/>Datastore")]
  node_external_cloudinary[("Cloudinary<br/>Media storage")]
  node_external_email["Gmail OAuth2<br/>Mail delivery"]
end

node_backend_server -->|"starts"| node_backend_app
node_backend_app -->|"loads"| node_backend_config
node_backend_app -->|"connects"| node_backend_db
node_backend_app -->|"uses"| node_backend_middleware
node_backend_app -->|"mounts"| node_backend_routes
node_backend_routes -->|"dispatches"| node_backend_auth_ctrl
node_backend_routes -->|"dispatches"| node_backend_user_ctrl
node_backend_routes -->|"dispatches"| node_backend_listing_ctrl
node_backend_routes -->|"dispatches"| node_backend_favorite_ctrl
node_backend_auth_ctrl -->|"reads/writes"| node_backend_models
node_backend_user_ctrl -->|"reads/writes"| node_backend_models
node_backend_listing_ctrl -->|"reads/writes"| node_backend_models
node_backend_favorite_ctrl -->|"updates"| node_backend_models
node_backend_auth_ctrl -->|"uses"| node_backend_utils
node_backend_user_ctrl -->|"uses"| node_backend_utils
node_backend_listing_ctrl -->|"uses"| node_backend_utils
node_backend_utils -->|"invokes"| node_backend_email
node_backend_utils -->|"uploads"| node_external_cloudinary
node_backend_email -->|"sends via"| node_external_email
node_backend_db -->|"connects to"| node_external_mongo
node_frontend_app -->|"renders"| node_frontend_routes
node_frontend_app -->|"wraps"| node_frontend_layout
node_frontend_routes -->|"navigates to"| node_frontend_auth_ui
node_frontend_routes -->|"navigates to"| node_frontend_listing_ui
node_frontend_routes -->|"navigates to"| node_frontend_profile_ui
node_frontend_routes -->|"guards with"| node_frontend_state
node_frontend_auth_ui -->|"calls"| node_frontend_api
node_frontend_listing_ui -->|"calls"| node_frontend_api
node_frontend_profile_ui -->|"calls"| node_frontend_api
node_frontend_api -->|"requests"| node_backend_routes
node_frontend_state -->|"syncs with"| node_frontend_api
node_frontend_api -.->|"uploads media"| node_external_cloudinary

click node_backend_server "https://github.com/aakash070802/brick-nest-estate/blob/main/backend/server.js"
click node_backend_app "https://github.com/aakash070802/brick-nest-estate/blob/main/backend/src/app.js"
click node_backend_config "https://github.com/aakash070802/brick-nest-estate/blob/main/backend/src/config/config.js"
click node_backend_db "https://github.com/aakash070802/brick-nest-estate/blob/main/backend/src/config/database.js"
click node_backend_auth_ctrl "https://github.com/aakash070802/brick-nest-estate/blob/main/backend/src/controller/auth.controller.js"
click node_backend_user_ctrl "https://github.com/aakash070802/brick-nest-estate/blob/main/backend/src/controller/user.controller.js"
click node_backend_listing_ctrl "https://github.com/aakash070802/brick-nest-estate/blob/main/backend/src/controller/listing.controller.js"
click node_backend_favorite_ctrl "https://github.com/aakash070802/brick-nest-estate/blob/main/backend/src/controller/favorite.controller.js"
click node_backend_routes "https://github.com/aakash070802/brick-nest-estate/blob/main/backend/src/routes/auth.route.js"
click node_backend_middleware "https://github.com/aakash070802/brick-nest-estate/blob/main/backend/src/middleware/auth.middleware.js"
click node_backend_models "https://github.com/aakash070802/brick-nest-estate/blob/main/backend/src/models/user.model.js"
click node_backend_utils "https://github.com/aakash070802/brick-nest-estate/blob/main/backend/src/utils/ApiResponse.js"
click node_backend_email "https://github.com/aakash070802/brick-nest-estate/blob/main/backend/src/services/email.service.js"
click node_frontend_app "https://github.com/aakash070802/brick-nest-estate/blob/main/frontend/src/App.jsx"
click node_frontend_routes "https://github.com/aakash070802/brick-nest-estate/blob/main/frontend/src/routes/routesConfig.jsx"
click node_frontend_layout "https://github.com/aakash070802/brick-nest-estate/blob/main/frontend/src/components/layout/Layout.jsx"
click node_frontend_state "https://github.com/aakash070802/brick-nest-estate/blob/main/frontend/src/redux/features/userSlice.js"
click node_frontend_api "https://github.com/aakash070802/brick-nest-estate/blob/main/frontend/src/services/api.js"
click node_frontend_auth_ui "https://github.com/aakash070802/brick-nest-estate/blob/main/frontend/src/containers/auth/Login.jsx"
click node_frontend_listing_ui "https://github.com/aakash070802/brick-nest-estate/blob/main/frontend/src/containers/Home.jsx"
click node_frontend_profile_ui "https://github.com/aakash070802/brick-nest-estate/blob/main/frontend/src/containers/user/Profile.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_app,node_backend_config,node_backend_db,node_backend_auth_ctrl,node_backend_user_ctrl,node_backend_listing_ctrl,node_backend_favorite_ctrl,node_backend_routes,node_backend_middleware,node_backend_models,node_backend_utils,node_backend_email toneBlue
class node_frontend_app,node_frontend_routes,node_frontend_layout,node_frontend_state,node_frontend_api,node_frontend_auth_ui,node_frontend_listing_ui,node_frontend_profile_ui toneAmber
class node_external_mongo,node_external_cloudinary,node_external_email toneMint
```

## Components

### Backend

Express API, auth, persistence, and media handling

- [Server](https://github.com/aakash070802/brick-nest-estate/blob/main/backend/server.js): Node entrypoint · Boots the Node process and starts the API · `backend/server.js`
- [Express App](https://github.com/aakash070802/brick-nest-estate/blob/main/backend/src/app.js): HTTP app · Central Express application and middleware composition · `backend/src/app.js`
- [Config](https://github.com/aakash070802/brick-nest-estate/blob/main/backend/src/config/config.js): Env config · Loads environment-driven settings · `backend/src/config/config.js`
- [Database](https://github.com/aakash070802/brick-nest-estate/blob/main/backend/src/config/database.js): Mongo connector · Initializes MongoDB connectivity · `backend/src/config/database.js`
- [Auth](https://github.com/aakash070802/brick-nest-estate/blob/main/backend/src/controller/auth.controller.js): Auth controller · Login, refresh, logout, and recovery flows · `backend/src/controller/auth.controller.js`
- [User](https://github.com/aakash070802/brick-nest-estate/blob/main/backend/src/controller/user.controller.js): User controller · Profile, password, avatar, and account state actions · `backend/src/controller/user.controller.js`
- [Listing](https://github.com/aakash070802/brick-nest-estate/blob/main/backend/src/controller/listing.controller.js): Listing controller · Listing CRUD, ownership, search, and media workflows · `backend/src/controller/listing.controller.js`
- [Favorites](https://github.com/aakash070802/brick-nest-estate/blob/main/backend/src/controller/favorite.controller.js): Favorite controller · User-scoped favorite toggle and removal actions · `backend/src/controller/favorite.controller.js`
- [Routes](https://github.com/aakash070802/brick-nest-estate/blob/main/backend/src/routes/auth.route.js): Route modules · Domain route layer for auth, users, listings, and favorites · `backend/src/routes/auth.route.js`
- [Middleware](https://github.com/aakash070802/brick-nest-estate/blob/main/backend/src/middleware/auth.middleware.js): Request guard · Auth, error handling, and upload middleware · `backend/src/middleware/auth.middleware.js`
- [Models](https://github.com/aakash070802/brick-nest-estate/blob/main/backend/src/models/user.model.js): Mongoose models · User, listing, session, OTP, and activity persistence · `backend/src/models/user.model.js`
- [Utils](https://github.com/aakash070802/brick-nest-estate/blob/main/backend/src/utils/ApiResponse.js): Cross-cutting utils · Response, errors, sessions, OTP, logging, and Cloudinary helpers · `backend/src/utils/ApiResponse.js`
- [Email Service](https://github.com/aakash070802/brick-nest-estate/blob/main/backend/src/services/email.service.js): Nodemailer service · Sends OTP and recovery mail via Gmail OAuth2 · `backend/src/services/email.service.js`

### Frontend

React SPA, routing, state, and API-facing UI

- [App](https://github.com/aakash070802/brick-nest-estate/blob/main/frontend/src/App.jsx): React shell · Top-level SPA composition and provider wiring · `frontend/src/App.jsx`
- [Routes](https://github.com/aakash070802/brick-nest-estate/blob/main/frontend/src/routes/routesConfig.jsx): Route config · Client-side route definitions and protected navigation · `frontend/src/routes/routesConfig.jsx`
- [Layout](https://github.com/aakash070802/brick-nest-estate/blob/main/frontend/src/components/layout/Layout.jsx): Shell components · Shared header and page layout structure · `frontend/src/components/layout/Layout.jsx`
- [Redux](https://github.com/aakash070802/brick-nest-estate/blob/main/frontend/src/redux/features/userSlice.js): Client state · Persisted user/auth state and store setup · `frontend/src/redux/features/userSlice.js`
- [API Layer](https://github.com/aakash070802/brick-nest-estate/blob/main/frontend/src/services/api.js): Service layer · Backend access through auth, listing, and user services · `frontend/src/services/api.js`
- [Auth UI](https://github.com/aakash070802/brick-nest-estate/blob/main/frontend/src/containers/auth/Login.jsx): Auth screens · Login and register flows with shared form components · `frontend/src/containers/auth/Login.jsx`
- [Listings UI](https://github.com/aakash070802/brick-nest-estate/blob/main/frontend/src/containers/Home.jsx): Listing screens · Home, search, details, and listing management views · `frontend/src/containers/Home.jsx`
- [Profile UI](https://github.com/aakash070802/brick-nest-estate/blob/main/frontend/src/containers/user/Profile.jsx): Profile screens · Profile, password, and account actions · `frontend/src/containers/user/Profile.jsx`

### External

Third-party runtime dependencies

- **MongoDB**: Datastore · Primary system of record
- **Cloudinary**: Media storage · Stores listing images and avatars
- **Gmail OAuth2**: Mail delivery · Transport for OTP and recovery emails

## Connections

- Server → Express App: starts · Server boots the Express application
- Express App → Config: loads · App reads env-driven settings
- Express App → Database: connects · Initializes database connection at startup
- Express App → Middleware: uses · Composes request guards and error handling
- Express App → Routes: mounts · Registers domain routes on the Express app
- Routes → Auth: dispatches · Auth routes call auth controller actions
- Routes → User: dispatches · User routes call profile/account actions
- Routes → Listing: dispatches · Listing routes call property workflows
- Routes → Favorites: dispatches · Favorite routes call user-scoped actions
- Auth → Models: reads/writes · Auth touches user, session, OTP, and activity data
- User → Models: reads/writes · User flows update profile and audit state
- Listing → Models: reads/writes · Listing CRUD and search query persisted listings
- Favorites → Models: updates · Favorites are stored on the user record
- Auth → Utils: uses · Token, session, response, and error helpers
- User → Utils: uses · Uses upload, response, and session helpers
- Listing → Utils: uses · Uses media and response utilities
- Utils → Email Service: invokes · OTP flow sends email through the mail service
- Utils → Cloudinary: uploads · Media helpers push files to Cloudinary
- Email Service → Gmail OAuth2: sends via · Email service delivers OTP mail
- Database → MongoDB: connects to · MongoDB is the primary datastore
- App → Routes: renders · App composes the route tree
- App → Layout: wraps · Shared shell provides header and layout
- Routes → Auth UI: navigates to · Routes expose auth screens
- Routes → Listings UI: navigates to · Routes expose browsing and listing screens
- Routes → Profile UI: navigates to · Routes expose profile/account screens
- Routes → Redux: guards with · Protected routes depend on client auth state
- Auth UI → API Layer: calls · Auth forms submit through the API layer
- Listings UI → API Layer: calls · Listing views fetch and mutate data through services
- Profile UI → API Layer: calls · Profile actions use user services
- API Layer → Routes: requests · Frontend services hit backend route modules
- Redux → API Layer: syncs with · Redux state is updated from API responses
- API Layer → Cloudinary: uploads media · Client uploads are part of listing/avatar flows
