How juanjo380/rutatransporte works
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: app Next app · controllers Controllers · auth.js Auth API · server.js API server
Components 19
Frontend
Next.js app for user-facing navigation, sessions, and role-specific screens.
- Next app · Main frontend application shell and routing host.
frontend/src/app - Routes · Client-side route definitions and navigation structure.
frontend/src/app/routes.tsx - Auth context · Stores auth session and persists token state locally.
frontend/src/app/context/auth-context.tsx - Theme context · Manages visual theme and appearance preferences.
frontend/src/app/context/theme-context.tsx - Route guards · Protects pages and redirects users by role.
frontend/src/app/components/protected-route.tsx - Role screens · Primary login, student, admin, and driver views.
frontend/src/app/pages - UI kit · Reusable design-system primitives and feedback components.
frontend/src/app/components/ui - Feature UI · 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 · Runtime entrypoint wiring middleware, routes, and health checks.
backend/server.js - Auth API · Registration, login, and current-user endpoints.
backend/src/routes/auth.js - Domain API · Schedule, reservation, and admin route modules.
backend/src/routes - Controllers · Request orchestration for auth, admin, schedules, and reservations.
backend/src/controllers - Middleware · Authentication, role checks, and validation layers.
backend/src/middleware - Prisma client · Shared Prisma client used by controllers and services.
backend/src/lib/prisma.js - Domain models · Usuario, Ruta, Horario, and Reserva entities.
backend/src/models
Infra
Supabase and Prisma persistence setup.
- Prisma schema · Database model and migration definition.
backend/prisma/schema.prisma - Supabase config · Deployment configuration for the managed PostgreSQL environment.
supabase/config.toml - PostgreSQL · Authoritative persistence layer for users, routes, schedules, and reservations.
Other components
- Browser · End-user entry point for the web app.
Connections 21
- 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.