How zaygal/copalog works
Purpose and Runtime
CopaLog is a full-stack NYSC service-intelligence platform for service logs, CDS attendance, absence escalation, verification, messaging, and public aggregate analytics. It runs as a Next.js 16 App Router application on Vercel, using TypeScript and Tailwind. Primary application entry points are copalog/src/app/page.tsx, copalog/src/app/layout.tsx, and copalog/src/middleware.ts.
Identity, Access, and Role Routing
Supabase Auth provides email/password and OAuth authentication. Authentication callbacks, sign-out, registration, and guided onboarding are implemented under copalog/src/app/auth/. Middleware establishes the request boundary: it obtains Supabase session state and routes users away from unauthorized role areas. Role hierarchy is HQ Admin → State Coordinator → LGA Officer → PPA Supervisor → Corps Member; database RLS remains the authoritative data-scoping boundary.
Grounding: copalog/src/middleware.ts, copalog/src/lib/supabase/middleware.ts, copalog/src/app/auth/callback/route.ts.
Role-Specific Dashboard Shells
/dashboard is the authenticated operational surface. Its layout/error/loading boundaries support all role views, while separate server pages and client components implement role-specific data presentation and polling. Corps members manage logs and portfolios; supervisors review work; LGA/state/HQ roles view progressively broader operational data.
Grounding: copalog/src/app/dashboard/layout.tsx, copalog/src/app/dashboard/corps/page.tsx, copalog/src/app/dashboard/hq/page.tsx.
Service Log Verification Flow
Corps members submit daily activities, then supervisors approve, flag, or reject them. The corps log creation/history routes form the visible entry points; role dashboards consume the resulting scoped service-log data. Telegram can also submit logs through external n8n automation into the same service domain.
Grounding: copalog/src/app/dashboard/corps/log/page.tsx, copalog/src/app/dashboard/corps/logs/page.tsx, copalog/src/app/dashboard/supervisor/page.tsx.
CDS Attendance and Absence Escalation
LGA officers generate CDS sessions/codes and oversee attendance; members can mark attendance in the web UI or through Telegram /attend. Attendance is associated with the session’s actual date. Consecutive absence detection produces flags for LGA review and possible HQ escalation. This stage centers on the CDS route family and its generated/marked/aggregated views.
Grounding: copalog/src/app/dashboard/cds/page.tsx, copalog/src/app/dashboard/cds/generate/page.tsx, copalog/src/app/dashboard/cds/attendance/page.tsx.
Administrative APIs and Controlled Writes
Next.js route handlers expose privileged administrative mutations: create users, search members, and upload the official NYSC roster CSV. Admin routes require Bearer-token authentication and are rate-limited through Upstash Redis; roster data gates registration when populated. Server actions provide another mutation boundary for App Router UI flows.
Grounding: copalog/src/app/api/admin/upload-roster/route.ts, copalog/src/app/api/admin/search-members/route.ts, copalog/src/lib/ratelimit.ts.
Data and External-Service Boundaries
Supabase PostgreSQL holds profiles, corps-member metadata, logs, CDS entities, attendance, flags, messages, audit data, roster, states, and LGAs. Browser/server Supabase clients separate client access from trusted server/service-role queries. Public analytics use server-side aggregation and expose results through a public page/API, never service credentials. Telegram Bot API integration is mediated by hosted n8n; dashboards refresh through 10-second client polling. Sentry instruments client/server runtime failures.
Grounding: copalog/src/lib/supabase/client.ts, copalog/src/lib/supabase/server.ts, copalog/src/app/api/portfolio/route.ts.
Public and Observability Surface
Unauthenticated users can access national aggregate analytics and the Nigeria activity map; state geography is served as static data. Sentry is initialized separately for server and client instrumentation, providing an operational monitoring boundary outside application data flows.
Grounding: copalog/src/app/public/page.tsx, copalog/src/app/public/NigeriaMap.tsx, copalog/instrumentation.ts.
Main entry points: server.ts Supabase Client Layers · layout.tsx Dashboard Shell · middleware.ts Auth Middleware · page.tsx Service Log Workflow
Components 17
Application Surfaces
- Next.js App Router · Vercel-hosted full-stack application entry and route host.
copalog/src/app/layout.tsx - Auth Middleware · Loads session and redirects unauthorized role access.
copalog/src/middleware.ts - Auth & Onboarding
copalog/src/app/auth/callback/route.ts - Dashboard Shell · Shared operational layout, loading, and error boundaries.
copalog/src/app/dashboard/layout.tsx - Role Dashboards · Corps, supervisor, LGA, state, and HQ scoped views.
copalog/src/app/dashboard/hq/page.tsx - Service Log Workflow · Members submit logs; supervisors approve, flag, or reject them.
copalog/src/app/dashboard/corps/log/page.tsx - CDS & Attendance · Session generation, marking, and attendance review.
copalog/src/app/dashboard/cds/page.tsx - Absence Escalation · Consecutive absences create flags for LGA review and HQ escalation.
copalog/src/app/dashboard/cds/attendance/page.tsx - Admin APIs · Privileged roster upload and member search writes.
copalog/src/app/api/admin/upload-roster/route.ts - Public Analytics · Unauthenticated national aggregates and Nigeria activity map.
copalog/src/app/public/page.tsx
Platform Boundaries
- Supabase Auth
- Supabase Client Layers · Separates browser access from trusted server and service-role queries.
copalog/src/lib/supabase/server.ts - Supabase PostgreSQL + RLS · Authoritative role-scoped storage for operational and audit data.
- Upstash Redis
copalog/src/lib/ratelimit.ts
Automation & Observability
- Hosted n8n · Mediates Telegram commands into service workflows.
- Telegram Bot API
- Sentry · Captures client and server runtime failures.
copalog/instrumentation.ts
Connections 19
- Next.js App Router → Auth Middleware: all requests
- Auth Middleware → Supabase Auth: session lookup
- Auth Middleware → Dashboard Shell: authorized access
- Auth & Onboarding → Supabase Auth: sign-in and OAuth
- Dashboard Shell → Role Dashboards: role routes
- Dashboard Shell → Service Log Workflow: member workflow
- Dashboard Shell → CDS & Attendance: LGA workflow
- Service Log Workflow → Supabase Client Layers: read/write logs
- CDS & Attendance → Supabase Client Layers: read/write attendance
- Supabase Client Layers → Supabase PostgreSQL + RLS: scoped queries
- Supabase PostgreSQL + RLS → Absence Escalation: absence data
- Absence Escalation → Role Dashboards: flags and escalation
- Admin APIs → Upstash Redis: rate limit
- Admin APIs → Supabase Client Layers: controlled writes
- Public Analytics → Supabase Client Layers: server aggregation
- Telegram Bot API → Hosted n8n: bot commands
- Hosted n8n → Service Log Workflow: submit logs
- Hosted n8n → CDS & Attendance: /attend
- Next.js App Router → Sentry: runtime errors