# saiabhinav001/ai_4_impact architecture

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

- Interactive diagram: https://gitdiagram.com/saiabhinav001/ai_4_impact
- Repository: https://github.com/saiabhinav001/ai_4_impact

## Overview

1. This repo is a Next.js App Router application with a clear split between browser UI, server-rendered pages, and route-handler APIs. The `src/app` tree contains the user-facing routes, while `src/app/api` holds the backend boundary for all persistence, auth, and file operations.

2. The main product surface is a registration portal for two event types: hackathon and workshop. The reusable registration UI lives under `src/components/registration`, with forms, track selection, file upload, payment sections, and a portal shell that likely switches behavior based on the selected registration type.

3. There are two primary public flows:
   - registration and submission for participants,
   - team/workflow actions after registration.
   The public pages include `/`, `/auth`, `/dashboard`, and `/team`, which appear to route users into the appropriate experience after authentication or registration state checks.

4. The backend is organized around domain-specific API endpoints rather than a single monolithic API. Under `src/app/api`, there are distinct groups for:
   - `register` and `registrations` for creating and reading registration records,
   - `team` and `teams` for team access, dashboard, selection, and submission,
   - `upload` for file uploads,
   - `users/profile` for user data,
   - `hackathon/phase` and `hackathon/timeline` for event state,
   - `admin/*` for operational/admin functions.

5. Firebase is the main infrastructure boundary. The presence of `firebaseAdmin.js`, `lib/admin.js`, `lib/client.js`, `lib/firebase.js`, plus `firestore.rules` and `storage.rules`, indicates a split between client-side Firebase access and privileged server-side admin access. This strongly suggests Firestore is the primary database and Firebase Storage is used for uploaded assets such as payment screenshots and PPT files.

6. Authentication and authorization are centralized rather than embedded in each UI page. `middleware.js`, `lib/auth.js`, `lib/server/auth.js`, and `src/app/api/admin/_utils/auth.js` indicate request-time protection for both end-user and admin paths. The `lib/constants/roles.js` file suggests role-based access control, and `scripts/set-admin-claims.mjs` implies custom claims are used for admin privileges.

7. The admin subsystem is a separate operational console under `src/app/admin` with its own login page and API endpoints. It supports analytics, registration viewing, submission review, payment verification, DB initialization, team credential regeneration, and sending team credentials email in bulk or individually. This is the main human-in-the-loop control plane for the event organizers.

8. File handling is an important part of the architecture. There are dedicated upload routes for payment screenshots and PPTs, plus a cleanup utility in `src/app/api/register/_utils/screenshotCleanup.js`. That means uploaded files are treated as managed artifacts, not just incidental attachments, and there is explicit lifecycle handling to prevent orphaned storage objects.

9. The hackathon domain has its own state model. `lib/constants/phases.js` plus the `hackathon/phase` and `hackathon/timeline` APIs show that event progression is externally modeled as phases/timeline data, likely used to gate UI behavior and team actions. This is a separate control plane from registration records.

10. Server-side helper modules under `lib/server` and `src/app/api/*/_utils` suggest a layered backend: route handlers are thin, and shared logic lives in server utilities. This is where validation, credential-email formatting, and hackathon-specific server functions are centralized.

11. The repo also contains one-off operational scripts under `scripts/` for maintenance and data migration: backfilling access, cleaning test data, listing collections, initializing the database, checking credential state, and deploying Firestore config. These scripts indicate a production system with ongoing data hygiene and admin operations, not just a static frontend.

12. Deployment/runtime configuration is standard Next.js plus Firebase. `next.config.mjs`, `firebase.json`, `firestore.indexes.json`, `firestore.rules`, `storage.rules`, and `public/` assets show the project is designed to deploy as a web app with Firebase-backed services and security rules enforcing access at the data layer.

13. A useful architecture diagram should emphasize three boundaries:
   - browser UI in `src/app` and `src/components`,
   - Next.js route handlers in `src/app/api`,
   - Firebase services and rules as the persistence/auth/storage backend.
   The admin console is a privileged branch of the same app, not a separate service.

14. In short, this is an event-registration and team-management platform built on Next.js + Firebase, with public participant flows, protected team workflows, and an admin control plane operating over Firestore/Storage through server-side APIs and custom auth.

Main entry points: [`firestore.rules`](https://github.com/saiabhinav001/ai_4_impact/blob/main/firestore.rules) (Firestore), [`src/app/api/register/route.js`](https://github.com/saiabhinav001/ai_4_impact/blob/main/src/app/api/register/route.js) (Register API), [`lib/firebase.js`](https://github.com/saiabhinav001/ai_4_impact/blob/main/lib/firebase.js) (Firebase Clients), [`src/app/auth/page.jsx`](https://github.com/saiabhinav001/ai_4_impact/blob/main/src/app/auth/page.jsx) (Auth)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["App UI"]
  node_home["Home<br/>public page<br/>[page.tsx]"]
  node_auth_page["Auth<br/>login page<br/>[page.jsx]"]
  node_dashboard_page["Dashboard<br/>protected page<br/>[page.jsx]"]
  node_team_page["Team<br/>[page.jsx]"]
  node_registration_portal["Reg Portal<br/>registration shell"]
  node_hackathon_form["Hackathon Form<br/>registration form<br/>[HackathonForm.tsx]"]
  node_workshop_form["Workshop Form<br/>registration form<br/>[WorkshopForm.tsx]"]
  node_uploads_ui["Uploads UI<br/>form widgets<br/>[FileUpload.tsx]"]
  node_admin_page["Admin Console<br/>operator page<br/>[page.js]"]
  node_admin_login["Admin Login<br/>admin auth page<br/>[page.js]"]
end

subgraph group_api["Route APIs"]
  node_register_api["Register API<br/>route handlers<br/>[route.js]"]
  node_registrations_api["Registrations API<br/>read API<br/>[route.js]"]
  node_team_api["Team API<br/>workflow API<br/>[route.js]"]
  node_upload_api["Upload API<br/>file API<br/>[route.js]"]
  node_users_api["Users API<br/>profile API<br/>[route.js]"]
  node_hackathon_api["Hackathon API<br/>phase API<br/>[route.js]"]
  node_admin_api["Admin API<br/>ops API<br/>[route.js]"]
end

subgraph group_backend["Shared Backend"]
  node_auth_core{{"Auth Core<br/>auth middleware<br/>[middleware.js]"}}
  node_server_utils{{"Server Utils<br/>server helpers<br/>[auth.js]"}}
  node_firebase_clients[("Firebase Clients<br/>client/admin SDK<br/>[firebase.js]")]
  node_domain_constants["Domain Consts<br/>config constants<br/>[phases.js]"]
end

subgraph group_infra["Firebase Infra"]
  node_firestore[("Firestore<br/>datastore<br/>[firestore.rules]")]
  node_storage[("Storage<br/>asset store<br/>[storage.rules]")]
  node_firebase_config["Firebase Config<br/>deploy config<br/>[firebase.json]"]
end

subgraph group_ops["Admin & Ops"]
  node_ops_scripts["Ops Scripts<br/>maintenance scripts<br/>[init-db-once.cjs]"]
end

node_home -->|"start registration"| node_registration_portal
node_home -->|"sign in"| node_auth_page
node_auth_page -->|"session entry"| node_dashboard_page
node_auth_page -->|"team access"| node_team_page
node_registration_portal -->|"hackathon"| node_hackathon_form
node_registration_portal -->|"workshop"| node_workshop_form
node_hackathon_form -->|"attach files"| node_uploads_ui
node_workshop_form -->|"attach files"| node_uploads_ui
node_hackathon_form -->|"submit"| node_register_api
node_workshop_form -->|"submit"| node_register_api
node_register_api -->|"persist/read"| node_registrations_api
node_team_page -->|"workflow calls"| node_team_api
node_dashboard_page -->|"profile"| node_users_api
node_uploads_ui -->|"upload"| node_upload_api
node_hackathon_api -->|"phases"| node_domain_constants
node_register_api -->|"write records"| node_firestore
node_team_api -->|"team state"| node_firestore
node_upload_api -->|"store files"| node_storage
node_users_api -->|"read/write profile"| node_firestore
node_admin_page -->|"ops actions"| node_admin_api
node_admin_login -->|"admin auth"| node_auth_core
node_admin_api -->|"shared logic"| node_server_utils
node_auth_core -->|"verify claims"| node_firebase_clients
node_server_utils -->|"backend access"| node_firebase_clients
node_firebase_clients -->|"admin sdk"| node_firestore
node_firebase_clients -->|"admin sdk"| node_storage
node_firebase_config -->|"rules/indexes"| node_firestore
node_firebase_config -->|"rules"| node_storage
node_ops_scripts -->|"maintain"| node_firebase_config
node_ops_scripts -->|"backfill/cleanup"| node_firestore

click node_home "https://github.com/saiabhinav001/ai_4_impact/blob/main/src/app/page.tsx"
click node_auth_page "https://github.com/saiabhinav001/ai_4_impact/blob/main/src/app/auth/page.jsx"
click node_dashboard_page "https://github.com/saiabhinav001/ai_4_impact/blob/main/src/app/dashboard/page.jsx"
click node_team_page "https://github.com/saiabhinav001/ai_4_impact/blob/main/src/app/team/page.jsx"
click node_registration_portal "https://github.com/saiabhinav001/ai_4_impact/blob/main/src/components/registration/RegistrationPortal.tsx"
click node_hackathon_form "https://github.com/saiabhinav001/ai_4_impact/blob/main/src/components/registration/HackathonForm.tsx"
click node_workshop_form "https://github.com/saiabhinav001/ai_4_impact/blob/main/src/components/registration/WorkshopForm.tsx"
click node_uploads_ui "https://github.com/saiabhinav001/ai_4_impact/blob/main/src/components/registration/FileUpload.tsx"
click node_admin_page "https://github.com/saiabhinav001/ai_4_impact/blob/main/src/app/admin/page.js"
click node_admin_login "https://github.com/saiabhinav001/ai_4_impact/blob/main/src/app/admin/login/page.js"
click node_register_api "https://github.com/saiabhinav001/ai_4_impact/blob/main/src/app/api/register/route.js"
click node_registrations_api "https://github.com/saiabhinav001/ai_4_impact/blob/main/src/app/api/registrations/hackathon/route.js"
click node_team_api "https://github.com/saiabhinav001/ai_4_impact/blob/main/src/app/api/team/access/resolve/route.js"
click node_upload_api "https://github.com/saiabhinav001/ai_4_impact/blob/main/src/app/api/upload/route.js"
click node_users_api "https://github.com/saiabhinav001/ai_4_impact/blob/main/src/app/api/users/profile/route.js"
click node_hackathon_api "https://github.com/saiabhinav001/ai_4_impact/blob/main/src/app/api/hackathon/phase/route.js"
click node_admin_api "https://github.com/saiabhinav001/ai_4_impact/blob/main/src/app/api/admin/analytics/route.js"
click node_auth_core "https://github.com/saiabhinav001/ai_4_impact/blob/main/middleware.js"
click node_server_utils "https://github.com/saiabhinav001/ai_4_impact/blob/main/lib/server/auth.js"
click node_firebase_clients "https://github.com/saiabhinav001/ai_4_impact/blob/main/lib/firebase.js"
click node_domain_constants "https://github.com/saiabhinav001/ai_4_impact/blob/main/lib/constants/phases.js"
click node_firestore "https://github.com/saiabhinav001/ai_4_impact/blob/main/firestore.rules"
click node_storage "https://github.com/saiabhinav001/ai_4_impact/blob/main/storage.rules"
click node_firebase_config "https://github.com/saiabhinav001/ai_4_impact/blob/main/firebase.json"
click node_ops_scripts "https://github.com/saiabhinav001/ai_4_impact/blob/main/scripts/init-db-once.cjs"

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_home,node_auth_page,node_dashboard_page,node_team_page,node_registration_portal,node_hackathon_form,node_workshop_form,node_uploads_ui,node_admin_page,node_admin_login toneBlue
class node_register_api,node_registrations_api,node_team_api,node_upload_api,node_users_api,node_hackathon_api,node_admin_api toneAmber
class node_auth_core,node_server_utils,node_firebase_clients,node_domain_constants toneMint
class node_firestore,node_storage,node_firebase_config toneRose
class node_ops_scripts toneIndigo
```

## Components

### App UI

Public routes and reusable registration components in the Next.js app router.

- [Home](https://github.com/saiabhinav001/ai_4_impact/blob/main/src/app/page.tsx): public page · Landing route that routes users into registration or account flows. · `src/app/page.tsx`
- [Auth](https://github.com/saiabhinav001/ai_4_impact/blob/main/src/app/auth/page.jsx): login page · Authentication entry point for participants and admins. · `src/app/auth/page.jsx`
- [Dashboard](https://github.com/saiabhinav001/ai_4_impact/blob/main/src/app/dashboard/page.jsx): protected page · User dashboard for post-registration status and actions. · `src/app/dashboard/page.jsx`
- [Team](https://github.com/saiabhinav001/ai_4_impact/blob/main/src/app/team/page.jsx): team page · Team workflow page for access, selection, and submission actions. · `src/app/team/page.jsx`
- [Reg Portal](https://github.com/saiabhinav001/ai_4_impact/blob/main/src/components/registration/RegistrationPortal.tsx): registration shell · Reusable registration experience that switches between event types and steps. · `src/components/registration/RegistrationPortal.tsx`
- [Hackathon Form](https://github.com/saiabhinav001/ai_4_impact/blob/main/src/components/registration/HackathonForm.tsx): registration form · Participant registration form for the hackathon flow. · `src/components/registration/HackathonForm.tsx`
- [Workshop Form](https://github.com/saiabhinav001/ai_4_impact/blob/main/src/components/registration/WorkshopForm.tsx): registration form · Participant registration form for the workshop flow. · `src/components/registration/WorkshopForm.tsx`
- [Uploads UI](https://github.com/saiabhinav001/ai_4_impact/blob/main/src/components/registration/FileUpload.tsx): form widgets · Shared file upload and payment UI used during registration and submission. · `src/components/registration/FileUpload.tsx`
- [Admin Console](https://github.com/saiabhinav001/ai_4_impact/blob/main/src/app/admin/page.js): operator page · Privileged console for reviewing registrations, submissions, analytics, and verification tasks. · `src/app/admin/page.js`
- [Admin Login](https://github.com/saiabhinav001/ai_4_impact/blob/main/src/app/admin/login/page.js): admin auth page · Dedicated login entry for the administrative console. · `src/app/admin/login/page.js`

### Route APIs

Next.js route handlers for registration, team, upload, user, hackathon, and admin workflows.

- [Register API](https://github.com/saiabhinav001/ai_4_impact/blob/main/src/app/api/register/route.js): route handlers · Backend entry for creating registration records and handling registration variants. · `src/app/api/register/route.js`
- [Registrations API](https://github.com/saiabhinav001/ai_4_impact/blob/main/src/app/api/registrations/hackathon/route.js): read API · Registration retrieval endpoints for hackathon and workshop records. · `src/app/api/registrations/hackathon/route.js`
- [Team API](https://github.com/saiabhinav001/ai_4_impact/blob/main/src/app/api/team/access/resolve/route.js): workflow API · Team access, dashboard, selection, and submission endpoints. · `src/app/api/team/access/resolve/route.js`
- [Upload API](https://github.com/saiabhinav001/ai_4_impact/blob/main/src/app/api/upload/route.js): file API · Upload endpoints for payment screenshots and PPT artifacts. · `src/app/api/upload/route.js`
- [Users API](https://github.com/saiabhinav001/ai_4_impact/blob/main/src/app/api/users/profile/route.js): profile API · User profile endpoint used by authenticated flows. · `src/app/api/users/profile/route.js`
- [Hackathon API](https://github.com/saiabhinav001/ai_4_impact/blob/main/src/app/api/hackathon/phase/route.js): phase API · Event phase and timeline endpoints that gate user and team behavior. · `src/app/api/hackathon/phase/route.js`
- [Admin API](https://github.com/saiabhinav001/ai_4_impact/blob/main/src/app/api/admin/analytics/route.js): ops API · Administrative endpoints for analytics, review, credentialing, verification, and init tasks. · `src/app/api/admin/analytics/route.js`

### Shared Backend

Auth, Firebase wrappers, server helpers, and domain constants shared across routes.

- [Auth Core](https://github.com/saiabhinav001/ai_4_impact/blob/main/middleware.js): auth middleware · Request-time auth and role checks for user and admin paths. · `middleware.js`
- [Server Utils](https://github.com/saiabhinav001/ai_4_impact/blob/main/lib/server/auth.js): server helpers · Shared server-side logic for auth and hackathon domain behavior. · `lib/server/auth.js`
- [Firebase Clients](https://github.com/saiabhinav001/ai_4_impact/blob/main/lib/firebase.js): client/admin SDK · Client and admin Firebase wrappers used by server and browser code. · `lib/firebase.js`
- [Domain Consts](https://github.com/saiabhinav001/ai_4_impact/blob/main/lib/constants/phases.js): config constants · Centralized role and phase definitions used across UI and server flows. · `lib/constants/phases.js`

### Firebase Infra

Firebase services, security rules, and deployment/runtime configuration.

- [Firestore](https://github.com/saiabhinav001/ai_4_impact/blob/main/firestore.rules): datastore · Primary application database for registrations, teams, users, and admin state. · `firestore.rules`
- [Storage](https://github.com/saiabhinav001/ai_4_impact/blob/main/storage.rules): asset store · Firebase Storage for uploaded screenshots and presentation files. · `storage.rules`
- [Firebase Config](https://github.com/saiabhinav001/ai_4_impact/blob/main/firebase.json): deploy config · Firebase project wiring, indexes, and runtime deployment configuration. · `firebase.json`

### Admin & Ops

Operator console and maintenance scripts for the live event system.

- [Ops Scripts](https://github.com/saiabhinav001/ai_4_impact/blob/main/scripts/init-db-once.cjs): maintenance scripts · One-off scripts for backfills, cleanup, initialization, and credential operations. · `scripts/init-db-once.cjs`

## Connections

- Home → Reg Portal: start registration · Landing users into the main participant flow.
- Home → Auth: sign in · Routes unauthenticated users to authentication.
- Auth → Dashboard: session entry · Authenticated users proceed to protected pages.
- Auth → Team: team access · Authenticated users can enter team workflows.
- Reg Portal → Hackathon Form: hackathon · Switches the portal into hackathon registration.
- Reg Portal → Workshop Form: workshop · Switches the portal into workshop registration.
- Hackathon Form → Uploads UI: attach files · Uses shared upload and payment controls.
- Workshop Form → Uploads UI: attach files · Uses shared upload and payment controls.
- Hackathon Form → Register API: submit · Creates hackathon registration records.
- Workshop Form → Register API: submit · Creates workshop registration records.
- Register API → Registrations API: persist/read · Registration data is stored and later retrieved through domain endpoints.
- Team → Team API: workflow calls · Team access, dashboard, selection, and submission actions.
- Dashboard → Users API: profile · Reads authenticated user profile state.
- Uploads UI → Upload API: upload · Sends screenshots and PPTs to the file backend.
- Hackathon API → Domain Consts: phases · Uses phase and timeline definitions to gate behavior.
- Register API → Firestore: write records · Registration writes go to the primary database.
- Team API → Firestore: team state · Team access and submission state are persisted in Firestore.
- Upload API → Storage: store files · Uploaded artifacts are stored in Firebase Storage.
- Users API → Firestore: read/write profile · User profile data is sourced from Firestore.
- Admin Console → Admin API: ops actions · Console actions call privileged administrative endpoints.
- Admin Login → Auth Core: admin auth · Admin sign-in is protected by request-time auth checks.
- Admin API → Server Utils: shared logic · Admin handlers depend on server-side auth and helper utilities.
- Auth Core → Firebase Clients: verify claims · Auth middleware relies on Firebase admin/client capabilities.
- Server Utils → Firebase Clients: backend access · Server helpers use Firebase wrappers for privileged operations.
- Firebase Clients → Firestore: admin sdk · Privileged server access to Firestore.
- Firebase Clients → Storage: admin sdk · Privileged server access to Storage.
- Firebase Config → Firestore: rules/indexes · Deployment config governs database behavior and indexing.
- Firebase Config → Storage: rules · Deployment config governs storage access control.
- Ops Scripts → Firebase Config: maintain · Scripts operate on Firebase configuration and data lifecycle.
- Ops Scripts → Firestore: backfill/cleanup · Maintenance scripts mutate and inspect production data.
