# aziz-boujaada/pnematique_bousta_api architecture

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

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

## Overview

#### Purpose and Consumers
Pneumatique Bousta is a Laravel 12 REST backend for a Flutter mobile client. It centralizes tire/article catalog data, stock by depot, dashboard statistics, user access, and administrative user operations. HTTP entry points are the Laravel front controller at `public/index.php` and API route definitions in `routes/api.php`.

#### HTTP API and Access Boundary
API controllers receive requests and return JSON, with authentication centered on Laravel Sanctum configuration in `config/sanctum.php`. Public authentication flows are handled by `app/Http/Controllers/Api/AuthController.php`; protected inventory, depot, and reporting endpoints are exposed through controllers under `app/Http/Controllers/Api/`. Administrative access is a separate authorization boundary implemented by `app/Http/Middleware/AdminMiddleware.php`.

#### Identity, Registration, and Recovery
User accounts are represented by `app/Models/User.php`, with registration/login input validation isolated in `app/Http/Requests/RegisterRequest.php` and `app/Http/Requests/LoginRequest.php`. Password recovery uses OTP records and service logic in `app/Models/ResetPasswordOtp.php`, `app/Services/OTPService.php`, and `app/Http/Controllers/Api/ResetPasswordController.php`. Email delivery is an external infrastructure dependency, configured through `config/mail.php` and rendered from `resources/views/emails/`.

#### Inventory Read Model
Articles, stock records, and depots form the core inventory domain: `app/Models/Article.php`, `app/Models/Stock.php`, and `app/Models/Depot.php`. Article list/search/filter operations flow from `app/Http/Controllers/Api/ArticleController.php` into `app/Services/ArticleService.php`. The service layer is the principal boundary for source-aware or multi-database inventory retrieval; clients may identify an article by reference plus source database.

#### Article Detail and Stock Aggregation
Detailed article retrieval is separated from listing in `app/Services/ArticleDetailsService.php` and returns article information plus stock distribution across depots. This stage joins/aggregates article, stock, and depot domain data before response formatting. Its API boundary is `app/Http/Controllers/Api/ArticleController.php`, while `app/DTOs/ArticleDTO.php` provides a stable client-facing article shape.

#### Depots and Dashboard Metrics
Depot discovery is a dedicated read path through `app/Http/Controllers/Api/DepotController.php` and `app/Services/DepotService.php`. Dashboard-oriented aggregates are isolated in `app/Http/Controllers/Api/StatsController.php` and `app/Services/StatsService.php`, keeping reporting calculations distinct from article browsing and detail queries.

#### Persistence and Runtime Infrastructure
Laravel bootstraps through `bootstrap/app.php`; dependency and provider wiring begins in `app/Providers/AppServiceProvider.php`. Database connectivity is deployment-configured in `config/database.php` and may target SQL Server, MySQL, PostgreSQL, or SQLite, including multiple inventory sources. Application-owned schema covers users, tokens, jobs/cache, and password OTPs under `database/migrations/`; asynchronous work is supported by `config/queue.php`. Sanctum personal access tokens are persisted via `database/migrations/2026_07_06_152124_create_personal_access_tokens_table.php`.

#### Response Contract Layer
Controllers delegate business work to services and use DTOs to prevent direct database-model exposure. `app/DTOs/ArticleDTO.php` and `app/DTOs/UserDTO.php` define consistent payload boundaries for the mobile client, including source-aware article identity and authenticated-user data.

Main entry points: [`routes/api.php`](https://github.com/aziz-boujaada/pnematique_bousta_api/blob/main/routes/api.php) (API routes), [`app/Models/Article.php`](https://github.com/aziz-boujaada/pnematique_bousta_api/blob/main/app/Models/Article.php) (Article, stock, and depot), [`app/Http/Controllers/Api/ArticleController.php`](https://github.com/aziz-boujaada/pnematique_bousta_api/blob/main/app/Http/Controllers/Api/ArticleController.php) (Article API), [`app/Services/ArticleService.php`](https://github.com/aziz-boujaada/pnematique_bousta_api/blob/main/app/Services/ArticleService.php) (Article catalog service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["HTTP API"]
  node_front["Laravel front controller<br/>entrypoint<br/>[index.php]"]
  node_routes["API routes<br/>routing<br/>[api.php]"]
  node_article_controller["Article API<br/>controller"]
  node_depot_controller["Depot API<br/>controller"]
  node_stats_controller["Stats API<br/>controller"]
end

subgraph group_domain["Application Services"]
  node_article_service["Article catalog service<br/>[ArticleService.php]"]
  node_details_service["Article detail aggregation"]
  node_depot_service["Depot service<br/>[DepotService.php]"]
  node_stats_service["Dashboard metrics service<br/>[StatsService.php]"]
  node_inventory_models["Article, stock, and depot<br/>inventory models<br/>[Article.php]"]
  node_article_dto["Article response DTO<br/>[ArticleDTO.php]"]
end

subgraph group_identity["Identity &amp; Recovery"]
  node_auth_controller["Authentication API<br/>controller<br/>[AuthController.php]"]
  node_reset_controller["Password recovery API<br/>controller"]
  node_access{{"Sanctum and admin access<br/>auth boundary<br/>[sanctum.php]"}}
  node_auth_inputs["Registration and login validation<br/>request validation"]
  node_user["User account<br/>model<br/>[User.php]"]
  node_otp_service["OTP recovery service<br/>[OTPService.php]"]
  node_otp["Password OTP<br/>model"]
end

subgraph group_infra["Runtime &amp; Infrastructure"]
  node_runtime["Laravel bootstrap and providers<br/>runtime<br/>[app.php]"]
  node_databases[("Multi-source databases<br/>persistence<br/>[database.php]")]
  node_mail["Email delivery<br/>external mail<br/>[mail.php]"]
end

node_mobile(("Flutter mobile client"))

node_mobile -->|"JSON requests"| node_front
node_front -->|"dispatches"| node_routes
node_routes -->|"protected routes"| node_access
node_routes -->|"article endpoints"| node_article_controller
node_routes -->|"depot endpoints"| node_depot_controller
node_routes -->|"dashboard endpoints"| node_stats_controller
node_routes -->|"public auth"| node_auth_controller
node_routes -->|"recovery endpoints"| node_reset_controller
node_access -->|"authenticates"| node_user
node_auth_controller -->|"validates"| node_auth_inputs
node_auth_controller -->|"creates and signs in"| node_user
node_reset_controller -->|"uses"| node_otp_service
node_otp_service -->|"stores and verifies"| node_otp
node_otp_service -->|"sends OTP email"| node_mail
node_article_controller -->|"list and search"| node_article_service
node_article_controller -->|"detail lookup"| node_details_service
node_article_service -->|"retrieves"| node_inventory_models
node_details_service -->|"aggregates"| node_inventory_models
node_depot_controller -->|"discovers"| node_depot_service
node_depot_service -->|"reads depots"| node_inventory_models
node_stats_controller -->|"requests metrics"| node_stats_service
node_stats_service -->|"aggregates"| node_inventory_models
node_article_service -->|"maps payload"| node_article_dto
node_details_service -->|"maps payload"| node_article_dto
node_inventory_models -->|"queries"| node_databases
node_user -->|"persists"| node_databases
node_otp -->|"persists"| node_databases
node_runtime -->|"boots application"| node_routes

click node_front "https://github.com/aziz-boujaada/pnematique_bousta_api/blob/main/public/index.php"
click node_routes "https://github.com/aziz-boujaada/pnematique_bousta_api/blob/main/routes/api.php"
click node_article_controller "https://github.com/aziz-boujaada/pnematique_bousta_api/blob/main/app/Http/Controllers/Api/ArticleController.php"
click node_depot_controller "https://github.com/aziz-boujaada/pnematique_bousta_api/blob/main/app/Http/Controllers/Api/DepotController.php"
click node_stats_controller "https://github.com/aziz-boujaada/pnematique_bousta_api/blob/main/app/Http/Controllers/Api/StatsController.php"
click node_auth_controller "https://github.com/aziz-boujaada/pnematique_bousta_api/blob/main/app/Http/Controllers/Api/AuthController.php"
click node_reset_controller "https://github.com/aziz-boujaada/pnematique_bousta_api/blob/main/app/Http/Controllers/Api/ResetPasswordController.php"
click node_access "https://github.com/aziz-boujaada/pnematique_bousta_api/blob/main/config/sanctum.php"
click node_auth_inputs "https://github.com/aziz-boujaada/pnematique_bousta_api/blob/main/app/Http/Requests/RegisterRequest.php"
click node_user "https://github.com/aziz-boujaada/pnematique_bousta_api/blob/main/app/Models/User.php"
click node_otp_service "https://github.com/aziz-boujaada/pnematique_bousta_api/blob/main/app/Services/OTPService.php"
click node_otp "https://github.com/aziz-boujaada/pnematique_bousta_api/blob/main/app/Models/ResetPasswordOtp.php"
click node_article_service "https://github.com/aziz-boujaada/pnematique_bousta_api/blob/main/app/Services/ArticleService.php"
click node_details_service "https://github.com/aziz-boujaada/pnematique_bousta_api/blob/main/app/Services/ArticleDetailsService.php"
click node_depot_service "https://github.com/aziz-boujaada/pnematique_bousta_api/blob/main/app/Services/DepotService.php"
click node_stats_service "https://github.com/aziz-boujaada/pnematique_bousta_api/blob/main/app/Services/StatsService.php"
click node_inventory_models "https://github.com/aziz-boujaada/pnematique_bousta_api/blob/main/app/Models/Article.php"
click node_article_dto "https://github.com/aziz-boujaada/pnematique_bousta_api/blob/main/app/DTOs/ArticleDTO.php"
click node_runtime "https://github.com/aziz-boujaada/pnematique_bousta_api/blob/main/bootstrap/app.php"
click node_databases "https://github.com/aziz-boujaada/pnematique_bousta_api/blob/main/config/database.php"
click node_mail "https://github.com/aziz-boujaada/pnematique_bousta_api/blob/main/config/mail.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_front,node_routes,node_article_controller,node_depot_controller,node_stats_controller toneBlue
class node_article_service,node_details_service,node_depot_service,node_stats_service,node_inventory_models,node_article_dto toneAmber
class node_auth_controller,node_reset_controller,node_access,node_auth_inputs,node_user,node_otp_service,node_otp toneMint
class node_runtime,node_databases,node_mail toneRose
class node_mobile toneNeutral
```

## Components

### HTTP API

- [Laravel front controller](https://github.com/aziz-boujaada/pnematique_bousta_api/blob/main/public/index.php): entrypoint · `public/index.php`
- [API routes](https://github.com/aziz-boujaada/pnematique_bousta_api/blob/main/routes/api.php): routing · `routes/api.php`
- [Article API](https://github.com/aziz-boujaada/pnematique_bousta_api/blob/main/app/Http/Controllers/Api/ArticleController.php): controller · List, search, filter, and detail endpoints. · `app/Http/Controllers/Api/ArticleController.php`
- [Depot API](https://github.com/aziz-boujaada/pnematique_bousta_api/blob/main/app/Http/Controllers/Api/DepotController.php): controller · `app/Http/Controllers/Api/DepotController.php`
- [Stats API](https://github.com/aziz-boujaada/pnematique_bousta_api/blob/main/app/Http/Controllers/Api/StatsController.php): controller · `app/Http/Controllers/Api/StatsController.php`

### Application Services

- [Article catalog service](https://github.com/aziz-boujaada/pnematique_bousta_api/blob/main/app/Services/ArticleService.php): service · Source-aware inventory list and search retrieval. · `app/Services/ArticleService.php`
- [Article detail aggregation](https://github.com/aziz-boujaada/pnematique_bousta_api/blob/main/app/Services/ArticleDetailsService.php): service · Combines article data with stock distribution by depot. · `app/Services/ArticleDetailsService.php`
- [Depot service](https://github.com/aziz-boujaada/pnematique_bousta_api/blob/main/app/Services/DepotService.php): service · `app/Services/DepotService.php`
- [Dashboard metrics service](https://github.com/aziz-boujaada/pnematique_bousta_api/blob/main/app/Services/StatsService.php): service · `app/Services/StatsService.php`
- [Article, stock, and depot](https://github.com/aziz-boujaada/pnematique_bousta_api/blob/main/app/Models/Article.php): inventory models · Core catalog and per-depot stock read model. · `app/Models/Article.php`
- [Article response DTO](https://github.com/aziz-boujaada/pnematique_bousta_api/blob/main/app/DTOs/ArticleDTO.php): DTO · Stable source-aware article payload. · `app/DTOs/ArticleDTO.php`

### Identity & Recovery

- [Authentication API](https://github.com/aziz-boujaada/pnematique_bousta_api/blob/main/app/Http/Controllers/Api/AuthController.php): controller · `app/Http/Controllers/Api/AuthController.php`
- [Password recovery API](https://github.com/aziz-boujaada/pnematique_bousta_api/blob/main/app/Http/Controllers/Api/ResetPasswordController.php): controller · `app/Http/Controllers/Api/ResetPasswordController.php`
- [Sanctum and admin access](https://github.com/aziz-boujaada/pnematique_bousta_api/blob/main/config/sanctum.php): auth boundary · Sanctum protects API access; middleware gates administration. · `config/sanctum.php`
- [Registration and login validation](https://github.com/aziz-boujaada/pnematique_bousta_api/blob/main/app/Http/Requests/RegisterRequest.php): request validation · `app/Http/Requests/RegisterRequest.php`
- [User account](https://github.com/aziz-boujaada/pnematique_bousta_api/blob/main/app/Models/User.php): model · `app/Models/User.php`
- [OTP recovery service](https://github.com/aziz-boujaada/pnematique_bousta_api/blob/main/app/Services/OTPService.php): service · `app/Services/OTPService.php`
- [Password OTP](https://github.com/aziz-boujaada/pnematique_bousta_api/blob/main/app/Models/ResetPasswordOtp.php): model · `app/Models/ResetPasswordOtp.php`

### Runtime & Infrastructure

- [Laravel bootstrap and providers](https://github.com/aziz-boujaada/pnematique_bousta_api/blob/main/bootstrap/app.php): runtime · `bootstrap/app.php`
- [Multi-source databases](https://github.com/aziz-boujaada/pnematique_bousta_api/blob/main/config/database.php): persistence · Configured for SQL Server, MySQL, PostgreSQL, or SQLite inventory sources. · `config/database.php`
- [Email delivery](https://github.com/aziz-boujaada/pnematique_bousta_api/blob/main/config/mail.php): external mail · Recovery emails use configured mail transport and templates. · `config/mail.php`

### Other components

- **Flutter mobile client**: client

## Connections

- Flutter mobile client → Laravel front controller: JSON requests
- Laravel front controller → API routes: dispatches
- API routes → Sanctum and admin access: protected routes
- API routes → Article API: article endpoints
- API routes → Depot API: depot endpoints
- API routes → Stats API: dashboard endpoints
- API routes → Authentication API: public auth
- API routes → Password recovery API: recovery endpoints
- Sanctum and admin access → User account: authenticates
- Authentication API → Registration and login validation: validates
- Authentication API → User account: creates and signs in
- Password recovery API → OTP recovery service: uses
- OTP recovery service → Password OTP: stores and verifies
- OTP recovery service → Email delivery: sends OTP email
- Article API → Article catalog service: list and search
- Article API → Article detail aggregation: detail lookup
- Article catalog service → Article, stock, and depot: retrieves
- Article detail aggregation → Article, stock, and depot: aggregates
- Depot API → Depot service: discovers
- Depot service → Article, stock, and depot: reads depots
- Stats API → Dashboard metrics service: requests metrics
- Dashboard metrics service → Article, stock, and depot: aggregates
- Article catalog service → Article response DTO: maps payload
- Article detail aggregation → Article response DTO: maps payload
- Article, stock, and depot → Multi-source databases: queries
- User account → Multi-source databases: persists
- Password OTP → Multi-source databases: persists
- Laravel bootstrap and providers → API routes: boots application
