# elmehdiaderab/e-commerce_emsi architecture

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

- Interactive diagram: https://gitdiagram.com/elmehdiaderab/e-commerce_emsi
- Repository: https://github.com/elmehdiaderab/e-commerce_emsi

## Overview

##### Project type and purpose
- This is a full-stack ASP.NET Core MVC web application (“E-Commerce” prototype).
- Purpose: allow users to browse products, add items to a shopping cart, and manage products via CRUD operations.

##### File structure
- Top-level solution file: E-Commerce.sln.
- Project folder “WebApplication2” contains:
- Controllers (HomeController, ProductsController) – handle HTTP requests.
- Models (Product, Cart, CartItem, ErrorViewModel) – define domain entities and view models.
- Data (WebApplication2Context, Migrations) – Entity Framework Core DB context and schema migrations.
- Views – Razor templates under Home/, Products/, Shared/ – UI layer.
- wwwroot – static assets (CSS, JS, images, Bootstrap, jQuery libraries).
- Configuration: appsettings.json / appsettings.Development.json.
- Program.cs – application entry point and middleware configuration.
- SessionExtensions.cs – helper methods to store Cart in user session.
- SQLite database files (.db, .db-wal, .db-shm).

##### README for additional insights
- Tech stack: .NET 8, ASP.NET Core, EF Core, Bootstrap.

##### Main components and their interactions
a. Browser (Client)
– Renders HTML/CSS/JS served by the app; sends HTTP GET/POST to Controllers.
b. Web Server / Application Layer
– ASP.NET Core runtime hosts:
- MVC Controllers: interpret routes, user actions.
- Razor View Engine: composes HTML from Views + Models.
- Middleware pipeline (configured in Program.cs): routing, static files, sessions.
c. Business & Session Layer
– Controllers invoke SessionExtensions to manage shopping cart state between requests.
d. Data Access Layer
– EF Core DbContext (WebApplication2Context) exposes DbSet<Product>, DbSet<CartItem>, etc.
– Migrations manage schema evolution.
e. Database
– SQLite file stored locally; receives SQL queries from EF Core.
f. Static Assets & Libraries
– wwwroot contains CSS/JS and 3rd-party libs (Bootstrap, jQuery, validation).

##### Architectural patterns & principles
- MVC: strict separation of concerns (Models, Views, Controllers).
- Layered architecture:
- Presentation (Views + static assets)
- Application / Business (Controllers + services/helpers)
- Persistence (EF Core context + SQLite)
- Convention over configuration: folder names map to routing.

##### Diagramming recommendations
- Keep it 2-3 tiers deep to avoid clutter: UI → App → Database.

## Diagram (Mermaid)

```mermaid
flowchart TD
    Client["Client Browser"]:::client
    Static["Static Assets (CSS/JS)"]:::static
    click Static "https://github.com/elmehdiaderab/e-commerce_emsi/tree/master/WebApplication2/wwwroot"

    subgraph "ASP.NET Core App"
        subgraph "Configuration"
            Settings["appsettings.json"]:::config
            click Settings "https://github.com/elmehdiaderab/e-commerce_emsi/blob/master/WebApplication2/appsettings.json"
            SettingsDev["appsettings.Development.json"]:::config
            click SettingsDev "https://github.com/elmehdiaderab/e-commerce_emsi/blob/master/WebApplication2/appsettings.Development.json"
        end
        Entry["Program.cs"]:::server
        click Entry "https://github.com/elmehdiaderab/e-commerce_emsi/blob/master/WebApplication2/Program.cs"

        subgraph "Presentation Layer"
            ViewHomePrivacy["Privacy.cshtml"]:::view
            click ViewHomePrivacy "https://github.com/elmehdiaderab/e-commerce_emsi/blob/master/WebApplication2/Views/Home/Privacy.cshtml"
            ViewProdCreate["Create.cshtml"]:::view
            click ViewProdCreate "https://github.com/elmehdiaderab/e-commerce_emsi/blob/master/WebApplication2/Views/Products/Create.cshtml"
            ViewProdDelete["Delete.cshtml"]:::view
            click ViewProdDelete "https://github.com/elmehdiaderab/e-commerce_emsi/blob/master/WebApplication2/Views/Products/Delete.cshtml"
            ViewProdDetails["Details.cshtml"]:::view
            click ViewProdDetails "https://github.com/elmehdiaderab/e-commerce_emsi/blob/master/WebApplication2/Views/Products/Details.cshtml"
            ViewProdEdit["Edit.cshtml"]:::view
            click ViewProdEdit "https://github.com/elmehdiaderab/e-commerce_emsi/blob/master/WebApplication2/Views/Products/Edit.cshtml"
            ViewProdIndex["Index.cshtml"]:::view
            click ViewProdIndex "https://github.com/elmehdiaderab/e-commerce_emsi/blob/master/WebApplication2/Views/Products/Index.cshtml"
            ViewCart["ViewCart.cshtml"]:::view
            click ViewCart "https://github.com/elmehdiaderab/e-commerce_emsi/blob/master/WebApplication2/Views/Products/ViewCart.cshtml"
            SharedLayout["_Layout.cshtml"]:::view
            click SharedLayout "https://github.com/elmehdiaderab/e-commerce_emsi/blob/master/WebApplication2/Views/Shared/_Layout.cshtml"
            SharedValidation["_ValidationScriptsPartial.cshtml"]:::view
            click SharedValidation "https://github.com/elmehdiaderab/e-commerce_emsi/blob/master/WebApplication2/Views/Shared/_ValidationScriptsPartial.cshtml"
            SharedError["Error.cshtml"]:::view
            click SharedError "https://github.com/elmehdiaderab/e-commerce_emsi/blob/master/WebApplication2/Views/Shared/Error.cshtml"
            ViewImports["_ViewImports.cshtml"]:::view
            click ViewImports "https://github.com/elmehdiaderab/e-commerce_emsi/blob/master/WebApplication2/Views/_ViewImports.cshtml"
            ViewStart["_ViewStart.cshtml"]:::view
            click ViewStart "https://github.com/elmehdiaderab/e-commerce_emsi/blob/master/WebApplication2/Views/_ViewStart.cshtml"
        end

        subgraph "Controllers Layer"
            HomeCtrl["HomeController.cs"]:::ctrl
            click HomeCtrl "https://github.com/elmehdiaderab/e-commerce_emsi/blob/master/WebApplication2/Controllers/HomeController.cs"
            ProdCtrl["ProductsController.cs"]:::ctrl
            click ProdCtrl "https://github.com/elmehdiaderab/e-commerce_emsi/blob/master/WebApplication2/Controllers/ProductsController.cs"
        end

        Session["SessionExtensions.cs"]:::helper
        click Session "https://github.com/elmehdiaderab/e-commerce_emsi/blob/master/WebApplication2/SessionExtensions.cs"

        subgraph "Data Access Layer"
            DbContext["WebApplication2Context.cs"]:::data
            click DbContext "https://github.com/elmehdiaderab/e-commerce_emsi/blob/master/WebApplication2/Data/WebApplication2Context.cs"
            Migrations["Migrations"]:::data
            click Migrations "https://github.com/elmehdiaderab/e-commerce_emsi/blob/master/WebApplication2/Migrations/20240210194935_initialCreate.cs"
            click Migrations "https://github.com/elmehdiaderab/e-commerce_emsi/blob/master/WebApplication2/Migrations/20240210194935_initialCreate.Designer.cs"
            click Migrations "https://github.com/elmehdiaderab/e-commerce_emsi/blob/master/WebApplication2/Migrations/WebApplication2ContextModelSnapshot.cs"
        end
    end

    Db["SQLite Database Files"]:::db
    click Db "https://github.com/elmehdiaderab/e-commerce_emsi/blob/master/WebApplication2/WebApplication2Context-829a52d7-e910-4fcd-98fd-0542b30075d8.db"
    click Db "https://github.com/elmehdiaderab/e-commerce_emsi/blob/master/WebApplication2/WebApplication2Context-829a52d7-e910-4fcd-98fd-0542b30075d8.db-shm"
    click Db "https://github.com/elmehdiaderab/e-commerce_emsi/blob/master/WebApplication2/WebApplication2Context-829a52d7-e910-4fcd-98fd-0542b30075d8.db-wal"

    Client -->|HTTP Request| HomeCtrl
    Client -->|HTTP Request| ProdCtrl
    Client -->|Fetch Static Files| Static
    HomeCtrl -->|"Render View"| ViewHomePrivacy
    ProdCtrl -->|"Render View"| ViewProdIndex
    ProdCtrl -->|"Render View"| ViewProdDetails
    ProdCtrl -->|"Render View"| ViewProdCreate
    ProdCtrl -->|"Render View"| ViewProdEdit
    ProdCtrl -->|"Render View"| ViewProdDelete
    ProdCtrl -->|"Render View"| ViewCart
    HomeCtrl -->|Session API| Session
    ProdCtrl -->|Session API| Session
    HomeCtrl -->|EF Query| DbContext
    ProdCtrl -->|EF Query| DbContext
    DbContext -->|SQL Commands| Db

    classDef client fill:#D0E8FF,stroke:#0366D6,stroke-width:1px;
    classDef static fill:#E8F6D0,stroke:#3F681C,stroke-width:1px,stroke-dasharray: 5 5;
    classDef server fill:#C8F7FF,stroke:#117A65,stroke-width:1px;
    classDef config fill:#FFF3CD,stroke:#856404,stroke-width:1px;
    classDef view fill:#F0F0F0,stroke:#6C757D,stroke-width:1px;
    classDef ctrl fill:#D1C4E9,stroke:#512DA8,stroke-width:1px;
    classDef helper fill:#FFE0B2,stroke:#EF6C00,stroke-width:1px,stroke-dasharray: 2 2;
    classDef data fill:#D6EAF8,stroke:#1B4F72,stroke-width:1px;
    classDef db fill:#FDEDEC,stroke:#C0392B,stroke-width:1px,shape:cylinder;
```
