# juanjo380/rutatransporte architecture

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

- Interactive diagram: https://gitdiagram.com/juanjo380/rutatransporte
- Repository: https://github.com/juanjo380/rutatransporte

## Overview

1. RutaTransporte is split into two deployable applications plus Supabase/PostgreSQL infrastructure: a Next.js frontend and an Express/Prisma backend. The frontend owns user experience and navigation; the backend owns authentication and database access. There is also a Supabase config directory that supports the PostgreSQL deployment.

2. The main system boundary is clear: the browser talks to the frontend, and the frontend talks to the backend through `NEXT_PUBLIC_API_URL`. The backend then connects to PostgreSQL via Prisma using the Supabase database URLs. This means UI state and API state are separated, with the backend acting as the authoritative source only for auth and persistence-ready data.

3. The frontend is a Next.js 16 app using React 19 and TypeScript, but it also uses `react-router-dom` for in-app route handling. The primary screens are `login`, `student-home`, `admin-dashboard`, and `driver-view`, which map directly to the three business roles plus authentication entry.

4. Frontend cross-cutting concerns are handled with React context: `auth-context` manages session state and localStorage persistence, while `theme-context` manages appearance. Route protection is implemented with dedicated components such as `protected-route` and `role-based-redirect`, so access control is enforced on the client before rendering role-specific pages.

5. Most business-facing UI on the frontend is currently composed from reusable feature components like `bus-schedule-card`, `reservation-dialog`, `my-reservations`, and `driver-profile`. The app also includes a large set of Radix/shadcn-style primitives under `src/app/components/ui`, indicating a componentized design system rather than page-specific markup.

6. The frontend styling stack is centralized: global styles live in `globals.css` and `src/app/styles/*`, with Tailwind and theme CSS used to keep layout, tokens, and dark/light behavior consistent. Notifications are handled with `sonner`, which suggests user actions such as login or reservation updates surface immediate toast feedback.

7. The backend is an Express 5 API with a layered structure: route modules in `src/routes`, request handling in `src/controllers`, request gating in `src/middleware`, persistence helpers in `src/lib`, and domain model files in `src/models`. `server.js` is the runtime entrypoint that wires the middleware and routes together.

8. Prisma is the persistence layer. `prisma/schema.prisma` and `prisma/migrations` define the database model and schema evolution, while `src/lib/prisma.js` centralizes database client access. The documented domain entities are `Usuario`, `Ruta`, `Horario`, and `Reserva`, with role and reservation-state enums shaping business rules.

9. Authentication is the only fully connected business flow today. The backend exposes `POST /api/auth/register`, `POST /api/auth/login`, and `GET /api/auth/me`, signs JWTs with `JWT_SECRET`, and hashes passwords with `bcryptjs`. The frontend consumes this flow to establish the session, then uses the stored token/session state to control protected navigation.

10. Operationally, the backend also exposes `GET /health` and `GET /db-check` for runtime and database verification. The README notes that reservations, schedules, and admin workflows are scaffolded in the codebase but still rely on simulated in-memory data or are not publicly implemented yet, so the architecture is partially split between a real auth/persistence foundation and a prototype-level business UI layer.

Main entry points: [`frontend/src/app`](https://github.com/juanjo380/rutatransporte/tree/main/frontend/src/app) (Next app), [`backend/src/controllers`](https://github.com/juanjo380/rutatransporte/tree/main/backend/src/controllers) (Controllers), [`backend/src/routes/auth.js`](https://github.com/juanjo380/rutatransporte/blob/main/backend/src/routes/auth.js) (Auth API), [`backend/server.js`](https://github.com/juanjo380/rutatransporte/blob/main/backend/server.js) (API server)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_next_app["Next app<br/>nextjs app"]
  node_app_routes["Routes<br/>router<br/>[routes.tsx]"]
  node_auth_context["Auth context<br/>session state<br/>[auth-context.tsx]"]
  node_theme_context["Theme context<br/>ui state<br/>[theme-context.tsx]"]
  node_route_guards["Route guards<br/>access control"]
  node_screens["Role screens<br/>pages"]
  node_ui_kit["UI kit<br/>component library"]
  node_feature_ui["Feature UI<br/>composed components"]
end

subgraph group_backend["Backend"]
  node_express_server["API server<br/>express service<br/>[server.js]"]
  node_auth_routes["Auth API<br/>auth routes<br/>[auth.js]"]
  node_domain_routes["Domain API<br/>feature routes"]
  node_controllers["Controllers<br/>request handlers"]
  node_middleware["Middleware<br/>request gate"]
  node_prisma_client["Prisma client<br/>db access<br/>[prisma.js]"]
  node_models["Domain models<br/>domain schema"]
end

subgraph group_infra["Infra"]
  node_prisma_schema["Prisma schema<br/>database schema<br/>[schema.prisma]"]
  node_supabase_config["Supabase config<br/>postgres config<br/>[config.toml]"]
  node_postgres[("PostgreSQL<br/>database")]
end

node_browser(("Browser<br/>client"))

node_browser -->|"opens"| node_next_app
node_next_app -->|"navigates"| node_app_routes
node_next_app -->|"reads session"| node_auth_context
node_next_app -->|"reads theme"| node_theme_context
node_next_app -->|"protects pages"| node_route_guards
node_route_guards -->|"allows access"| node_screens
node_screens -->|"compose"| node_feature_ui
node_feature_ui -->|"uses primitives"| node_ui_kit
node_next_app -->|"API calls"| node_express_server
node_express_server -->|"mounts"| node_auth_routes
node_express_server -->|"mounts"| node_domain_routes
node_domain_routes -->|"delegates"| node_controllers
node_auth_routes -->|"delegates"| node_controllers
node_controllers -->|"passes through"| node_middleware
node_controllers -->|"queries"| node_prisma_client
node_prisma_client -->|"maps to"| node_prisma_schema
node_prisma_schema -->|"persists to"| node_postgres
node_supabase_config -->|"configures"| node_postgres
node_controllers -->|"shapes domain"| node_models
node_auth_routes -->|"auth data"| node_postgres
node_next_app -->|"uses auth API"| node_auth_routes

click node_next_app "https://github.com/juanjo380/rutatransporte/tree/main/frontend/src/app"
click node_app_routes "https://github.com/juanjo380/rutatransporte/blob/main/frontend/src/app/routes.tsx"
click node_auth_context "https://github.com/juanjo380/rutatransporte/blob/main/frontend/src/app/context/auth-context.tsx"
click node_theme_context "https://github.com/juanjo380/rutatransporte/blob/main/frontend/src/app/context/theme-context.tsx"
click node_route_guards "https://github.com/juanjo380/rutatransporte/blob/main/frontend/src/app/components/protected-route.tsx"
click node_screens "https://github.com/juanjo380/rutatransporte/tree/main/frontend/src/app/pages"
click node_ui_kit "https://github.com/juanjo380/rutatransporte/tree/main/frontend/src/app/components/ui"
click node_feature_ui "https://github.com/juanjo380/rutatransporte/tree/main/frontend/src/app/components"
click node_express_server "https://github.com/juanjo380/rutatransporte/blob/main/backend/server.js"
click node_auth_routes "https://github.com/juanjo380/rutatransporte/blob/main/backend/src/routes/auth.js"
click node_domain_routes "https://github.com/juanjo380/rutatransporte/tree/main/backend/src/routes"
click node_controllers "https://github.com/juanjo380/rutatransporte/tree/main/backend/src/controllers"
click node_middleware "https://github.com/juanjo380/rutatransporte/tree/main/backend/src/middleware"
click node_prisma_client "https://github.com/juanjo380/rutatransporte/blob/main/backend/src/lib/prisma.js"
click node_models "https://github.com/juanjo380/rutatransporte/tree/main/backend/src/models"
click node_prisma_schema "https://github.com/juanjo380/rutatransporte/blob/main/backend/prisma/schema.prisma"
click node_supabase_config "https://github.com/juanjo380/rutatransporte/blob/main/supabase/config.toml"

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_next_app,node_app_routes,node_auth_context,node_theme_context,node_route_guards,node_screens,node_ui_kit,node_feature_ui toneBlue
class node_express_server,node_auth_routes,node_domain_routes,node_controllers,node_middleware,node_prisma_client,node_models toneAmber
class node_prisma_schema,node_supabase_config,node_postgres toneMint
class node_browser toneNeutral
```

## Components

### Frontend

Next.js app for user-facing navigation, sessions, and role-specific screens.

- [Next app](https://github.com/juanjo380/rutatransporte/tree/main/frontend/src/app): nextjs app · Main frontend application shell and routing host. · `frontend/src/app`
- [Routes](https://github.com/juanjo380/rutatransporte/blob/main/frontend/src/app/routes.tsx): router · Client-side route definitions and navigation structure. · `frontend/src/app/routes.tsx`
- [Auth context](https://github.com/juanjo380/rutatransporte/blob/main/frontend/src/app/context/auth-context.tsx): session state · Stores auth session and persists token state locally. · `frontend/src/app/context/auth-context.tsx`
- [Theme context](https://github.com/juanjo380/rutatransporte/blob/main/frontend/src/app/context/theme-context.tsx): ui state · Manages visual theme and appearance preferences. · `frontend/src/app/context/theme-context.tsx`
- [Route guards](https://github.com/juanjo380/rutatransporte/blob/main/frontend/src/app/components/protected-route.tsx): access control · Protects pages and redirects users by role. · `frontend/src/app/components/protected-route.tsx`
- [Role screens](https://github.com/juanjo380/rutatransporte/tree/main/frontend/src/app/pages): pages · Primary login, student, admin, and driver views. · `frontend/src/app/pages`
- [UI kit](https://github.com/juanjo380/rutatransporte/tree/main/frontend/src/app/components/ui): component library · Reusable design-system primitives and feedback components. · `frontend/src/app/components/ui`
- [Feature UI](https://github.com/juanjo380/rutatransporte/tree/main/frontend/src/app/components): composed components · Business-facing widgets for schedules, reservations, and driver views. · `frontend/src/app/components`

### Backend

Express API for authentication, business routes, and database access.

- [API server](https://github.com/juanjo380/rutatransporte/blob/main/backend/server.js): express service · Runtime entrypoint wiring middleware, routes, and health checks. · `backend/server.js`
- [Auth API](https://github.com/juanjo380/rutatransporte/blob/main/backend/src/routes/auth.js): auth routes · Registration, login, and current-user endpoints. · `backend/src/routes/auth.js`
- [Domain API](https://github.com/juanjo380/rutatransporte/tree/main/backend/src/routes): feature routes · Schedule, reservation, and admin route modules. · `backend/src/routes`
- [Controllers](https://github.com/juanjo380/rutatransporte/tree/main/backend/src/controllers): request handlers · Request orchestration for auth, admin, schedules, and reservations. · `backend/src/controllers`
- [Middleware](https://github.com/juanjo380/rutatransporte/tree/main/backend/src/middleware): request gate · Authentication, role checks, and validation layers. · `backend/src/middleware`
- [Prisma client](https://github.com/juanjo380/rutatransporte/blob/main/backend/src/lib/prisma.js): db access · Shared Prisma client used by controllers and services. · `backend/src/lib/prisma.js`
- [Domain models](https://github.com/juanjo380/rutatransporte/tree/main/backend/src/models): domain schema · Usuario, Ruta, Horario, and Reserva entities. · `backend/src/models`

### Infra

Supabase and Prisma persistence setup.

- [Prisma schema](https://github.com/juanjo380/rutatransporte/blob/main/backend/prisma/schema.prisma): database schema · Database model and migration definition. · `backend/prisma/schema.prisma`
- [Supabase config](https://github.com/juanjo380/rutatransporte/blob/main/supabase/config.toml): postgres config · Deployment configuration for the managed PostgreSQL environment. · `supabase/config.toml`
- **PostgreSQL**: database · Authoritative persistence layer for users, routes, schedules, and reservations.

### Other components

- **Browser**: client · End-user entry point for the web app.

## Connections

- Browser → Next app: opens · Users interact with the frontend application.
- Next app → Routes: navigates · Frontend routes structure the in-app experience.
- Next app → Auth context: reads session · UI consumes authentication state.
- Next app → Theme context: reads theme · UI consumes appearance settings.
- Next app → Route guards: protects pages · Access control is enforced before role screens render.
- Route guards → Role screens: allows access · Only permitted users reach the role-specific pages.
- Role screens → Feature UI: compose · Pages are assembled from reusable feature components.
- Feature UI → UI kit: uses primitives · Feature components build on the shared component library.
- Next app → API server: API calls · Frontend talks to backend via the configured API URL.
- API server → Auth API: mounts · Authentication endpoints are registered on the API server.
- API server → Domain API: mounts · Business routes are registered on the API server.
- Domain API → Controllers: delegates · Route handlers delegate work to controllers.
- Auth API → Controllers: delegates · Auth route handlers delegate work to controllers.
- Controllers → Middleware: passes through · Requests are gated by auth, role, and validation middleware.
- Controllers → Prisma client: queries · Controllers use the shared Prisma client for persistence.
- Prisma client → Prisma schema: maps to · Client operates against the Prisma-defined schema.
- Prisma schema → PostgreSQL: persists to · Migrations and schema target PostgreSQL.
- Supabase config → PostgreSQL: configures · Supabase settings support the database deployment.
- Controllers → Domain models: shapes domain · Domain objects define business entities and rules.
- Auth API → PostgreSQL: auth data · Authentication data is stored in the database.
- Next app → Auth API: uses auth API · The frontend consumes register, login, and me endpoints.
