# nikhil-2x/summerhacks architecture

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

- Interactive diagram: https://gitdiagram.com/nikhil-2x/summerhacks
- Repository: https://github.com/nikhil-2x/summerhacks

## Overview

1. **Overall shape**
   - This is a Next.js 14 App Router application with a clear split between UI pages/components and server-side route handlers.
   - The runtime is TypeScript/React on the frontend, with Next.js API routes handling OCR, AI analysis, chat, auth, and lookup services.

2. **Primary user-facing surfaces**
   - `app/page.tsx` and `components/homeclient.tsx` form the main landing/workflow surface for uploading reports and viewing results.
   - Separate route pages exist for `login`, `signup`, and `clinics`, so the app is not just a single dashboard; it has distinct entry points for auth and clinic discovery.

3. **Core report-processing flow**
   - The main data path is: user uploads a blood report through `components/upload-zone.tsx` → server OCR/analysis endpoints process the file → structured results are rendered in `components/results-display.tsx`, `results-panel.tsx`, and `insights-panel.tsx`.
   - `app/api/verify-ocr/route.ts` suggests a correction/validation step after OCR, before or alongside downstream analysis.

4. **Server API boundary**
   - All backend capabilities are exposed via `app/api/*` route handlers, including:
     - `/api/analyze` for blood report analysis
     - `/api/analyze-menu` for dietary/menu interpretation
     - `/api/chat` for conversational health guidance
     - `/api/clinics` and `/api/clinic-details` for clinic/specialist lookup
     - `/api/patient/insight` for patient-specific insights
     - `/api/auth/[...all]` for authentication/session endpoints
   - This keeps the UI thin and pushes sensitive logic, AI calls, and data access behind server boundaries.

5. **AI and OCR subsystem**
   - `lib/glm-ocr.ts` and the README indicate OCR plus Google Generative AI-backed interpretation.
   - The architecture likely uses OCR to extract text/values from uploaded blood reports, then sends normalized data to AI analysis endpoints that produce structured insights and explanations for the UI.

6. **Chat and voice consultation**
   - `components/chat-interface.tsx`, `chat-drawer.tsx`, and `/api/chat` form the text-chat subsystem.
   - `components/VoiceDoctor.tsx` plus `lib/vapi.json` indicate a separate real-time voice agent path, integrated with Vapi/Daily-style calling infrastructure for live consultations.

7. **Clinic and patient guidance**
   - The clinic subsystem is separate from the report analysis flow: `/api/clinics` and `/api/clinic-details` provide location/specialist information, while `/api/patient/insight` appears to tailor outputs based on patient context.
   - The README’s “nearest specialist healthcare location” feature suggests this is a post-analysis recommendation layer, not part of OCR itself.

8. **Authentication and session management**
   - Auth is implemented with `lib/auth.ts`, `lib/auth-client.ts`, and the catch-all auth route.
   - The app uses database-backed sessions/accounts via Prisma, so authenticated access is a first-class boundary around analysis history, insights, and possibly exports/chat.

9. **Persistence layer**
   - `prisma/schema.prisma` and `lib/db.ts` define the database boundary, with PostgreSQL as the backing store.
   - The visible schema emphasis is on auth entities such as User, Session, and Account, which means persistence is likely focused on identity/session state and whatever application records are stored around analysis workflows.

10. **Shared UI system**
   - `components/ui/*` is a large reusable design system built on Radix UI primitives and styled with Tailwind CSS.
   - Higher-level composites like drawers, sheets, dialogs, modals, tables, and charts are used to present results, mobile-friendly insights, and interactive workflows.

11. **Export and utility layer**
   - `lib/export-utils.ts` plus `components/export-modal.tsx` suggest a dedicated export path for report outputs and analysis summaries.
   - `lib/utils.ts` and the hook utilities provide common formatting, responsive behavior, and state helpers used across the app.

12. **Responsive/mobile behavior**
   - The presence of `mobile-insights-sheet.tsx`, drawers, sheets, and `hooks/use-mobile.ts` shows that the app intentionally splits certain experiences into desktop panels versus mobile overlays.
   - This is important for the architecture diagram because insights, chat, and analysis are presented as adaptive UI layers rather than a single fixed layout.

13. **Static and supporting assets**
   - `public/` holds static assets, while `sample reports/` likely provides demo/test inputs for OCR and analysis flows.
   - `https/first.http` is a manual request file for exercising endpoints during development.

14. **Key architectural takeaway**
   - The repo is organized around a single pipeline: authenticated upload/analysis on the server, AI/OCR enrichment in the middle, and rich client-side presentation on the front end.
   - The main boundaries to show in a diagram are: UI shell, API/service layer, persistence/auth, and external AI/voice providers.

Main entry points: [`components/homeclient.tsx`](https://github.com/nikhil-2x/summerhacks/blob/main/components/homeclient.tsx) (Home client), [`components/ui`](https://github.com/nikhil-2x/summerhacks/tree/main/components/ui) (UI primitives), [`app/api/analyze/route.ts`](https://github.com/nikhil-2x/summerhacks/blob/main/app/api/analyze/route.ts) (Analyze API), [`lib/db.ts`](https://github.com/nikhil-2x/summerhacks/blob/main/lib/db.ts) (Database)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_app_page["Home<br/>page<br/>[page.tsx]"]
  node_home_client["Home client<br/>client component<br/>[homeclient.tsx]"]
  node_upload_zone["Upload zone<br/>upload ui<br/>[upload-zone.tsx]"]
  node_results_display["Results display<br/>results ui"]
  node_results_panel["Results panel<br/>results ui<br/>[results-panel.tsx]"]
  node_insights_panel["Insights panel<br/>insights ui<br/>[insights-panel.tsx]"]
  node_chat_interface["Chat interface<br/>chat ui<br/>[chat-interface.tsx]"]
  node_chat_drawer["Chat drawer<br/>overlay ui<br/>[chat-drawer.tsx]"]
  node_voice_doctor["Voice doctor<br/>voice ui<br/>[VoiceDoctor.tsx]"]
  node_auth_form["Auth form<br/>auth ui<br/>[auth-form.tsx]"]
  node_clinics_page["Clinics<br/>page<br/>[page.tsx]"]
  node_login_page["Login<br/>page<br/>[page.tsx]"]
  node_signup_page["Signup<br/>page<br/>[page.tsx]"]
end

subgraph group_server["Server APIs"]
  node_api_analyze["Analyze API<br/>route handler<br/>[route.ts]"]
  node_api_verify_ocr["Verify OCR<br/>route handler<br/>[route.ts]"]
  node_api_chat["Chat API<br/>route handler<br/>[route.ts]"]
  node_api_clinics["Clinics API<br/>route handler<br/>[route.ts]"]
  node_api_patient_insight["Patient insight API<br/>route handler<br/>[route.ts]"]
  node_api_auth["Auth API<br/>route handler<br/>[route.ts]"]
  node_api_menu_analyze["Menu API<br/>route handler<br/>[route.ts]"]
  node_api_clinic_details["Clinic details API<br/>route handler<br/>[route.ts]"]
end

subgraph group_platform["Platform"]
  node_glm_ocr["GLM OCR<br/>ocr library<br/>[glm-ocr.ts]"]
  node_auth_lib["Auth core<br/>auth library<br/>[auth.ts]"]
  node_auth_client["Auth client<br/>client auth<br/>[auth-client.ts]"]
  node_db[("Database<br/>db layer<br/>[db.ts]")]
  node_export_utils["Export utils<br/>export helpers<br/>[export-utils.ts]"]
  node_vapi_config["Vapi config<br/>voice config<br/>[vapi.json]"]
  node_schema["Prisma schema<br/>data model<br/>[schema.prisma]"]
end

subgraph group_ui["UI Kit"]
  node_ui_kit["UI primitives<br/>design system"]
end

node_app_page -->|"renders"| node_home_client
node_home_client -->|"uses"| node_upload_zone
node_home_client -->|"shows"| node_results_display
node_home_client -->|"routes to"| node_results_panel
node_home_client -->|"routes to"| node_insights_panel
node_upload_zone -->|"submits to"| node_api_analyze
node_api_analyze -->|"extracts with"| node_glm_ocr
node_api_analyze -->|"validates via"| node_api_verify_ocr
node_api_analyze -->|"persists"| node_db
node_results_display -->|"exports"| node_export_utils
node_chat_interface -->|"sends messages to"| node_api_chat
node_chat_drawer -->|"wraps"| node_chat_interface
node_voice_doctor -->|"configured by"| node_vapi_config
node_clinics_page -->|"loads"| node_api_clinics
node_api_clinics -->|"expands to"| node_api_clinic_details
node_login_page -->|"renders"| node_auth_form
node_signup_page -->|"renders"| node_auth_form
node_api_auth -->|"uses"| node_auth_lib
node_auth_form -->|"uses"| node_auth_client
node_auth_lib -->|"reads/writes"| node_db
node_db -->|"defined by"| node_schema
node_api_patient_insight -->|"reads"| node_db
node_api_menu_analyze -->|"interprets with"| node_glm_ocr
node_ui_kit -.->|"supports"| node_home_client
node_ui_kit -.->|"supports"| node_chat_interface
node_ui_kit -.->|"supports"| node_results_panel
node_ui_kit -.->|"supports"| node_insights_panel

click node_app_page "https://github.com/nikhil-2x/summerhacks/blob/main/app/page.tsx"
click node_home_client "https://github.com/nikhil-2x/summerhacks/blob/main/components/homeclient.tsx"
click node_upload_zone "https://github.com/nikhil-2x/summerhacks/blob/main/components/upload-zone.tsx"
click node_results_display "https://github.com/nikhil-2x/summerhacks/blob/main/components/results-display.tsx"
click node_results_panel "https://github.com/nikhil-2x/summerhacks/blob/main/components/results-panel.tsx"
click node_insights_panel "https://github.com/nikhil-2x/summerhacks/blob/main/components/insights-panel.tsx"
click node_chat_interface "https://github.com/nikhil-2x/summerhacks/blob/main/components/chat-interface.tsx"
click node_chat_drawer "https://github.com/nikhil-2x/summerhacks/blob/main/components/chat-drawer.tsx"
click node_voice_doctor "https://github.com/nikhil-2x/summerhacks/blob/main/components/VoiceDoctor.tsx"
click node_auth_form "https://github.com/nikhil-2x/summerhacks/blob/main/components/auth/auth-form.tsx"
click node_clinics_page "https://github.com/nikhil-2x/summerhacks/blob/main/app/clinics/page.tsx"
click node_login_page "https://github.com/nikhil-2x/summerhacks/blob/main/app/login/page.tsx"
click node_signup_page "https://github.com/nikhil-2x/summerhacks/blob/main/app/signup/page.tsx"
click node_api_analyze "https://github.com/nikhil-2x/summerhacks/blob/main/app/api/analyze/route.ts"
click node_api_verify_ocr "https://github.com/nikhil-2x/summerhacks/blob/main/app/api/verify-ocr/route.ts"
click node_api_chat "https://github.com/nikhil-2x/summerhacks/blob/main/app/api/chat/route.ts"
click node_api_clinics "https://github.com/nikhil-2x/summerhacks/blob/main/app/api/clinics/route.ts"
click node_api_patient_insight "https://github.com/nikhil-2x/summerhacks/blob/main/app/api/patient/insight/route.ts"
click node_api_auth "https://github.com/nikhil-2x/summerhacks/blob/main/app/api/auth/[...all]/route.ts"
click node_api_menu_analyze "https://github.com/nikhil-2x/summerhacks/blob/main/app/api/analyze-menu/route.ts"
click node_api_clinic_details "https://github.com/nikhil-2x/summerhacks/blob/main/app/api/clinic-details/route.ts"
click node_glm_ocr "https://github.com/nikhil-2x/summerhacks/blob/main/lib/glm-ocr.ts"
click node_auth_lib "https://github.com/nikhil-2x/summerhacks/blob/main/lib/auth.ts"
click node_auth_client "https://github.com/nikhil-2x/summerhacks/blob/main/lib/auth-client.ts"
click node_db "https://github.com/nikhil-2x/summerhacks/blob/main/lib/db.ts"
click node_export_utils "https://github.com/nikhil-2x/summerhacks/blob/main/lib/export-utils.ts"
click node_vapi_config "https://github.com/nikhil-2x/summerhacks/blob/main/lib/vapi.json"
click node_schema "https://github.com/nikhil-2x/summerhacks/blob/main/prisma/schema.prisma"
click node_ui_kit "https://github.com/nikhil-2x/summerhacks/tree/main/components/ui"

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_app_page,node_home_client,node_upload_zone,node_results_display,node_results_panel,node_insights_panel,node_chat_interface,node_chat_drawer,node_voice_doctor,node_auth_form,node_clinics_page,node_login_page,node_signup_page toneBlue
class node_api_analyze,node_api_verify_ocr,node_api_chat,node_api_clinics,node_api_patient_insight,node_api_auth,node_api_menu_analyze,node_api_clinic_details toneAmber
class node_glm_ocr,node_auth_lib,node_auth_client,node_db,node_export_utils,node_vapi_config,node_schema toneMint
class node_ui_kit toneRose
```

## Components

### Frontend

App Router pages and client components

- [Home](https://github.com/nikhil-2x/summerhacks/blob/main/app/page.tsx): page · Main entry page for upload and report workflow · `app/page.tsx`
- [Home client](https://github.com/nikhil-2x/summerhacks/blob/main/components/homeclient.tsx): client component · Orchestrates upload, analysis state, and results display · `components/homeclient.tsx`
- [Upload zone](https://github.com/nikhil-2x/summerhacks/blob/main/components/upload-zone.tsx): upload ui · Blood report upload and file intake surface · `components/upload-zone.tsx`
- [Results display](https://github.com/nikhil-2x/summerhacks/blob/main/components/results-display.tsx): results ui · Primary structured output for analyzed reports · `components/results-display.tsx`
- [Results panel](https://github.com/nikhil-2x/summerhacks/blob/main/components/results-panel.tsx): results ui · Tabbed or panel-based presentation of analysis output · `components/results-panel.tsx`
- [Insights panel](https://github.com/nikhil-2x/summerhacks/blob/main/components/insights-panel.tsx): insights ui · Clinical insights and interpretation view · `components/insights-panel.tsx`
- [Chat interface](https://github.com/nikhil-2x/summerhacks/blob/main/components/chat-interface.tsx): chat ui · Text-based health guidance conversation surface · `components/chat-interface.tsx`
- [Chat drawer](https://github.com/nikhil-2x/summerhacks/blob/main/components/chat-drawer.tsx): overlay ui · Drawer wrapper for chat on smaller screens · `components/chat-drawer.tsx`
- [Voice doctor](https://github.com/nikhil-2x/summerhacks/blob/main/components/VoiceDoctor.tsx): voice ui · Real-time voice consultation client · `components/VoiceDoctor.tsx`
- [Auth form](https://github.com/nikhil-2x/summerhacks/blob/main/components/auth/auth-form.tsx): auth ui · Login and signup form component · `components/auth/auth-form.tsx`
- [Clinics](https://github.com/nikhil-2x/summerhacks/blob/main/app/clinics/page.tsx): page · Clinic discovery and specialist lookup page · `app/clinics/page.tsx`
- [Login](https://github.com/nikhil-2x/summerhacks/blob/main/app/login/page.tsx): page · Authentication entry page · `app/login/page.tsx`
- [Signup](https://github.com/nikhil-2x/summerhacks/blob/main/app/signup/page.tsx): page · Account creation entry page · `app/signup/page.tsx`

### Server APIs

Route handlers for OCR, AI, chat, auth, and lookups

- [Analyze API](https://github.com/nikhil-2x/summerhacks/blob/main/app/api/analyze/route.ts): route handler · Main report analysis endpoint · `app/api/analyze/route.ts`
- [Verify OCR](https://github.com/nikhil-2x/summerhacks/blob/main/app/api/verify-ocr/route.ts): route handler · OCR correction and validation step · `app/api/verify-ocr/route.ts`
- [Chat API](https://github.com/nikhil-2x/summerhacks/blob/main/app/api/chat/route.ts): route handler · Conversational health guidance endpoint · `app/api/chat/route.ts`
- [Clinics API](https://github.com/nikhil-2x/summerhacks/blob/main/app/api/clinics/route.ts): route handler · Clinic and specialist lookup endpoint · `app/api/clinics/route.ts`
- [Patient insight API](https://github.com/nikhil-2x/summerhacks/blob/main/app/api/patient/insight/route.ts): route handler · Patient-specific insight generation endpoint · `app/api/patient/insight/route.ts`
- [Auth API](https://github.com/nikhil-2x/summerhacks/blob/main/app/api/auth/[...all]/route.ts): route handler · Catch-all authentication and session endpoint · `app/api/auth/[...all]/route.ts`
- [Menu API](https://github.com/nikhil-2x/summerhacks/blob/main/app/api/analyze-menu/route.ts): route handler · Dietary or menu interpretation endpoint · `app/api/analyze-menu/route.ts`
- [Clinic details API](https://github.com/nikhil-2x/summerhacks/blob/main/app/api/clinic-details/route.ts): route handler · Detailed clinic and specialist lookup endpoint · `app/api/clinic-details/route.ts`

### Platform

Shared libraries, database, and external integration config

- [GLM OCR](https://github.com/nikhil-2x/summerhacks/blob/main/lib/glm-ocr.ts): ocr library · OCR and text extraction helper · `lib/glm-ocr.ts`
- [Auth core](https://github.com/nikhil-2x/summerhacks/blob/main/lib/auth.ts): auth library · Server auth configuration and session logic · `lib/auth.ts`
- [Auth client](https://github.com/nikhil-2x/summerhacks/blob/main/lib/auth-client.ts): client auth · Client-side auth helpers · `lib/auth-client.ts`
- [Database](https://github.com/nikhil-2x/summerhacks/blob/main/lib/db.ts): db layer · Database access boundary · `lib/db.ts`
- [Export utils](https://github.com/nikhil-2x/summerhacks/blob/main/lib/export-utils.ts): export helpers · Report export and formatting helpers · `lib/export-utils.ts`
- [Vapi config](https://github.com/nikhil-2x/summerhacks/blob/main/lib/vapi.json): voice config · Voice-agent integration configuration · `lib/vapi.json`
- [Prisma schema](https://github.com/nikhil-2x/summerhacks/blob/main/prisma/schema.prisma): data model · Database schema for auth and app records · `prisma/schema.prisma`

### UI Kit

Reusable design-system primitives

- [UI primitives](https://github.com/nikhil-2x/summerhacks/tree/main/components/ui): design system · Reusable Radix/Tailwind component set · `components/ui`

## Connections

- Home → Home client: renders · The home page mounts the interactive workflow client
- Home client → Upload zone: uses · Upload area starts the report intake flow
- Home client → Results display: shows · Structured analysis results are rendered in the main view
- Home client → Results panel: routes to · Results can be presented in panel form
- Home client → Insights panel: routes to · Clinical insights are shown as a separate view
- Upload zone → Analyze API: submits to · Uploaded report data is sent for analysis
- Analyze API → GLM OCR: extracts with · OCR is used to read report text and values
- Analyze API → Verify OCR: validates via · OCR output can be corrected or checked before final interpretation
- Analyze API → Database: persists · Analysis-related records and sessions can be stored
- Results display → Export utils: exports · Displayed results can be packaged for export
- Chat interface → Chat API: sends messages to · Text chat is backed by the server chat endpoint
- Chat drawer → Chat interface: wraps · Mobile drawer hosts the chat experience
- Voice doctor → Vapi config: configured by · Voice consultation uses the external voice-agent config
- Clinics → Clinics API: loads · Clinic discovery page fetches lookup data
- Clinics API → Clinic details API: expands to · Detailed clinic information is fetched separately
- Login → Auth form: renders · Login page uses the shared auth form
- Signup → Auth form: renders · Signup page uses the shared auth form
- Auth API → Auth core: uses · Server auth routes are implemented with shared auth logic
- Auth form → Auth client: uses · Forms rely on client-side auth helpers
- Auth core → Database: reads/writes · Auth state is backed by the database
- Database → Prisma schema: defined by · Prisma schema defines the persistence model
- Patient insight API → Database: reads · Patient-specific insights can use stored context
- Menu API → GLM OCR: interprets with · Menu analysis reuses AI/OCR style interpretation helpers
- UI primitives → Home client: supports · The client workflow is built from shared UI primitives
- UI primitives → Chat interface: supports · Chat uses the shared component system
- UI primitives → Results panel: supports · Results views are composed from primitives
- UI primitives → Insights panel: supports · Insights presentation is built on the shared design system
