How baa4ts/pet works
1. Overall shape
- This is a two-app monorepo: apps/backend exposes the API and auth/data services, and apps/frontend is a Vite/React client that consumes them.
- The repository is centered around a school/education dashboard (“Polo educativo tecnologico”) with three main content domains: Ausencias, Eventos, and Noticias.
2. Backend responsibility boundary
- The backend is the system of record for application data and access control.
- It handles authentication, role-based behavior, and CRUD-style domain endpoints for the three content areas.
- The backend also exposes an OpenAPI contract in apps/backend/docs/openapi.yaml, which suggests the API is intended to be documented and consumed explicitly by the client.
3. Backend runtime and framework
- The server entry point is apps/backend/src/index.ts.
- The backend is structured as an Express app with route registration centralized in src/routes/Routes.ts.
- Type augmentation in src/types/express.d.ts indicates custom request/session typing is used across middleware and routes.
4. Backend domain modules
- Each domain is isolated under its own folder:
- src/routes/Ausencias
- src/routes/Eventos
- src/routes/Noticias
- Each module has a .route.ts and .scheme.ts, which strongly suggests a separation between transport handlers and validation/schema definitions.
- This makes the backend diagram naturally split into three independent feature pipelines feeding the same API layer.
5. Backend cross-cutting concerns
- Authentication is handled through src/configuracion/Auth.ts and enforced by src/middlewares/Auth.middleware.ts.
- Role definitions live in src/configuracion/Roles.ts, so authorization is likely role-based rather than purely session-based.
- src/middlewares/Archivos.middleware.ts implies file upload / file handling is a separate cross-cutting concern, probably attached to some routes when media or attachments are involved.
6. Backend data layer
- Persistence is managed with Prisma, configured in src/configuracion/Prisma.ts, prisma/schema.prisma, and a migration under prisma/migrations.
- The presence of scripts/seed.ts indicates the database has seeded initial data, likely for development or demo content.
- The architecture is therefore API → service/route layer → Prisma ORM → database.
7. Backend auxiliary documentation and setup
- The backend contains repo-specific documentation for Prisma and Better Auth in documentacion/, plus .env.example for required runtime configuration.
- This indicates the backend has nontrivial setup dependencies around database credentials and auth provider configuration.
- package.json, pnpm-lock.yaml, and prisma.config.ts show a TypeScript + pnpm toolchain with Prisma integrated into the build/deploy workflow.
8. Frontend responsibility boundary
- The frontend is a separate SPA in apps/frontend, built with Vite and React/TypeScript.
- It is responsible for rendering public screens, login/register flows, authenticated user pages, and a “TV” display mode for content presentation.
- The frontend does not appear to own business data; it consumes the backend through action modules.
9. Frontend data flow
- API access is wrapped in src/actions/* for Ausencias, Eventos, and Noticias, which keeps network calls out of the UI components.
- src/providers/Client.provider.ts and src/providers/TanStack.tsx suggest a shared client configuration plus TanStack Query/state management for server data.
- Response types in src/types/*Response.d.ts indicate the frontend is typed against backend payload shapes, making the API contract a key integration boundary.
10. Frontend routing and access control
- Routing is organized in src/pages/App.router.tsx, with page-level folders for authentication, home, TV, and user profile.
- Guard logic lives in src/loaders/requireGuest.ts, requireSession.ts, and routeGuard.ts, so access control is enforced on the client side as well.
- This creates a clear split between public routes, guest-only auth pages, and protected app pages.
11. Frontend presentation areas
- The src/components/TV section contains dedicated presentation components for Ausencias, Eventos, and Noticias, which implies a public display/dashboard mode optimized for passive viewing.
- Standard UI primitives live under src/components/ui, so the app likely uses a design-system style component layer for forms and controls.
- Helpers like formatearFecha.ts and validateEmail.ts support display formatting and form validation at the edge of the UI.
12. Likely end-to-end flow
- User enters the frontend SPA, routes are guarded based on session state, and authenticated screens fetch data through action modules.
- The client calls the backend API, the backend validates input with route schemes, checks auth/roles, and persists/reads data through Prisma.
- Content for the TV views is fetched from the same domain APIs and rendered in a presentation-focused layer.
13. What matters most for an architecture diagram
- Show two top-level apps: Frontend SPA and Backend API.
- Inside the backend, emphasize Auth, Roles, Prisma/DB, and the three domain modules (Ausencias, Eventos, Noticias).
- Inside the frontend, emphasize Routing/Guards, Actions/API client, TanStack/provider layer, and the TV/public presentation components.
Main entry points: Routes.ts Route hub · Ausencias.action.ts API actions · App.router.tsx Router · Home.tsx Pages
Components 24
Backend API
Express API, auth, domain routes, and persistence
- API entry · Starts the backend server and wires the app
apps/backend/src/index.ts - Route hub · Central route registration for all API modules
apps/backend/src/routes/Routes.ts - Auth config · Authentication and session configuration
apps/backend/src/configuracion/Auth.ts - Roles · Role definitions used by access control
apps/backend/src/configuracion/Roles.ts - Auth guard · Enforces authentication on protected routes
apps/backend/src/middlewares/Auth.middleware.ts - Files guard · Handles file upload and file-related middleware
apps/backend/src/middlewares/Archivos.middleware.ts - Ausencias · Absence endpoints and validation
apps/backend/src/routes/Ausencias/Ausencias.route.ts - Ausencias schema · Request/response shapes for absence routes
apps/backend/src/routes/Ausencias/Ausencias.scheme.ts - Eventos · Event endpoints and validation
apps/backend/src/routes/Eventos/Eventos.route.ts - Eventos schema · Request/response shapes for event routes
apps/backend/src/routes/Eventos/Eventos.scheme.ts - Noticias · News endpoints and validation
apps/backend/src/routes/Noticias/Noticias.route.ts - Noticias schema · Request/response shapes for news routes
apps/backend/src/routes/Noticias/Noticias.scheme.ts - Prisma ORM · Shared Prisma client configuration for persistence
apps/backend/src/configuracion/Prisma.ts - DB schema · Database model definitions
apps/backend/prisma/schema.prisma - Seed data · Initial database seed script
apps/backend/scripts/seed.ts - OpenAPI spec · Documented backend interface for clients
apps/backend/docs/openapi.yaml
Frontend SPA
React client, routing, and presentation layers
- App shell · Frontend application entry and composition
apps/frontend/src/App.tsx - Router · Defines application pages and route structure
apps/frontend/src/pages/App.router.tsx - Route guards · Guest/session protection for client routes
apps/frontend/src/loaders/routeGuard.ts - API actions · Domain-specific backend request wrappers
apps/frontend/src/actions/Ausencias.action.ts - Providers · Shared client and TanStack Query setup
apps/frontend/src/providers/TanStack.tsx - TV views · Display-focused sections for content broadcasting
apps/frontend/src/components/TV/SeccionNoticias.tsx - Pages · Auth, home, TV, and profile pages
apps/frontend/src/pages/home/Home.tsx - API types · Typed response shapes aligned to backend payloads
apps/frontend/src/types/NoticiasResponse.d.ts
Connections 24
- API entry → Route hub: registers · Server bootstraps the route tree
- Route hub → Auth config: uses · Routes depend on auth configuration
- Route hub → Auth guard: protects · Protected endpoints pass through auth middleware
- Route hub → Files guard: handles files · File-related routes use upload middleware
- Route hub → Ausencias: mounts · Registers the absences domain module
- Route hub → Eventos: mounts · Registers the events domain module
- Route hub → Noticias: mounts · Registers the news domain module
- Ausencias → Ausencias schema: validates · Absence routes use their schema definitions
- Eventos → Eventos schema: validates · Event routes use their schema definitions
- Noticias → Noticias schema: validates · News routes use their schema definitions
- Auth guard → Roles: checks · Authorization behavior is role-based
- Route hub → Prisma ORM: reads/writes · Domain handlers persist through Prisma
- Prisma ORM → DB schema: models · Prisma client is generated from schema
- Seed data → Prisma ORM: seeds · Seed script populates the database through Prisma
- OpenAPI spec → API actions: contracts · Frontend action layer consumes the documented API surface
- App shell → Router: composes · App shell renders the router
- Router → Route guards: protects · Routes are gated by session and guest logic
- Router → Pages: renders · Route tree maps to page-level screens
- Pages → API actions: fetches · Pages load backend data through action modules
- API actions → API types: typed by · Actions are aligned with response types
- App shell → Providers: wraps · App is composed with shared providers
- Pages → TV views: shows · TV mode uses dedicated presentation components
- TV views → API actions: consumes · TV views reuse the same domain data layer
- Providers → API actions: supports · Shared client configuration underpins requests