# mugheesrashid/cpinitiative architecture

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

- Interactive diagram: https://gitdiagram.com/mugheesrashid/cpinitiative
- Repository: https://github.com/mugheesrashid/cpinitiative

## Overview

#### Purpose and Runtime
Competitive Programming Initiative’s public site promotes programming resources, classes, contests, clubs, workshops, and tournament results. It is a TypeScript Next.js Pages Router application, hosted/deployed through Vercel per the README. Browser UI is under `src/pages/` and `src/components/`; server capabilities are Next API routes under `src/pages/api/`.

#### Application Shell and Public Content
`src/pages/_app.tsx` establishes app-wide behavior, while reusable site chrome and metadata are composed through `src/components/Layout.tsx`, `src/components/Header.tsx`, and `src/components/SEO.tsx`. Primary public entry routes include `src/pages/index.tsx`, `src/pages/classes.tsx`, `src/pages/contests.tsx`, `src/pages/clubs.tsx`, and `src/pages/workshops.tsx`. Domain pages mostly assemble dedicated presentational components and local data rather than exposing a separate backend content system.

#### Program Content Domains
Classes, video classes, workshops, contests, and tournament results are independently organized content domains:
- Live-class pages and registration: `src/pages/classes/register.tsx`, `src/components/classes/registration/CourseSelectionSection.tsx`, `src/components/classes/registration/PaymentSection.tsx`.
- Video-class equivalents: `src/pages/video-classes/register.tsx`, `src/components/video-classes/registration/PaymentSection.tsx`.
- Workshop route variants map to event-specific components, e.g. `src/pages/workshops/ioi25.tsx` and `src/components/workshops/ioi25/Hero.tsx`.
- Tournament historical results are explicit routes: `src/pages/tournament/2024-results.tsx`, `src/pages/tournament/2025-results.tsx`, `src/pages/tournament/2026-results.tsx`.

#### Registration and Financial-Aid Flow
Registration UIs collect student details, course/level selection, financial-aid inputs, and payment state. The submission boundary is API routes: `src/pages/api/classes/process-registration.ts` for standard registration and `src/pages/api/classes/process-live-registration.ts` for live classes. Financial-aid approvals are handled separately by `src/pages/api/classes/approve-financial-aid.ts` and `src/pages/api/classes/approve-live-financial-aid.ts`. Shared registration types and operational utilities reside in `src/types/registration.ts`, `src/util/classes/paypalClient.ts`, and `src/util/classes/sendWelcomeEmail.ts`.

#### Identity, Firebase, and Administration
Firebase is a client/application data boundary configured from `firebase.ts`, surfaced through `src/firebase/FirebaseContext.tsx` and `src/firebase/useFirebase.tsx`. User state and registration retrieval are encapsulated in `src/hooks/useFirebaseUser.tsx` and `src/hooks/useClassRegistrations.ts`. NextAuth is exposed at `src/pages/api/auth/[...nextauth].ts`; permission checks are centralized in `src/util/permissions.ts`. Protected operational views exist for live and video registrations at `src/pages/classes/admin/view-registrations.tsx` and `src/pages/video-classes/admin/view-registrations.tsx`.

#### External Service Integrations
The service layer connects several external systems:
- PayPal supports class-payment processing via `src/util/classes/paypalClient.ts`.
- Welcome emails use templates in `src/util/classes/email_templates/` and delivery logic in `src/util/classes/sendWelcomeEmail.ts`.
- Newsletter enrollment is served by `src/pages/api/join-mailing-list.ts`, with Mailjet/Mailgun adapters in `src/util/mailjet.ts` and `src/util/mailgun.ts`.
- Volunteer-hours viewing and updates flow through `src/pages/view-hours.tsx`, `src/pages/api/getHours.ts`, and `src/pages/api/addHours.ts`; README-required Google OAuth/Sheets credentials make Google Sheets an operational data dependency.

#### Static Assets and Announcements
Static downloadable program material is served from `public/`, including tournament PDFs and solution archives. Announcements are MDX-backed content in `src/components/announcements/data/`, rendered through `src/components/announcements/Announcements.tsx`. This creates a repository-managed content boundary distinct from Firebase-backed operational data.

Main entry points: [`src/pages/_app.tsx`](https://github.com/mugheesrashid/cpinitiative/blob/master/src/pages/_app.tsx) (Next.js Pages app), [`src/pages/classes.tsx`](https://github.com/mugheesrashid/cpinitiative/blob/master/src/pages/classes.tsx) (Program routes), [`src/pages/api/classes/process-registration.ts`](https://github.com/mugheesrashid/cpinitiative/blob/master/src/pages/api/classes/process-registration.ts) (Registration APIs), [`src/pages/classes/register.tsx`](https://github.com/mugheesrashid/cpinitiative/blob/master/src/pages/classes/register.tsx) (Registration UI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_public["Public site"]
  node_next_app["Next.js Pages app<br/>[_app.tsx]"]
  node_site_shell["Site shell<br/>UI chrome<br/>[Layout.tsx]"]
  node_public_routes["Program routes<br/>page routes<br/>[classes.tsx]"]
  node_workshop_pages["Workshop variants<br/>event pages<br/>[ioi25.tsx]"]
  node_tournament_results["Tournament results<br/>historical routes<br/>[2024-results.tsx]"]
  node_announcements["Announcements<br/>MDX content"]
  node_static_assets["Downloads &amp; archives<br/>static assets"]
end

subgraph group_registration["Registration"]
  node_registration_ui["Registration UI<br/>form workflow<br/>[register.tsx]"]
  node_video_registration_ui["Video registration UI<br/>form workflow<br/>[register.tsx]"]
  node_registration_api["Registration APIs<br/>Next API routes"]
  node_aid_api["Financial-aid APIs<br/>Next API routes"]
  node_registration_services["Payment &amp; welcome service<br/>registration utilities<br/>[paypalClient.ts]"]
end

subgraph group_operations["Identity &amp; operations"]
  node_firebase_boundary[("Firebase data boundary<br/>client data service<br/>[firebase.ts]")]
  node_firebase_context["Firebase context<br/>client provider"]
  node_registration_hooks["Registration retrieval<br/>client hooks"]
  node_auth_permissions["Auth &amp; permissions<br/>access control<br/>[&#91;...nextauth&#93;.ts]"]
  node_admin_views["Registration admin<br/>protected views"]
end

subgraph group_integrations["External services"]
  node_newsletter_api["Newsletter API<br/>Next API route"]
  node_paypal{{"PayPal<br/>payment provider"}}
  node_email_delivery["Email delivery<br/>welcome-email service"]
  node_mail_providers{{"Mailjet / Mailgun<br/>mail providers<br/>[mailjet.ts]"}}
  node_hours_api["Volunteer-hours APIs<br/>Next API routes<br/>[getHours.ts]"]
  node_google_sheets[("Google Sheets<br/>operational data store")]
end

node_next_app -->|"composes"| node_site_shell
node_next_app -->|"serves"| node_public_routes
node_public_routes -->|"includes"| node_workshop_pages
node_public_routes -->|"links to"| node_tournament_results
node_next_app -->|"renders"| node_announcements
node_next_app -->|"serves"| node_static_assets
node_public_routes -->|"opens"| node_registration_ui
node_public_routes -->|"opens"| node_video_registration_ui
node_registration_ui -->|"submits"| node_registration_api
node_video_registration_ui -->|"submits"| node_registration_api
node_registration_ui -->|"requests aid"| node_aid_api
node_registration_api -->|"uses"| node_registration_services
node_registration_api -->|"stores registrations"| node_firebase_boundary
node_aid_api -->|"updates approvals"| node_firebase_boundary
node_registration_services -->|"charges through"| node_paypal
node_registration_services -->|"sends welcome"| node_email_delivery
node_firebase_context -->|"connects to"| node_firebase_boundary
node_registration_hooks -->|"uses"| node_firebase_context
node_admin_views -->|"loads registrations"| node_registration_hooks
node_admin_views -->|"requires"| node_auth_permissions
node_next_app -->|"enrolls subscribers"| node_newsletter_api
node_newsletter_api -->|"uses"| node_mail_providers
node_next_app -->|"views and updates hours"| node_hours_api
node_hours_api -->|"reads and writes"| node_google_sheets

click node_next_app "https://github.com/mugheesrashid/cpinitiative/blob/master/src/pages/_app.tsx"
click node_site_shell "https://github.com/mugheesrashid/cpinitiative/blob/master/src/components/Layout.tsx"
click node_public_routes "https://github.com/mugheesrashid/cpinitiative/blob/master/src/pages/classes.tsx"
click node_workshop_pages "https://github.com/mugheesrashid/cpinitiative/blob/master/src/pages/workshops/ioi25.tsx"
click node_tournament_results "https://github.com/mugheesrashid/cpinitiative/blob/master/src/pages/tournament/2024-results.tsx"
click node_registration_ui "https://github.com/mugheesrashid/cpinitiative/blob/master/src/pages/classes/register.tsx"
click node_video_registration_ui "https://github.com/mugheesrashid/cpinitiative/blob/master/src/pages/video-classes/register.tsx"
click node_registration_api "https://github.com/mugheesrashid/cpinitiative/blob/master/src/pages/api/classes/process-registration.ts"
click node_aid_api "https://github.com/mugheesrashid/cpinitiative/blob/master/src/pages/api/classes/approve-financial-aid.ts"
click node_registration_services "https://github.com/mugheesrashid/cpinitiative/blob/master/src/util/classes/paypalClient.ts"
click node_firebase_boundary "https://github.com/mugheesrashid/cpinitiative/blob/master/firebase.ts"
click node_firebase_context "https://github.com/mugheesrashid/cpinitiative/blob/master/src/firebase/FirebaseContext.tsx"
click node_registration_hooks "https://github.com/mugheesrashid/cpinitiative/blob/master/src/hooks/useClassRegistrations.ts"
click node_auth_permissions "https://github.com/mugheesrashid/cpinitiative/blob/master/src/pages/api/auth/%5B...nextauth%5D.ts"
click node_admin_views "https://github.com/mugheesrashid/cpinitiative/blob/master/src/pages/classes/admin/view-registrations.tsx"
click node_newsletter_api "https://github.com/mugheesrashid/cpinitiative/blob/master/src/pages/api/join-mailing-list.ts"
click node_email_delivery "https://github.com/mugheesrashid/cpinitiative/blob/master/src/util/classes/sendWelcomeEmail.ts"
click node_mail_providers "https://github.com/mugheesrashid/cpinitiative/blob/master/src/util/mailjet.ts"
click node_hours_api "https://github.com/mugheesrashid/cpinitiative/blob/master/src/pages/api/getHours.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_next_app,node_site_shell,node_public_routes,node_workshop_pages,node_tournament_results,node_announcements,node_static_assets toneBlue
class node_registration_ui,node_video_registration_ui,node_registration_api,node_aid_api,node_registration_services toneAmber
class node_firebase_boundary,node_firebase_context,node_registration_hooks,node_auth_permissions,node_admin_views toneMint
class node_newsletter_api,node_paypal,node_email_delivery,node_mail_providers,node_hours_api,node_google_sheets toneRose
```

## Components

### Public site

- [Next.js Pages app](https://github.com/mugheesrashid/cpinitiative/blob/master/src/pages/_app.tsx): application · Vercel-hosted public site and API runtime. · `src/pages/_app.tsx`
- [Site shell](https://github.com/mugheesrashid/cpinitiative/blob/master/src/components/Layout.tsx): UI chrome · `src/components/Layout.tsx`
- [Program routes](https://github.com/mugheesrashid/cpinitiative/blob/master/src/pages/classes.tsx): page routes · Classes, contests, clubs, and workshops pages. · `src/pages/classes.tsx`
- [Workshop variants](https://github.com/mugheesrashid/cpinitiative/blob/master/src/pages/workshops/ioi25.tsx): event pages · `src/pages/workshops/ioi25.tsx`
- [Tournament results](https://github.com/mugheesrashid/cpinitiative/blob/master/src/pages/tournament/2024-results.tsx): historical routes · `src/pages/tournament/2024-results.tsx`
- **Announcements**: MDX content · Repository-managed announcement content.
- **Downloads & archives**: static assets

### Registration

- [Registration UI](https://github.com/mugheesrashid/cpinitiative/blob/master/src/pages/classes/register.tsx): form workflow · Collects student, selection, aid, and payment inputs. · `src/pages/classes/register.tsx`
- [Video registration UI](https://github.com/mugheesrashid/cpinitiative/blob/master/src/pages/video-classes/register.tsx): form workflow · `src/pages/video-classes/register.tsx`
- [Registration APIs](https://github.com/mugheesrashid/cpinitiative/blob/master/src/pages/api/classes/process-registration.ts): Next API routes · Processes standard and live class registrations. · `src/pages/api/classes/process-registration.ts`
- [Financial-aid APIs](https://github.com/mugheesrashid/cpinitiative/blob/master/src/pages/api/classes/approve-financial-aid.ts): Next API routes · Approves standard and live financial aid. · `src/pages/api/classes/approve-financial-aid.ts`
- [Payment & welcome service](https://github.com/mugheesrashid/cpinitiative/blob/master/src/util/classes/paypalClient.ts): registration utilities · `src/util/classes/paypalClient.ts`

### Identity & operations

- [Firebase data boundary](https://github.com/mugheesrashid/cpinitiative/blob/master/firebase.ts): client data service · Provides application data and user state. · `firebase.ts`
- [Firebase context](https://github.com/mugheesrashid/cpinitiative/blob/master/src/firebase/FirebaseContext.tsx): client provider · `src/firebase/FirebaseContext.tsx`
- [Registration retrieval](https://github.com/mugheesrashid/cpinitiative/blob/master/src/hooks/useClassRegistrations.ts): client hooks · `src/hooks/useClassRegistrations.ts`
- [Auth & permissions](https://github.com/mugheesrashid/cpinitiative/blob/master/src/pages/api/auth/%5B...nextauth%5D.ts): access control · NextAuth authentication with centralized permission checks. · `src/pages/api/auth/[...nextauth].ts`
- [Registration admin](https://github.com/mugheesrashid/cpinitiative/blob/master/src/pages/classes/admin/view-registrations.tsx): protected views · Operational views for live and video registrations. · `src/pages/classes/admin/view-registrations.tsx`

### External services

- [Newsletter API](https://github.com/mugheesrashid/cpinitiative/blob/master/src/pages/api/join-mailing-list.ts): Next API route · `src/pages/api/join-mailing-list.ts`
- **PayPal**: payment provider
- [Email delivery](https://github.com/mugheesrashid/cpinitiative/blob/master/src/util/classes/sendWelcomeEmail.ts): welcome-email service · Templates and delivery logic send registration welcomes. · `src/util/classes/sendWelcomeEmail.ts`
- [Mailjet / Mailgun](https://github.com/mugheesrashid/cpinitiative/blob/master/src/util/mailjet.ts): mail providers · `src/util/mailjet.ts`
- [Volunteer-hours APIs](https://github.com/mugheesrashid/cpinitiative/blob/master/src/pages/api/getHours.ts): Next API routes · Retrieves and updates volunteer hours. · `src/pages/api/getHours.ts`
- **Google Sheets**: operational data store

## Connections

- Next.js Pages app → Site shell: composes
- Next.js Pages app → Program routes: serves
- Program routes → Workshop variants: includes
- Program routes → Tournament results: links to
- Next.js Pages app → Announcements: renders
- Next.js Pages app → Downloads & archives: serves
- Program routes → Registration UI: opens
- Program routes → Video registration UI: opens
- Registration UI → Registration APIs: submits
- Video registration UI → Registration APIs: submits
- Registration UI → Financial-aid APIs: requests aid
- Registration APIs → Payment & welcome service: uses
- Registration APIs → Firebase data boundary: stores registrations
- Financial-aid APIs → Firebase data boundary: updates approvals
- Payment & welcome service → PayPal: charges through
- Payment & welcome service → Email delivery: sends welcome
- Firebase context → Firebase data boundary: connects to
- Registration retrieval → Firebase context: uses
- Registration admin → Registration retrieval: loads registrations
- Registration admin → Auth & permissions: requires
- Next.js Pages app → Newsletter API: enrolls subscribers
- Newsletter API → Mailjet / Mailgun: uses
- Next.js Pages app → Volunteer-hours APIs: views and updates hours
- Volunteer-hours APIs → Google Sheets: reads and writes
