# samarth-mahajan/student_housing_project architecture

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

- Interactive diagram: https://gitdiagram.com/samarth-mahajan/student_housing_project
- Repository: https://github.com/samarth-mahajan/student_housing_project

## Overview

##### Project Type and Purpose
- This is a full-stack, property-listing web application managed as a monorepo (Turborepo).
- Frontend: a React TypeScript SPA that lets students, landlords, and moderators browse, list, chat about, and favorite properties.
- Backend: a Node.js service (Express + MikroORM) exposing REST endpoints for authentication, property CRUD, chat, media uploads, questionnaires, favorites, and insights.
- Shared code: TypeScript models and utilities in a `packages/common` workspace.
- Tests: Bruno API test scripts and Playwright E2E tests.
- Deployment: Azure VM running Ubuntu + Nginx, MySQL, Azure Blob Storage for media, SSL via Let’s Encrypt.

##### File-Structure Analysis
- `apps/frontend`: React app (TSX components under `src/components`, API client in `src/api.ts`).
- `apps/backend`: Node.js service using MikroORM (entities, migrations, seeders under `src/db`), routers, middlewares, blob-storage integration.
- `packages/common`: shared TypeScript interfaces and constants.
- `bruno`: API test definitions and environment configs.
- `credentials`: VM SSH keys and related files.
- Root config: `turbo.json`, workspace-level ESLint & TSConfig under `packages/eslint-config` and `packages/typescript-config`.

##### Key README Insights
- Turborepo to share configs & models.
- `.env` controls ports and blob-storage endpoint.
- Run with `npm run dev` (both apps) or per workspace.
- CI/CD hints: GitHub Actions docs, but no explicit `.github` folder shown in file tree (likely exists).
- DB migrations auto-run on startup; Azure VM + Nginx front-end.

##### Main Components
a. Frontend SPA (React)
b. Backend API Service (Node.js + Express + MikroORM)
c. MySQL Database
d. Azure Blob Storage (media files)
e. Nginx reverse proxy / static asset server
f. Shared code package (for dev context)
g. Testing tools: Bruno (API tests), Playwright (E2E)
h. Developer workstations with Turborepo (local dev)
i. Azure VM infrastructure (OS, SSL certs, VM network)

##### Relationships & Interactions
- Frontend ↔ Backend: HTTP/HTTPS calls (authenticate, fetch listings, post messages, file uploads).
- Backend ↔ MySQL: ORM queries & migrations.
- Backend ↔ Azure Blob Storage: media upload/download.
- Nginx ↔ Frontend: serves compiled static assets; Nginx ↔ Backend: reverse-proxy API routes to Node.js.
- Developer machine ↔ Turborepo: runs local dev commands; invokes both apps.
- Bruno & Playwright run HTTP tests against Nginx endpoint.

##### Architectural Patterns & Principles
- Monorepo with workspace isolation (apps vs packages).
- MVC-style division in backend: routers → controllers → entities → DB.
- Shared TypeScript models for type safety across tiers.
- Infrastructure decoupling: Blob storage abstracted in `blob-storage.ts`.
- Database versioning via MikroORM migrations/seeders.

##### Technologies & Frameworks
- React, React Router (frontend).
- Node.js, Express, MikroORM, MySQL (backend).
- Turborepo, TypeScript, ESLint, Tailwind CSS (dev infra).
- Azure VM, Nginx, Let’s Encrypt, Azure Blob Storage (deployment).
- Bruno, Playwright (testing).

##### Final Advice
- Both runtime deployment (production topology) and code organization (monorepo).
- Be detailed: break out subcomponents in backend (Routers, Middlewares, ORM) if needed.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Local Development"
        Developer["Developer Machine"]:::dev
        Turborepo["Turborepo Monorepo"]:::infra
        Developer -->|"runs npm run dev"| Turborepo

        subgraph "Monorepo"
            subgraph "apps/frontend"
                FE_Entry["index.tsx"]:::file
                FE_API["api.ts / api/api.ts"]:::file
                FE_Comp["components"]:::dir
            end
            subgraph "apps/backend"
                BE_Entry["index.ts"]:::file
                BE_Blob["blob-storage.ts"]:::file
                BE_Chat["chat.ts"]:::file
                BE_Routers["routers"]:::dir
                BE_MW["auth.middleware.ts"]:::file
                BE_DB["db/index.ts"]:::file
                BE_Mig["db/migrations"]:::dir
                BE_Seed["DatabaseSeeder.ts"]:::file
                BE_Entities["entities"]:::dir
            end
            subgraph "packages/common"
                Common_Models["models"]:::dir
                Common_Const["constants.ts"]:::file
                Common_Util["util.ts"]:::file
            end
            subgraph "bruno"
                Bruno_TS["*.bru"]:::file
                Bruno_Env["environments"]:::dir
            end
            subgraph "Playwright"
                PW_Config["playwright.config.js"]:::file
                PW_Tests["tests/example.spec.js"]:::file
            end
            subgraph "Configs"
                Turbo["turbo.json"]:::file
                ESLint["packages/eslint-config"]:::dir
                TSC["packages/typescript-config"]:::dir
            end
        end
        Developer -->|"runs API tests"| Bruno_TS
        Developer -->|"runs E2E tests"| PW_Config
    end

    subgraph "Production - Azure VM"
        VM["Azure VM (Ubuntu)"]:::infra
        Nginx["Nginx Reverse Proxy"]:::nginx
        SPA["React SPA Static"]:::frontend
        API["Node.js API Service"]:::backend
        DB["MySQL Database"]:::database
        Blob["Azure Blob Storage"]:::cloud

        VM --> Nginx
        Nginx -->|"serve static (80/443)"| SPA
        Nginx -->|"proxy /api (443)"| API
        SPA -->|"HTTPS:443 GET/POST"| API
        API -->|"SQL Queries"| DB
        API -->|"Upload/Download"| Blob
        Bruno_TS -->|"HTTP Tests"| Nginx
        PW_Config -->|"Browser Tests"| Nginx
    end

    click FE_Entry "https://github.com/samarth-mahajan/student_housing_project/blob/main/apps/frontend/src/index.tsx"
    click FE_API "https://github.com/samarth-mahajan/student_housing_project/blob/main/apps/frontend/src/api.ts"
    click FE_Comp "https://github.com/samarth-mahajan/student_housing_project/tree/main/apps/frontend/src/components"
    click BE_Entry "https://github.com/samarth-mahajan/student_housing_project/blob/main/apps/backend/src/index.ts"
    click BE_Blob "https://github.com/samarth-mahajan/student_housing_project/blob/main/apps/backend/src/blob-storage.ts"
    click BE_Chat "https://github.com/samarth-mahajan/student_housing_project/blob/main/apps/backend/src/chat.ts"
    click BE_Routers "https://github.com/samarth-mahajan/student_housing_project/tree/main/apps/backend/src/routers"
    click BE_MW "https://github.com/samarth-mahajan/student_housing_project/blob/main/apps/backend/src/middlewares/auth.middleware.ts"
    click BE_DB "https://github.com/samarth-mahajan/student_housing_project/blob/main/apps/backend/src/db/index.ts"
    click BE_Mig "https://github.com/samarth-mahajan/student_housing_project/tree/main/apps/backend/src/db/migrations"
    click BE_Seed "https://github.com/samarth-mahajan/student_housing_project/blob/main/apps/backend/src/db/seeders/DatabaseSeeder.ts"
    click BE_Entities "https://github.com/samarth-mahajan/student_housing_project/tree/main/apps/backend/src/entities"
    click Common_Models "https://github.com/samarth-mahajan/student_housing_project/tree/main/packages/common/src/models"
    click Common_Const "https://github.com/samarth-mahajan/student_housing_project/blob/main/packages/common/src/constants.ts"
    click Common_Util "https://github.com/samarth-mahajan/student_housing_project/blob/main/packages/common/src/util.ts"
    click Bruno_TS "https://github.com/samarth-mahajan/student_housing_project/tree/main/bruno"
    click Bruno_Env "https://github.com/samarth-mahajan/student_housing_project/blob/main/bruno/environments/local.bru"
    click PW_Config "https://github.com/samarth-mahajan/student_housing_project/blob/main/playwright.config.js"
    click PW_Tests "https://github.com/samarth-mahajan/student_housing_project/blob/main/tests/example.spec.js"
    click Turbo "https://github.com/samarth-mahajan/student_housing_project/blob/main/turbo.json"
    click ESLint "https://github.com/samarth-mahajan/student_housing_project/tree/main/packages/eslint-config"
    click TSC "https://github.com/samarth-mahajan/student_housing_project/tree/main/packages/typescript-config"

    classDef frontend fill:#cce5ff,stroke:#004085,color:#004085
    classDef backend fill:#d4edda,stroke:#155724,color:#155724
    classDef database fill:#fff3cd,stroke:#856404,color:#856404
    classDef cloud fill:#e2e3e5,stroke:#6c757d,color:#6c757d
    classDef nginx fill:#d6d8d9,stroke:#1b1e21,color:#1b1e21
    classDef dev fill:#f5c6cb,stroke:#721c24,color:#721c24
    classDef infra fill:#bee5eb,stroke:#0c5460,color:#0c5460
    classDef shared fill:#ffeeba,stroke:#856404,color:#856404
    classDef test fill:#f8d7da,stroke:#721c24,color:#721c24
    classDef file fill:#d1ecf1,stroke:#0c5460,color:#0c5460
    classDef dir fill:#d1ecf1,stroke:#0c5460,color:#0c5460
```
