# asaufi/plateforme-immobiliere architecture

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

- Interactive diagram: https://gitdiagram.com/asaufi/plateforme-immobiliere
- Repository: https://github.com/asaufi/plateforme-immobiliere

## Overview

##### Project type and purpose
- This is a **full-stack, server-side-rendered (SSR) web application** using the MVC pattern.
- Purpose: manage users and properties with authentication (Passport), routing (Express), views (EJS), and persistent storage (a database accessed via models).

##### File structure
- **Entry point**: bin/www.ts → creates HTTP server, loads app.ts
- **App configuration**: app.ts → sets up Express, view engine, static files, middleware, routes
- **Config**: config/passportConfig.ts → Passport strategies
- **Middlewares**: isAuthenticated, isAgent → authorization gates
- **Routes**: routes/*.ts → route definitions delegating to controllers (implicitly in route handlers)
- **Models**: models/User.ts, models/Property.ts → data schemas (likely Mongoose)
- **Views**: views/*.ejs → server-side templates
- **Public assets**: public/stylesheets/style.css
- **Tests**: tests/*.ts

##### Main components and their interactions
a. **Client**
- Browser requests pages and submits forms; receives HTML/CSS.
b. **Express Server (app.ts + bin/www.ts)**
- Serves static assets
- Applies middleware chain
- Dispatches to route handlers
c. **Middleware Layer**
- Logging, body parsing, session management, Passport authentication
- Authorization guards (isAuthenticated, isAgent)
d. **Routing Layer**
- routes/index.ts, users.ts, auth.ts
- Each route invokes controller logic (inline or delegated)
e. **Controller/Handler Logic**
- Interacts with models, prepares data, chooses view or redirect
f. **Models/Data Access**
- models/User.ts, Property.ts define schema and DB methods
g. **Views**
- EJS templates (index, login, register, properties, etc.) render HTML
h. **Tests**

##### Architectural patterns and principles
- **MVC**: clear separation between Controllers (routes/handlers), Models (data), Views (EJS)
- **Middleware pipeline**: pluggable request-processing stages (authentication, authorization)
- **Single Monolith**: all code runs in one Node.js process; no microservices

##### Final checklist
- All major components (Browser, Express App, Middleware, Routes, Controllers, Models, Database, Views)
- Clear labels indicating filenames or folder names (e.g., “routes/auth.ts”)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Side
    subgraph "Client"
        Browser["Browser"]:::client
        StaticFiles["Static Files"]:::client
    end

    %% Server Side
    subgraph "Server"
        EntryPoint["Entry Point\n(bin/www.ts)"]:::server
        ExpressApp["Express App\n(app.ts)"]:::server
        subgraph "Configuration"
            PassportConfig["PassportConfig\n(config/passportConfig.ts)"]:::server
        end
        subgraph "Middleware Layer"
            AuthGuard["isAuthenticated"]:::server
            AgentGuard["isAgent"]:::server
        end
        subgraph "Routing & Controllers"
            HomeRoute["Home Routes\n(routes/index.ts)"]:::server
            AuthRoute["Auth Routes\n(routes/auth.ts)"]:::server
            UserRoute["User Routes\n(routes/users.ts)"]:::server
        end
        subgraph "Models & Data Access"
            UserModel["User Model\n(models/User.ts)"]:::server
            PropertyModel["Property Model\n(models/Property.ts)"]:::server
            DB["Database"]:::db
        end
        subgraph "Views"
            LayoutView["Layout Template\n(views/layout.ejs)"]:::view
            IndexView["Home Page\n(views/index.ejs)"]:::view
            ErrorView["Error Page\n(views/error.ejs)"]:::view
            LoginView["Login Page\n(views/login.ejs)"]:::view
            RegisterView["Register Page\n(views/register.ejs)"]:::view
            PropertiesView["Properties Page\n(views/properties.ejs)"]:::view
            AjouterView["Add Property\n(views/ajouter.ejs)"]:::view
            EditView["Edit Property\n(views/edit.ejs)"]:::view
        end
    end

    %% Test Suite
    subgraph "Tests"
        TestAjouter["ajouter.test.ts"]:::test
        TestProperty["property.test.ts"]:::test
        TestRender["render.test.ts"]:::test
        TestUser["user.test.ts"]:::test
    end

    %% Request Flow
    Browser -->|"HTTP Request"| ExpressApp
    Browser -->|"Request CSS"| StaticFiles
    StaticFiles -->|"Served by"| ExpressApp

    %% Server Initialization
    EntryPoint -->|"loads"| ExpressApp
    ExpressApp -->|"configures"| PassportConfig

    %% Middleware Chain
    ExpressApp -->|"uses"| AuthGuard
    ExpressApp -->|"uses"| AgentGuard

    %% Routing
    AuthGuard --> HomeRoute
    AuthGuard --> AuthRoute
    AuthGuard --> UserRoute

    %% Data Flow
    HomeRoute -->|"reads/writes"| UserModel
    HomeRoute -->|"reads/writes"| PropertyModel
    AuthRoute -->|"reads/writes"| UserModel
    UserRoute -->|"reads/writes"| UserModel
    UserRoute -->|"reads/writes"| PropertyModel

    UserModel --> DB
    PropertyModel --> DB
    DB --> UserModel
    DB --> PropertyModel

    %% Rendering
    HomeRoute -->|"renders"| LayoutView
    HomeRoute --> IndexView
    HomeRoute --> ErrorView
    AuthRoute --> LoginView
    AuthRoute --> RegisterView
    UserRoute --> PropertiesView
    UserRoute --> AjouterView
    UserRoute --> EditView

    %% Response
    LayoutView --> Browser
    IndexView --> Browser
    ErrorView --> Browser
    LoginView --> Browser
    RegisterView --> Browser
    PropertiesView --> Browser
    AjouterView --> Browser
    EditView --> Browser

    %% Tests
    TestAjouter --> UserRoute
    TestProperty --> PropertyModel
    TestRender --> LayoutView
    TestUser --> UserModel

    %% Click Events
    click StaticFiles "https://github.com/asaufi/plateforme-immobiliere/blob/main/public/stylesheets/style.css"
    click EntryPoint "https://github.com/asaufi/plateforme-immobiliere/blob/main/bin/www.ts"
    click ExpressApp "https://github.com/asaufi/plateforme-immobiliere/blob/main/app.ts"
    click PassportConfig "https://github.com/asaufi/plateforme-immobiliere/blob/main/config/passportConfig.ts"
    click AuthGuard "https://github.com/asaufi/plateforme-immobiliere/blob/main/middlewares/isAuthenticated.ts"
    click AgentGuard "https://github.com/asaufi/plateforme-immobiliere/blob/main/middlewares/isAgent.ts"
    click HomeRoute "https://github.com/asaufi/plateforme-immobiliere/blob/main/routes/index.ts"
    click AuthRoute "https://github.com/asaufi/plateforme-immobiliere/blob/main/routes/auth.ts"
    click UserRoute "https://github.com/asaufi/plateforme-immobiliere/blob/main/routes/users.ts"
    click UserModel "https://github.com/asaufi/plateforme-immobiliere/blob/main/models/User.ts"
    click PropertyModel "https://github.com/asaufi/plateforme-immobiliere/blob/main/models/Property.ts"
    click LayoutView "https://github.com/asaufi/plateforme-immobiliere/blob/main/views/layout.ejs"
    click IndexView "https://github.com/asaufi/plateforme-immobiliere/blob/main/views/index.ejs"
    click ErrorView "https://github.com/asaufi/plateforme-immobiliere/blob/main/views/error.ejs"
    click LoginView "https://github.com/asaufi/plateforme-immobiliere/blob/main/views/login.ejs"
    click RegisterView "https://github.com/asaufi/plateforme-immobiliere/blob/main/views/register.ejs"
    click PropertiesView "https://github.com/asaufi/plateforme-immobiliere/blob/main/views/properties.ejs"
    click AjouterView "https://github.com/asaufi/plateforme-immobiliere/blob/main/views/ajouter.ejs"
    click EditView "https://github.com/asaufi/plateforme-immobiliere/blob/main/views/edit.ejs"
    click TestAjouter "https://github.com/asaufi/plateforme-immobiliere/blob/main/tests/ajouter.test.ts"
    click TestProperty "https://github.com/asaufi/plateforme-immobiliere/blob/main/tests/property.test.ts"
    click TestRender "https://github.com/asaufi/plateforme-immobiliere/blob/main/tests/render.test.ts"
    click TestUser "https://github.com/asaufi/plateforme-immobiliere/blob/main/tests/user.test.ts"

    %% Styles
    classDef client fill:#e3f2fd,stroke:#90caf9
    classDef server fill:#e8f5e9,stroke:#66bb6a
    classDef db fill:#fff3e0,stroke:#ffb74d
    classDef view fill:#f3e5f5,stroke:#ce93d8
    classDef test fill:#ffebee,stroke:#ef5350
```
