# aziz-boujaada/nextact-ecom architecture

> Architecture diagram of the GitHub repository aziz-boujaada/nextact-ecom, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/aziz-boujaada/nextact-ecom
- Repository: https://github.com/aziz-boujaada/nextact-ecom

## Overview

#### Purpose and Entry Points
NextAct-Ecom is a Laravel REST backend for an externally hosted React/TypeScript frontend. It manages product catalog, counterparties, purchasing, sales, stock, invoicing, refunds, quotations, and operational reporting. HTTP enters through `public/index.php`; API surface is defined in `routes/api.php`, with browser-oriented routes in `routes/web.php`.

#### API, Validation, and Access Control
Resource controllers provide the application boundary, especially sales, purchases, products, invoices, and dashboard endpoints. Request objects enforce input contracts before controller/service execution. JWT authentication configuration is present, while role and fine-grained permission checks are middleware concerns.
- `app/Http/Controllers/Api/AuthController.php`
- `app/Http/Controllers/Api/SaleController.php`
- `app/Http/Middleware/PermissionsMiddleware.php`

#### Core Commerce Domain
Eloquent models and migrations define the persistent transactional graph: products belong to categories; suppliers support purchases; clients receive sales; header/item records model purchases, sales, quotations, and refunds. Financial extensions include invoices, payments, allocations, and purchase invoices.
- `app/Models/Product.php`
- `app/Models/Sale.php`
- `database/migrations/2026_05_22_142046_create_payment_allocations_table.php`

#### Transaction and Stock Flow
Sales and purchases are handled through dedicated services and item services rather than only controller CRUD. The intended control flow is request validation → controller → transactional domain service → models/database. Sale processing validates available stock, calculates totals, and creates/updates item records; purchase and refund paths similarly affect inventory. Stock movement is a durable audit boundary.
- `app/Services/SaleService.php`
- `app/Services/StockService.php`
- `app/Models/StockMovement.php`

#### Documents, Imports, and Notifications
The backend generates document views for invoices and quotations, supports product spreadsheet import/export, and manages low-stock alerts. Mail templates/services indicate email notification delivery for stock alerts and sale payment activity; file storage is mediated by Laravel filesystem configuration and `storage/`.
- `resources/views/invoices/invoice.blade.php`
- `app/Imports/ProductsImport.php`
- `app/Services/AlertsService.php`

#### Reporting, Settings, and AI
Dashboard and reports endpoints aggregate operational data over the commerce models. Company settings provide tenant/business presentation configuration. An AI chat API delegates intent detection, business-rule interpretation, prompt construction, and report retrieval to a separate service cluster, forming a boundary to an unspecified AI provider configured through Laravel services/environment.
- `app/Http/Controllers/Api/AiChatController.php`
- `app/Services/AiChat/ChatService.php`
- `app/Services/ReportsService.php`

#### Runtime and Infrastructure
This is a PHP/Laravel application using MySQL as its stated primary datastore. Laravel configuration includes cache, queues/jobs, mail, filesystem, sessions, JWT, and external-service settings; deployment requires PHP’s public web entry point and database migrations. Vite assets exist but the principal UI is maintained outside this repository.
- `config/database.php`
- `config/queue.php`
- `database/migrations/0001_01_01_000002_create_jobs_table.php`

Main entry points: [`app/Http/Controllers/Api/SaleController.php`](https://github.com/aziz-boujaada/nextact-ecom/blob/main/app/Http/Controllers/Api/SaleController.php) (Resource controllers), [`app/Models/Sale.php`](https://github.com/aziz-boujaada/nextact-ecom/blob/main/app/Models/Sale.php) (Commerce models), [`app/Services/SaleService.php`](https://github.com/aziz-boujaada/nextact-ecom/blob/main/app/Services/SaleService.php) (Transaction services), [`app/Services/StockService.php`](https://github.com/aziz-boujaada/nextact-ecom/blob/main/app/Services/StockService.php) (Stock service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["HTTP API"]
  node_frontend["External React frontend<br/>client"]
  node_entry["Laravel public entry<br/>PHP entry point<br/>[index.php]"]
  node_api_routes["API routes<br/>route registry<br/>[api.php]"]
  node_controllers["Resource controllers<br/>HTTP controllers<br/>[SaleController.php]"]
  node_request_validation["Request validation<br/>request contracts"]
  node_access_control["JWT and permissions<br/>auth middleware"]
end

subgraph group_commerce["Commerce Domain"]
  node_commerce_services["Transaction services<br/>domain services<br/>[SaleService.php]"]
  node_stock_service["Stock service<br/>inventory service<br/>[StockService.php]"]
  node_commerce_models["Commerce models<br/>Eloquent models<br/>[Sale.php]"]
  node_stock_movements["Stock movement audit<br/>Eloquent model<br/>[StockMovement.php]"]
end

subgraph group_operations["Documents &amp; Operations"]
  node_documents["Invoice and quotation views<br/>document rendering<br/>[invoice.blade.php]"]
  node_product_imports["Product import/export<br/>spreadsheet integration<br/>[ProductsImport.php]"]
  node_alerts["Low-stock alerts<br/>notification service<br/>[AlertsService.php]"]
  node_reports["Reports and dashboard<br/>reporting service<br/>[ReportsService.php]"]
  node_ai_chat["AI chat service<br/>AI orchestration<br/>[ChatService.php]"]
  node_ai_provider{{"AI provider<br/>external service"}}
end

subgraph group_runtime["Runtime &amp; Infrastructure"]
  node_mysql[("MySQL<br/>primary datastore<br/>[database.php]")]
  node_migrations["Schema migrations<br/>database schema"]
  node_queue["Jobs queue<br/>Laravel queue"]
end

node_frontend -->|"HTTPS requests"| node_entry
node_entry -->|"boots API"| node_api_routes
node_api_routes -->|"protected routes"| node_access_control
node_access_control -->|"authorized request"| node_request_validation
node_request_validation -->|"validated input"| node_controllers
node_controllers -->|"sales and purchases"| node_commerce_services
node_commerce_services -->|"inventory changes"| node_stock_service
node_commerce_services -->|"transaction records"| node_commerce_models
node_stock_service -->|"audit movements"| node_stock_movements
node_commerce_models -->|"persists"| node_mysql
node_stock_movements -->|"persists"| node_mysql
node_migrations -->|"creates schema"| node_mysql
node_controllers -->|"invoice and quote output"| node_documents
node_product_imports -->|"imports products"| node_commerce_models
node_stock_service -->|"low-stock events"| node_alerts
node_alerts -.->|"async delivery"| node_queue
node_controllers -->|"dashboard endpoints"| node_reports
node_reports -->|"aggregates"| node_commerce_models
node_controllers -->|"AI chat endpoint"| node_ai_chat
node_ai_chat -->|"retrieves reports"| node_reports
node_ai_chat -->|"delegates AI"| node_ai_provider

click node_entry "https://github.com/aziz-boujaada/nextact-ecom/blob/main/public/index.php"
click node_api_routes "https://github.com/aziz-boujaada/nextact-ecom/blob/main/routes/api.php"
click node_controllers "https://github.com/aziz-boujaada/nextact-ecom/blob/main/app/Http/Controllers/Api/SaleController.php"
click node_access_control "https://github.com/aziz-boujaada/nextact-ecom/blob/main/app/Http/Middleware/PermissionsMiddleware.php"
click node_commerce_services "https://github.com/aziz-boujaada/nextact-ecom/blob/main/app/Services/SaleService.php"
click node_stock_service "https://github.com/aziz-boujaada/nextact-ecom/blob/main/app/Services/StockService.php"
click node_commerce_models "https://github.com/aziz-boujaada/nextact-ecom/blob/main/app/Models/Sale.php"
click node_stock_movements "https://github.com/aziz-boujaada/nextact-ecom/blob/main/app/Models/StockMovement.php"
click node_mysql "https://github.com/aziz-boujaada/nextact-ecom/blob/main/config/database.php"
click node_migrations "https://github.com/aziz-boujaada/nextact-ecom/blob/main/database/migrations/2026_05_22_142046_create_payment_allocations_table.php"
click node_documents "https://github.com/aziz-boujaada/nextact-ecom/blob/main/resources/views/invoices/invoice.blade.php"
click node_product_imports "https://github.com/aziz-boujaada/nextact-ecom/blob/main/app/Imports/ProductsImport.php"
click node_alerts "https://github.com/aziz-boujaada/nextact-ecom/blob/main/app/Services/AlertsService.php"
click node_reports "https://github.com/aziz-boujaada/nextact-ecom/blob/main/app/Services/ReportsService.php"
click node_ai_chat "https://github.com/aziz-boujaada/nextact-ecom/blob/main/app/Services/AiChat/ChatService.php"
click node_queue "https://github.com/aziz-boujaada/nextact-ecom/blob/main/database/migrations/0001_01_01_000002_create_jobs_table.php"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_frontend,node_entry,node_api_routes,node_controllers,node_request_validation,node_access_control toneBlue
class node_commerce_services,node_stock_service,node_commerce_models,node_stock_movements toneAmber
class node_documents,node_product_imports,node_alerts,node_reports,node_ai_chat,node_ai_provider toneMint
class node_mysql,node_migrations,node_queue toneRose
```

## Components

### HTTP API

- **External React frontend**: client · Hosted outside this repository.
- [Laravel public entry](https://github.com/aziz-boujaada/nextact-ecom/blob/main/public/index.php): PHP entry point · `public/index.php`
- [API routes](https://github.com/aziz-boujaada/nextact-ecom/blob/main/routes/api.php): route registry · `routes/api.php`
- [Resource controllers](https://github.com/aziz-boujaada/nextact-ecom/blob/main/app/Http/Controllers/Api/SaleController.php): HTTP controllers · Sales, purchases, products, invoices, dashboard, and auth endpoints. · `app/Http/Controllers/Api/SaleController.php`
- **Request validation**: request contracts
- [JWT and permissions](https://github.com/aziz-boujaada/nextact-ecom/blob/main/app/Http/Middleware/PermissionsMiddleware.php): auth middleware · `app/Http/Middleware/PermissionsMiddleware.php`

### Commerce Domain

- [Transaction services](https://github.com/aziz-boujaada/nextact-ecom/blob/main/app/Services/SaleService.php): domain services · Coordinates sale, purchase, refund, item, and total processing. · `app/Services/SaleService.php`
- [Stock service](https://github.com/aziz-boujaada/nextact-ecom/blob/main/app/Services/StockService.php): inventory service · Validates availability and records inventory effects. · `app/Services/StockService.php`
- [Commerce models](https://github.com/aziz-boujaada/nextact-ecom/blob/main/app/Models/Sale.php): Eloquent models · Products, parties, transactional headers/items, invoices, payments, and allocations. · `app/Models/Sale.php`
- [Stock movement audit](https://github.com/aziz-boujaada/nextact-ecom/blob/main/app/Models/StockMovement.php): Eloquent model · Durable inventory movement boundary. · `app/Models/StockMovement.php`

### Documents & Operations

- [Invoice and quotation views](https://github.com/aziz-boujaada/nextact-ecom/blob/main/resources/views/invoices/invoice.blade.php): document rendering · `resources/views/invoices/invoice.blade.php`
- [Product import/export](https://github.com/aziz-boujaada/nextact-ecom/blob/main/app/Imports/ProductsImport.php): spreadsheet integration · `app/Imports/ProductsImport.php`
- [Low-stock alerts](https://github.com/aziz-boujaada/nextact-ecom/blob/main/app/Services/AlertsService.php): notification service · Delivers stock and sale-payment email activity. · `app/Services/AlertsService.php`
- [Reports and dashboard](https://github.com/aziz-boujaada/nextact-ecom/blob/main/app/Services/ReportsService.php): reporting service · Aggregates operational data from commerce records. · `app/Services/ReportsService.php`
- [AI chat service](https://github.com/aziz-boujaada/nextact-ecom/blob/main/app/Services/AiChat/ChatService.php): AI orchestration · Interprets intents, applies business rules, and retrieves reports. · `app/Services/AiChat/ChatService.php`
- **AI provider**: external service · Configured external AI boundary.

### Runtime & Infrastructure

- [MySQL](https://github.com/aziz-boujaada/nextact-ecom/blob/main/config/database.php): primary datastore · `config/database.php`
- [Schema migrations](https://github.com/aziz-boujaada/nextact-ecom/blob/main/database/migrations/2026_05_22_142046_create_payment_allocations_table.php): database schema · `database/migrations/2026_05_22_142046_create_payment_allocations_table.php`
- [Jobs queue](https://github.com/aziz-boujaada/nextact-ecom/blob/main/database/migrations/0001_01_01_000002_create_jobs_table.php): Laravel queue · Supports asynchronous runtime work. · `database/migrations/0001_01_01_000002_create_jobs_table.php`

## Connections

- External React frontend → Laravel public entry: HTTPS requests
- Laravel public entry → API routes: boots API
- API routes → JWT and permissions: protected routes
- JWT and permissions → Request validation: authorized request
- Request validation → Resource controllers: validated input
- Resource controllers → Transaction services: sales and purchases
- Transaction services → Stock service: inventory changes
- Transaction services → Commerce models: transaction records
- Stock service → Stock movement audit: audit movements
- Commerce models → MySQL: persists
- Stock movement audit → MySQL: persists
- Schema migrations → MySQL: creates schema
- Resource controllers → Invoice and quotation views: invoice and quote output
- Product import/export → Commerce models: imports products
- Stock service → Low-stock alerts: low-stock events
- Low-stock alerts → Jobs queue: async delivery
- Resource controllers → Reports and dashboard: dashboard endpoints
- Reports and dashboard → Commerce models: aggregates
- Resource controllers → AI chat service: AI chat endpoint
- AI chat service → Reports and dashboard: retrieves reports
- AI chat service → AI provider: delegates AI
