How manuekle/sira works
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: prisma.ts Prisma data · (roles) Role dashboards · admin Admin API · docente Teacher API
Components 22
Client UI
Browser-facing routes, layouts, and reusable components.
- App shell · Root layouts, providers, and cross-app navigation scaffolding.
app/layout.tsx - Role dashboards · Admin, docente, and estudiante dashboard segments with role-specific layouts and pages.
app/dashboard/(roles) - Auth flows · Login, password recovery, reset, and initial-password setup pages.
app/login - Student tools · Student-specific scan, attendance, history, and schedule experiences.
app/dashboard/(roles)/estudiante - Teacher tools · Teacher group, class, QR, bitácora, and report screens.
app/dashboard/(roles)/docente - Admin tools · Administration screens for users, subjects, schedules, rooms, and planning.
app/dashboard/(roles)/admin - Shared UI · Reusable components, design-system primitives, and role-agnostic widgets.
components/ui - Client hooks · Custom hooks for dashboard data, subjects, users, and local UI state.
hooks
Server API
Next.js route handlers and auth gates.
- API surface · Application-wide route handlers for shared operations and health checks.
app/api - Admin API · Catalog, users, schedules, rooms, planning, and report routes for admins.
app/api/admin - Teacher API · Teacher routes for classes, attendance, dashboards, schedules, and requests.
app/api/docente - Student API · Student routes for dashboard, schedule, current class, history, and subjects.
app/api/estudiante - Auth API · NextAuth and password lifecycle endpoints.
app/api/auth/[...nextauth]/route.ts - Attendance scan · QR attendance intake and validation entrypoint.
app/api/asistencia/scan/route.ts - Justify absence · Absence justification and eligibility checks.
app/api/justificar-ausencia/route.ts
Domain Services
Shared business logic, persistence, and integrations.
- Domain services · Shared server-side business logic and aggregation services.
services/dashboardService.ts - Prisma data · Prisma client and schema-backed persistence over MongoDB.
lib/prisma.ts - Domain utils · Class, event, time, cache, rate-limit, CSV, and role helpers.
lib
Ops & Delivery
Deployment, PWA, email, and file delivery concerns.
- Email system · Outbound email templates and mailer integration for notifications and recovery.
app/emails - Blob storage · Blob upload and delete integration for files and attachments.
app/api/blob/delete/route.ts - PWA assets · Service worker, manifest, offline fallback, and installable app assets.
public/sw.js
Quality
Tests and validation coverage mirroring the runtime boundaries.
- Test suite · API, component, hook, integration, E2E, and performance tests.
tests
Connections 32
- 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.