# berru-g/projet-messagerie architecture

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

- Interactive diagram: https://gitdiagram.com/berru-g/projet-messagerie
- Repository: https://github.com/berru-g/projet-messagerie

## Overview

##### Project type and purpose
- This is a monolithic full-stack PHP/MySQL web application (“Template PHP/MySQL”) providing a social file-sharing platform with authentication, posts, likes, private/public file uploads (CSV, JSON, Excel, images, PDFs), basic PWA support (manifest.json, sw.js), and a built-in data-visualization toolkit.
- The README describes user flows (login/register, file upload, search, data-to-chart, social feed) and highlights core features: secure authentication, posts, likes, profile dashboard, file sharing, data-visualization, and protection against SQL/XSS.

##### File structure
- Top-level entry point: index.php.
- assets/: static front-end (CSS, JS, images, videos, small No-Code SQL-builder UI).
- includes/: PHP backend utilities (config.php, config.sql, functions.php, header/footer, delete/toggle file/share handlers).
- pages/: distinct PHP “controllers”/views for each feature (login, register, SQL-editor, data-to-chart, gallery, profile, search, factures, wallet API).
- uploads/: filesystem storage for user-uploaded files organized by user ID.
- wallet/: PHP API for cryptocurrency wallet integration.
- lang/: localization JSON files.
- manifest.json & sw.js: PWA manifest and service worker.
- .github/workflows/deploy.yml: CI/CD deployment pipeline.
- .htaccess files: Apache hosting configuration (.hta_host, .hta_local).

##### Key architectural patterns
- MVC-style separation by grouping controllers (pages/), views/templates (includes/header.php, footer.php), and model interactions (includes/functions.php + config.php + MySQL).
- Monolithic server handles HTTP, PHP execution, database access, and file I/O.
- PWA caching layers on the client via service worker.
- CI/CD pipeline deploying from GitHub to target web server.

##### Main components & their responsibilities
a. Client (Web Browser)
- Renders HTML/CSS/JS from assets/, supports PWA (manifest, service worker).
- Interacts via HTTP(S) with the web server.
- Executes data-visualization scripts (data-to-chart.js, sqleditor.js, wallet.js).
b. Web Server (Apache/Nginx + PHP-FPM)
- Serves static assets (assets/, SQL-builder-NoCode).
- Routes dynamic requests to index.php/pages/*.php.
- Loads includes/ (config, shared header/footer, business logic).
- Handles authentication, sessions, CRUD operations on posts/likes, file uploads.
- Implements wallet API endpoints (wallet/api_wallet.php).
c. Database (MySQL)
- User table, posts table, likes table, file metadata table (mysql schema from includes/config.sql).
- Stores authentication credentials, profile data, social graph, file share metadata.
d. File Storage (Server Filesystem)
- uploads/: stores user files (CSV/JSON/Excel/Image).
- profile_pictures/: avatars.
e. CI/CD & Hosting
- GitHub Actions (.github/workflows/deploy.yml) builds/tests (if any), then deploys code to .hta_host environment.
- .hta_local for local development.
f. External dependencies (optional/inferred)
- Potential email/SMS service for password resets (not in repo but may exist).
- Google Sheets API support (upload CSV/Google Sheet mention).

##### Relationships & data flows
- User → HTTP Request → Web Server → PHP Execution → MySQL (read/write) → PHP → HTTP Response → User.
- File upload: User → POST file → Web Server saves to uploads/ → metadata written to MySQL → confirmation to User.
- Data-to-chart: User loads JSON/CSV → JS fetches file via HTTP → Chart.js (or custom) renders on browser.
- Social Feed: User posts image/PDF → PHP stores file + post metadata → MySQL update → other users fetch feed.
- PWA: Browser registers sw.js → caches assets/pages → serves cached content offline.

- Routing Layer: index.php + pages/*.php
- Business Logic Layer: includes/functions.php, includes/toggle_share.php, wallet/api_wallet.php
- Config Layer: includes/config.php (.sql)
- PWA Support: manifest.json, sw.js

##### Architectural patterns & technologies
- MVC-style separation (controllers in pages/, views in includes/, models via functions+MySQL).
- Monolith over microservices—everything runs on one server.
- PWA pattern (offline caching via service worker).
- Front-end tools: vanilla JS, Chart (data-to-chart), SQL-builder No-Code UI.
- Security: prepared statements via includes/functions.php, input sanitization, XSS protection.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Client (Browser)" 
        frontEndJS["Static Assets (assets/)"]:::client
        sqlBuilder["SQL-builder-NoCode"]:::client
        manifestC["manifest.json"]:::client
        swC["sw.js"]:::client
        cache["Service Worker Cache"]:::client
        frontEndJS --> cache
        sqlBuilder --> cache
        manifestC --> cache
        swC --> cache
    end

    subgraph "Web Server (PHP Layer)"
        subgraph "Routing Layer"
            router["index.php"]:::server
            pages["pages/"]:::server
        end
        subgraph "Business Logic"
            funcs["includes/functions.php"]:::server
            deleteFile["includes/delete_file.php"]:::server
            deletePen["includes/delete_pen.php"]:::server
            toggleShare["includes/toggle_share.php"]:::server
            walletAPI["wallet/api_wallet.php"]:::server
            walletBL["wallet/wallet.php"]:::server
        end
        subgraph "Views/Templates"
            header["includes/header.php"]:::server
            footer["includes/footer.php"]:::server
        end
        subgraph "Config & Schema"
            config["includes/config.php"]:::server
            schema["includes/config.sql"]:::server
        end
        subgraph "PWA Support"
            manifestS["manifest.json"]:::server
            swServer["sw.js"]:::server
        end

        router --> pages
        pages --> funcs
        funcs --> config
        funcs --> schema
        pages --> deleteFile
        pages --> deletePen
        pages --> toggleShare
        pages --> walletAPI
        pages --> walletBL
        pages --> header
        pages --> footer
        pages --> manifestS
        pages --> swServer
    end

    DB[(MySQL Database)]:::db
    subgraph "File Storage"
        uploads["uploads/"]:::storage
        profilePics["uploads/profile_pictures/"]:::storage
    end

    subgraph "CI/CD & Hosting"
        deploy[".github/workflows/deploy.yml"]:::ci
        htahost[".hta_host"]:::ci
        htalocal[".hta_local"]:::ci
        htaccess[".htaccess"]:::ci
        gitignore[".gitignore"]:::ci
        robots["robots.txt"]:::ci
        sitemap["sitemap.xml"]:::ci
    end

    frontEndJS -->|"HTTP Request"| router
    sqlBuilder -->|"HTTP Request"| router
    manifestC -->|"HTTP Request"| router
    swC -->|"Register SW"| swServer

    router -->|"Query/Update"| DB
    router -->|"Save/Retrieve"| uploads
    router -->|"Save/Retrieve"| profilePics
    DB -->|"Result"| router
    router -->|"Response"| frontEndJS

    deploy -.->|"Deploy Code"| router
    htahost -.-> router
    htalocal -.-> router
    htaccess -.-> router

    classDef client fill:#D0E6FF,stroke:#0366D6,color:#0366D6
    classDef server fill:#E6FFEA,stroke:#28A745,color:#28A745
    classDef db fill:#FFF5BA,stroke:#FFD33D,color:#8A6E00
    classDef storage fill:#FFE5D0,stroke:#FF7400,color:#A63F00
    classDef ci fill:#EDEDED,stroke:#6A737D,color:#586069

    click frontEndJS "https://github.com/berru-g/projet-messagerie/tree/main/assets/"
    click sqlBuilder "https://github.com/berru-g/projet-messagerie/tree/main/SQL-builder-NoCode/"
    click manifestC "https://github.com/berru-g/projet-messagerie/blob/main/manifest.json"
    click swC "https://github.com/berru-g/projet-messagerie/blob/main/sw.js"
    click router "https://github.com/berru-g/projet-messagerie/blob/main/index.php"
    click pages "https://github.com/berru-g/projet-messagerie/tree/main/pages/"
    click funcs "https://github.com/berru-g/projet-messagerie/blob/main/includes/functions.php"
    click deleteFile "https://github.com/berru-g/projet-messagerie/blob/main/includes/delete_file.php"
    click deletePen "https://github.com/berru-g/projet-messagerie/blob/main/includes/delete_pen.php"
    click toggleShare "https://github.com/berru-g/projet-messagerie/blob/main/includes/toggle_share.php"
    click walletAPI "https://github.com/berru-g/projet-messagerie/blob/main/wallet/api_wallet.php"
    click walletBL "https://github.com/berru-g/projet-messagerie/blob/main/wallet/wallet.php"
    click header "https://github.com/berru-g/projet-messagerie/blob/main/includes/header.php"
    click footer "https://github.com/berru-g/projet-messagerie/blob/main/includes/footer.php"
    click config "https://github.com/berru-g/projet-messagerie/blob/main/includes/config.php"
    click schema "https://github.com/berru-g/projet-messagerie/blob/main/includes/config.sql"
    click uploads "https://github.com/berru-g/projet-messagerie/tree/main/uploads/"
    click profilePics "https://github.com/berru-g/projet-messagerie/tree/main/uploads/profile_pictures/"
    click deploy "https://github.com/berru-g/projet-messagerie/blob/main/.github/workflows/deploy.yml"
    click htahost "https://github.com/berru-g/projet-messagerie/blob/main/.hta_host"
    click htalocal "https://github.com/berru-g/projet-messagerie/blob/main/.hta_local"
    click htaccess "https://github.com/berru-g/projet-messagerie/blob/main/.htaccess"
    click gitignore "https://github.com/berru-g/projet-messagerie/blob/main/.gitignore"
    click robots "https://github.com/berru-g/projet-messagerie/blob/main/robots.txt"
    click sitemap "https://github.com/berru-g/projet-messagerie/blob/main/sitemap.xml"
```
