How garg-tejas/blood-report-parser works
1. Overall shape
- BloodParser is a Next.js App Router application with a thin server-side API layer and a mostly client-driven dashboard UI.
- The main architecture is: file upload → AI extraction → normalized biomarker results → interactive insights/chat/export.
2. Top-level application boundary
- app/layout.tsx, app/page.tsx, and app/globals.css define the single-page dashboard shell.
- app/page.tsx is the likely orchestration point for the upload workflow, results display, insights panel, and chat drawer.
3. User input subsystem
- components/upload-zone.tsx is the entry point for PDF/image uploads.
- The repo supports report images and PDFs up to 10MB, so the UI boundary is designed around asynchronous file ingestion rather than form-style input.
4. Analysis backend
- app/api/analyze/route.ts is the core processing endpoint.
- Per the README, it implements a dual pipeline:
- OCR-first path: GLM-OCR document parsing, then Gemini structured extraction.
- Fallback path: direct Gemini Vision multimodal extraction for faster/free-tier usage.
- This route is the primary integration boundary to external AI services.
5. OCR access control
- app/api/verify-ocr/route.ts exists specifically to gate the OCR path.
- The README indicates security controls here: timing-safe passphrase comparison, per-IP cooldown tracking, and a temporary lockout after failed attempts.
- Architecturally, this separates “can use secure OCR mode” from the actual extraction pipeline.
6. Report data model and derived scoring
- components/results-panel.tsx and components/results-display.tsx render the extracted biomarkers and summary state.
- The dashboard computes a health score from categorized biomarkers, then presents counts for normal/borderline/abnormal results.
- That means the UI is not a passive renderer; it also performs a meaningful client-side derivation from normalized analysis output.
7. Clinical interpretation layer
- components/insights-panel.tsx and components/mobile-insights-sheet.tsx provide contextual explanations for biomarkers.
- The design suggests a two-pane information model: the left side shows biomarker cards, while the right side shows explanations that update on hover/click.
- This is the main “understanding” layer between raw extraction and user-facing interpretation.
8. AI assistant subsystem
- components/chat-drawer.tsx and components/chat-interface.tsx back the contextual chat experience.
- app/api/chat/route.ts is the server endpoint that answers questions using full report context plus selected biomarker context.
- This is a separate conversation boundary from report extraction, which keeps Q&A isolated from the ingestion pipeline.
9. Export and review utilities
- components/export-modal.tsx and lib/export-utils.ts indicate a reporting/export boundary for packaging results.
- Even without user accounts or persistence, the app is designed to let users review and likely export analysis artifacts from the dashboard state.
10. Shared UI and responsiveness
- components/ui/* is a large Radix-based design system used across dialogs, drawers, sheets, tables, tabs, toasts, and other primitives.
- components/theme-provider.tsx, hooks/use-mobile.ts, and hooks/use-toast.ts support theme, responsive behavior, and feedback.
- The presence of drawer/sheet/mobile-specific components shows the UI is intentionally split between desktop split-pane and mobile stacked layouts.
11. External dependencies that shape architecture
- The important runtime stack is Node.js + Next.js 16 + React 19 + Tailwind CSS 4.
- AI integration depends on Google Generative AI and GLM-OCR (Z.ai).
- react-markdown/remark-gfm implies chat or insight content can include rendered markdown, which affects how responses are displayed.
12. Configuration and deployment boundaries
- .env.example shows the app is environment-driven, with keys for at least Gemini, ZAI/OCR, and the OCR passphrase.
- The repo is positioned for Vercel deployment, which fits the serverless API route model used by app/api/*.
13. What an architecture diagram should show
- One clear path from upload UI → analyze API → AI providers → normalized report state → results/insights/chat UI.
- A second, separate path for OCR verification → gated OCR analyze flow.
- A shared UI layer of reusable components and a shared utility layer (lib/*) underneath the dashboard experience.
Main entry points: page.tsx Dashboard · results-panel.tsx Results panel · route.ts Analyze API · layout.tsx Layout
Components 22
App shell
Next.js App Router surface and API routes
- Layout · Root document shell and providers
app/layout.tsx - Dashboard · Main orchestration for upload, results, insights, and chat
app/page.tsx - Global styles · App-wide styling layer
app/globals.css - Analyze API · Dual pipeline extraction endpoint with OCR-first and vision fallback
app/api/analyze/route.ts - Chat API · Contextual assistant endpoint over report data
app/api/chat/route.ts - OCR verify · Gates access to secure OCR mode with cooldown and lockout
app/api/verify-ocr/route.ts
Dashboard UI
Primary interactive dashboard components
- Upload zone · PDF and image upload entry point
components/upload-zone.tsx - Results panel · Primary biomarker summary and status view
components/results-panel.tsx - Results display · Detailed normalized biomarker rendering
components/results-display.tsx - Insights panel · Clinical explanations for selected biomarkers
components/insights-panel.tsx - Mobile sheet · Mobile-friendly insights presentation
components/mobile-insights-sheet.tsx - Chat drawer · Contextual chat container for report questions
components/chat-drawer.tsx - Chat interface · Conversation view and message composition
components/chat-interface.tsx - Export modal · Dashboard export and review dialog
components/export-modal.tsx - OCR unlock · Passphrase dialog for unlocking OCR path
components/ocr-unlock-dialog.tsx
Shared primitives
Design system, hooks, and utilities
- Theme provider · Theme and color-mode wiring
components/theme-provider.tsx - UI kit · Reusable Radix-based primitives across the dashboard
components/ui - use-mobile · Responsive layout detection
hooks/use-mobile.ts - use-toast · Toast notification state
hooks/use-toast.ts - Utils · Shared helper functions
lib/utils.ts
Core logic
Reusable parsing and export helpers
- Export utils · Formatting and packaging support for exports
lib/export-utils.ts - GLM-OCR · OCR integration helper for document parsing
lib/glm-ocr.ts
Connections 27
- Layout → Dashboard: renders · Root shell hosts the dashboard page
- Layout → Theme provider: wraps · Provides app-wide theme context
- Layout → Global styles: loads · Global styling is applied at the document level
- Dashboard → Upload zone: starts · Upload workflow begins here
- Dashboard → Results panel: shows · Primary analysis summary is displayed in the page shell
- Dashboard → Insights panel: shows · Insight pane is part of the main dashboard
- Dashboard → Chat drawer: opens · Chat experience is launched from the dashboard
- Dashboard → Export modal: exports · Review/export actions are surfaced from the page
- Dashboard → OCR unlock: unlocks · OCR access flow is initiated from the dashboard
- Upload zone → Analyze API: uploads · Files are sent to the analysis endpoint
- OCR unlock → OCR verify: verifies · Passphrase checks are handled by the verify route
- OCR verify → Analyze API: gates · Successful verification enables the OCR-first path
- Analyze API → GLM-OCR: ocr-first · Document parsing begins with OCR when enabled
- Analyze API → Chat API: context feed · Normalized report state becomes chat context
- Results panel → Results display: drills into · Summary state expands into detailed biomarker view
- Results panel → Insights panel: selects · Chosen biomarker drives contextual explanation
- Results panel → Mobile sheet: adapts · Mobile presentation mirrors the insight model
- Chat drawer → Chat interface: contains · Drawer hosts the conversation UI
- Chat interface → Chat API: queries · Questions are answered by the server endpoint
- Export modal → Export utils: formats · Export packaging uses shared helpers
- Results panel → Export utils: feeds · Current report state is prepared for export
- UI kit → Results panel: builds · Dashboard surfaces use shared primitives
- UI kit → Chat drawer: builds · Drawer and dialog behavior rely on the design system
- UI kit → OCR unlock: builds · Security prompt uses shared primitives
- use-mobile → Mobile sheet: drives · Responsive branching selects the mobile sheet
- use-toast → Dashboard: notifies · Feedback/toast state supports dashboard actions
- Utils → Dashboard: supports · General helpers are used by the dashboard layer