# guillenme/nawi-2 architecture

> Architecture diagram of the GitHub repository guillenme/nawi-2, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/guillenme/nawi-2
- Repository: https://github.com/guillenme/nawi-2

## Overview

1. **Repository type and runtime**
   - This is a **Laravel PHP monolith** with a classic server-rendered UI.
   - The primary delivery path is **HTTP -> Laravel routing -> controllers -> Eloquent models -> Blade views**.
   - Front-end behavior is lightweight, built from `resources/js`, `resources/css`, and `resources/sass`, then served through the Laravel/Vite pipeline.

2. **Core domain**
   - The app models a **taxi platform** with distinct personas and workflows: **admin, taxista, pasajero, taxi, viaje, documentos, calificaciones, suscripciones**.
   - The domain is centered on user onboarding, role assignment, document validation, taxi registration, trip management, and ratings.

3. **Application boundaries**
   - `app/Http/Controllers` contains the main business entry points.
   - `app/Models` contains the persistent domain objects.
   - `app/Services` isolates cross-cutting or integration logic such as geolocation, payment, external API access, role handling, document-status handling, and security logging.
   - `resources/views` contains all UI rendering; there is no separate SPA boundary.

4. **User and authentication subsystem**
   - Authentication is split across several controllers: standard login/register, password reset, email verification, and a custom `WebAuthController` / `AuthController`.
   - `app/Http/Requests` adds request validation for passenger and driver registration.
   - The presence of both `sanctum` config and OAuth-related migration tables indicates the project supports **token-based auth for API access** alongside web sessions.

5. **Role- and type-based access control**
   - `Role`, `Usuario`, `Admin`, `Taxista`, and `Pasajero` suggest the system separates identity from role-specific profiles.
   - `ValidateUserTypeMiddleware` and `RoleService` indicate access is not just authenticated/unauthenticated; it is **persona-aware**, gating controllers and dashboards by user type.
   - `AuthServiceProvider` and `security` config likely centralize authorization policies and security rules.

6. **Taxi and trip management**
   - `TaxiController`, `TaxistaController`, `ViajeController`, `PasajeroViajeController`, and `TaxistaViajeController` form the operational core.
   - Trips (`Viaje`) appear to carry state, location, and additional operational fields, implying a lifecycle such as request/assignment/in-progress/completed/cancelled.
   - Taxi ownership/association is modeled separately from drivers and passengers, which is important for diagramming the domain boundaries.

7. **Document and compliance workflow**
   - The system has explicit document entities: `Matricula`, `Licencia`, `EstatusDocumento`, `Foto`, and related controller/service support.
   - Admin and taxista views include **document review/management screens**, so document validation is a first-class workflow, not a side feature.
   - The `EstatusDocumentoService` suggests document approval/rejection status is normalized and reused across the app.

8. **Payments, subscriptions, and external integrations**
   - `PaymentService` and `Suscripcion` imply some subscription or billing flow, likely tied to driver/taxi enablement.
   - `ExternalApiService` and `GeolocationService` indicate the app integrates with outside systems for location-based or third-party data.
   - These are isolated in services, so the controllers likely orchestrate them rather than embedding external calls directly.

9. **Security and request handling**
   - Several middleware layers are notable: **input sanitization, rate limiting, API throttling, security headers, CSRF, auth, user-type validation**.
   - `SecurityLoggerService` shows security-relevant events are intentionally logged.
   - This means request flow is hardened at the middleware boundary before reaching business controllers.

10. **Data model and persistence**
   - The database layer is Eloquent-driven with migrations for users, roles, admins, taxistas, pasajeros, taxis, viajes, ratings, subscriptions, photos, and tokens.
   - Later migrations add operational fields to trips and adjust taxi/document constraints, showing the schema evolved around real workflow needs.
   - Seeders for roles, genres, languages, and document status provide baseline reference data.

11. **Presentation layer**
   - Blade templates are organized by audience: `auth`, `admin`, `taxista`, `perfil`, `home`, `welcome`, and `offline`.
   - There are dedicated screens for dashboards, document management, taxi CRUD, profile editing, and password reset emails.
   - The UI is therefore segmented by role and task, matching the backend authorization model.

12. **Offline/PWA behavior**
   - `public/service-worker.js`, `manifest.json`, `offline.html`, and related update/debug assets show the app includes **PWA/offline support**.
   - This is a meaningful architectural boundary: the public folder contains not just static assets, but client-side caching and offline fallback behavior.
   - For an architecture diagram, this is a separate client capability layered over the Laravel server.

13. **Routing and entry points**
   - `routes/web.php` is the main browser-facing entry, `routes/api.php` exposes API endpoints, and `routes/console.php` handles artisan commands.
   - `app/Console/Kernel.php` and `app/Http/Kernel.php` define scheduled/background and HTTP middleware orchestration.
   - `public/index.php` is the single web entry point into the framework.

14. **Operational concern**
   - The repository includes extensive docs focused on **email setup, password reset, environment review, and security analysis**, which suggests authentication and notification flow are operationally important.
   - The `.env.example`, mail config, queue config, and logging config indicate deployment depends on environment-driven infrastructure for email, background work, and observability.

Main entry points: [`routes/web.php`](https://github.com/guillenme/nawi-2/blob/main/routes/web.php) (Web routes), [`app/Http/Kernel.php`](https://github.com/guillenme/nawi-2/blob/main/app/Http/Kernel.php) (HTTP kernel), [`app/Http/Controllers/AdminController.php`](https://github.com/guillenme/nawi-2/blob/main/app/Http/Controllers/AdminController.php) (Personas), [`app/Http/Controllers/ViajeController.php`](https://github.com/guillenme/nawi-2/blob/main/app/Http/Controllers/ViajeController.php) (Trips)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_runtime["Runtime"]
  node_public_index["Entry<br/>[index.php]"]
  node_routes_web["Web routes<br/>browser routes<br/>[web.php]"]
  node_routes_api["API routes<br/>[api.php]"]
  node_http_kernel["HTTP kernel<br/>middleware stack<br/>[Kernel.php]"]
  node_console_kernel["Console kernel<br/>artisan scheduler<br/>[Kernel.php]"]
end

subgraph group_group_domain["Domain"]
  node_auth_controllers["Auth flow<br/>auth controllers<br/>[AuthController.php]"]
  node_persona_controllers["Personas<br/>persona controllers"]
  node_trip_controllers["Trips<br/>trip controllers"]
  node_document_controllers["Documents<br/>document controllers"]
  node_identity_models[("Identity<br/>auth models<br/>[Usuario.php]")]
  node_mobility_models[("Mobility<br/>fleet models<br/>[Taxi.php]")]
  node_compliance_models[("Compliance<br/>doc models<br/>[Licencia.php]")]
end

subgraph group_group_ui["UI"]
  node_blade_views["Blade UI<br/>server views<br/>[welcome.blade.php]"]
  node_frontend_assets["Assets<br/>[app.js]"]
  node_pwa_public["PWA<br/>offline client<br/>[service-worker.js]"]
end

subgraph group_group_infra["Infra"]
  node_role_service["Role service<br/>access service<br/>[RoleService.php]"]
  node_document_service["Doc status<br/>workflow service"]
  node_geo_service["Geolocation<br/>location service"]
  node_payment_service["Payments<br/>billing service<br/>[PaymentService.php]"]
  node_external_api_service["External API<br/>integration service"]
  node_security_logger["Security log<br/>audit service"]
  node_database_schema[("Schema<br/>migrations")]
end

node_public_index -->|"bootstraps"| node_http_kernel
node_http_kernel -->|"dispatches"| node_routes_web
node_http_kernel -->|"dispatches"| node_routes_api
node_routes_web -->|"maps to"| node_auth_controllers
node_routes_web -->|"maps to"| node_persona_controllers
node_routes_web -->|"maps to"| node_trip_controllers
node_routes_web -->|"maps to"| node_document_controllers
node_routes_api -->|"uses"| node_external_api_service
node_auth_controllers -->|"persists"| node_identity_models
node_persona_controllers -->|"uses"| node_identity_models
node_trip_controllers -->|"persists"| node_mobility_models
node_document_controllers -->|"persists"| node_compliance_models
node_trip_controllers -->|"uses"| node_geo_service
node_trip_controllers -->|"uses"| node_payment_service
node_document_controllers -->|"uses"| node_document_service
node_persona_controllers -->|"gates"| node_role_service
node_persona_controllers -->|"logs"| node_security_logger
node_http_kernel -->|"guards"| node_security_logger
node_http_kernel -->|"renders"| node_blade_views
node_blade_views -->|"includes"| node_frontend_assets
node_pwa_public -.->|"backs up"| node_blade_views
node_console_kernel -.->|"maintains"| node_database_schema
node_identity_models -->|"maps to"| node_database_schema
node_mobility_models -->|"maps to"| node_database_schema
node_compliance_models -->|"maps to"| node_database_schema

click node_public_index "https://github.com/guillenme/nawi-2/blob/main/public/index.php"
click node_routes_web "https://github.com/guillenme/nawi-2/blob/main/routes/web.php"
click node_routes_api "https://github.com/guillenme/nawi-2/blob/main/routes/api.php"
click node_http_kernel "https://github.com/guillenme/nawi-2/blob/main/app/Http/Kernel.php"
click node_console_kernel "https://github.com/guillenme/nawi-2/blob/main/app/Console/Kernel.php"
click node_auth_controllers "https://github.com/guillenme/nawi-2/blob/main/app/Http/Controllers/AuthController.php"
click node_persona_controllers "https://github.com/guillenme/nawi-2/blob/main/app/Http/Controllers/AdminController.php"
click node_trip_controllers "https://github.com/guillenme/nawi-2/blob/main/app/Http/Controllers/ViajeController.php"
click node_document_controllers "https://github.com/guillenme/nawi-2/blob/main/app/Http/Controllers/LicenciaController.php"
click node_identity_models "https://github.com/guillenme/nawi-2/blob/main/app/Models/Usuario.php"
click node_mobility_models "https://github.com/guillenme/nawi-2/blob/main/app/Models/Taxi.php"
click node_compliance_models "https://github.com/guillenme/nawi-2/blob/main/app/Models/Licencia.php"
click node_role_service "https://github.com/guillenme/nawi-2/blob/main/app/Services/RoleService.php"
click node_document_service "https://github.com/guillenme/nawi-2/blob/main/app/Services/EstatusDocumentoService.php"
click node_geo_service "https://github.com/guillenme/nawi-2/blob/main/app/Services/GeolocationService.php"
click node_payment_service "https://github.com/guillenme/nawi-2/blob/main/app/Services/PaymentService.php"
click node_external_api_service "https://github.com/guillenme/nawi-2/blob/main/app/Services/ExternalApiService.php"
click node_security_logger "https://github.com/guillenme/nawi-2/blob/main/app/Services/SecurityLoggerService.php"
click node_blade_views "https://github.com/guillenme/nawi-2/blob/main/resources/views/welcome.blade.php"
click node_frontend_assets "https://github.com/guillenme/nawi-2/blob/main/resources/js/app.js"
click node_pwa_public "https://github.com/guillenme/nawi-2/blob/main/public/service-worker.js"
click node_database_schema "https://github.com/guillenme/nawi-2/blob/main/database/migrations/2025_09_25_151341_create_roles_table.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_public_index,node_routes_web,node_routes_api,node_http_kernel,node_console_kernel toneBlue
class node_auth_controllers,node_persona_controllers,node_trip_controllers,node_document_controllers,node_identity_models,node_mobility_models,node_compliance_models toneAmber
class node_blade_views,node_frontend_assets,node_pwa_public toneMint
class node_role_service,node_document_service,node_geo_service,node_payment_service,node_external_api_service,node_security_logger,node_database_schema toneRose
```

## Components

### Runtime

Laravel request, console, and middleware orchestration

- [Entry](https://github.com/guillenme/nawi-2/blob/main/public/index.php): web entry · Single HTTP entry point into the framework · `public/index.php`
- [Web routes](https://github.com/guillenme/nawi-2/blob/main/routes/web.php): browser routes · Primary server-rendered request map · `routes/web.php`
- [API routes](https://github.com/guillenme/nawi-2/blob/main/routes/api.php): api routes · Token/API surface for programmatic access · `routes/api.php`
- [HTTP kernel](https://github.com/guillenme/nawi-2/blob/main/app/Http/Kernel.php): middleware stack · Assembles request middleware and web pipeline · `app/Http/Kernel.php`
- [Console kernel](https://github.com/guillenme/nawi-2/blob/main/app/Console/Kernel.php): artisan scheduler · Coordinates console commands and scheduled work · `app/Console/Kernel.php`

### Domain

Core taxi platform concepts and workflows

- [Auth flow](https://github.com/guillenme/nawi-2/blob/main/app/Http/Controllers/AuthController.php): auth controllers · Login, register, reset, verification, and custom auth entry points · `app/Http/Controllers/AuthController.php`
- [Personas](https://github.com/guillenme/nawi-2/blob/main/app/Http/Controllers/AdminController.php): persona controllers · Admin, taxista, pasajero, and profile control surfaces · `app/Http/Controllers/AdminController.php`
- [Trips](https://github.com/guillenme/nawi-2/blob/main/app/Http/Controllers/ViajeController.php): trip controllers · Taxi, viaje, and role-specific trip orchestration · `app/Http/Controllers/ViajeController.php`
- [Documents](https://github.com/guillenme/nawi-2/blob/main/app/Http/Controllers/LicenciaController.php): document controllers · License, vehicle registration, and photo workflows · `app/Http/Controllers/LicenciaController.php`
- [Identity](https://github.com/guillenme/nawi-2/blob/main/app/Models/Usuario.php): auth models · Users, roles, profiles, and typed identities · `app/Models/Usuario.php`
- [Mobility](https://github.com/guillenme/nawi-2/blob/main/app/Models/Taxi.php): fleet models · Taxi, driver, passenger, and trip records · `app/Models/Taxi.php`
- [Compliance](https://github.com/guillenme/nawi-2/blob/main/app/Models/Licencia.php): doc models · Document, status, subscription, and rating records · `app/Models/Licencia.php`

### UI

Server-rendered views and client assets

- [Blade UI](https://github.com/guillenme/nawi-2/blob/main/resources/views/welcome.blade.php): server views · Role-based Blade rendering for auth, admin, taxista, perfil, and offline screens · `resources/views/welcome.blade.php`
- [Assets](https://github.com/guillenme/nawi-2/blob/main/resources/js/app.js): vite assets · Lightweight CSS/JS/Sass bundle for the server-rendered UI · `resources/js/app.js`
- [PWA](https://github.com/guillenme/nawi-2/blob/main/public/service-worker.js): offline client · Service worker, manifest, and offline fallback behavior · `public/service-worker.js`

### Infra

Security, config, queues, mail, and external integrations

- [Role service](https://github.com/guillenme/nawi-2/blob/main/app/Services/RoleService.php): access service · Persona-aware role and access decisions · `app/Services/RoleService.php`
- [Doc status](https://github.com/guillenme/nawi-2/blob/main/app/Services/EstatusDocumentoService.php): workflow service · Normalizes approval and rejection states for documents · `app/Services/EstatusDocumentoService.php`
- [Geolocation](https://github.com/guillenme/nawi-2/blob/main/app/Services/GeolocationService.php): location service · Location lookup and trip/location support · `app/Services/GeolocationService.php`
- [Payments](https://github.com/guillenme/nawi-2/blob/main/app/Services/PaymentService.php): billing service · Subscription or billing orchestration · `app/Services/PaymentService.php`
- [External API](https://github.com/guillenme/nawi-2/blob/main/app/Services/ExternalApiService.php): integration service · Boundary for third-party API calls · `app/Services/ExternalApiService.php`
- [Security log](https://github.com/guillenme/nawi-2/blob/main/app/Services/SecurityLoggerService.php): audit service · Records security-relevant events · `app/Services/SecurityLoggerService.php`
- [Schema](https://github.com/guillenme/nawi-2/blob/main/database/migrations/2025_09_25_151341_create_roles_table.php): migrations · Eloquent-backed tables, tokens, roles, documents, trips, and ratings · `database/migrations/2025_09_25_151341_create_roles_table.php`

## Connections

- Entry → HTTP kernel: bootstraps · HTTP requests enter the middleware pipeline
- HTTP kernel → Web routes: dispatches · Web requests route into browser controllers
- HTTP kernel → API routes: dispatches · API requests route into token-based endpoints
- Web routes → Auth flow: maps to · Authentication and account flows
- Web routes → Personas: maps to · Dashboards, profiles, and persona views
- Web routes → Trips: maps to · Taxi and trip operations
- Web routes → Documents: maps to · Document review and upload screens
- API routes → External API: uses · API-facing operations can delegate integration calls
- Auth flow → Identity: persists · Login, registration, and verification use identity records
- Personas → Identity: uses · Role-specific profiles and dashboards
- Trips → Mobility: persists · Taxi and trip state live in fleet models
- Documents → Compliance: persists · License, photo, and compliance data
- Trips → Geolocation: uses · Trip flows depend on geolocation support
- Trips → Payments: uses · Subscription/billing actions are coordinated here
- Documents → Doc status: uses · Document status transitions are normalized
- Personas → Role service: gates · Persona-aware access and dashboard selection
- Personas → Security log: logs · Security-sensitive actions are audited
- HTTP kernel → Security log: guards · Middleware hardens requests before controllers
- HTTP kernel → Blade UI: renders · Server responses resolve to Blade templates
- Blade UI → Assets: includes · Views are styled and scripted by bundled assets
- PWA → Blade UI: backs up · Offline fallback complements the server-rendered UI
- Console kernel → Schema: maintains · Scheduled or artisan tasks support data lifecycle
- Identity → Schema: maps to · Users, roles, tokens, and profiles are persisted here
- Mobility → Schema: maps to · Taxi and trip tables form the operational core
- Compliance → Schema: maps to · Documents, ratings, and subscriptions are stored here
