# manuekle/sira architecture

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

- Interactive diagram: https://gitdiagram.com/manuekle/sira
- Repository: https://github.com/manuekle/sira

## Overview

1. **Overall shape**
   - SIRA is a **single Next.js application** organized as a full-stack monolith.
   - The same repo contains the **UI**, **API routes**, **domain utilities**, **database schema**, **email templates**, **tests**, and **deployment config**.
   - Architecturally, the main boundaries are: **browser UI**, **server route handlers**, **persistence/services**, and **external infrastructure**.

2. **Primary user-facing subsystems**
   - The app is split by role into three major dashboard areas under `app/dashboard/(roles)`: **admin**, **docente**, and **estudiante**.
   - Each role has its own layouts, loading/error states, and route segments, which makes role-based navigation a first-class architectural boundary.
   - There are also standalone auth and utility flows like **login**, **forgot/reset password**, and **justificar-ausencia**.

3. **Backend API layer**
   - The backend is implemented with **Next.js API Routes** under `app/api`.
   - The route tree mirrors the business domains:
     - `admin/*` for catalog, users, schedules, rooms, reports, planning
     - `docente/*` for classes, attendance, schedules, reports, requests
     - `estudiante/*` for dashboard, schedule, history, current class
     - shared routes for **auth**, **health**, **rooms**, **subjects**, **users**, **students**, **attendance scanning**, and **absence justification**
   - This indicates the API is not generic CRUD only; it is segmented by **actor role** and **workflow**.

4. **Core domain modules**
   - The main business domains are:
     - **User and role management**
     - **Subjects / assignments**
     - **Groups, classes, schedules, and enrollment**
     - **Attendance tracking**
     - **Reports and dashboards**
     - **Rooms and resource assignment**
     - **Events / calendar**
     - **Absence justification and academic communications**
   - The presence of specialized routes like `planeador`, `bitacora`, `generar-qr`, `current-class`, and `live` shows the system is centered around **academic operations**, not just data administration.

5. **Attendance and QR workflow**
   - Attendance is a major subsystem with its own scan and class-level routes.
   - The flow is:
     - a docente generates a **QR token** for a class
     - the estudiante scans it through the student scan page
     - scan requests go to `app/api/asistencia/scan` or class attendance endpoints
     - results feed dashboards, reports, and bitácora/history views
   - This subsystem is time-sensitive and likely uses validation schemas and class state checks to prevent stale or invalid attendance submissions.

6. **Authentication, authorization, and session control**
   - Authentication is handled by **NextAuth.js**, with routes under `app/api/auth/[...nextauth]`.
   - The repo also includes password recovery flows and initial-password setup, which suggests onboarding and account recovery are part of the auth boundary.
   - Authorization is role-driven and reinforced by route separation, plus runtime guards such as `force-password-change-guard` and `leave-page-guard`.
   - `proxy.ts` likely acts as a request gate for protected routing or role redirects.

7. **Data access and persistence**
   - Persistence is implemented with **Prisma ORM** and a **MongoDB** backend.
   - The Prisma schema and seed/reset scripts in `prisma/` define the canonical data model and bootstrapping path.
   - Server-side code uses `lib/prisma.ts` and domain helpers instead of direct database access from components, which keeps persistence behind a shared server boundary.
   - This means the diagram should show the database as a shared backend dependency for all API and server-rendered features.

8. **Shared server services**
   - Several supporting services sit between route handlers and storage:
     - `lib/email.ts` for outbound mail
     - `lib/redis.ts` and `lib/cache.ts` for optional caching
     - `lib/rateLimit.ts` for request control
     - `lib/csv-parser.ts` and `lib/csv-encoding.ts` for bulk import/export flows
     - `lib/class-*`, `lib/time-utils.ts`, `lib/event-utils.ts` for domain logic
   - `services/dashboardService.ts` suggests server-side aggregation logic separated from UI components.
   - These modules are important architectural seams because they consolidate business logic outside the route handlers.

9. **Media, files, and external integrations**
   - The app integrates with **Vercel Blob Storage** for file/blob operations, including upload/delete flows.
   - Email is built with **React Email** templates plus **Nodemailer**, supporting reset-password, welcome, report-ready, and notification messages.
   - QR generation/scanning and PDF/report generation are part of the system’s operational outputs.
   - The architecture therefore includes external delivery channels: **email**, **blob storage**, and possibly downloadable **PDF artifacts**.

10. **Client-side architecture**
   - The frontend is componentized with reusable UI in `components/ui` and domain-specific components under `components/admin`, `components/docente`, `components/estudiante`, `components/classes`, `components/subjects`, etc.
   - Shared app shells live in layouts like `sidebar-layout`, `theme-provider`, and dashboard role layouts.
   - Hooks in `hooks/` encapsulate client data-fetching and state concerns, including subject/user/student dashboards and unsaved changes handling.
   - The UI stack is heavily based on **Tailwind CSS**, **Radix UI**, and **shadcn/ui**, which suggests a design-system-oriented component boundary.

11. **Data fetching and state strategy**
   - The repo uses **TanStack Query / React Query** patterns through custom hooks, though the README notes this migration is still partial.
   - Server routes are the source of truth, while client hooks and dashboard components consume those APIs.
   - This gives the app a clear flow: **browser UI → API route → service logic → Prisma/MongoDB**, with React Query acting as the client cache and synchronization layer where adopted.

12. **PWA, offline, and delivery concerns**
   - The presence of `public/sw.js`, `manifest.json`, `offline.html`, and icon assets shows the app has **PWA/offline** support.
   - That makes the client runtime more than a basic web UI: it can install, cache assets, and provide fallback behavior when connectivity is limited.
   - `vercel.json` indicates deployment is optimized for Vercel hosting and its serverless/app-router model.

13. **Testing and quality boundary**
   - The repo has a strong test split:
     - **API tests** for route behavior
     - **component tests**
     - **hook tests**
     - **integration tests**
     - **Playwright E2E flows**
     - **performance tests**
   - The testing structure mirrors the runtime boundaries, which is useful for an architecture diagram because it validates the separation between UI, business logic, and API services.

14. **Documentation and operational assets**
   - The `docs/` folder contains architecture, deployment, testing, security, and database diagrams, indicating the repo is intended to be maintained as a system, not just shipped as code.
   - CSV templates in `public/formatos/` support bulk administrative workflows for users, subjects, groups, schedules, and enrollments.
   - These assets support the admin/import layer and should be shown as part of the operational ingress into the system.

15. **Suggested diagram framing**
   - A clear diagram should center on three role-based clients feeding a common server layer.
   - From there, show shared backend services branching to **MongoDB via Prisma**, **Redis cache**, **email delivery**, **blob storage**, and **PWA/offline assets**.
   - The most important functional flow to highlight is the **attendance QR loop**, because it touches student scanning, docente class management, dashboards, reports, and justification workflows.

Main entry points: [`lib/prisma.ts`](https://github.com/manuekle/sira/blob/main/lib/prisma.ts) (Prisma data), [`app/dashboard/(roles)`](https://github.com/manuekle/sira/tree/main/app/dashboard/(roles)) (Role dashboards), [`app/api/admin`](https://github.com/manuekle/sira/tree/main/app/api/admin) (Admin API), [`app/api/docente`](https://github.com/manuekle/sira/tree/main/app/api/docente) (Teacher API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Client UI"]
  node_app_shell["App shell<br/>next-app<br/>[layout.tsx]"]
  node_role_dashboards["Role dashboards<br/>next-routes"]
  node_auth_flows["Auth flows<br/>next-routes"]
  node_student_tools["Student tools<br/>student-ui"]
  node_teacher_tools["Teacher tools<br/>teacher-ui"]
  node_admin_tools["Admin tools<br/>admin-ui"]
  node_shared_ui["Shared UI<br/>ui-kit"]
  node_client_hooks["Client hooks<br/>state-hooks"]
end

subgraph group_server["Server API"]
  node_api_gateway["API surface<br/>next-api"]
  node_admin_api["Admin API<br/>role-api"]
  node_docente_api["Teacher API<br/>role-api"]
  node_student_api["Student API<br/>role-api"]
  node_auth_api["Auth API<br/>auth-routes<br/>[route.ts]"]
  node_attendance_scan["Attendance scan<br/>workflow-api<br/>[route.ts]"]
  node_justification_api["Justify absence<br/>workflow-api<br/>[route.ts]"]
end

subgraph group_domain["Domain Services"]
  node_domain_services["Domain services<br/>business-logic"]
  node_persistence[("Prisma data<br/>orm-layer<br/>[prisma.ts]")]
  node_domain_utils["Domain utils<br/>server-lib"]
end

subgraph group_infra["Ops & Delivery"]
  node_email_system["Email system<br/>delivery"]
  node_file_storage["Blob storage<br/>external-storage<br/>[route.ts]"]
  node_pwa_assets["PWA assets<br/>[sw.js]"]
end

subgraph group_quality["Quality"]
  node_test_suite["Test suite<br/>tests"]
end

node_app_shell -->|"renders"| node_role_dashboards
node_app_shell -->|"includes"| node_auth_flows
node_role_dashboards -->|"contains"| node_student_tools
node_role_dashboards -->|"contains"| node_teacher_tools
node_role_dashboards -->|"contains"| node_admin_tools
node_student_tools -->|"consumes"| node_student_api
node_teacher_tools -->|"consumes"| node_docente_api
node_admin_tools -->|"consumes"| node_admin_api
node_client_hooks -->|"fetches"| node_student_api
node_client_hooks -->|"fetches"| node_docente_api
node_client_hooks -->|"fetches"| node_admin_api
node_api_gateway -->|"routes"| node_auth_api
node_api_gateway -->|"routes"| node_attendance_scan
node_api_gateway -->|"routes"| node_justification_api
node_admin_api -->|"reads/writes"| node_persistence
node_docente_api -->|"reads/writes"| node_persistence
node_student_api -->|"reads"| node_persistence
node_auth_api -->|"reads/writes"| node_persistence
node_attendance_scan -->|"validates"| node_domain_services
node_justification_api -->|"evaluates"| node_domain_services
node_admin_api -->|"uses"| node_domain_utils
node_docente_api -->|"uses"| node_domain_utils
node_student_api -->|"uses"| node_domain_utils
node_domain_services -->|"aggregates"| node_persistence
node_domain_utils -.->|"supports"| node_persistence
node_email_system -->|"sends mail"| node_auth_api
node_email_system -->|"sends mail"| node_docente_api
node_file_storage -->|"uploads"| node_admin_api
node_pwa_assets -.->|"supports"| node_app_shell
node_test_suite -->|"verifies"| node_api_gateway
node_test_suite -->|"verifies"| node_role_dashboards
node_test_suite -->|"verifies"| node_domain_services

click node_app_shell "https://github.com/manuekle/sira/blob/main/app/layout.tsx"
click node_role_dashboards "https://github.com/manuekle/sira/tree/main/app/dashboard/(roles)"
click node_auth_flows "https://github.com/manuekle/sira/tree/main/app/login"
click node_student_tools "https://github.com/manuekle/sira/tree/main/app/dashboard/(roles)/estudiante"
click node_teacher_tools "https://github.com/manuekle/sira/tree/main/app/dashboard/(roles)/docente"
click node_admin_tools "https://github.com/manuekle/sira/tree/main/app/dashboard/(roles)/admin"
click node_shared_ui "https://github.com/manuekle/sira/tree/main/components/ui"
click node_client_hooks "https://github.com/manuekle/sira/tree/main/hooks"
click node_api_gateway "https://github.com/manuekle/sira/tree/main/app/api"
click node_admin_api "https://github.com/manuekle/sira/tree/main/app/api/admin"
click node_docente_api "https://github.com/manuekle/sira/tree/main/app/api/docente"
click node_student_api "https://github.com/manuekle/sira/tree/main/app/api/estudiante"
click node_auth_api "https://github.com/manuekle/sira/blob/main/app/api/auth/[...nextauth]/route.ts"
click node_attendance_scan "https://github.com/manuekle/sira/blob/main/app/api/asistencia/scan/route.ts"
click node_justification_api "https://github.com/manuekle/sira/blob/main/app/api/justificar-ausencia/route.ts"
click node_domain_services "https://github.com/manuekle/sira/blob/main/services/dashboardService.ts"
click node_persistence "https://github.com/manuekle/sira/blob/main/lib/prisma.ts"
click node_domain_utils "https://github.com/manuekle/sira/tree/main/lib"
click node_email_system "https://github.com/manuekle/sira/tree/main/app/emails"
click node_file_storage "https://github.com/manuekle/sira/blob/main/app/api/blob/delete/route.ts"
click node_pwa_assets "https://github.com/manuekle/sira/blob/main/public/sw.js"
click node_test_suite "https://github.com/manuekle/sira/tree/main/tests"

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_app_shell,node_role_dashboards,node_auth_flows,node_student_tools,node_teacher_tools,node_admin_tools,node_shared_ui,node_client_hooks toneBlue
class node_api_gateway,node_admin_api,node_docente_api,node_student_api,node_auth_api,node_attendance_scan,node_justification_api toneAmber
class node_domain_services,node_persistence,node_domain_utils toneMint
class node_email_system,node_file_storage,node_pwa_assets toneRose
class node_test_suite toneIndigo
```

## Components

### Client UI

Browser-facing routes, layouts, and reusable components.

- [App shell](https://github.com/manuekle/sira/blob/main/app/layout.tsx): next-app · Root layouts, providers, and cross-app navigation scaffolding. · `app/layout.tsx`
- [Role dashboards](https://github.com/manuekle/sira/tree/main/app/dashboard/(roles)): next-routes · Admin, docente, and estudiante dashboard segments with role-specific layouts and pages. · `app/dashboard/(roles)`
- [Auth flows](https://github.com/manuekle/sira/tree/main/app/login): next-routes · Login, password recovery, reset, and initial-password setup pages. · `app/login`
- [Student tools](https://github.com/manuekle/sira/tree/main/app/dashboard/(roles)/estudiante): student-ui · Student-specific scan, attendance, history, and schedule experiences. · `app/dashboard/(roles)/estudiante`
- [Teacher tools](https://github.com/manuekle/sira/tree/main/app/dashboard/(roles)/docente): teacher-ui · Teacher group, class, QR, bitácora, and report screens. · `app/dashboard/(roles)/docente`
- [Admin tools](https://github.com/manuekle/sira/tree/main/app/dashboard/(roles)/admin): admin-ui · Administration screens for users, subjects, schedules, rooms, and planning. · `app/dashboard/(roles)/admin`
- [Shared UI](https://github.com/manuekle/sira/tree/main/components/ui): ui-kit · Reusable components, design-system primitives, and role-agnostic widgets. · `components/ui`
- [Client hooks](https://github.com/manuekle/sira/tree/main/hooks): state-hooks · Custom hooks for dashboard data, subjects, users, and local UI state. · `hooks`

### Server API

Next.js route handlers and auth gates.

- [API surface](https://github.com/manuekle/sira/tree/main/app/api): next-api · Application-wide route handlers for shared operations and health checks. · `app/api`
- [Admin API](https://github.com/manuekle/sira/tree/main/app/api/admin): role-api · Catalog, users, schedules, rooms, planning, and report routes for admins. · `app/api/admin`
- [Teacher API](https://github.com/manuekle/sira/tree/main/app/api/docente): role-api · Teacher routes for classes, attendance, dashboards, schedules, and requests. · `app/api/docente`
- [Student API](https://github.com/manuekle/sira/tree/main/app/api/estudiante): role-api · Student routes for dashboard, schedule, current class, history, and subjects. · `app/api/estudiante`
- [Auth API](https://github.com/manuekle/sira/blob/main/app/api/auth/[...nextauth]/route.ts): auth-routes · NextAuth and password lifecycle endpoints. · `app/api/auth/[...nextauth]/route.ts`
- [Attendance scan](https://github.com/manuekle/sira/blob/main/app/api/asistencia/scan/route.ts): workflow-api · QR attendance intake and validation entrypoint. · `app/api/asistencia/scan/route.ts`
- [Justify absence](https://github.com/manuekle/sira/blob/main/app/api/justificar-ausencia/route.ts): workflow-api · Absence justification and eligibility checks. · `app/api/justificar-ausencia/route.ts`

### Domain Services

Shared business logic, persistence, and integrations.

- [Domain services](https://github.com/manuekle/sira/blob/main/services/dashboardService.ts): business-logic · Shared server-side business logic and aggregation services. · `services/dashboardService.ts`
- [Prisma data](https://github.com/manuekle/sira/blob/main/lib/prisma.ts): orm-layer · Prisma client and schema-backed persistence over MongoDB. · `lib/prisma.ts`
- [Domain utils](https://github.com/manuekle/sira/tree/main/lib): server-lib · Class, event, time, cache, rate-limit, CSV, and role helpers. · `lib`

### Ops & Delivery

Deployment, PWA, email, and file delivery concerns.

- [Email system](https://github.com/manuekle/sira/tree/main/app/emails): delivery · Outbound email templates and mailer integration for notifications and recovery. · `app/emails`
- [Blob storage](https://github.com/manuekle/sira/blob/main/app/api/blob/delete/route.ts): external-storage · Blob upload and delete integration for files and attachments. · `app/api/blob/delete/route.ts`
- [PWA assets](https://github.com/manuekle/sira/blob/main/public/sw.js): pwa · Service worker, manifest, offline fallback, and installable app assets. · `public/sw.js`

### Quality

Tests and validation coverage mirroring the runtime boundaries.

- [Test suite](https://github.com/manuekle/sira/tree/main/tests): tests · API, component, hook, integration, E2E, and performance tests. · `tests`

## Connections

- App shell → Role dashboards: renders · The root shell hosts the role-based dashboard areas.
- App shell → Auth flows: includes · Global app routes expose authentication and recovery flows.
- Role dashboards → Student tools: contains · Student dashboard segment exposes learning and attendance tools.
- Role dashboards → Teacher tools: contains · Teacher dashboard segment exposes class and reporting tools.
- Role dashboards → Admin tools: contains · Admin dashboard segment exposes operational management tools.
- Student tools → Student API: consumes · Student screens fetch dashboard, schedule, history, and current-class data.
- Teacher tools → Teacher API: consumes · Teacher screens interact with class, attendance, and report workflows.
- Admin tools → Admin API: consumes · Admin screens drive catalog, planning, room, and user operations.
- Client hooks → Student API: fetches · Hooks synchronize student-facing state with server data.
- Client hooks → Teacher API: fetches · Hooks synchronize teacher-facing state with server data.
- Client hooks → Admin API: fetches · Hooks synchronize admin dashboard state with server data.
- API surface → Auth API: routes · Shared API surface includes auth lifecycle endpoints.
- API surface → Attendance scan: routes · Shared API surface includes QR attendance intake.
- API surface → Justify absence: routes · Shared API surface includes absence justification workflow.
- Admin API → Prisma data: reads/writes · Administrative routes persist catalog and planning data.
- Teacher API → Prisma data: reads/writes · Teacher routes persist classes, attendance, and reports.
- Student API → Prisma data: reads · Student routes query dashboard and personal academic state.
- Auth API → Prisma data: reads/writes · Authentication and password flows use the shared data layer.
- Attendance scan → Domain services: validates · Attendance scan relies on class-state and aggregation logic.
- Justify absence → Domain services: evaluates · Absence justification uses shared workflow and domain rules.
- Admin API → Domain utils: uses · Admin routes reuse CSV, schedule, cache, and role helpers.
- Teacher API → Domain utils: uses · Teacher routes reuse class, time, and email helpers.
- Student API → Domain utils: uses · Student routes reuse schedule and attendance helpers.
- Domain services → Prisma data: aggregates · Service layer composes Prisma queries into dashboard views.
- Domain utils → Prisma data: supports · Shared utilities sit alongside persistence and server-side state.
- Email system → Auth API: sends mail · Password recovery and onboarding emails originate from auth flows.
- Email system → Teacher API: sends mail · Teacher workflows can emit class, report, and notification emails.
- Blob storage → Admin API: uploads · Administrative routes handle blobs for imports and assets.
- PWA assets → App shell: supports · Installable/offline assets augment the client shell.
- Test suite → API surface: verifies · API tests validate shared and role-specific route behavior.
- Test suite → Role dashboards: verifies · Component and E2E tests cover role-based UI flows.
- Test suite → Domain services: verifies · Integration tests cover shared business logic and aggregation.
