# imarafat64/shopwise architecture

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

- Interactive diagram: https://gitdiagram.com/imarafat64/shopwise
- Repository: https://github.com/imarafat64/shopwise

## Overview

##### Project Type and Purpose
- This is a full-stack, monolithic e-commerce application built with Laravel (PHP).
- It supports three user roles—Admin, Seller, Customer—each with its own UI flows.
- Core features include product/catalog management, shopping cart, Stripe payments, coupons, and order tracking.

##### File Structure and README
- MVC Structure
– app/Http/Controllers (Admin, Seller, Auth, Stripe)
– app/Models (User, Product, Cart, Category, Coupon, Payment, etc.)
– resources/views (Blade templates for frontend, admin, seller, auth)
- Routing & Middleware
– routes/web.php, routes/auth.php
– Role-based middleware under app/Http/Middleware
- Configuration & Services
– config/database.php (MySQL)
– config/stripe.php (Stripe API)
– config/auth.php (guards for admin, seller, user)
- Asset Pipeline
– package.json, vite.config.js, tailwind.config.js
– public/assets/dist (compiled CSS/JS)
- Data Layer
– database/migrations define tables: users, categories, carts, products, product_images, payments, coupons

##### Main Components
a. Clients
– Customer Browser (frontend storefront)
– Seller Browser (seller dashboard)
– Admin Browser (administration dashboard)
b. Web Server / Load Balancer
– Nginx or Apache entrypoint serving public/index.php
c. Laravel Application (Single Monolith)
– HTTP Kernel & Middleware (Auth, Role enforcement)
– Controllers (Auth, Home, Profile, Admin, Seller, StripeController)
– Services / Business Logic (CartService, PaymentService, CouponService)
– Models & ORM (Eloquent ORM mapping to MySQL)
– Views (Blade templates)
d. Data Store
– MySQL Database (users, products, carts, orders, coupons)
– Optional Cache/Session Storage (file, Redis, configured under config/cache & config/session)
– Queues (jobs for email, order processing via config/queue)
e. External Services
– Stripe API for payment processing
– Mail service (SMTP/SES) for email verification, order confirmations

##### Relationships and Data Flows
- HTTP Requests from each client flow to the Web Server, then into the Laravel Kernel.
- Middleware checks roles/permissions before dispatching to Controllers.
- Controllers orchestrate calls to Models/Services, then read/write to the Database.
- PaymentController (StripeController) calls out to Stripe’s REST API.
- Responses (HTML via Blade views or JSON for AJAX) flow back to the client.
- Jobs (email, notifications) are queued; workers pull from the queue and send via Mail service.

##### Architectural Patterns and Principles
- MVC (Model-View-Controller)
- Role-Based Access Control via custom middleware (AdminMiddleware, SellerMiddleware, UserMiddleware)
- Service Layers for business logic (cart management, coupon application, payment processing)
- Eloquent ORM for ActiveRecord pattern
- Asset bundling/build pipeline (Vite, Tailwind, PostCSS)

##### Essential Elements
- Component Labels (e.g., “AdminController”, “Product Model”, “Stripe API”)
- Version notes (Laravel 11, PHP 8.x, MySQL 8.x)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Clients Layer
    subgraph "Clients" 
        direction TB
        CustomerBrowser["Customer Browser"]:::client
        SellerBrowser["Seller Browser"]:::client
        AdminBrowser["Admin Browser"]:::client
    end

    %% Web Server Layer
    WebServerEntry["Web Server / Entry Point"]:::server

    %% Laravel Monolith
    subgraph "Laravel Application (Monolith)" 
        direction TB
        KernelMiddleware["HTTP Kernel & Middleware"]:::server
        Routing["Routing & Guards"]:::server
        subgraph "Controllers (HTTP Layer)"
            direction TB
            HomeController["HomeController"]:::controller
            ProfileController["ProfileController"]:::controller
            StripeController["StripeController"]:::controller
            AdminController["AdminController"]:::controller
            AdminProductController["AdminProductController"]:::controller
            SellerController["SellerController"]:::controller
            SellerProductController["SellerProductController"]:::controller
            AuthSessionController["AuthenticatedSessionController"]:::controller
        end
        subgraph "Service Layer"
            direction TB
            CartService["CartService"]:::service
            PaymentService["PaymentService"]:::service
            CouponService["CouponService"]:::service
        end
        subgraph "Models & ORM"
            direction TB
            UserModel["User Model"]:::model
            ProductModel["Product Model"]:::model
            CategoryModel["Category Model"]:::model
            CartModel["Cart Model"]:::model
            PaymentModel["Payment Model"]:::model
            CouponModel["Coupon Model"]:::model
            ProductImageModel["ProductImage Model"]:::model
        end
        Views["Blade Views"]:::view
        Assets["Asset Pipeline"]:::view
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        MySQL["MySQL Database"]:::database
        Cache["Cache/Session Storage"]:::database
        Queue["Queue (Jobs)"]:::database
        Migrations["DB Migrations"]:::database
    end

    %% External Services
    subgraph "External Services"
        direction TB
        StripeAPI["Stripe API"]:::external
        MailService["Mail Service"]:::external
    end

    %% Flows
    CustomerBrowser -->|HTTP/HTTPS| WebServerEntry
    SellerBrowser -->|HTTP/HTTPS| WebServerEntry
    AdminBrowser -->|HTTP/HTTPS| WebServerEntry

    WebServerEntry -->|index.php & bootstrap| KernelMiddleware
    KernelMiddleware -->|route request| Routing
    Routing -->|dispatch| HomeController
    Routing -->|dispatch| ProfileController
    Routing -->|dispatch| StripeController
    Routing -->|dispatch| AdminController
    Routing -->|dispatch| AdminProductController
    Routing -->|dispatch| SellerController
    Routing -->|dispatch| SellerProductController
    Routing -->|dispatch| AuthSessionController

    HomeController -->|uses| CartService
    ProfileController -->|uses| UserModel
    StripeController -->|uses| PaymentService
    AdminProductController -->|uses| ProductModel
    SellerProductController -->|uses| ProductModel

    CartService -->|queries| CartModel
    CartService -->|queries| CouponModel
    PaymentService -->|queries| PaymentModel
    PaymentService -->|calls| StripeAPI
    CouponService -->|queries| CouponModel

    UserModel -->|ORM| MySQL
    ProductModel -->|ORM| MySQL
    CategoryModel -->|ORM| MySQL
    CartModel -->|ORM| MySQL
    PaymentModel -->|ORM| MySQL
    CouponModel -->|ORM| MySQL
    ProductImageModel -->|ORM| MySQL

    Migrations -->|defines tables| MySQL
    Cache -->|stores sessions/cache| KernelMiddleware
    Queue -->|jobs| MailService
    StripeController -->|REST API| StripeAPI
    StripeAPI -->|webhook callback| WebServerEntry

    Views -->|renders| Browsers
    Assets -->|serves| Browsers

    %% Click Events
    click CustomerBrowser "https://github.com/imarafat64/shopwise/tree/main/resources/views/frontend"
    click CustomerBrowser "https://github.com/imarafat64/shopwise/tree/main/public/frontend"
    click SellerBrowser "https://github.com/imarafat64/shopwise/tree/main/resources/views/seller"
    click SellerBrowser "https://github.com/imarafat64/shopwise/tree/main/public/assets/dist"
    click AdminBrowser "https://github.com/imarafat64/shopwise/tree/main/resources/views/admin"
    click AdminBrowser "https://github.com/imarafat64/shopwise/tree/main/public/backend"
    click WebServerEntry "https://github.com/imarafat64/shopwise/blob/main/public/index.php"
    click WebServerEntry "https://github.com/imarafat64/shopwise/blob/main/bootstrap/app.php"
    click KernelMiddleware "https://github.com/imarafat64/shopwise/blob/main/app/Http/Middleware/AdminMiddleware.php"
    click KernelMiddleware "https://github.com/imarafat64/shopwise/blob/main/app/Http/Middleware/SellerMiddleware.php"
    click KernelMiddleware "https://github.com/imarafat64/shopwise/blob/main/app/Http/Middleware/UserMiddleware.php"
    click KernelMiddleware "https://github.com/imarafat64/shopwise/blob/main/app/Http/Middleware/Role.php"
    click Routing "https://github.com/imarafat64/shopwise/blob/main/routes/web.php"
    click Routing "https://github.com/imarafat64/shopwise/blob/main/routes/auth.php"
    click Routing "https://github.com/imarafat64/shopwise/blob/main/config/auth.php"
    click HomeController "https://github.com/imarafat64/shopwise/blob/main/app/Http/Controllers/HomeController.php"
    click ProfileController "https://github.com/imarafat64/shopwise/blob/main/app/Http/Controllers/ProfileController.php"
    click StripeController "https://github.com/imarafat64/shopwise/blob/main/app/Http/Controllers/StripeController.php"
    click AdminController "https://github.com/imarafat64/shopwise/blob/main/app/Http/Controllers/Admin/AdminController.php"
    click AdminProductController "https://github.com/imarafat64/shopwise/blob/main/app/Http/Controllers/Admin/AdminProductController.php"
    click SellerController "https://github.com/imarafat64/shopwise/blob/main/app/Http/Controllers/Seller/SellerController.php"
    click SellerProductController "https://github.com/imarafat64/shopwise/blob/main/app/Http/Controllers/Seller/SellerProductController.php"
    click AuthSessionController "https://github.com/imarafat64/shopwise/blob/main/app/Http/Controllers/Auth/AuthenticatedSessionController.php"
    click UserModel "https://github.com/imarafat64/shopwise/blob/main/app/Models/User.php"
    click ProductModel "https://github.com/imarafat64/shopwise/blob/main/app/Models/Product.php"
    click CategoryModel "https://github.com/imarafat64/shopwise/blob/main/app/Models/Category.php"
    click CartModel "https://github.com/imarafat64/shopwise/blob/main/app/Models/Cart.php"
    click PaymentModel "https://github.com/imarafat64/shopwise/blob/main/app/Models/Payment.php"
    click CouponModel "https://github.com/imarafat64/shopwise/blob/main/app/Models/Coupon.php"
    click ProductImageModel "https://github.com/imarafat64/shopwise/blob/main/app/Models/ProductImage.php"
    click Cache "https://github.com/imarafat64/shopwise/blob/main/config/cache.php"
    click Queue "https://github.com/imarafat64/shopwise/blob/main/config/queue.php"
    click Migrations "https://github.com/imarafat64/shopwise/blob/main/database/migrations/*_create_users_table.php"
    click Migrations "https://github.com/imarafat64/shopwise/blob/main/database/migrations/*_create_categories_table.php"
    click Migrations "https://github.com/imarafat64/shopwise/blob/main/database/migrations/*_create_products_table.php"
    click Migrations "https://github.com/imarafat64/shopwise/blob/main/database/migrations/*_create_carts_table.php"
    click Migrations "https://github.com/imarafat64/shopwise/blob/main/database/migrations/*_create_payments_table.php"
    click Migrations "https://github.com/imarafat64/shopwise/blob/main/database/migrations/*_create_coupons_table.php"
    click Migrations "https://github.com/imarafat64/shopwise/blob/main/database/migrations/*_create_product_images_table.php"
    click StripeAPI "https://github.com/imarafat64/shopwise/blob/main/config/stripe.php"
    click MailService "https://github.com/imarafat64/shopwise/blob/main/config/mail.php"

    %% Styles
    classDef client fill:#D6E9F8,stroke:#31708F,stroke-width:2px
    classDef server fill:#f5f5f5,stroke:#333,stroke-width:2px
    classDef controller fill:#FCF8E3,stroke:#8A6D3B,stroke-width:2px
    classDef service fill:#F2DEDE,stroke:#A94442,stroke-width:2px
    classDef model fill:#DFF0D8,stroke:#3C763D,stroke-width:2px
    classDef view fill:#F5F5F5,stroke:#31708F,stroke-width:2px
    classDef database fill:#FFFFFF,stroke:#5BC0DE,stroke-width:2px,stroke-dasharray: 5 5
    classDef external fill:#EBDEF0,stroke:#884EA0,stroke-width:2px
```
