# elamaimhamza/ecomsite architecture

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

- Interactive diagram: https://gitdiagram.com/elamaimhamza/ecomsite
- Repository: https://github.com/elamaimhamza/ecomsite

## Overview

##### Project Type and Purpose
- This is a full-stack e-commerce web application built on Laravel (PHP).
- The backend exposes RESTful APIs (routes/api.php) and web routes (routes/web.php), backed by MVC controllers (app/Http/Controllers) and Eloquent models (app/Models).
- It supports products, genres, shopping carts, orders, payments, deliveries, user management, statistics, and SEO (referencement).

##### File Structure Analysis
- Top-level “app” folder follows Laravel’s MVC:
- Http/Controllers → API & web controllers
- Models → Eloquent ORM entities
- Middleware → request guards (authentication, role checks)
- “config” folder: environment-agnostic settings (database, cache, mail, queue, cors, services).
- “database” folder: migrations define the schema for users, produits, paniers, commandes, etc.; seeders populate initial data.
- “resources” folder: frontend assets (CSS/JS via Vite), Blade templates for server-rendered views.
- “public/index.php” is the entry point for HTTP requests.
- “bootstrap”, “vendor”, and “storage” support framework bootstrapping, third-party dependencies, and caching/logs/uploads.

##### Architectural Patterns and Key Technologies
- **MVC (Model-View-Controller)**: clear separation of concerns.
- **Service Container & Dependency Injection** via app/Providers.
- **Eloquent ORM** for database access.
- **Sanctum** for API token authentication (config/sanctum.php).
- **Queue workers** for background jobs (config/queue.php).
- **File/Database/Cache** drivers for storage and caching.
- **Blade + Vite (Vue/JS)** for the frontend asset pipeline.

a. Main Components
- Client (Browser or Mobile App)
- Load Balancer / Reverse Proxy (e.g., Nginx)
- Web Server + PHP-FPM
- Laravel Application
- Router → Middleware → Controllers → Services → Models
- Blade rendering / API JSON responses
- Database (MySQL/PostgreSQL)
- Cache Store (Redis or file cache)
- Queue Worker (for emails, order processing)
- File Storage (local disk or S3)
- External Services (Mail service, Payment gateway)
b. Relationships & Data Flow
- Client → HTTP → Nginx → index.php
- index.php → Framework bootstrap → Router → Controller
- Controller ↔ Models ↔ Database
- Controller ↔ Cache Store
- Controller dispatches Jobs → Queue → Worker → Database/Mail
- Controller interacts with External Payment/Mail APIs
- Blade templates served back to Client or JSON payloads
c. Important Patterns
- Middleware chain (authentication, role checks)
- Repository/Service layer (if introduced)
- Event broadcasting or observers for statistics
d. Technologies & Libraries
- PHP 8+, Laravel Framework
- MySQL/PostgreSQL, Redis
- Vite + Vue/React (resources/js)
- Blade templates (resources/views)
- Laravel Sanctum, Laravel Queues, Laravel Mail

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    User["Client<br/>(Browser/Mobile)"]:::frontend
    User -->|HTTP/HTTPS| Nginx["Nginx<br/>(Load Balancer/Reverse Proxy)"]:::backend

    %% Server Entry
    Nginx --> PHP["PHP-FPM & public/index.php"]:::backend

    %% Laravel Application Layer
    subgraph "Laravel Application" 
        direction TB
        %% Routing
        APIRouter["API Router<br/>(routes/api.php)"]:::backend
        WebRouter["Web Router<br/>(routes/web.php)"]:::backend

        %% Middleware
        subgraph "Middleware" 
            direction TB
            AuthMiddleware["AuthApiMiddleware"]:::backend
            GestionnaireMiddleware["GestionnaireMiddleware"]:::backend
        end

        %% Controllers
        subgraph "Controllers" 
            direction TB
            AuthCtrl["AuthController"]:::backend
            ProduitCtrl["ProduitController"]:::backend
            PanierCtrl["PanierController"]:::backend
            CommandeCtrl["CommandeController"]:::backend
            PaiementCtrl["PaiementController"]:::backend
            LivraisonCtrl["LivraisonController"]:::backend
            RefCtrl["ReferencementController"]:::backend
            StatCtrl["StatistiqueController"]:::backend
            GenreCtrl["GenreController"]:::backend
            TypeProdCtrl["TypeProduitController"]:::backend
            LignePanierCtrl["LignePanierController"]:::backend
            LigneCommandeCtrl["LigneCommandeController"]:::backend
            UtilisateurCtrl["UtilisateurController"]:::backend
        end

        %% Services & Models
        Services["Services / Business Logic"]:::backend
        subgraph "Models" 
            direction TB
            UserModel["User & Utilisateur"]:::backend
            ProduitModel["Produit / TypeProduit / Genre"]:::backend
            PanierModel["Panier / LignePanier"]:::backend
            CommandeModel["Commande / LigneCommande"]:::backend
            PaiementModel["Paiement"]:::backend
            LivraisonModel["Livraison"]:::backend
            RefModel["Referencement"]:::backend
            StatModel["Statistique"]:::backend
        end
    end

    %% Data & Async Layers
    ControllersBox["Controllers"] --- Services
    Services --> ModelBox["Models"] 
    ModelBox -->|SQL queries| DB["Relational DB<br/>(MySQL/PostgreSQL)"]:::datastore
    Services -->|cache get/set| Cache["Cache Store<br/>(Redis/File)"]:::datastore
    Services -->|dispatch jobs| Queue["Queue Worker"]:::datastore
    Queue -->|process jobs| DB
    Queue -->|send emails| MailCloud["Mail Service"]:::external
    Services -->|store files| Storage["File Storage<br/>(Local/S3)"]:::datastore
    Services -->|external API calls| PaymentCloud["Payment Gateway"]:::external

    %% Routing & Controllers Flow
    PHP --> APIRouter
    PHP --> WebRouter
    APIRouter --> AuthMiddleware
    WebRouter --> AuthMiddleware
    AuthMiddleware --> GestionnaireMiddleware
    GestionnaireMiddleware --> AuthCtrl
    GestionnaireMiddleware --> ProduitCtrl
    GestionnaireMiddleware --> PanierCtrl
    GestionnaireMiddleware --> CommandeCtrl
    GestionnaireMiddleware --> PaiementCtrl
    GestionnaireMiddleware --> LivraisonCtrl
    GestionnaireMiddleware --> RefCtrl
    GestionnaireMiddleware --> StatCtrl
    GestionnaireMiddleware --> GenreCtrl
    GestionnaireMiddleware --> TypeProdCtrl
    GestionnaireMiddleware --> LignePanierCtrl
    GestionnaireMiddleware --> LigneCommandeCtrl
    GestionnaireMiddleware --> UtilisateurCtrl

    %% Click Events
    click APIRouter "https://github.com/elamaimhamza/ecomsite/blob/main/routes/api.php"
    click WebRouter "https://github.com/elamaimhamza/ecomsite/blob/main/routes/web.php"
    click AuthCtrl "https://github.com/elamaimhamza/ecomsite/blob/main/app/Http/Controllers/AuthController.php"
    click ProduitCtrl "https://github.com/elamaimhamza/ecomsite/blob/main/app/Http/Controllers/ProduitController.php"
    click PanierCtrl "https://github.com/elamaimhamza/ecomsite/blob/main/app/Http/Controllers/PanierController.php"
    click CommandeCtrl "https://github.com/elamaimhamza/ecomsite/blob/main/app/Http/Controllers/CommandeController.php"
    click PaiementCtrl "https://github.com/elamaimhamza/ecomsite/blob/main/app/Http/Controllers/PaiementController.php"
    click LivraisonCtrl "https://github.com/elamaimhamza/ecomsite/blob/main/app/Http/Controllers/LivraisonController.php"
    click RefCtrl "https://github.com/elamaimhamza/ecomsite/blob/main/app/Http/Controllers/ReferencementController.php"
    click StatCtrl "https://github.com/elamaimhamza/ecomsite/blob/main/app/Http/Controllers/StatistiqueController.php"
    click GenreCtrl "https://github.com/elamaimhamza/ecomsite/blob/main/app/Http/Controllers/GenreController.php"
    click TypeProdCtrl "https://github.com/elamaimhamza/ecomsite/blob/main/app/Http/Controllers/TypeProduitController.php"
    click LignePanierCtrl "https://github.com/elamaimhamza/ecomsite/blob/main/app/Http/Controllers/LignePanierController.php"
    click LigneCommandeCtrl "https://github.com/elamaimhamza/ecomsite/blob/main/app/Http/Controllers/LigneCommandeController.php"
    click UtilisateurCtrl "https://github.com/elamaimhamza/ecomsite/blob/main/app/Http/Controllers/UtilisateurController.php"
    click UserModel "https://github.com/elamaimhamza/ecomsite/blob/main/app/Models/User.php"
    click ProduitModel "https://github.com/elamaimhamza/ecomsite/blob/main/app/Models/Produit.php"
    click PanierModel "https://github.com/elamaimhamza/ecomsite/blob/main/app/Models/Panier.php"
    click CommandeModel "https://github.com/elamaimhamza/ecomsite/blob/main/app/Models/Commande.php"
    click PaiementModel "https://github.com/elamaimhamza/ecomsite/blob/main/app/Models/Paiement.php"
    click LivraisonModel "https://github.com/elamaimhamza/ecomsite/blob/main/app/Models/Livraison.php"
    click RefModel "https://github.com/elamaimhamza/ecomsite/blob/main/app/Models/Referencement.php"
    click StatModel "https://github.com/elamaimhamza/ecomsite/blob/main/app/Models/Statistique.php"
    click AuthMiddleware "https://github.com/elamaimhamza/ecomsite/blob/main/app/Http/Middleware/AuthApiMiddleware.php"
    click GestionnaireMiddleware "https://github.com/elamaimhamza/ecomsite/blob/main/app/Http/Middleware/GestionnaireMiddleware.php"
    click DB "https://github.com/elamaimhamza/ecomsite/tree/main/database/migrations"
    click Cache "https://github.com/elamaimhamza/ecomsite/blob/main/config/cache.php"
    click Queue "https://github.com/elamaimhamza/ecomsite/blob/main/config/queue.php"
    click Storage "https://github.com/elamaimhamza/ecomsite/tree/main/storage/app/public"
    click MailCloud "https://github.com/elamaimhamza/ecomsite/blob/main/config/mail.php"

    %% Styles
    classDef frontend fill:#D6E8FF,stroke:#333,stroke-width:1px
    classDef backend fill:#D0F0C0,stroke:#333,stroke-width:1px
    classDef datastore fill:#FFE7A0,stroke:#333,stroke-width:1px
    classDef external fill:#E0E0E0,stroke:#333,stroke-width:1px
```
