How zachzic/commerce-api works
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: api.php API routes · User.php Users and tokens · EmployeController.php Employee management · StockController.php Stock API
Components 20
API entry and identity
- API routes
routes/api.php - Authentication
app/Http/Controllers/Api/AuthController.php - Owner setup
app/Http/Middleware/EnsureSetupTokenIsValid.php - Admin recovery
app/Console/Commands/CreateAdminCommand.php - Users and tokens
app/Models/User.php
Establishments and access
- Establishments
app/Http/Controllers/Api/EtablissementController.php - Employee management
app/Http/Controllers/Api/EmployeController.php - Employee records
app/Models/Employe.php - Establishment resolution
app/Http/Controllers/Concerns/ResolvesEtablissementId.php - Tenant query scope
app/Models/Scopes/EtablissementScope.php
Product catalogue
- Categories
app/Http/Controllers/Api/CategorieController.php - Products
app/Http/Controllers/Api/ProduitController.php - Product records
app/Models/Produit.php
Stock operations
- Stock API
app/Http/Controllers/Api/StockController.php - Stock balances
app/Models/Stock.php - Stock movements
app/Models/MouvementStock.php - Stock alerts API
app/Http/Controllers/Api/AlerteStockController.php - Stock alert records
app/Models/AlerteStock.php
Other components
- API client
- PostgreSQL database
Connections 30
- API client → API routes: sends request
README.md - API routes → Authentication: routes auth
routes/api.php - API routes → Owner setup: guards setup
- API routes → Establishments: routes requests
routes/api.php - API routes → Employee management: routes requests
routes/api.php - API routes → Categories: routes requests
routes/api.php - API routes → Products: routes requests
routes/api.php - API routes → Stock API: routes requests
routes/api.php - API routes → Stock alerts API: routes requests
routes/api.php - Authentication → Users and tokens: authenticates users
app/Http/Controllers/Api/AuthController.php - Admin recovery → Users and tokens: creates admin
app/Console/Commands/CreateAdminCommand.php - Employee management → Establishment resolution: resolves establishment
app/Http/Controllers/Api/EmployeController.php - Employee management → Employee records: creates and reads
app/Http/Controllers/Api/EmployeController.php - Employee management → Users and tokens: creates and updates
app/Http/Controllers/Api/EmployeController.php - Employee records → Establishments: relates employee
app/Models/Employe.php - Tenant query scope → Users and tokens: checks user scope
app/Models/Scopes/EtablissementScope.php - Users and tokens → Employee records: resolves active site
app/Models/User.php - Categories → Product records: manages categories
app/Http/Controllers/Api/CategorieController.php - Products → Product records: manages products
app/Http/Controllers/Api/ProduitController.php - Stock API → Establishment resolution: resolves establishment
app/Http/Controllers/Api/StockController.php - Stock API → Stock balances: reads and adjusts
app/Http/Controllers/Api/StockController.php - Stock API → Stock movements: records movements
app/Http/Controllers/Api/StockController.php - Stock movements → Stock balances: updates balances
app/Models/MouvementStock.php - Stock balances → Stock alert records: creates alerts
app/Models/Stock.php - Stock alerts API → Stock alert records: manages alerts
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