# luisfer2405/wisp architecture

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

- Interactive diagram: https://gitdiagram.com/luisfer2405/wisp
- Repository: https://github.com/luisfer2405/wisp

## Overview

1. **Project shape**
   - This is a split frontend/backend application for a WISP operations platform.
   - The root script `iniciar_wisp.sh` is the main local entrypoint; it starts the FastAPI backend and the Vite frontend together.
   - The repo also includes database verification, seeding, and repair scripts, which suggests the backend depends on a real relational datastore rather than mock data.

2. **Backend runtime and composition**
   - The backend is a Python API built around `backend/app/main.py`.
   - Its structure is modular: `core/` holds cross-cutting infrastructure, `modules/` holds business domains, and `shared/` contains reusable primitives.
   - The likely request path is: router → service/business logic → model/database access → response schema.

3. **Backend infrastructure layer**
   - `core/config.py`, `core/database.py`, `core/security.py`, and `core/dependencies.py` define the runtime environment, DB session handling, auth/security helpers, and dependency injection.
   - This is the boundary where environment config, database wiring, and API security are centralized so modules do not duplicate them.

4. **Backend domain modules**
   - The backend currently exposes at least two clear domains:
     - `modules/auth`: login/registration and token handling.
     - `modules/wisp`: the main operational domain for subscriber/network/business data.
   - Each module follows the same pattern: `router.py` for HTTP endpoints, `schemas.py` for request/response contracts, `models.py` for persistence objects, and `service.py` where applicable for business rules.

5. **Backend shared abstractions**
   - `shared/enums.py`, `shared/exceptions.py`, and `shared/utils.py` indicate common domain values, typed error handling, and helper functions shared across modules.
   - This usually means business constraints are enforced consistently across auth and WISP workflows, rather than inline in individual endpoints.

6. **Data and validation tooling**
   - The backend includes several operational scripts: `seed_data.py`, `fix_db.py`, `validate_postgres.py`, `verify_db_schema.py`, `check_alignment.py`, and `check_data.py`.
   - These files imply the repo is schema-sensitive and probably uses PostgreSQL, with explicit checks to keep code, enums, and DB state aligned.
   - The `docs/database.md` and related docs reinforce that the data model is an important architectural boundary.

7. **Authentication and access control flow**
   - The frontend has `AuthContext`, `ProtectedRoute`, `LoginPage`, `RegisterPage`, and auth service files; the backend has an `auth` module and security helpers.
   - The architecture is likely JWT-based: user credentials go from the auth UI to the backend auth router/service, a token is returned, and the frontend stores it in context and uses it for protected API requests.
   - Protected UI routes and backend dependency checks together define the access boundary.

8. **Frontend structure**
   - The frontend is a TypeScript React app organized by feature rather than by technical layer.
   - There are route-level modules for major business areas: dashboard, subscribers, network, billing, orders, tickets, reports, settings, cashbox, analytics, and profile.
   - `layouts/DashboardLayout.tsx`, `Sidebar`, and `TopNav` define the shared application shell around those pages.

9. **Frontend reusable UI and workflow components**
   - The `components/` directory contains business-focused reusable widgets such as client tables, filters, search bars, modals, metrics panels, pagination, payment/order creation, and table reports.
   - This indicates the UI is built from a set of domain-specific primitives reused across subscriber, billing, and operational screens.
   - Pages are thin orchestration layers; the interaction-heavy logic lives in these shared components.

10. **Frontend data access boundary**
    - `services/api.ts`, `auth.service.ts`, `auth.ts`, and `billing.service.ts` centralize HTTP communication with the backend.
    - `hooks/useClients.ts` suggests local data-fetching and state orchestration live close to the feature consuming them, rather than in a global store.
    - The frontend therefore depends on the backend through a small service layer, not direct ad hoc fetch calls from every page.

11. **Business domains represented in the UI**
    - The largest visible domains are subscriber management, network inventory/topology, billing and payments, orders/work orders, tickets, and admin/settings.
    - `network/` includes pages for nodes, OLTs, ONUs, and network maps, which aligns with the separate `docs/olt-integration.md`.
    - The app is not just CRUD; it appears to support operational workflows like onboarding clients, generating bills, tracking payments, and managing service tickets.

12. **External and operational boundaries**
    - `docker-compose.yml`, `.env.example`, and the startup script imply environment-based configuration and container-friendly deployment.
    - `backend/test_api.py`, `test_jwt.py`, and verification scripts show the repo includes lightweight validation around API behavior and security.
    - The docs folder is part of the architecture: it captures business rules, database design, and OLT integration expectations that shape how frontend and backend should evolve.

13. **What to show in an architecture diagram**
    - Draw the frontend as a React/Vite SPA with a shared shell, route modules, reusable business components, and a service/auth layer.
    - Draw the backend as a FastAPI application with a core infrastructure layer and domain modules for auth and WISP operations.
    - Put the database behind backend models/services, and show auth/JWT as the cross-cutting security path between frontend and backend.
    - Include scripts/docs/docker as supporting operational artifacts around the application, not part of the runtime request path.

Main entry points: [`frontend/src/App.tsx`](https://github.com/luisfer2405/wisp/blob/main/frontend/src/App.tsx) (App routes), [`backend/app/main.py`](https://github.com/luisfer2405/wisp/blob/main/backend/app/main.py) (API app), [`backend/app/core/dependencies.py`](https://github.com/luisfer2405/wisp/blob/main/backend/app/core/dependencies.py) (Dependencies), [`backend/app/modules/auth/router.py`](https://github.com/luisfer2405/wisp/blob/main/backend/app/modules/auth/router.py) (Auth module)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend SPA"]
  node_frontend_main["Frontend boot<br/>vite bootstrap<br/>[main.tsx]"]
  node_frontend_app["App routes<br/>route shell<br/>[App.tsx]"]
  node_dashboard_layout["Dashboard shell<br/>layout"]
  node_auth_context(("Auth state<br/>context<br/>[AuthContext.tsx]"))
  node_protected_route{{"Protected route<br/>route guard<br/>[ProtectedRoute.tsx]"}}
  node_api_service["API client<br/>http service<br/>[api.ts]"]
  node_auth_service["Auth service<br/>auth client<br/>[auth.service.ts]"]
  node_login_page["Login<br/>auth page<br/>[LoginPage.tsx]"]
  node_clients_page["Clients<br/>subscriber page<br/>[ClientsPage.tsx]"]
  node_billing_page["Billing"]
  node_network_page["Network<br/>[NetworkPage.tsx]"]
end

subgraph group_backend["Backend API"]
  node_backend_main["API app<br/>[main.py]"]
  node_core_config["Config<br/>[config.py]"]
  node_core_database[("Database<br/>db wiring<br/>[database.py]")]
  node_core_security{{"Security<br/>auth helpers<br/>[security.py]"}}
  node_core_deps["Dependencies<br/>injection<br/>[dependencies.py]"]
  node_auth_module["Auth module<br/>auth domain<br/>[router.py]"]
  node_wisp_module["WISP module<br/>ops domain<br/>[router.py]"]
  node_shared_primitives["Shared types<br/>common primitives<br/>[enums.py]"]
end

subgraph group_ops["Ops & Data"]
  node_entrypoint["Start app<br/>shell entrypoint<br/>[iniciar_wisp.sh]"]
  node_db_tooling["DB tooling<br/>ops scripts"]
  node_database_docs["Data docs<br/>architecture docs<br/>[database.md]"]
end

node_entrypoint -->|"starts"| node_backend_main
node_entrypoint -->|"starts"| node_frontend_main
node_frontend_main -->|"mounts"| node_frontend_app
node_frontend_app -->|"uses"| node_dashboard_layout
node_frontend_app -->|"routes to"| node_login_page
node_frontend_app -->|"routes to"| node_clients_page
node_frontend_app -->|"routes to"| node_billing_page
node_frontend_app -->|"routes to"| node_network_page
node_auth_context -->|"protects"| node_protected_route
node_login_page -->|"calls"| node_auth_service
node_auth_service -->|"uses"| node_api_service
node_api_service -->|"requests"| node_backend_main
node_backend_main -->|"loads"| node_core_config
node_backend_main -->|"injects"| node_core_deps
node_backend_main -->|"includes"| node_auth_module
node_backend_main -->|"includes"| node_wisp_module
node_core_deps -->|"binds"| node_core_database
node_core_deps -->|"binds"| node_core_security
node_auth_module -->|"uses"| node_core_security
node_auth_module -->|"uses"| node_shared_primitives
node_wisp_module -->|"persists via"| node_core_database
node_wisp_module -->|"uses"| node_shared_primitives
node_core_database -.->|"checked by"| node_db_tooling
node_db_tooling -.->|"guided by"| node_database_docs
node_core_config -.->|"constrained by"| node_database_docs

click node_entrypoint "https://github.com/luisfer2405/wisp/blob/main/iniciar_wisp.sh"
click node_frontend_main "https://github.com/luisfer2405/wisp/blob/main/frontend/src/main.tsx"
click node_frontend_app "https://github.com/luisfer2405/wisp/blob/main/frontend/src/App.tsx"
click node_dashboard_layout "https://github.com/luisfer2405/wisp/blob/main/frontend/src/layouts/DashboardLayout.tsx"
click node_auth_context "https://github.com/luisfer2405/wisp/blob/main/frontend/src/contexts/AuthContext.tsx"
click node_protected_route "https://github.com/luisfer2405/wisp/blob/main/frontend/src/components/ProtectedRoute.tsx"
click node_api_service "https://github.com/luisfer2405/wisp/blob/main/frontend/src/services/api.ts"
click node_auth_service "https://github.com/luisfer2405/wisp/blob/main/frontend/src/services/auth.service.ts"
click node_login_page "https://github.com/luisfer2405/wisp/blob/main/frontend/src/modules/auth/LoginPage.tsx"
click node_clients_page "https://github.com/luisfer2405/wisp/blob/main/frontend/src/modules/subscribers/ClientsPage.tsx"
click node_billing_page "https://github.com/luisfer2405/wisp/blob/main/frontend/src/modules/billing/BillingGeneratePage.tsx"
click node_network_page "https://github.com/luisfer2405/wisp/blob/main/frontend/src/modules/network/NetworkPage.tsx"
click node_backend_main "https://github.com/luisfer2405/wisp/blob/main/backend/app/main.py"
click node_core_config "https://github.com/luisfer2405/wisp/blob/main/backend/app/core/config.py"
click node_core_database "https://github.com/luisfer2405/wisp/blob/main/backend/app/core/database.py"
click node_core_security "https://github.com/luisfer2405/wisp/blob/main/backend/app/core/security.py"
click node_core_deps "https://github.com/luisfer2405/wisp/blob/main/backend/app/core/dependencies.py"
click node_auth_module "https://github.com/luisfer2405/wisp/blob/main/backend/app/modules/auth/router.py"
click node_wisp_module "https://github.com/luisfer2405/wisp/blob/main/backend/app/modules/wisp/router.py"
click node_shared_primitives "https://github.com/luisfer2405/wisp/blob/main/backend/app/shared/enums.py"
click node_db_tooling "https://github.com/luisfer2405/wisp/blob/main/backend/validate_postgres.py"
click node_database_docs "https://github.com/luisfer2405/wisp/blob/main/docs/database.md"

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_frontend_main,node_frontend_app,node_dashboard_layout,node_auth_context,node_protected_route,node_api_service,node_auth_service,node_login_page,node_clients_page,node_billing_page,node_network_page toneBlue
class node_backend_main,node_core_config,node_core_database,node_core_security,node_core_deps,node_auth_module,node_wisp_module,node_shared_primitives toneAmber
class node_entrypoint,node_db_tooling,node_database_docs toneMint
```

## Components

### Frontend SPA

React/Vite client with shared shell, auth state, feature pages, and API services.

- [Frontend boot](https://github.com/luisfer2405/wisp/blob/main/frontend/src/main.tsx): vite bootstrap · Client application bootstrap and root mounting. · `frontend/src/main.tsx`
- [App routes](https://github.com/luisfer2405/wisp/blob/main/frontend/src/App.tsx): route shell · Top-level application routing and page composition. · `frontend/src/App.tsx`
- [Dashboard shell](https://github.com/luisfer2405/wisp/blob/main/frontend/src/layouts/DashboardLayout.tsx): layout · Shared authenticated layout for the main app experience. · `frontend/src/layouts/DashboardLayout.tsx`
- [Auth state](https://github.com/luisfer2405/wisp/blob/main/frontend/src/contexts/AuthContext.tsx): context · Stores login state and token/session behavior for the UI. · `frontend/src/contexts/AuthContext.tsx`
- [Protected route](https://github.com/luisfer2405/wisp/blob/main/frontend/src/components/ProtectedRoute.tsx): route guard · Blocks unauthenticated access to private screens. · `frontend/src/components/ProtectedRoute.tsx`
- [API client](https://github.com/luisfer2405/wisp/blob/main/frontend/src/services/api.ts): http service · Central HTTP layer used by feature screens. · `frontend/src/services/api.ts`
- [Auth service](https://github.com/luisfer2405/wisp/blob/main/frontend/src/services/auth.service.ts): auth client · Frontend auth-specific API calls and token handling. · `frontend/src/services/auth.service.ts`
- [Login](https://github.com/luisfer2405/wisp/blob/main/frontend/src/modules/auth/LoginPage.tsx): auth page · User sign-in screen connected to the auth flow. · `frontend/src/modules/auth/LoginPage.tsx`
- [Clients](https://github.com/luisfer2405/wisp/blob/main/frontend/src/modules/subscribers/ClientsPage.tsx): subscriber page · Representative subscriber-management screen. · `frontend/src/modules/subscribers/ClientsPage.tsx`
- [Billing](https://github.com/luisfer2405/wisp/blob/main/frontend/src/modules/billing/BillingGeneratePage.tsx): billing page · Representative billing and payments workflow screen. · `frontend/src/modules/billing/BillingGeneratePage.tsx`
- [Network](https://github.com/luisfer2405/wisp/blob/main/frontend/src/modules/network/NetworkPage.tsx): network page · Representative network operations screen. · `frontend/src/modules/network/NetworkPage.tsx`

### Backend API

FastAPI application with core infrastructure, domain modules, and shared primitives.

- [API app](https://github.com/luisfer2405/wisp/blob/main/backend/app/main.py): fastapi app · Backend application entrypoint and router assembly. · `backend/app/main.py`
- [Config](https://github.com/luisfer2405/wisp/blob/main/backend/app/core/config.py): runtime config · Environment and application configuration. · `backend/app/core/config.py`
- [Database](https://github.com/luisfer2405/wisp/blob/main/backend/app/core/database.py): db wiring · Database engine and session setup. · `backend/app/core/database.py`
- [Security](https://github.com/luisfer2405/wisp/blob/main/backend/app/core/security.py): auth helpers · JWT and authentication/security primitives. · `backend/app/core/security.py`
- [Dependencies](https://github.com/luisfer2405/wisp/blob/main/backend/app/core/dependencies.py): injection · FastAPI dependency providers for shared runtime services. · `backend/app/core/dependencies.py`
- [Auth module](https://github.com/luisfer2405/wisp/blob/main/backend/app/modules/auth/router.py): auth domain · Authentication routes, schemas, models, and service logic. · `backend/app/modules/auth/router.py`
- [WISP module](https://github.com/luisfer2405/wisp/blob/main/backend/app/modules/wisp/router.py): ops domain · Main operational domain for subscriber and network data. · `backend/app/modules/wisp/router.py`
- [Shared types](https://github.com/luisfer2405/wisp/blob/main/backend/app/shared/enums.py): common primitives · Enums and reusable error/util helpers shared across modules. · `backend/app/shared/enums.py`

### Ops & Data

Startup, database, docs, and verification scripts that support the runtime systems.

- [Start app](https://github.com/luisfer2405/wisp/blob/main/iniciar_wisp.sh): shell entrypoint · Local script that launches backend and frontend together. · `iniciar_wisp.sh`
- [DB tooling](https://github.com/luisfer2405/wisp/blob/main/backend/validate_postgres.py): ops scripts · Schema checks, seeding, repair, and PostgreSQL validation scripts. · `backend/validate_postgres.py`
- [Data docs](https://github.com/luisfer2405/wisp/blob/main/docs/database.md): architecture docs · Documentation that defines database and business-rule boundaries. · `docs/database.md`

## Connections

- Start app → API app: starts · Launches the FastAPI backend.
- Start app → Frontend boot: starts · Launches the Vite frontend.
- Frontend boot → App routes: mounts · Bootstraps the top-level app.
- App routes → Dashboard shell: uses · Wraps authenticated screens in the shared layout.
- App routes → Login: routes to · Exposes the auth entry screen.
- App routes → Clients: routes to · Exposes subscriber workflows.
- App routes → Billing: routes to · Exposes billing workflows.
- App routes → Network: routes to · Exposes network operations screens.
- Auth state → Protected route: protects · Provides session state for guarded routes.
- Login → Auth service: calls · Submits credentials through the auth client.
- Auth service → API client: uses · Shares the common HTTP client.
- API client → API app: requests · Frontend API traffic targets the backend.
- API app → Config: loads · Initializes the app from configuration.
- API app → Dependencies: injects · Uses dependency providers across routes.
- API app → Auth module: includes · Registers authentication endpoints.
- API app → WISP module: includes · Registers core operational endpoints.
- Dependencies → Database: binds · Provides database sessions to request handlers.
- Dependencies → Security: binds · Provides auth/security dependencies.
- Auth module → Security: uses · Validates identity and issues tokens.
- Auth module → Shared types: uses · Shares enums and error conventions.
- WISP module → Database: persists via · Relies on relational persistence.
- WISP module → Shared types: uses · Shares domain values and common helpers.
- Database → DB tooling: checked by · Database state is verified and repaired by scripts.
- DB tooling → Data docs: guided by · Scripts align with documented schema and rules.
- Config → Data docs: constrained by · Runtime config follows documented data boundaries.
