# nhienkrb/app-simple-crud-e-commerce architecture

> Architecture diagram of the GitHub repository nhienkrb/app-simple-crud-e-commerce, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nhienkrb/app-simple-crud-e-commerce
- Repository: https://github.com/nhienkrb/app-simple-crud-e-commerce

## Overview

##### Project Type and Purpose
- This is a full-stack CRUD e-commerce application.
- Frontend: React (Vite) single-page app with Material-UI components.
- Backend: Laravel REST API (controllers, services, repositories) exposing endpoints for categories, products, orders, loyalty points, promotions and news.
- Database: relational (MySQL/Postgres) managed via Laravel migrations and seeders.

##### File Structure Analysis
- Top level: two main directories, `frontend/` and `backend/`, plus global `.gitignore` and root `README.md`.
- backend/
- app/Http/Controllers/Api – REST endpoints
- app/Services & app/Repositories – service layer and data-access layer
- app/Models – database entities (Product, Order, User, etc.)
- database/migrations & seeders – schema definition and initial data
- routes/api.php – API route definitions
- config/, bootstrap/, public/index.php – Laravel bootstrapping and configuration
- frontend/
- src/pages – page components for home, products, cart, checkout, auth, news
- src/components – reusable UI elements (Navbar, ProductCard, CartTable, etc.)
- src/context & hooksCustom – React Contexts (Auth, Cart) and custom hooks for data fetching
- public/ – static assets (images, fonts)
- vite.config.js, package.json – build and dependency configuration

##### Key Architectural Themes
- Separation of concerns: frontend UI / backend API / database.
- Backend patterns: MVC + Service layer + Repository layer + Policy (authorization).
- Frontend patterns: Component hierarchy + Context for global state + custom hooks for API calls.
- Stateless REST communication between UI and API over HTTP/JSON.
- Authentication using Laravel Sanctum (implied by sanctum config).

##### Components
a. Frontend SPA
- React components tree
- Context providers (AuthContext, CartContext)
- Custom hooks invoking HTTP requests
b. API Gateway
- API routes → Controllers
- Middleware (Authentication, CORS, CSRF)
c. Domain Logic
- Service classes (AuthService, ProductService, OrderService, etc.)
- Repository classes accessing Eloquent models
d. Database
- Tables: users, products, categories, orders, order_details, promotions, loyalty_points, news
- Migrations & seeders
e. External/Internal Services
- Email service (mail config)
- Queue/Cache/Logging (config files)
- Static asset hosting (frontend CDN or web server)

##### Architectural Patterns & Technologies
- Frontend: React, Vite, Material-UI, React Router, Context API
- Backend: PHP, Laravel (MVC, Service/Repository patterns), Sanctum for auth, MySQL, Redis for cache/queue
- DevOps: Vite build, npm scripts, Composer, Artisan, environment files (.env)

– API Gateway (routes + middleware)
– Controllers → Services → Repositories → Models
– User actions → SPA → API → DB → API → SPA → User

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        direction TB
        Browser["Browser"]:::external
        Main["main.jsx / App.jsx"]:::frontend
        Components["Components"]:::frontend
        Pages["Pages"]:::frontend
        AuthCtx["AuthContext Provider"]:::frontend
        CartCtx["CartContext Provider"]:::frontend
        Hooks["Custom Hooks (API Fetch)"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        direction TB
        APIGateway["API Gateway\n(routes & middleware)"]:::backend
        Middleware["HTTP Middleware"]:::backend
        Controllers["API Controllers"]:::backend
        AuthController["Auth Controller"]:::backend
        Requests["Request Validation Classes"]:::backend
        Services["Domain Services"]:::service
        Repos["Data Repositories"]:::service
        Models["Eloquent Models"]:::service
    end

    %% Infrastructure Layer
    subgraph "Infrastructure Layer"
        direction TB
        DB[(Relational Database)]:::db
        Migrations["Database Migrations"]:::db
        Seeders["Database Seeders"]:::db
        Mail["Mail Service"]:::external
        QueueCache["Queue & Cache"]:::external
        Sanctum["Sanctum Config"]:::external
        CDN["CDN / Static Hosting"]:::external
        READMERoot["Root README"]:::external
        READMEBackend["Backend README"]:::external
    end

    %% Connections
    Browser -->|loads| Main
    Main -->|renders| Components
    Main -->|routes| Pages
    Main -->|provides| AuthCtx
    Main -->|provides| CartCtx
    Components -->|use| Hooks
    Pages -->|use| Hooks
    Hooks -->|fetches| APIGateway

    APIGateway -->|checks| Middleware
    APIGateway -->|routes to| Controllers
    APIGateway -->|auth via| Sanctum
    Controllers -->|validates via| Requests
    Controllers -->|calls| Services
    Controllers -->|handles auth via| AuthController
    Services -->|uses| Repos
    Services -->|sends emails via| Mail
    Services -->|queues jobs via| QueueCache
    Repos -->|queries| Models
    Models -->|maps to| DB

    Migrations -->|define schema| DB
    Seeders -->|seed data| DB
    CDN ---|serves| Browser
    READMERoot -.->|overview| Main
    READMEBackend -.->|backend docs| APIGateway

    %% Click Events
    click Main "https://github.com/nhienkrb/app-simple-crud-e-commerce/blob/main/frontend/src/main.jsx"
    click Components "https://github.com/nhienkrb/app-simple-crud-e-commerce/tree/main/frontend/src/components/"
    click Pages "https://github.com/nhienkrb/app-simple-crud-e-commerce/tree/main/frontend/src/pages/"
    click AuthCtx "https://github.com/nhienkrb/app-simple-crud-e-commerce/blob/main/frontend/src/context/AuthContext.jsx"
    click CartCtx "https://github.com/nhienkrb/app-simple-crud-e-commerce/blob/main/frontend/src/context/CartContext.jsx"
    click Hooks "https://github.com/nhienkrb/app-simple-crud-e-commerce/tree/main/frontend/src/hooksCustom/"
    click APIGateway "https://github.com/nhienkrb/app-simple-crud-e-commerce/blob/main/backend/routes/api.php"
    click Middleware "https://github.com/nhienkrb/app-simple-crud-e-commerce/tree/main/backend/app/Http/Middleware/"
    click Controllers "https://github.com/nhienkrb/app-simple-crud-e-commerce/tree/main/backend/app/Http/Controllers/Api/"
    click AuthController "https://github.com/nhienkrb/app-simple-crud-e-commerce/blob/main/backend/app/Http/Controllers/Auth/AuthController.php"
    click Requests "https://github.com/nhienkrb/app-simple-crud-e-commerce/tree/main/backend/app/Http/Requests/"
    click Services "https://github.com/nhienkrb/app-simple-crud-e-commerce/tree/main/backend/app/Services/"
    click Repos "https://github.com/nhienkrb/app-simple-crud-e-commerce/tree/main/backend/app/Repositories/"
    click Models "https://github.com/nhienkrb/app-simple-crud-e-commerce/tree/main/backend/app/Models/"
    click Migrations "https://github.com/nhienkrb/app-simple-crud-e-commerce/tree/main/backend/database/migrations/"
    click Seeders "https://github.com/nhienkrb/app-simple-crud-e-commerce/tree/main/backend/database/seeders/"
    click Mail "https://github.com/nhienkrb/app-simple-crud-e-commerce/blob/main/backend/config/mail.php"
    click QueueCache "https://github.com/nhienkrb/app-simple-crud-e-commerce/blob/main/backend/config/queue.php"
    click Sanctum "https://github.com/nhienkrb/app-simple-crud-e-commerce/blob/main/backend/config/sanctum.php"
    click READMERoot "https://github.com/nhienkrb/app-simple-crud-e-commerce/blob/main/README.md"
    click READMEBackend "https://github.com/nhienkrb/app-simple-crud-e-commerce/blob/main/backend/README.md"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085,color:#004085
    classDef backend fill:#d4edda,stroke:#155724,color:#155724
    classDef service fill:#e2e3e5,stroke:#6c757d,color:#6c757d
    classDef db fill:#fff3cd,stroke:#856404,color:#856404
    classDef external stroke-dasharray:5 5,fill:#f8d7da,stroke:#721c24,color:#721c24
```
