# Architecture ## Request Flow ``` HTTP Request → public/index.php → bootstrap/app.php (loads config, registers PDO, services) → Application::boot() (loads routes/web.php) → Router::dispatch(Request) (matches URL, runs middleware pipeline) → [Middleware] (AuthMiddleware, ApiKeyMiddleware) → Controller::method() (parse input → call repository/service → render) → Template::render() (PHP native, layout composition) → Response::send() ``` ## Layer Map | Layer | Location | Responsibility | |-------|----------|----------------| | Entry | `public/index.php` | Bootstrap only | | Routes | `routes/web.php` (581 lines) | All ~80 routes; manual DI wiring | | Core | `src/Core/` (25 files) | Framework infrastructure | | Controllers | `src/Modules/*/Controller.php` | Request parsing → response | | Services | `src/Modules/*/Service.php` | Business logic | | Repositories | `src/Modules/*/Repository.php` | PDO data access (34+ repos) | | Views | `resources/views/` | PHP templates with `$e()` / `$t()` | | Components | `resources/views/components/` | Reusable UI blocks | | Frontend modules | `public/assets/js/modules/` | Small vanilla JS enhancements loaded by layout | ## Module Inventory (`src/Modules/`) | Module | Files | Key Classes | Purpose | |--------|-------|-------------|---------| | **Auth** | 3 | `AuthController`, `AuthMiddleware`, `AuthService` | Login/logout, session | | **Users** | 2 | `UserController`, `UserRepository` | User CRUD | | **Orders** | 3 | `OrdersController` (1187 LOC), `OrdersRepository` (1221 LOC) | Order list, detail, status, payment, correlated subquery for return-risk | | **Shipments** | 17 | `ShipmentController`, provider services + tracking services | Shipment creation, label download, tracking polling | | **Accounting** | 5 | `AccountingController`, `ReceiptService`, `ReceiptRepository` | Receipts, invoices, PDF, Excel export | | **Email** | 3 | `EmailSendingService`, `VariableResolver`, `AttachmentGenerator` | Template-based email with PDF attachments | | **Automation** | 6 | `AutomationService` (834 LOC), `AutomationRepository`, `AutomationExecutionLogRepository` | Event→condition→action rules, email triggers | | **Settings** | 51+ | Integration controllers, OAuth clients, API clients, mappers | Allegro/shopPRO/Apaczka/InPost config, status mappings | | **Cron** | 12 | `CronRepository`, `CronHandlerFactory`, handler classes | Scheduled imports, syncs, token refresh | | **Printing** | 4 | `PrintApiController`, `PrintJobRepository`, `ApiKeyMiddleware` | REST API for Windows print client | | **Statistics** | 2 | `OrdersStatisticsController`, `OrdersStatisticsRepository` | Dashboard aggregates | | **Info** | 1 | `InfoController` | Health check | ## Frontend Enhancement Modules ### Checkbox Multiselect (`public/assets/js/modules/checkbox-multiselect.js`) - Loaded globally from `resources/views/layouts/app.php`. - Enhances native `