How utkarsharma7/aha works
Purpose and Runtime
This is a Next.js App Router healthcare application serving patient, clinician, practitioner, and administrator workflows. The root entry point is src/app/page.js; global application shell and styling begin at src/app/layout.js and src/app/globals.css. It runs as a Node.js/Next.js application with React client/server components and route handlers.
User-Facing Domains
Patient workflows cover health profiles, records, consultations, challenges, journeys, triage, emergency chat, and AI diagnosis. Key route families are src/app/health-profile-2/page.jsx, src/app/records/page.js, and src/app/ai-diagnose-2/page.js.
Plans are a major domain with separate care, diet, and exercise experiences: src/app/plans/care/page.jsx, src/app/plans/diet/page.jsx, and src/app/plans/exercise/page.jsx. Prescription and lab-report detail pages provide analysis, chat, correction, and plan-related views through src/app/prescription/[id]/page.js and src/app/labreport/[id]/page.js.
API Boundary and Backend Integration
The Next.js API layer is primarily a same-origin proxy boundary under src/app/api/proxy. It exposes domain-specific HTTP routes while isolating browser UI code from backend endpoint addressing and request mechanics; shared backend configuration is centered in src/config/api.js and client access is represented by src/services/api.js.
Proxy routes are organized by healthcare aggregate, including src/app/api/proxy/patient/care_plan/overview/route.js, src/app/api/proxy/patient/diet/plan/propose/route.js, and src/app/api/proxy/modules/[moduleCode]/intake/route.js. Dynamic route segments carry resource identity such as patient, plan, chat, report, phase, and invitation IDs.
Care-Plan and Coaching Lifecycle
Care planning is a staged workflow: retrieve an overview, capture/clarify/confirm goals, generate goal-track phases, review phases, and handle advancement decisions. The public UI and proxy implementation boundaries are src/app/plans/care/page.jsx, src/lib/carePlanProxy.js, and src/app/api/proxy/patient/care_plan/phase/[phaseId]/advancement/suggest/route.js.
Diet planning follows an analogous lifecycle: profile questionnaire → goal analysis/confirmation → proposal/plan confirmation → phase outline/generation → daily logging and coaching check-ins. Relevant paths are src/app/plans/diet/components/GoalsManager.jsx, src/lib/dietProxy.js, and src/app/api/proxy/patient/diet/log/route.js.
Conversations, Clinical Records, and Uploads
Chat is modeled as persistent sessions with start, turn, history/list, and specialized diagnosis, emergency, lab, prescription, triage, and care-episode variants. Core routes include src/app/api/proxy/chat/start/route.js, src/app/api/proxy/diagnosisChat/turn/route.js, and src/app/api/proxy/patient/care-episode/[careEpisodeId]/chats/[chatSessionId]/turn/route.js.
Clinical-document ingestion enters through lab-report and prescription uploads, then flows into report/prescription detail, analysis, correction, and care-episode planning. This boundary is represented by src/app/api/proxy/upload/labreport/route.js, src/app/api/proxy/upload/prescription/route.js, and src/app/api/proxy/prescription/[id]/care-episode/plan/route.js.
Roles, Access, and Operations
Authentication has dedicated API handlers, while role-specific UI shells guard patient and doctor views: src/app/api/auth/authenticate/route.js, src/components/AuthGuard.jsx, and src/components/doctor/DoctorAuthGuard.jsx. Doctor workflows are isolated under src/app/doctor/layout.js; invitations and patient selection support clinician-to-patient relationships.
Administrative observability is a separate surface for LLM calls, chat sessions, and turns, backed by an admin API proxy and service layer: src/app/admin/observability/layout.jsx, src/app/api/admin/[...path]/route.js, and src/services/adminObservabilityApi.js. Feature flags are centralized through src/config/featureFlags.js and src/context/FeatureFlagContext.js.
Main entry points: api.js Backend API client · layout.js App shell · route.js Conversation proxy · page.js Clinical detail views
Components 22
User applications
- App shell · Provides the global application shell and styling.
src/app/layout.js - Home entry
src/app/page.js - Patient workflows · Health profiles, records, consultations, triage, emergency chat, and AI diagnosis.
src/app/health-profile-2/page.jsx - Clinical detail views · Prescription and lab-report analysis, correction, chat, and planning views.
src/app/prescription/[id]/page.js
Planning workflows
- Care plans
src/app/plans/care/page.jsx - Care-plan lifecycle · Coordinates overview, goals, phases, review, and advancement.
src/lib/carePlanProxy.js - Diet plans
src/app/plans/diet/page.jsx - Diet goals · Captures and confirms diet goals.
src/app/plans/diet/components/GoalsManager.jsx - Diet lifecycle · Handles proposals, phases, logs, and coaching check-ins.
src/lib/dietProxy.js - Exercise plans
src/app/plans/exercise/page.jsx
Next.js API boundary
- Backend API client · Shared client access to backend services.
src/services/api.js - Backend configuration · Central backend endpoint configuration.
src/config/api.js - Care-plan proxy · Same-origin care-plan overview and lifecycle boundary.
src/app/api/proxy/patient/care_plan/overview/route.js - Diet proxy · Same-origin diet proposal, phases, and logging boundary.
src/app/api/proxy/patient/diet/log/route.js - Conversation proxy · Persistent chat sessions, turns, and specialized clinical conversations.
src/app/api/proxy/chat/start/route.js - Document ingestion · Accepts lab-report and prescription uploads.
src/app/api/proxy/upload/labreport/route.js - Healthcare backend · Domain APIs for clinical data, plans, chats, and processing.
Access and operations
- Authentication and guards · Authentication handlers and patient/doctor UI guards.
src/app/api/auth/authenticate/route.js - Doctor workspace · Clinician workflows, invitations, and patient selection.
src/app/doctor/layout.js - Admin observability · Observes LLM calls, chat sessions, and turns.
src/app/admin/observability/layout.jsx - Admin proxy
src/app/api/admin/[...path]/route.js - Feature flags · Centralized feature-flag context.
src/context/FeatureFlagContext.js
Connections 22
- App shell → Home entry: hosts
- App shell → Patient workflows: hosts
- App shell → Care plans: hosts
- App shell → Authentication and guards: applies access
- Patient workflows → Conversation proxy: conversations
- Clinical detail views → Document ingestion: uploads
- Clinical detail views → Conversation proxy: clinical chat
- Care plans → Care-plan lifecycle: coordinates
- Care-plan lifecycle → Care-plan proxy: same-origin calls
- Diet plans → Diet goals: captures goals
- Diet goals → Diet lifecycle: drives
- Diet lifecycle → Diet proxy: same-origin calls
- Care-plan proxy → Backend API client: forwards via
- Diet proxy → Backend API client: forwards via
- Conversation proxy → Backend API client: forwards via
- Document ingestion → Backend API client: forwards via
- Backend API client → Backend configuration: uses
- Backend API client → Healthcare backend: backend requests
- Doctor workspace → Authentication and guards: guarded by
- Admin observability → Admin proxy: queries
- Admin proxy → Healthcare backend: observability requests
- App shell → Feature flags: consumes