# hamza9021/roomify architecture

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

- Interactive diagram: https://gitdiagram.com/hamza9021/roomify
- Repository: https://github.com/hamza9021/roomify

## Overview

##### Project type and purpose
- This is a full-stack web application.
- Frontend: React (Vite), Tailwind CSS, handles user interface (auth, listings, messaging, profile).
- Backend: Node.js/Express REST API, follows MVC pattern, handles authentication, data persistence, file uploads, and external service integration (Cloudinary).
- Database: Presumably MongoDB (model files under `src/Models`).

##### File structure
- Top level:
- BACKEND/ – Express API
- FRONTEND/ – React single-page app
- readme.md – (empty)
- BACKEND/ layered by concern:
- src/Routes → maps endpoints to controllers
- src/Controllers → business logic
- src/Models → data schemas
- src/Middlewares → authentication, file upload
- src/Services → external integrations (Cloudinary, Passport, token generation)
- src/Utils → error handling, async wrappers, DB connection
- app.js & index.js → bootstrapping Express server
- FRONTEND/ organized by feature:
- src/Components/Auth, Listings, Messages, Profile Update → React components
- main.jsx & App.jsx → application entrypoints
- index.html → HTML shell
- config files: vite.config.js, tailwind.config.js, vercel.json

##### README for additional insights
- (Empty in this case; file tree implies usage of JWT, Cloudinary, RESTful design, client ↔ server interaction.)

a. Main components:
1. Client (Browser) running React/Vite SPA
2. Web Server (Express app) exposing REST API
3. Database (MongoDB) for persisting users, listings, messages, reviews
4. External Service: Cloudinary for image storage
5. Authentication service (JWT & Passport strategies)

b. Relationships & interactions:
- Client ↔ Web Server: HTTP(S) requests (GET/POST/PUT/DELETE) to `/api/auth`, `/api/listings`, `/api/messages`, `/api/reviews`, `/api/users`.
- Web Server → Database: CRUD operations via Mongoose models.
- Web Server → Cloudinary: Upload and retrieve listing images.
- Web Server internal layering:
– Routes call Controllers → Controllers call Services/Models → Models talk to DB.
– Middleware (auth, multer) intercept HTTP requests.
– Utils handle errors and token generation.

c. Architectural patterns & design principles:
- MVC pattern (Models-Views-Controllers) on the backend.
- Single-page application on the frontend.
- RESTful API layer between frontend and backend.
- Separation of concerns: routing, business logic, data access, third-party integrations each in their own folder.
- Token‐based authentication (JWT, access & refresh tokens).

d. Key technologies & frameworks:
- Frontend: React, Vite, Tailwind CSS
- Backend: Node.js, Express.js, Passport.js, Multer, Cloudinary SDK
- Database: MongoDB (via Mongoose)
- Deployment/config: Vercel (frontend), environment variables (.env)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "Frontend (React SPA)" 
        direction TB
        BROWSER["Browser"]:::frontend
        MAIN["main.jsx"]:::frontend
        APP["App.jsx"]:::frontend
        INDEXHTML["index.html"]:::frontend
        CSS["index.css"]:::frontend
        TAILWIND["tailwind.config.js"]:::frontend
        VITE["vite.config.js"]:::frontend
        subgraph "Auth Components"
            direction TB
            LOGIN["Login.jsx"]:::frontend
            LOGOUT["Logout.jsx"]:::frontend
            REGISTER["Register.jsx"]:::frontend
        end
        subgraph "Listing Components"
            direction TB
            CREATE["CreateListing.jsx"]:::frontend
        end
        subgraph "Message Components"
            direction TB
            MESSAGESUI["Messages.jsx"]:::frontend
        end
        subgraph "Profile Components"
            direction TB
            LISTINGDETAIL["ListingDetail.jsx"]:::frontend
            UPDATEUSER["UpdateUser.jsx"]:::frontend
        end
    end

    %% Backend Layer
    subgraph "Backend (Express API)" 
        direction TB
        ENTRY["index.js / app.js"]:::server
        subgraph "Routes (API Gateway)"
            direction TB
            AUTHROUTE["auth.routes.js"]:::server
            LISTINGROUTE["listing.routes.js"]:::server
            MESSAGEROUTE["message.routes.js"]:::server
            REVIEWROUTE["review.routes.js"]:::server
            USERROUTE["user.routes.js"]:::server
        end
        subgraph "Middlewares"
            direction TB
            AUTHMW["auth.middleware.js"]:::server
            MULTER["multer.js"]:::server
        end
        subgraph "Controllers"
            direction TB
            LISTINGCTRL["listing.controllers.js"]:::server
            MESSAGECTRL["message.controllers.js"]:::server
            REVIEWCTRL["review.controllers.js"]:::server
            USERCTRL["user.controllers.js"]:::server
        end
        subgraph "Services"
            direction TB
            CLOUDSERV["cloudinary.js"]:::server
            PASSPORT["passport.js"]:::server
            TOKENUTIL["generateAccessAndRefreshToken.js"]:::server
        end
        subgraph "Models"
            direction TB
            LISTINGMODEL["listing.models.js"]:::server
            MESSAGEMODEL["message.models.js"]:::server
            REVIEWMODEL["review.models.js"]:::server
            USERMODEL["user.models.js"]:::server
        end
        subgraph "Utils"
            direction TB
            DBCONN["db.js"]:::server
            ASYNCWRAP["asyncWrap.js"]:::server
            APIERROR["ApiError.js"]:::server
            APIRESPONSE["ApiResponse.js"]:::server
        end
    end

    %% External Systems
    DB["MongoDB"]:::external
    CLOUD["Cloudinary"]:::external

    %% Connections
    BROWSER -->|serves SPA| MAIN
    MAIN --> APP
    APP --> INDEXHTML
    APP --> CSS
    APP --> TAILWIND
    APP --> VITE
    APP --> LOGIN
    APP --> LOGOUT
    APP --> REGISTER
    APP --> CREATE
    APP --> MESSAGESUI
    APP --> LISTINGDETAIL
    APP --> UPDATEUSER

    BROWSER -->|HTTP /api/...| AUTHROUTE
    BROWSER -->|HTTP /api/...| LISTINGROUTE
    BROWSER -->|HTTP /api/...| MESSAGEROUTE
    BROWSER -->|HTTP /api/...| REVIEWROUTE
    BROWSER -->|HTTP /api/...| USERROUTE

    ENTRY --> AUTHROUTE
    ENTRY --> LISTINGROUTE
    ENTRY --> MESSAGEROUTE
    ENTRY --> REVIEWROUTE
    ENTRY --> USERROUTE
    AUTHROUTE --> AUTHMW
    LISTINGROUTE --> MULTER
    AUTHROUTE --> LISTINGCTRL
    LISTINGROUTE --> LISTINGCTRL
    MESSAGEROUTE --> MESSAGECTRL
    REVIEWROUTE --> REVIEWCTRL
    USERROUTE --> USERCTRL

    AUTHMW --> USERCTRL
    MULTER --> CLOUDSERV
    LISTINGCTRL --> LISTINGMODEL
    MESSAGECTRL --> MESSAGEMODEL
    REVIEWCTRL --> REVIEWMODEL
    USERCTRL --> USERMODEL

    LISTINGCTRL --> CLOUDSERV
    CLOUDSERV --> CLOUD
    LISTINGMODEL --> DBCONN
    MESSAGEMODEL --> DBCONN
    REVIEWMODEL --> DBCONN
    USERMODEL --> DBCONN
    DBCONN --> DB

    %% Click Events
    click MAIN "https://github.com/hamza9021/roomify/blob/main/FRONTEND/src/main.jsx"
    click APP "https://github.com/hamza9021/roomify/blob/main/FRONTEND/src/App.jsx"
    click INDEXHTML "https://github.com/hamza9021/roomify/blob/main/FRONTEND/index.html"
    click CSS "https://github.com/hamza9021/roomify/blob/main/FRONTEND/src/index.css"
    click TAILWIND "https://github.com/hamza9021/roomify/blob/main/FRONTEND/tailwind.config.js"
    click VITE "https://github.com/hamza9021/roomify/blob/main/FRONTEND/vite.config.js"
    click LOGIN "https://github.com/hamza9021/roomify/blob/main/FRONTEND/src/Components/Auth/Login.jsx"
    click LOGOUT "https://github.com/hamza9021/roomify/blob/main/FRONTEND/src/Components/Auth/Logout.jsx"
    click REGISTER "https://github.com/hamza9021/roomify/blob/main/FRONTEND/src/Components/Auth/Register.jsx"
    click CREATE "https://github.com/hamza9021/roomify/blob/main/FRONTEND/src/Components/Listings/CreateListing.jsx"
    click MESSAGESUI "https://github.com/hamza9021/roomify/blob/main/FRONTEND/src/Components/Messages/Messages.jsx"
    click LISTINGDETAIL "https://github.com/hamza9021/roomify/blob/main/FRONTEND/src/Components/Profile Update/ListingDetail.jsx"
    click UPDATEUSER "https://github.com/hamza9021/roomify/blob/main/FRONTEND/src/Components/Profile Update/UpdateUser.jsx"
    click ENTRY "https://github.com/hamza9021/roomify/blob/main/BACKEND/src/index.js"
    click ENTRY "https://github.com/hamza9021/roomify/blob/main/BACKEND/src/app.js"
    click AUTHROUTE "https://github.com/hamza9021/roomify/blob/main/BACKEND/src/Routes/auth.routes.js"
    click LISTINGROUTE "https://github.com/hamza9021/roomify/blob/main/BACKEND/src/Routes/listing.routes.js"
    click MESSAGEROUTE "https://github.com/hamza9021/roomify/blob/main/BACKEND/src/Routes/message.routes.js"
    click REVIEWROUTE "https://github.com/hamza9021/roomify/blob/main/BACKEND/src/Routes/review.routes.js"
    click USERROUTE "https://github.com/hamza9021/roomify/blob/main/BACKEND/src/Routes/user.routes.js"
    click LISTINGCTRL "https://github.com/hamza9021/roomify/blob/main/BACKEND/src/Controllers/listing.controllers.js"
    click MESSAGECTRL "https://github.com/hamza9021/roomify/blob/main/BACKEND/src/Controllers/message.controllers.js"
    click REVIEWCTRL "https://github.com/hamza9021/roomify/blob/main/BACKEND/src/Controllers/review.controllers.js"
    click USERCTRL "https://github.com/hamza9021/roomify/blob/main/BACKEND/src/Controllers/user.controllers.js"
    click LISTINGMODEL "https://github.com/hamza9021/roomify/blob/main/BACKEND/src/Models/listing.models.js"
    click MESSAGEMODEL "https://github.com/hamza9021/roomify/blob/main/BACKEND/src/Models/message.models.js"
    click REVIEWMODEL "https://github.com/hamza9021/roomify/blob/main/BACKEND/src/Models/review.models.js"
    click USERMODEL "https://github.com/hamza9021/roomify/blob/main/BACKEND/src/Models/user.models.js"
    click AUTHMW "https://github.com/hamza9021/roomify/blob/main/BACKEND/src/Middlewares/auth.middleware.js"
    click MULTER "https://github.com/hamza9021/roomify/blob/main/BACKEND/src/Middlewares/multer.js"
    click CLOUDSERV "https://github.com/hamza9021/roomify/blob/main/BACKEND/src/Services/cloudinary.js"
    click PASSPORT "https://github.com/hamza9021/roomify/blob/main/BACKEND/src/Services/passport.js"
    click TOKENUTIL "https://github.com/hamza9021/roomify/blob/main/BACKEND/src/Utils/generateAccessAndRefreshToken.js"
    click DBCONN "https://github.com/hamza9021/roomify/blob/main/BACKEND/src/Utils/db.js"
    click ASYNCWRAP "https://github.com/hamza9021/roomify/blob/main/BACKEND/src/Utils/asyncWrap.js"
    click APIERROR "https://github.com/hamza9021/roomify/blob/main/BACKEND/src/Utils/ApiError.js"
    click APIRESPONSE "https://github.com/hamza9021/roomify/blob/main/BACKEND/src/Utils/ApiResponse.js"

    %% Styles
    classDef frontend fill:#D6EAF8,stroke:#1B4F72,color:#1B2631
    classDef server fill:#D5F5E3,stroke:#145A32,color:#0B5345
    classDef external fill:#FCF3CF,stroke:#B9770E,color:#7E5109
```
