# zachzic/commerce-api architecture

> Architecture diagram of the GitHub repository zachzic/commerce-api, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/zachzic/commerce-api
- Repository: https://github.com/zachzic/commerce-api

## Overview

Commerce API is a Laravel REST backend for managing users and employees across multiple establishments, with a shared product catalogue and establishment-scoped stock. The main workflow is an API request routed to a controller, which validates and delegates domain operations to Eloquent models; stock movements update quantities and may create low-stock alerts. The README also documents token authentication, one-time owner setup, granular roles, and establishment isolation. Some controller/model links are supported by the source index rather than full excerpts; future POS and reporting features are not implemented in the supplied tree.

Main entry points: [`routes/api.php`](https://github.com/zachzic/commerce-api/blob/main/routes/api.php) (API routes), [`app/Models/User.php`](https://github.com/zachzic/commerce-api/blob/main/app/Models/User.php) (Users and tokens), [`app/Http/Controllers/Api/EmployeController.php`](https://github.com/zachzic/commerce-api/blob/main/app/Http/Controllers/Api/EmployeController.php) (Employee management), [`app/Http/Controllers/Api/StockController.php`](https://github.com/zachzic/commerce-api/blob/main/app/Http/Controllers/Api/StockController.php) (Stock API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API entry and identity"]
  node_routes["API routes<br/>[api.php]"]
  node_auth["Authentication<br/>[AuthController.php]"]
  node_setup["Owner setup"]
  node_admin["Admin recovery"]
  node_users["Users and tokens<br/>[User.php]"]
end

subgraph group_org["Establishments and access"]
  node_establishments["Establishments"]
  node_employees["Employee management"]
  node_employee_model["Employee records<br/>[Employe.php]"]
  node_tenant_context["Establishment resolution"]
  node_tenant_scope["Tenant query scope"]
end

subgraph group_catalog["Product catalogue"]
  node_categories["Categories"]
  node_products["Products"]
  node_product_model["Product records<br/>[Produit.php]"]
end

subgraph group_inventory["Stock operations"]
  node_stock_api["Stock API"]
  node_stock_model["Stock balances<br/>[Stock.php]"]
  node_movements["Stock movements<br/>[MouvementStock.php]"]
  node_alerts_api["Stock alerts API"]
  node_alerts["Stock alert records<br/>[AlerteStock.php]"]
end

node_client(("API client"))
node_database[("PostgreSQL database")]

node_client -->|"sends request"| node_routes
node_routes -->|"routes auth"| node_auth
node_routes -->|"guards setup"| node_setup
node_routes -->|"routes requests"| node_establishments
node_routes -->|"routes requests"| node_employees
node_routes -->|"routes requests"| node_categories
node_routes -->|"routes requests"| node_products
node_routes -->|"routes requests"| node_stock_api
node_routes -->|"routes requests"| node_alerts_api
node_auth -->|"authenticates users"| node_users
node_admin -->|"creates admin"| node_users
node_employees -->|"resolves establishment"| node_tenant_context
node_employees -->|"creates and reads"| node_employee_model
node_employees -->|"creates and updates"| node_users
node_employee_model -->|"relates employee"| node_establishments
node_tenant_scope -->|"checks user scope"| node_users
node_users -->|"resolves active site"| node_employee_model
node_categories -->|"manages categories"| node_product_model
node_products -->|"manages products"| node_product_model
node_stock_api -->|"resolves establishment"| node_tenant_context
node_stock_api -->|"reads and adjusts"| node_stock_model
node_stock_api -->|"records movements"| node_movements
node_movements -->|"updates balances"| node_stock_model
node_stock_model -->|"creates alerts"| node_alerts
node_alerts_api -->|"manages alerts"| node_alerts
node_stock_model -.->|"persists balances"| node_database
node_movements -.->|"persists movements"| node_database
node_alerts -.->|"persists alerts"| node_database
node_product_model -.->|"persists products"| node_database
node_employee_model -.->|"persists employees"| node_database

click node_routes "https://github.com/zachzic/commerce-api/blob/main/routes/api.php"
click node_auth "https://github.com/zachzic/commerce-api/blob/main/app/Http/Controllers/Api/AuthController.php"
click node_setup "https://github.com/zachzic/commerce-api/blob/main/app/Http/Middleware/EnsureSetupTokenIsValid.php"
click node_admin "https://github.com/zachzic/commerce-api/blob/main/app/Console/Commands/CreateAdminCommand.php"
click node_users "https://github.com/zachzic/commerce-api/blob/main/app/Models/User.php"
click node_establishments "https://github.com/zachzic/commerce-api/blob/main/app/Http/Controllers/Api/EtablissementController.php"
click node_employees "https://github.com/zachzic/commerce-api/blob/main/app/Http/Controllers/Api/EmployeController.php"
click node_employee_model "https://github.com/zachzic/commerce-api/blob/main/app/Models/Employe.php"
click node_tenant_context "https://github.com/zachzic/commerce-api/blob/main/app/Http/Controllers/Concerns/ResolvesEtablissementId.php"
click node_tenant_scope "https://github.com/zachzic/commerce-api/blob/main/app/Models/Scopes/EtablissementScope.php"
click node_categories "https://github.com/zachzic/commerce-api/blob/main/app/Http/Controllers/Api/CategorieController.php"
click node_products "https://github.com/zachzic/commerce-api/blob/main/app/Http/Controllers/Api/ProduitController.php"
click node_product_model "https://github.com/zachzic/commerce-api/blob/main/app/Models/Produit.php"
click node_stock_api "https://github.com/zachzic/commerce-api/blob/main/app/Http/Controllers/Api/StockController.php"
click node_stock_model "https://github.com/zachzic/commerce-api/blob/main/app/Models/Stock.php"
click node_movements "https://github.com/zachzic/commerce-api/blob/main/app/Models/MouvementStock.php"
click node_alerts_api "https://github.com/zachzic/commerce-api/blob/main/app/Http/Controllers/Api/AlerteStockController.php"
click node_alerts "https://github.com/zachzic/commerce-api/blob/main/app/Models/AlerteStock.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_routes,node_auth,node_setup,node_admin,node_users,node_client toneBlue
class node_establishments,node_employees,node_employee_model,node_tenant_context,node_tenant_scope,node_database toneAmber
class node_categories,node_products,node_product_model toneMint
class node_stock_api,node_stock_model,node_movements,node_alerts_api,node_alerts toneRose
```

## Components

### API entry and identity

- [API routes](https://github.com/zachzic/commerce-api/blob/main/routes/api.php): `routes/api.php`
- [Authentication](https://github.com/zachzic/commerce-api/blob/main/app/Http/Controllers/Api/AuthController.php): `app/Http/Controllers/Api/AuthController.php`
- [Owner setup](https://github.com/zachzic/commerce-api/blob/main/app/Http/Middleware/EnsureSetupTokenIsValid.php): `app/Http/Middleware/EnsureSetupTokenIsValid.php`
- [Admin recovery](https://github.com/zachzic/commerce-api/blob/main/app/Console/Commands/CreateAdminCommand.php): `app/Console/Commands/CreateAdminCommand.php`
- [Users and tokens](https://github.com/zachzic/commerce-api/blob/main/app/Models/User.php): `app/Models/User.php`

### Establishments and access

- [Establishments](https://github.com/zachzic/commerce-api/blob/main/app/Http/Controllers/Api/EtablissementController.php): `app/Http/Controllers/Api/EtablissementController.php`
- [Employee management](https://github.com/zachzic/commerce-api/blob/main/app/Http/Controllers/Api/EmployeController.php): `app/Http/Controllers/Api/EmployeController.php`
- [Employee records](https://github.com/zachzic/commerce-api/blob/main/app/Models/Employe.php): `app/Models/Employe.php`
- [Establishment resolution](https://github.com/zachzic/commerce-api/blob/main/app/Http/Controllers/Concerns/ResolvesEtablissementId.php): `app/Http/Controllers/Concerns/ResolvesEtablissementId.php`
- [Tenant query scope](https://github.com/zachzic/commerce-api/blob/main/app/Models/Scopes/EtablissementScope.php): `app/Models/Scopes/EtablissementScope.php`

### Product catalogue

- [Categories](https://github.com/zachzic/commerce-api/blob/main/app/Http/Controllers/Api/CategorieController.php): `app/Http/Controllers/Api/CategorieController.php`
- [Products](https://github.com/zachzic/commerce-api/blob/main/app/Http/Controllers/Api/ProduitController.php): `app/Http/Controllers/Api/ProduitController.php`
- [Product records](https://github.com/zachzic/commerce-api/blob/main/app/Models/Produit.php): `app/Models/Produit.php`

### Stock operations

- [Stock API](https://github.com/zachzic/commerce-api/blob/main/app/Http/Controllers/Api/StockController.php): `app/Http/Controllers/Api/StockController.php`
- [Stock balances](https://github.com/zachzic/commerce-api/blob/main/app/Models/Stock.php): `app/Models/Stock.php`
- [Stock movements](https://github.com/zachzic/commerce-api/blob/main/app/Models/MouvementStock.php): `app/Models/MouvementStock.php`
- [Stock alerts API](https://github.com/zachzic/commerce-api/blob/main/app/Http/Controllers/Api/AlerteStockController.php): `app/Http/Controllers/Api/AlerteStockController.php`
- [Stock alert records](https://github.com/zachzic/commerce-api/blob/main/app/Models/AlerteStock.php): `app/Models/AlerteStock.php`

### Other components

- **API client**
- **PostgreSQL database**

## Connections

- API client → API routes: sends request (evidence: `README.md`)
- API routes → Authentication: routes auth (evidence: `routes/api.php`)
- API routes → Owner setup: guards setup
- API routes → Establishments: routes requests (evidence: `routes/api.php`)
- API routes → Employee management: routes requests (evidence: `routes/api.php`)
- API routes → Categories: routes requests (evidence: `routes/api.php`)
- API routes → Products: routes requests (evidence: `routes/api.php`)
- API routes → Stock API: routes requests (evidence: `routes/api.php`)
- API routes → Stock alerts API: routes requests (evidence: `routes/api.php`)
- Authentication → Users and tokens: authenticates users (evidence: `app/Http/Controllers/Api/AuthController.php`)
- Admin recovery → Users and tokens: creates admin (evidence: `app/Console/Commands/CreateAdminCommand.php`)
- Employee management → Establishment resolution: resolves establishment (evidence: `app/Http/Controllers/Api/EmployeController.php`)
- Employee management → Employee records: creates and reads (evidence: `app/Http/Controllers/Api/EmployeController.php`)
- Employee management → Users and tokens: creates and updates (evidence: `app/Http/Controllers/Api/EmployeController.php`)
- Employee records → Establishments: relates employee (evidence: `app/Models/Employe.php`)
- Tenant query scope → Users and tokens: checks user scope (evidence: `app/Models/Scopes/EtablissementScope.php`)
- Users and tokens → Employee records: resolves active site (evidence: `app/Models/User.php`)
- Categories → Product records: manages categories (evidence: `app/Http/Controllers/Api/CategorieController.php`)
- Products → Product records: manages products (evidence: `app/Http/Controllers/Api/ProduitController.php`)
- Stock API → Establishment resolution: resolves establishment (evidence: `app/Http/Controllers/Api/StockController.php`)
- Stock API → Stock balances: reads and adjusts (evidence: `app/Http/Controllers/Api/StockController.php`)
- Stock API → Stock movements: records movements (evidence: `app/Http/Controllers/Api/StockController.php`)
- Stock movements → Stock balances: updates balances (evidence: `app/Models/MouvementStock.php`)
- Stock balances → Stock alert records: creates alerts (evidence: `app/Models/Stock.php`)
- Stock alerts API → Stock alert records: manages alerts (evidence: `app/Http/Controllers/Api/AlerteStockController.php`)
- Stock balances → PostgreSQL database: persists balances
- Stock movements → PostgreSQL database: persists movements
- Stock alert records → PostgreSQL database: persists alerts
- Product records → PostgreSQL database: persists products
- Employee records → PostgreSQL database: persists employees
