How aziz-boujaada/mawater works
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: web.php Web and API routes · Meter.php Operational domain models · DashboardsController.php Role dashboards · MeterReadingsController.php Reading intake
Components 18
HTTP & Access
- Laravel entrypoint
public/index.php - Application bootstrap
bootstrap/app.php - Web and API routes
routes/web.php - Authentication
app/Http/Controllers/AuthController.php - Role middleware · Separates administrator, collector, repair-agent, and villager access.
app/Http/Middleware/AuthMiddleware.php - Role dashboards
app/Http/Controllers/DashboardsController.php
Water Operations
- Meter administration · Creates and updates resident-assigned meters.
app/Http/Controllers/MetersController.php - Reading intake · Validated readings become the billing source record.
app/Http/Controllers/MeterReadingsController.php - Repair tracking · Records field repairs and associated losses.
app/Http/Controllers/RepairController.php - Operational domain models · Users, villagers, meters, readings, repairs, and financial losses.
app/Models/Meter.php
Billing & Collections
- Invoice creation · Creates invoices from meter readings.
app/Http/Controllers/InvoiceController.php - Payment collection · Records full or partial payments and balances.
app/Http/Controllers/PaymentController.php - Invoice and payment models · Financial status and remaining balance integrity point.
app/Models/Invoice.php - Invoice PDF export · Renders invoices through Dompdf.
app/Services/ExportInvoiceAsPdf.php
Platform & Presentation
- MySQL database · Schema migrations define operational and billing relationships.
config/database.php - Blade presentation · Shared layout, role workspaces, invoice views, and PDF templates.
resources/views/layouts/app.blade.php - Dashboard statistics
app/Services/AdminStatisticsDashboardService.php - Vite assets
resources/js/app.js
Connections 22
- 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