# pedro1guevara/mern-real-estate architecture

> Architecture diagram of the GitHub repository pedro1guevara/mern-real-estate, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/pedro1guevara/mern-real-estate
- Repository: https://github.com/pedro1guevara/mern-real-estate

## Overview

##### Project Type and Purpose
- This is a MERN-stack full-stack web application for real-estate listings.
- Frontend: React.js (Vite), Tailwind CSS, Redux, React Router, i18n, Firebase SDK.
- Backend: Node.js with Express.js exposing RESTful routes for users and listings.
- Database: MongoDB (via Mongoose).
- External services: Firebase (client-side SDK), Google OAuth, Mapping/geocoding APIs.

##### File Structure
- Top-level “api/” directory – server code:
- index.js – Express app bootstrap
- controllers/ – business logic for auth, user, listing
- routes/ – mapping of REST endpoints
- models/ – Mongoose schemas (User, Listing)
- utils/ – error handling, JWT user verification
- Top-level “client/” directory – frontend code:
- src/pages/ – route-level React pages (Home, Profile, Listings, etc.)
- src/components/ – reusable UI pieces (Header, Map, OAuth, PrivateRoute, etc.)
- src/redux/ – Redux store and user slice
- src/i18n/ – internationalization setup
- src/firebase.js – Firebase configuration for client SDK
- Configuration: package.json, Vite/Tailwind, ESLint, PostCSS.

##### Key README Insights
- Implements full CRUD over Listings and Users.
- Authentication flows include email/password plus Google Sign-In.
- Responsive design, pagination, search & filter, image uploads.
- Defines REST API endpoints under /api/user/* and /api/listing/*.

##### Main Components & Relationships
a. Frontend (Client)
- Browser running React Single-Page App.
- Redux store managing global state (user session, listings).
- Firebase SDK for optional client-side services (e.g., image storage, auth helpers).
- External Map/Geocoding API for location picker and map display.
- OAuth component → Google Identity Platform.
b. Backend (Server)
- Express.js REST API
- Controllers (auth, user, listing)
- Mongoose models → MongoDB Atlas/Instance
- Middleware (error handler, JWT verifier)
c. Database
- MongoDB (collections: users, listings)
d. External Services
- Google OAuth / Identity Platform
- (Optional) Firebase Storage or other Firebase services
- Mapping/Geocoding API

Data Flows:
[Browser]<–HTTP(S)–>[React SPA]–(dispatch)–>[Redux]
[React SPA]–HTTP(S)→[Express API]–Mongoose→[MongoDB]→results
[React SPA]–SDK calls→[Firebase Services]
[React SPA]–REST/OAuth→[Google Identity]
[React SPA]–REST→[Mapping API]

##### Architectural Patterns & Design Principles
- Clear separation of concerns: UI vs. API vs. data layer.
- RESTful design for server endpoints.
- MVC-style server organization (routes → controllers → models).
- Client-side state management (Redux) for predictable UI state.
- Middleware chain in Express for auth and error handling.
- Internationalization (i18n) wrapper around React.

##### Essential Details to Capture
- All REST endpoints under /api/user and /api/listing.
- Middlewares: verifyUser, error handler.
- i18n wrapper around root component.
- Firebase initialization used by client.
- Mapping/LocationPicker integration.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "Frontend (Client)" 
        direction TB
        Browser["Browser"]:::frontend
        ReactApp["React SPA"]:::frontend
        IntlWrapper["IntlWrapper"]:::frontend
        ReduxStore["Redux Store"]:::frontend
        FirebaseSDK["Firebase SDK"]:::frontend
        MapAPI["Map/Geocoding API"]:::frontend
        GoogleOAuthComp["OAuth Component"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend (Server)"
        direction TB
        ExpressApp["Express App"]:::backend
        AuthRoutes["Auth Routes"]:::backend
        UserRoutes["User Routes"]:::backend
        ListingRoutes["Listing Routes"]:::backend
        AuthController["Auth Controller"]:::backend
        UserController["User Controller"]:::backend
        ListingController["Listing Controller"]:::backend
        VerifyUser["JWT Verification Middleware"]:::backend
        ErrorUtil["Error Handling Utility"]:::backend
        UserModel["User Model"]:::backend
        ListingModel["Listing Model"]:::backend
    end

    %% Database Layer
    subgraph "Database"
        direction TB
        MongoDB["MongoDB"]:::db
    end

    %% External Services
    subgraph "External Services"
        direction TB
        GoogleIdentity["Google Identity Platform"]:::ext
        FirebaseServices["Firebase Services"]:::ext
        MapService["Map/Geocoding Service"]:::ext
    end

    %% Frontend flows
    Browser -->|loads| ReactApp
    ReactApp -->|wraps| IntlWrapper
    ReactApp -->|uses| ReduxStore
    ReactApp -->|init| FirebaseSDK
    ReactApp -->|GET/POST /api| ExpressApp
    ReactApp -->|SDK calls| FirebaseServices
    ReactApp -->|REST/OAuth| GoogleIdentity
    ReactApp -->|REST| MapService

    %% Backend flows
    ExpressApp -->|use routes| AuthRoutes
    ExpressApp -->|use routes| UserRoutes
    ExpressApp -->|use routes| ListingRoutes
    AuthRoutes -->|POST /auth*| AuthController
    UserRoutes -->|/api/user| VerifyUser
    UserRoutes -->|GET/POST| UserController
    ListingRoutes -->|/api/listing| VerifyUser
    ListingRoutes -->|GET/POST/PUT/DELETE| ListingController
    AuthController -->|issues| VerifyUser
    AuthController -->|error| ErrorUtil
    UserController -->|db ops| UserModel
    ListingController -->|db ops| ListingModel
    UserModel -->|mongoose| MongoDB
    ListingModel -->|mongoose| MongoDB

    %% External flows
    VerifyUser -->|token verify| GoogleIdentity
    FirebaseSDK -->|auth/storage| FirebaseServices
    MapAPI -->|geocode| MapService

    %% Click Events - Frontend
    click ReactApp "https://github.com/pedro1guevara/mern-real-estate/blob/experimental/client/src/main.jsx"
    click IntlWrapper "https://github.com/pedro1guevara/mern-real-estate/blob/experimental/client/src/i18n/IntlWrapper.jsx"
    click ReduxStore "https://github.com/pedro1guevara/mern-real-estate/blob/experimental/client/src/redux/store.js"
    click FirebaseSDK "https://github.com/pedro1guevara/mern-real-estate/blob/experimental/client/src/firebase.js"
    click GoogleOAuthComp "https://github.com/pedro1guevara/mern-real-estate/blob/experimental/client/src/components/OAuth.jsx"
    click MapAPI "https://github.com/pedro1guevara/mern-real-estate/blob/experimental/client/src/components/ListingMap.jsx"

    %% Click Events - Backend
    click ExpressApp "https://github.com/pedro1guevara/mern-real-estate/blob/experimental/api/index.js"
    click AuthController "https://github.com/pedro1guevara/mern-real-estate/blob/experimental/api/controllers/auth.controller.js"
    click UserController "https://github.com/pedro1guevara/mern-real-estate/blob/experimental/api/controllers/user.controller.js"
    click ListingController "https://github.com/pedro1guevara/mern-real-estate/blob/experimental/api/controllers/listing.controller.js"
    click AuthRoutes "https://github.com/pedro1guevara/mern-real-estate/blob/experimental/api/routes/auth.route.js"
    click UserRoutes "https://github.com/pedro1guevara/mern-real-estate/blob/experimental/api/routes/user.route.js"
    click ListingRoutes "https://github.com/pedro1guevara/mern-real-estate/blob/experimental/api/routes/listing.route.js"
    click VerifyUser "https://github.com/pedro1guevara/mern-real-estate/blob/experimental/api/utils/verifyUser.js"
    click ErrorUtil "https://github.com/pedro1guevara/mern-real-estate/blob/experimental/api/utils/error.js"
    click UserModel "https://github.com/pedro1guevara/mern-real-estate/blob/experimental/api/models/user.model.js"
    click ListingModel "https://github.com/pedro1guevara/mern-real-estate/blob/experimental/api/models/listing.model.js"

    %% Click Events - Other Frontend Components
    click Header "https://github.com/pedro1guevara/mern-real-estate/blob/experimental/client/src/components/Header.jsx"
    click LanguageSelector "https://github.com/pedro1guevara/mern-real-estate/blob/experimental/client/src/components/LanguageSelector.jsx"
    click PrivateRoute "https://github.com/pedro1guevara/mern-real-estate/blob/experimental/client/src/components/PrivateRoute.jsx"
    click LocationPicker "https://github.com/pedro1guevara/mern-real-estate/blob/experimental/client/src/components/LocationPicker.jsx"
    click ListingItem "https://github.com/pedro1guevara/mern-real-estate/blob/experimental/client/src/components/ListingItem.jsx"
    click Contact "https://github.com/pedro1guevara/mern-real-estate/blob/experimental/client/src/components/Contact.jsx"
    click HomePage "https://github.com/pedro1guevara/mern-real-estate/blob/experimental/client/src/pages/Home.jsx"
    click ProfilePage "https://github.com/pedro1guevara/mern-real-estate/blob/experimental/client/src/pages/Profile.jsx"
    click SearchPage "https://github.com/pedro1guevara/mern-real-estate/blob/experimental/client/src/pages/Search.jsx"
    click ListingPage "https://github.com/pedro1guevara/mern-real-estate/blob/experimental/client/src/pages/Listing.jsx"
    click CreateListingPage "https://github.com/pedro1guevara/mern-real-estate/blob/experimental/client/src/pages/CreateListing.jsx"
    click UpdateListingPage "https://github.com/pedro1guevara/mern-real-estate/blob/experimental/client/src/pages/UpdateListing.jsx"
    click SignInPage "https://github.com/pedro1guevara/mern-real-estate/blob/experimental/client/src/pages/SignIn.jsx"
    click SignUpPage "https://github.com/pedro1guevara/mern-real-estate/blob/experimental/client/src/pages/SignUp.jsx"
    click AboutPage "https://github.com/pedro1guevara/mern-real-estate/blob/experimental/client/src/pages/About.jsx"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#333,stroke-width:1px
    classDef backend fill:#D0FFD6,stroke:#333,stroke-width:1px
    classDef db fill:#FFF1A8,stroke:#333,stroke-width:1px
    classDef ext fill:#FFD6D6,stroke:#333,stroke-width:1px
```
