How aziz-boujaada/nextact-ecom works
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: SaleController.php Resource controllers · Sale.php Commerce models · SaleService.php Transaction services · StockService.php Stock service
Components 19
HTTP API
- External React frontend · Hosted outside this repository.
- Laravel public entry
public/index.php - API routes
routes/api.php - Resource controllers · Sales, purchases, products, invoices, dashboard, and auth endpoints.
app/Http/Controllers/Api/SaleController.php - Request validation
- JWT and permissions
app/Http/Middleware/PermissionsMiddleware.php
Commerce Domain
- Transaction services · Coordinates sale, purchase, refund, item, and total processing.
app/Services/SaleService.php - Stock service · Validates availability and records inventory effects.
app/Services/StockService.php - Commerce models · Products, parties, transactional headers/items, invoices, payments, and allocations.
app/Models/Sale.php - Stock movement audit · Durable inventory movement boundary.
app/Models/StockMovement.php
Documents & Operations
- Invoice and quotation views
resources/views/invoices/invoice.blade.php - Product import/export
app/Imports/ProductsImport.php - Low-stock alerts · Delivers stock and sale-payment email activity.
app/Services/AlertsService.php - Reports and dashboard · Aggregates operational data from commerce records.
app/Services/ReportsService.php - AI chat service · Interprets intents, applies business rules, and retrieves reports.
app/Services/AiChat/ChatService.php - AI provider · Configured external AI boundary.
Runtime & Infrastructure
- MySQL
config/database.php - Schema migrations
database/migrations/2026_05_22_142046_create_payment_allocations_table.php - Jobs queue · Supports asynchronous runtime work.
database/migrations/0001_01_01_000002_create_jobs_table.php
Connections 21
- 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