How 25800049-sketch/smart-curriculum works
Purpose and runtime
This is a Next.js TypeScript application for school operations: role-governed users manage academic data and timetables, run QR-based attendance, view attendance analytics, administer tests, and receive personal planning suggestions. It combines App Router pages with same-repository API route handlers and server-side MongoDB services.
Entry points are the root and route-group layouts/pages: src/app/page.tsx, src/app/(app)/layout.tsx, src/app/(auth)/layout.tsx, and the public attendance route src/app/attend/[token]/page.tsx.
Application shells and access boundary
Authenticated application pages live under src/app/(app), while sign-in, password recovery, and reset flows live under src/app/(auth). The proxy is likely the request-wide routing/authentication boundary: src/proxy.ts.
Auth APIs support login, refresh, logout, token validation, CSRF, profile, password changes, and reset flows under src/app/api/auth/*. Server auth concerns are separated into session/cookie/token handling, current-user resolution, permissions, and guards: src/server/auth/session.ts, src/server/auth/guard.ts, src/server/auth/service.ts.
Persistence and domain model
MongoDB/Mongoose is the persistence layer, initialized through src/server/db/mongoose.ts. Domain models are divided by concern: academic entities (src/server/db/models/academic.models.ts), attendance (src/server/db/models/attendance.models.ts), authentication/identity (src/server/db/models/auth.models.ts), and tests (src/server/db/models/test.models.ts).
The documented schema contract is docs/SCHEMA.md. Seed, cleanup, and permission synchronization scripts establish or maintain operational data: scripts/seed.ts, scripts/cleanup.ts, scripts/sync-permissions.ts.
Academic administration and timetable
Administrators use pages for people, classes/subjects, timetable, and audit logs, backed by admin APIs and a consolidated service layer: src/app/(app)/admin/people/page.tsx, src/app/api/admin/timetable/route.ts, src/server/admin/service.ts.
The timetable is both an administrative source of truth and a shared input to user-facing timetable and planning features: src/app/(app)/timetable/page.tsx, src/app/api/timetable/me/route.ts, src/server/planner/timetable.ts. Static period definitions are centralized in src/config/periods.ts.
Attendance lifecycle
Attendance is session-oriented. Authorized users create/list sessions, open or close a session, generate its QR material, observe a live stream/roster, and can override records. These operations are exposed through src/app/api/attendance/sessions/route.ts, src/app/api/attendance/sessions/[id]/qr/route.ts, and src/app/api/attendance/sessions/[id]/stream/route.ts.
Students scan a QR code in the app or use the public tokenized attendance URL, which posts marking actions through src/app/api/attendance/mark/route.ts. Core policy, token/QR construction, and state transitions belong in src/server/attendance/policy.ts, src/server/attendance/qr.ts, and src/server/attendance/service.ts. The public route is intentionally separate from the authenticated shell: src/app/attend/[token]/attend-client.tsx.
Analytics and audit
Attendance data feeds scoped analytics and export endpoints: src/app/api/analytics/route.ts, src/app/api/analytics/export/route.ts, src/server/analytics/attendance.ts. The analytics page renders tables and charts from this data: src/app/(app)/analytics/page.tsx, src/components/analytics/trend-chart.tsx.
Material actions can be recorded through the audit subsystem, queried by the admin logs interface: src/server/audit/log.ts, src/server/audit/service.ts, src/app/api/admin/logs/route.ts.
Planner and tests
The personal planner combines the user’s timetable, computed free periods, task records, and suggestion logic: src/app/api/planner/me/route.ts, src/server/planner/free-periods.ts, src/server/planner/suggest.ts. Tasks have independent CRUD endpoints at src/app/api/tasks/route.ts.
Test administration is a distinct academic workflow with server service and API boundary: src/app/(app)/tests/tests-manager.tsx, src/app/api/tests/route.ts, src/server/tests/service.ts. Mail infrastructure and templates support operational notifications such as test announcements, welcome, and password-reset messages: src/server/mail/send.ts, src/server/mail/templates/test-announced.ts.
Main entry points: mongoose.ts MongoDB / Mongoose · layout.tsx Authenticated app shell · attendance/service.ts Attendance service · auth/service.ts Auth services
Components 23
App UI
App Router shells and user-facing workflows.
- Public entry
src/app/page.tsx - Auth shell · Sign-in and recovery flows are isolated from the app shell.
src/app/(auth)/layout.tsx - Authenticated app shell
src/app/(app)/layout.tsx - Public QR attendance · Tokenized attendance flow outside the authenticated shell.
src/app/attend/[token]/page.tsx
API Routes
Same-repository HTTP boundaries.
- Personal timetable · Serves the user's timetable for app features.
src/app/api/timetable/me/route.ts - Attendance sessions · Session lifecycle, QR generation, and live roster streaming.
src/app/api/attendance/sessions/route.ts - Attendance marking
src/app/api/attendance/mark/route.ts - Analytics API
src/app/api/analytics/route.ts - Personal planner API
src/app/api/planner/me/route.ts - Tests API
src/app/api/tests/route.ts
Server Domain
Authorization and operational business services.
- Request auth boundary · Applies request-wide routing and authentication policy.
src/proxy.ts - Auth services · Sessions, current-user resolution, permissions, and guards.
src/server/auth/service.ts - Academic administration · Manages people, academic structure, and timetables.
src/server/admin/service.ts - Attendance service · Enforces attendance policy and session state transitions.
src/server/attendance/service.ts - QR token builder
src/server/attendance/qr.ts - Attendance analytics · Computes scoped analytics and export data.
src/server/analytics/attendance.ts - Planner suggestions · Combines free periods and tasks into planning suggestions.
src/server/planner/suggest.ts - Test administration
src/server/tests/service.ts - Audit subsystem · Records material actions for administrative review.
src/server/audit/service.ts - Mail delivery · Sends operational notifications and templates.
src/server/mail/send.ts
Data & Operations
Persistence contract and maintenance tooling.
- MongoDB / Mongoose · Stores identity, academic, attendance, and test records.
src/server/db/mongoose.ts - Schema contract · Documents the persisted data model.
docs/SCHEMA.md - Data maintenance scripts · Seeds, cleans, and synchronizes permissions.
scripts/sync-permissions.ts
Connections 30
- Public entry → Auth shell: sign-in flows
- Request auth boundary → Auth services: enforces access
- Auth shell → Auth services: auth actions
- Authenticated app shell → Request auth boundary: authenticated requests
- Auth services → MongoDB / Mongoose: sessions and identity
- Academic administration → MongoDB / Mongoose: academic data
- Authenticated app shell → Personal timetable: views timetable
- Personal timetable → Academic administration: reads timetable
- Authenticated app shell → Attendance sessions: manages sessions
- Attendance sessions → Auth services: authorizes
- Attendance sessions → Attendance service: session operations
- Attendance service → QR token builder: creates QR material
- Attendance service → MongoDB / Mongoose: sessions and records
- Public QR attendance → Attendance marking: submits scan
- Attendance marking → Attendance service: marks attendance
- Attendance service → Attendance analytics: attendance data
- Authenticated app shell → Analytics API: renders analytics
- Analytics API → Attendance analytics: queries and exports
- Authenticated app shell → Personal planner API: requests plan
- Personal planner API → Planner suggestions: builds suggestions
- Planner suggestions → Personal timetable: uses timetable
- Planner suggestions → MongoDB / Mongoose: reads tasks
- Authenticated app shell → Tests API: administers tests
- Tests API → Test administration: test workflow
- Test administration → MongoDB / Mongoose: test records
- Test administration → Mail delivery: announcements
- Academic administration → Audit subsystem: records actions
- Audit subsystem → MongoDB / Mongoose: audit logs
- Schema contract → MongoDB / Mongoose: documents model
- Data maintenance scripts → MongoDB / Mongoose: maintains data