# baa4ts/pet architecture

> Architecture diagram of the GitHub repository baa4ts/pet, 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/baa4ts/pet
- Repository: https://github.com/baa4ts/pet

## Overview

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: [`apps/backend/src/routes/Routes.ts`](https://github.com/baa4ts/pet/blob/main/apps/backend/src/routes/Routes.ts) (Route hub), [`apps/frontend/src/actions/Ausencias.action.ts`](https://github.com/baa4ts/pet/blob/main/apps/frontend/src/actions/Ausencias.action.ts) (API actions), [`apps/frontend/src/pages/App.router.tsx`](https://github.com/baa4ts/pet/blob/main/apps/frontend/src/pages/App.router.tsx) (Router), [`apps/frontend/src/pages/home/Home.tsx`](https://github.com/baa4ts/pet/blob/main/apps/frontend/src/pages/home/Home.tsx) (Pages)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_backend["Backend API"]
  node_backend_entry["API entry<br/>Express bootstrap<br/>[index.ts]"]
  node_backend_routes["Route hub<br/>Route registry<br/>[Routes.ts]"]
  node_backend_auth["Auth config<br/>Auth setup<br/>[Auth.ts]"]
  node_backend_roles["Roles<br/>Authorization model<br/>[Roles.ts]"]
  node_backend_authmw["Auth guard<br/>Middleware<br/>[Auth.middleware.ts]"]
  node_backend_filesmw["Files guard<br/>Middleware"]
  node_backend_ausencias["Ausencias<br/>Domain module<br/>[Ausencias.route.ts]"]
  node_backend_ausencias_schema["Ausencias schema<br/>Validation schema"]
  node_backend_eventos["Eventos<br/>Domain module<br/>[Eventos.route.ts]"]
  node_backend_eventos_schema["Eventos schema<br/>Validation schema<br/>[Eventos.scheme.ts]"]
  node_backend_noticias["Noticias<br/>Domain module<br/>[Noticias.route.ts]"]
  node_backend_noticias_schema["Noticias schema<br/>Validation schema<br/>[Noticias.scheme.ts]"]
  node_backend_prisma[("Prisma ORM<br/>Data access<br/>[Prisma.ts]")]
  node_backend_schema["DB schema<br/>Prisma schema<br/>[schema.prisma]"]
  node_backend_seed["Seed data<br/>Bootstrap data<br/>[seed.ts]"]
  node_backend_openapi["OpenAPI spec<br/>API contract<br/>[openapi.yaml]"]
end

subgraph group_frontend["Frontend SPA"]
  node_frontend_app["App shell<br/>React bootstrap<br/>[App.tsx]"]
  node_frontend_router["Router<br/>Route map<br/>[App.router.tsx]"]
  node_frontend_guards["Route guards<br/>Access control<br/>[routeGuard.ts]"]
  node_frontend_actions["API actions<br/>Client data layer"]
  node_frontend_provider["Providers<br/>[TanStack.tsx]"]
  node_frontend_tv["TV views<br/>Presentation layer"]
  node_frontend_pages["Pages<br/>UI screens<br/>[Home.tsx]"]
  node_frontend_types["API types<br/>Contract types"]
end

node_backend_entry -->|"registers"| node_backend_routes
node_backend_routes -->|"uses"| node_backend_auth
node_backend_routes -->|"protects"| node_backend_authmw
node_backend_routes -->|"handles files"| node_backend_filesmw
node_backend_routes -->|"mounts"| node_backend_ausencias
node_backend_routes -->|"mounts"| node_backend_eventos
node_backend_routes -->|"mounts"| node_backend_noticias
node_backend_ausencias -->|"validates"| node_backend_ausencias_schema
node_backend_eventos -->|"validates"| node_backend_eventos_schema
node_backend_noticias -->|"validates"| node_backend_noticias_schema
node_backend_authmw -->|"checks"| node_backend_roles
node_backend_routes -->|"reads/writes"| node_backend_prisma
node_backend_prisma -->|"models"| node_backend_schema
node_backend_seed -->|"seeds"| node_backend_prisma
node_backend_openapi -->|"contracts"| node_frontend_actions
node_frontend_app -->|"composes"| node_frontend_router
node_frontend_router -->|"protects"| node_frontend_guards
node_frontend_router -->|"renders"| node_frontend_pages
node_frontend_pages -->|"fetches"| node_frontend_actions
node_frontend_actions -->|"typed by"| node_frontend_types
node_frontend_app -->|"wraps"| node_frontend_provider
node_frontend_pages -->|"shows"| node_frontend_tv
node_frontend_tv -->|"consumes"| node_frontend_actions
node_frontend_provider -->|"supports"| node_frontend_actions

click node_backend_entry "https://github.com/baa4ts/pet/blob/main/apps/backend/src/index.ts"
click node_backend_routes "https://github.com/baa4ts/pet/blob/main/apps/backend/src/routes/Routes.ts"
click node_backend_auth "https://github.com/baa4ts/pet/blob/main/apps/backend/src/configuracion/Auth.ts"
click node_backend_roles "https://github.com/baa4ts/pet/blob/main/apps/backend/src/configuracion/Roles.ts"
click node_backend_authmw "https://github.com/baa4ts/pet/blob/main/apps/backend/src/middlewares/Auth.middleware.ts"
click node_backend_filesmw "https://github.com/baa4ts/pet/blob/main/apps/backend/src/middlewares/Archivos.middleware.ts"
click node_backend_ausencias "https://github.com/baa4ts/pet/blob/main/apps/backend/src/routes/Ausencias/Ausencias.route.ts"
click node_backend_ausencias_schema "https://github.com/baa4ts/pet/blob/main/apps/backend/src/routes/Ausencias/Ausencias.scheme.ts"
click node_backend_eventos "https://github.com/baa4ts/pet/blob/main/apps/backend/src/routes/Eventos/Eventos.route.ts"
click node_backend_eventos_schema "https://github.com/baa4ts/pet/blob/main/apps/backend/src/routes/Eventos/Eventos.scheme.ts"
click node_backend_noticias "https://github.com/baa4ts/pet/blob/main/apps/backend/src/routes/Noticias/Noticias.route.ts"
click node_backend_noticias_schema "https://github.com/baa4ts/pet/blob/main/apps/backend/src/routes/Noticias/Noticias.scheme.ts"
click node_backend_prisma "https://github.com/baa4ts/pet/blob/main/apps/backend/src/configuracion/Prisma.ts"
click node_backend_schema "https://github.com/baa4ts/pet/blob/main/apps/backend/prisma/schema.prisma"
click node_backend_seed "https://github.com/baa4ts/pet/blob/main/apps/backend/scripts/seed.ts"
click node_backend_openapi "https://github.com/baa4ts/pet/blob/main/apps/backend/docs/openapi.yaml"
click node_frontend_app "https://github.com/baa4ts/pet/blob/main/apps/frontend/src/App.tsx"
click node_frontend_router "https://github.com/baa4ts/pet/blob/main/apps/frontend/src/pages/App.router.tsx"
click node_frontend_guards "https://github.com/baa4ts/pet/blob/main/apps/frontend/src/loaders/routeGuard.ts"
click node_frontend_actions "https://github.com/baa4ts/pet/blob/main/apps/frontend/src/actions/Ausencias.action.ts"
click node_frontend_provider "https://github.com/baa4ts/pet/blob/main/apps/frontend/src/providers/TanStack.tsx"
click node_frontend_tv "https://github.com/baa4ts/pet/blob/main/apps/frontend/src/components/TV/SeccionNoticias.tsx"
click node_frontend_pages "https://github.com/baa4ts/pet/blob/main/apps/frontend/src/pages/home/Home.tsx"
click node_frontend_types "https://github.com/baa4ts/pet/blob/main/apps/frontend/src/types/NoticiasResponse.d.ts"

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_backend_entry,node_backend_routes,node_backend_auth,node_backend_roles,node_backend_authmw,node_backend_filesmw,node_backend_ausencias,node_backend_ausencias_schema,node_backend_eventos,node_backend_eventos_schema,node_backend_noticias,node_backend_noticias_schema,node_backend_prisma,node_backend_schema,node_backend_seed,node_backend_openapi toneBlue
class node_frontend_app,node_frontend_router,node_frontend_guards,node_frontend_actions,node_frontend_provider,node_frontend_tv,node_frontend_pages,node_frontend_types toneAmber
```

## Components

### Backend API

Express API, auth, domain routes, and persistence

- [API entry](https://github.com/baa4ts/pet/blob/main/apps/backend/src/index.ts): Express bootstrap · Starts the backend server and wires the app · `apps/backend/src/index.ts`
- [Route hub](https://github.com/baa4ts/pet/blob/main/apps/backend/src/routes/Routes.ts): Route registry · Central route registration for all API modules · `apps/backend/src/routes/Routes.ts`
- [Auth config](https://github.com/baa4ts/pet/blob/main/apps/backend/src/configuracion/Auth.ts): Auth setup · Authentication and session configuration · `apps/backend/src/configuracion/Auth.ts`
- [Roles](https://github.com/baa4ts/pet/blob/main/apps/backend/src/configuracion/Roles.ts): Authorization model · Role definitions used by access control · `apps/backend/src/configuracion/Roles.ts`
- [Auth guard](https://github.com/baa4ts/pet/blob/main/apps/backend/src/middlewares/Auth.middleware.ts): Middleware · Enforces authentication on protected routes · `apps/backend/src/middlewares/Auth.middleware.ts`
- [Files guard](https://github.com/baa4ts/pet/blob/main/apps/backend/src/middlewares/Archivos.middleware.ts): Middleware · Handles file upload and file-related middleware · `apps/backend/src/middlewares/Archivos.middleware.ts`
- [Ausencias](https://github.com/baa4ts/pet/blob/main/apps/backend/src/routes/Ausencias/Ausencias.route.ts): Domain module · Absence endpoints and validation · `apps/backend/src/routes/Ausencias/Ausencias.route.ts`
- [Ausencias schema](https://github.com/baa4ts/pet/blob/main/apps/backend/src/routes/Ausencias/Ausencias.scheme.ts): Validation schema · Request/response shapes for absence routes · `apps/backend/src/routes/Ausencias/Ausencias.scheme.ts`
- [Eventos](https://github.com/baa4ts/pet/blob/main/apps/backend/src/routes/Eventos/Eventos.route.ts): Domain module · Event endpoints and validation · `apps/backend/src/routes/Eventos/Eventos.route.ts`
- [Eventos schema](https://github.com/baa4ts/pet/blob/main/apps/backend/src/routes/Eventos/Eventos.scheme.ts): Validation schema · Request/response shapes for event routes · `apps/backend/src/routes/Eventos/Eventos.scheme.ts`
- [Noticias](https://github.com/baa4ts/pet/blob/main/apps/backend/src/routes/Noticias/Noticias.route.ts): Domain module · News endpoints and validation · `apps/backend/src/routes/Noticias/Noticias.route.ts`
- [Noticias schema](https://github.com/baa4ts/pet/blob/main/apps/backend/src/routes/Noticias/Noticias.scheme.ts): Validation schema · Request/response shapes for news routes · `apps/backend/src/routes/Noticias/Noticias.scheme.ts`
- [Prisma ORM](https://github.com/baa4ts/pet/blob/main/apps/backend/src/configuracion/Prisma.ts): Data access · Shared Prisma client configuration for persistence · `apps/backend/src/configuracion/Prisma.ts`
- [DB schema](https://github.com/baa4ts/pet/blob/main/apps/backend/prisma/schema.prisma): Prisma schema · Database model definitions · `apps/backend/prisma/schema.prisma`
- [Seed data](https://github.com/baa4ts/pet/blob/main/apps/backend/scripts/seed.ts): Bootstrap data · Initial database seed script · `apps/backend/scripts/seed.ts`
- [OpenAPI spec](https://github.com/baa4ts/pet/blob/main/apps/backend/docs/openapi.yaml): API contract · Documented backend interface for clients · `apps/backend/docs/openapi.yaml`

### Frontend SPA

React client, routing, and presentation layers

- [App shell](https://github.com/baa4ts/pet/blob/main/apps/frontend/src/App.tsx): React bootstrap · Frontend application entry and composition · `apps/frontend/src/App.tsx`
- [Router](https://github.com/baa4ts/pet/blob/main/apps/frontend/src/pages/App.router.tsx): Route map · Defines application pages and route structure · `apps/frontend/src/pages/App.router.tsx`
- [Route guards](https://github.com/baa4ts/pet/blob/main/apps/frontend/src/loaders/routeGuard.ts): Access control · Guest/session protection for client routes · `apps/frontend/src/loaders/routeGuard.ts`
- [API actions](https://github.com/baa4ts/pet/blob/main/apps/frontend/src/actions/Ausencias.action.ts): Client data layer · Domain-specific backend request wrappers · `apps/frontend/src/actions/Ausencias.action.ts`
- [Providers](https://github.com/baa4ts/pet/blob/main/apps/frontend/src/providers/TanStack.tsx): App providers · Shared client and TanStack Query setup · `apps/frontend/src/providers/TanStack.tsx`
- [TV views](https://github.com/baa4ts/pet/blob/main/apps/frontend/src/components/TV/SeccionNoticias.tsx): Presentation layer · Display-focused sections for content broadcasting · `apps/frontend/src/components/TV/SeccionNoticias.tsx`
- [Pages](https://github.com/baa4ts/pet/blob/main/apps/frontend/src/pages/home/Home.tsx): UI screens · Auth, home, TV, and profile pages · `apps/frontend/src/pages/home/Home.tsx`
- [API types](https://github.com/baa4ts/pet/blob/main/apps/frontend/src/types/NoticiasResponse.d.ts): Contract types · Typed response shapes aligned to backend payloads · `apps/frontend/src/types/NoticiasResponse.d.ts`

## Connections

- 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
