# aziz-boujaada/mawater architecture

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

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

## Overview

#### 1. Purpose and Runtime
Mawater is a Laravel/PHP web application for a single village water association: resident and meter administration, periodic readings, billing, collections, repair tracking, loss tracking, and role-specific statistics. HTTP enters through `public/index.php`; Laravel bootstraps via `bootstrap/app.php`; browser routes are defined in `routes/web.php`, with an API boundary in `routes/api.php`. MySQL is the intended persistence layer (`config/database.php`); Docker deployment is supported by `Dockerfile`.

#### 2. Access Control and Role Workspaces
Authentication is handled by `app/Http/Controllers/AuthController.php`, with login validation in `app/Http/Requests/LoginRequest.php`. Authorization is a middleware boundary: `app/Http/Middleware/AuthMiddleware.php`, `app/Http/Middleware/AdminMiddleware.php`, `app/Http/Middleware/CollectorMiddleware.php`, and `app/Http/Middleware/RepairAgentMiddleware.php` separate administrator, collector, repair-agent, and villager capabilities. Dashboard dispatch and role-facing UI are centered on `app/Http/Controllers/DashboardsController.php` and views such as `resources/views/dashboards/admin.blade.php` and `resources/views/dashboards/collector.blade.php`.

#### 3. Core Domain and Persistence
Eloquent models represent the operational chain: users/residents, meters, readings, invoices, payments, repairs, and financial losses in `app/Models/User.php`, `app/Models/Villager.php`, `app/Models/Meter.php`, `app/Models/MeterReadings.php`, `app/Models/Invoice.php`, `app/Models/Payment.php`, `app/Models/Repair.php`, and `app/Models/FinancialLose.php`. Schema evolution defines their database relationships and billing changes, notably `database/migrations/2026_03_16_225308_create_meters_table.php`, `database/migrations/2026_03_16_225900_create_meter_readings_table.php`, and `database/migrations/2026_03_27_192938_change_meter_id_to_reading_id_in_invoices_table.php`.

#### 4. Meter-to-Billing Flow
Administrators manage assigned meters through `app/Http/Controllers/MetersController.php`; mutation logic is isolated in `app/Services/StoreMeterService.php` and `app/Services/UpdateMeterService.php`. Readings arrive through `app/Http/Controllers/MeterReadingsController.php`, are validated by `app/Http/Requests/StoreMeterReadings.php`, and persisted through `app/Services/StoreReadingService.php` / `app/Repositories/ReadingRepository.php`. This reading record is the billing boundary: invoices are created from readings by `app/Http/Controllers/InvoiceController.php` and `app/Services/StoreInvoiceService.php`, then rendered in invoice views and PDF form.

#### 5. Collections, Invoice Documents, and Reporting
Collectors record full or partial payment activity through `app/Http/Controllers/PaymentController.php`, `app/Http/Requests/StorePaymentRequest.php`, and `app/Services/StorePaymentService.php`; invoice/payment status and remaining balance are therefore financial integrity points. Invoice export is a server-side document boundary: `app/Services/ExportInvoiceAsPdf.php` renders `resources/views/Pdfs/invoicePdf.blade.php`, with Dompdf configuration in `config/dompdf.php`. Listing and filtering behavior is shared by `app/Services/ListingQueryService.php`.

#### 6. Repairs and Operational Costs
Repair agents use `app/Http/Controllers/RepairController.php`, with validated writes via `app/Http/Requests/StoreRepairRequest.php` and orchestration in `app/Services/StoreRepairService.php`. Repairs connect field meter condition to recorded repair history and financial-loss records, with the underlying domains defined in `app/Models/Repair.php`, `app/Models/FinancialLose.php`, and their migrations.

#### 7. Presentation and Supporting Infrastructure
Blade is the primary presentation layer, with shared layout/navigation in `resources/views/layouts/app.blade.php` and `resources/views/components/side-bar.blade.php`. Vite builds the CSS/JavaScript assets (`resources/css/app.css`, `resources/js/app.js`). Dashboard aggregates belong in `app/Services/AdminStatisticsDashboardService.php` and `app/Services/VillagerStatisticsDashboard.php`; Laravel provides configurable cache, sessions, queues, logging, mail, filesystem storage, localization, and JWT settings under `config/`.

Main entry points: [`routes/web.php`](https://github.com/aziz-boujaada/mawater/blob/main/routes/web.php) (Web and API routes), [`app/Models/Meter.php`](https://github.com/aziz-boujaada/mawater/blob/main/app/Models/Meter.php) (Operational domain models), [`app/Http/Controllers/DashboardsController.php`](https://github.com/aziz-boujaada/mawater/blob/main/app/Http/Controllers/DashboardsController.php) (Role dashboards), [`app/Http/Controllers/MeterReadingsController.php`](https://github.com/aziz-boujaada/mawater/blob/main/app/Http/Controllers/MeterReadingsController.php) (Reading intake)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_http["HTTP &amp; Access"]
  node_entry["Laravel entrypoint<br/>PHP runtime<br/>[index.php]"]
  node_bootstrap["Application bootstrap<br/>Laravel bootstrap<br/>[app.php]"]
  node_routes["Web and API routes<br/>route boundary<br/>[web.php]"]
  node_auth["Authentication<br/>auth controller/request<br/>[AuthController.php]"]
  node_authorization{{"Role middleware<br/>authorization boundary<br/>[AuthMiddleware.php]"}}
  node_dashboards["Role dashboards<br/>dashboard controller"]
end

subgraph group_operations["Water Operations"]
  node_meters["Meter administration<br/>controller and services"]
  node_readings["Reading intake<br/>controller/service/repository"]
  node_repairs["Repair tracking<br/>controller/service"]
  node_domain["Operational domain models<br/>Eloquent models<br/>[Meter.php]"]
end

subgraph group_finance["Billing &amp; Collections"]
  node_invoices["Invoice creation<br/>controller/service"]
  node_payments["Payment collection<br/>controller/service"]
  node_financial["Invoice and payment models<br/>Eloquent models<br/>[Invoice.php]"]
  node_pdf["Invoice PDF export<br/>document service"]
end

subgraph group_platform["Platform &amp; Presentation"]
  node_database[("MySQL database<br/>persistence<br/>[database.php]")]
  node_views["Blade presentation<br/>server-rendered UI<br/>[app.blade.php]"]
  node_statistics["Dashboard statistics<br/>aggregation services"]
  node_assets["Vite assets<br/>frontend build<br/>[app.js]"]
end

node_entry -->|"boots"| node_bootstrap
node_bootstrap -->|"serves"| node_routes
node_routes -->|"login"| node_auth
node_routes -->|"protects routes"| node_authorization
node_authorization -->|"permits role workspace"| node_dashboards
node_routes -->|"admin operations"| node_meters
node_routes -->|"reading submission"| node_readings
node_routes -->|"repair operations"| node_repairs
node_meters -->|"manages meters"| node_domain
node_readings -->|"stores readings"| node_domain
node_repairs -->|"records repair and loss"| node_domain
node_readings -->|"billing source"| node_invoices
node_invoices -->|"creates invoices"| node_financial
node_payments -->|"updates payment status"| node_financial
node_invoices -->|"exports"| node_pdf
node_domain -->|"persists"| node_database
node_financial -->|"persists"| node_database
node_dashboards -->|"requests aggregates"| node_statistics
node_statistics -->|"queries"| node_database
node_dashboards -->|"renders"| node_views
node_pdf -->|"renders PDF template"| node_views
node_views -->|"uses built assets"| node_assets

click node_entry "https://github.com/aziz-boujaada/mawater/blob/main/public/index.php"
click node_bootstrap "https://github.com/aziz-boujaada/mawater/blob/main/bootstrap/app.php"
click node_routes "https://github.com/aziz-boujaada/mawater/blob/main/routes/web.php"
click node_auth "https://github.com/aziz-boujaada/mawater/blob/main/app/Http/Controllers/AuthController.php"
click node_authorization "https://github.com/aziz-boujaada/mawater/blob/main/app/Http/Middleware/AuthMiddleware.php"
click node_dashboards "https://github.com/aziz-boujaada/mawater/blob/main/app/Http/Controllers/DashboardsController.php"
click node_meters "https://github.com/aziz-boujaada/mawater/blob/main/app/Http/Controllers/MetersController.php"
click node_readings "https://github.com/aziz-boujaada/mawater/blob/main/app/Http/Controllers/MeterReadingsController.php"
click node_repairs "https://github.com/aziz-boujaada/mawater/blob/main/app/Http/Controllers/RepairController.php"
click node_domain "https://github.com/aziz-boujaada/mawater/blob/main/app/Models/Meter.php"
click node_invoices "https://github.com/aziz-boujaada/mawater/blob/main/app/Http/Controllers/InvoiceController.php"
click node_payments "https://github.com/aziz-boujaada/mawater/blob/main/app/Http/Controllers/PaymentController.php"
click node_financial "https://github.com/aziz-boujaada/mawater/blob/main/app/Models/Invoice.php"
click node_pdf "https://github.com/aziz-boujaada/mawater/blob/main/app/Services/ExportInvoiceAsPdf.php"
click node_database "https://github.com/aziz-boujaada/mawater/blob/main/config/database.php"
click node_views "https://github.com/aziz-boujaada/mawater/blob/main/resources/views/layouts/app.blade.php"
click node_statistics "https://github.com/aziz-boujaada/mawater/blob/main/app/Services/AdminStatisticsDashboardService.php"
click node_assets "https://github.com/aziz-boujaada/mawater/blob/main/resources/js/app.js"

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_entry,node_bootstrap,node_routes,node_auth,node_authorization,node_dashboards toneBlue
class node_meters,node_readings,node_repairs,node_domain toneAmber
class node_invoices,node_payments,node_financial,node_pdf toneMint
class node_database,node_views,node_statistics,node_assets toneRose
```

## Components

### HTTP & Access

- [Laravel entrypoint](https://github.com/aziz-boujaada/mawater/blob/main/public/index.php): PHP runtime · `public/index.php`
- [Application bootstrap](https://github.com/aziz-boujaada/mawater/blob/main/bootstrap/app.php): Laravel bootstrap · `bootstrap/app.php`
- [Web and API routes](https://github.com/aziz-boujaada/mawater/blob/main/routes/web.php): route boundary · `routes/web.php`
- [Authentication](https://github.com/aziz-boujaada/mawater/blob/main/app/Http/Controllers/AuthController.php): auth controller/request · `app/Http/Controllers/AuthController.php`
- [Role middleware](https://github.com/aziz-boujaada/mawater/blob/main/app/Http/Middleware/AuthMiddleware.php): authorization boundary · Separates administrator, collector, repair-agent, and villager access. · `app/Http/Middleware/AuthMiddleware.php`
- [Role dashboards](https://github.com/aziz-boujaada/mawater/blob/main/app/Http/Controllers/DashboardsController.php): dashboard controller · `app/Http/Controllers/DashboardsController.php`

### Water Operations

- [Meter administration](https://github.com/aziz-boujaada/mawater/blob/main/app/Http/Controllers/MetersController.php): controller and services · Creates and updates resident-assigned meters. · `app/Http/Controllers/MetersController.php`
- [Reading intake](https://github.com/aziz-boujaada/mawater/blob/main/app/Http/Controllers/MeterReadingsController.php): controller/service/repository · Validated readings become the billing source record. · `app/Http/Controllers/MeterReadingsController.php`
- [Repair tracking](https://github.com/aziz-boujaada/mawater/blob/main/app/Http/Controllers/RepairController.php): controller/service · Records field repairs and associated losses. · `app/Http/Controllers/RepairController.php`
- [Operational domain models](https://github.com/aziz-boujaada/mawater/blob/main/app/Models/Meter.php): Eloquent models · Users, villagers, meters, readings, repairs, and financial losses. · `app/Models/Meter.php`

### Billing & Collections

- [Invoice creation](https://github.com/aziz-boujaada/mawater/blob/main/app/Http/Controllers/InvoiceController.php): controller/service · Creates invoices from meter readings. · `app/Http/Controllers/InvoiceController.php`
- [Payment collection](https://github.com/aziz-boujaada/mawater/blob/main/app/Http/Controllers/PaymentController.php): controller/service · Records full or partial payments and balances. · `app/Http/Controllers/PaymentController.php`
- [Invoice and payment models](https://github.com/aziz-boujaada/mawater/blob/main/app/Models/Invoice.php): Eloquent models · Financial status and remaining balance integrity point. · `app/Models/Invoice.php`
- [Invoice PDF export](https://github.com/aziz-boujaada/mawater/blob/main/app/Services/ExportInvoiceAsPdf.php): document service · Renders invoices through Dompdf. · `app/Services/ExportInvoiceAsPdf.php`

### Platform & Presentation

- [MySQL database](https://github.com/aziz-boujaada/mawater/blob/main/config/database.php): persistence · Schema migrations define operational and billing relationships. · `config/database.php`
- [Blade presentation](https://github.com/aziz-boujaada/mawater/blob/main/resources/views/layouts/app.blade.php): server-rendered UI · Shared layout, role workspaces, invoice views, and PDF templates. · `resources/views/layouts/app.blade.php`
- [Dashboard statistics](https://github.com/aziz-boujaada/mawater/blob/main/app/Services/AdminStatisticsDashboardService.php): aggregation services · `app/Services/AdminStatisticsDashboardService.php`
- [Vite assets](https://github.com/aziz-boujaada/mawater/blob/main/resources/js/app.js): frontend build · `resources/js/app.js`

## Connections

- Laravel entrypoint → Application bootstrap: boots
- Application bootstrap → Web and API routes: serves
- Web and API routes → Authentication: login
- Web and API routes → Role middleware: protects routes
- Role middleware → Role dashboards: permits role workspace
- Web and API routes → Meter administration: admin operations
- Web and API routes → Reading intake: reading submission
- Web and API routes → Repair tracking: repair operations
- Meter administration → Operational domain models: manages meters
- Reading intake → Operational domain models: stores readings
- Repair tracking → Operational domain models: records repair and loss
- Reading intake → Invoice creation: billing source
- Invoice creation → Invoice and payment models: creates invoices
- Payment collection → Invoice and payment models: updates payment status
- Invoice creation → Invoice PDF export: exports
- Operational domain models → MySQL database: persists
- Invoice and payment models → MySQL database: persists
- Role dashboards → Dashboard statistics: requests aggregates
- Dashboard statistics → MySQL database: queries
- Role dashboards → Blade presentation: renders
- Invoice PDF export → Blade presentation: renders PDF template
- Blade presentation → Vite assets: uses built assets
