How aakash070802/brick-nest-estate works
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: auth.route.js Routes · api.js API Layer · app.js Express App · routesConfig.jsx Routes
Components 24
Backend
Express API, auth, persistence, and media handling
- Server · Boots the Node process and starts the API
backend/server.js - Express App · Central Express application and middleware composition
backend/src/app.js - Config · Loads environment-driven settings
backend/src/config/config.js - Database · Initializes MongoDB connectivity
backend/src/config/database.js - Auth · Login, refresh, logout, and recovery flows
backend/src/controller/auth.controller.js - User · Profile, password, avatar, and account state actions
backend/src/controller/user.controller.js - Listing · Listing CRUD, ownership, search, and media workflows
backend/src/controller/listing.controller.js - Favorites · User-scoped favorite toggle and removal actions
backend/src/controller/favorite.controller.js - Routes · Domain route layer for auth, users, listings, and favorites
backend/src/routes/auth.route.js - Middleware · Auth, error handling, and upload middleware
backend/src/middleware/auth.middleware.js - Models · User, listing, session, OTP, and activity persistence
backend/src/models/user.model.js - Utils · Response, errors, sessions, OTP, logging, and Cloudinary helpers
backend/src/utils/ApiResponse.js - Email 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 · Top-level SPA composition and provider wiring
frontend/src/App.jsx - Routes · Client-side route definitions and protected navigation
frontend/src/routes/routesConfig.jsx - Layout · Shared header and page layout structure
frontend/src/components/layout/Layout.jsx - Redux · Persisted user/auth state and store setup
frontend/src/redux/features/userSlice.js - API Layer · Backend access through auth, listing, and user services
frontend/src/services/api.js - Auth UI · Login and register flows with shared form components
frontend/src/containers/auth/Login.jsx - Listings UI · Home, search, details, and listing management views
frontend/src/containers/Home.jsx - Profile UI · Profile, password, and account actions
frontend/src/containers/user/Profile.jsx
External
Third-party runtime dependencies
- MongoDB · Primary system of record
- Cloudinary · Stores listing images and avatars
- Gmail OAuth2 · Transport for OTP and recovery emails
Connections 32
- 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