How 1-abdulrahman/ai-hospital-assistant works
1. Repo shape
- This is a multi-app monorepo with one Python backend and two React/TypeScript frontends.
- The backend is the central service layer; the two UIs are separate clients for different users and workflows.
2. Backend as the orchestration hub
- company/backend/app/main.py wires the API together.
- The backend exposes route groups for auth, otp, chat, scheduling, portal, integrations, and health.
- The structure suggests a REST API built around request/response schemas, middleware, dependency injection, and error handling.
3. Primary business domains in the backend
- modules/orchestration coordinates multi-step flows and state transitions.
- modules/scheduling handles provider/slot selection, booking logic, idempotency, and reason-code mappings.
- modules/otp manages one-time-password verification and validation.
- modules/nlp provides intent/specialty inference and also includes training/evaluation assets.
- modules/fhir_gateway is the integration boundary to external healthcare systems using FHIR-style resources and mappings.
- modules/notification sends email notifications.
- modules/observability emits operational events/traces.
4. Healthcare/chat workflow
- The chat API and orchestration modules likely drive a patient-facing assistant flow.
- The hospital UI contains chat-specific components for consent, continuity, identity, OTP, and confirmation, which indicates a guided conversational booking/renewal experience.
- The backend persists assistant session state and continuity context, so conversations are resumable and auditable.
5. External system boundary: FHIR
- The fhir_gateway layer isolates all interaction with external hospital/EMR scheduling systems.
- It includes client code, mappers, schema definitions, and seed data, which suggests the rest of the backend works with normalized internal models and only the gateway speaks FHIR externally.
- Integration tests for native booking, slots, and schedule seeding reinforce that FHIR is a major backend dependency.
6. Data storage and persistence
- app/db/models.py, session.py, engine.py, and seed.py indicate a relational database backing the backend.
- Alembic migrations under backend/alembic/versions show schema evolution for assistant sessions, portal users, renewal fields, and related tables.
- The DB appears to store operational application state, not just transactional scheduling data.
7. Identity and access
- Backend auth-related routes and security helpers handle user access for the portal side.
- OTP is part of the patient identity verification flow in the hospital chat experience.
- core/security.py, core/rate_limit.py, and API middleware indicate the backend enforces cross-cutting protection and request control.
8. Portal UI
- company/portal-ui is an admin/operations dashboard built with Vite, React, and TypeScript.
- Pages like Dashboard, Sessions, Bookings, Tenants, Traces, Audit, and NlpMonitoring suggest it is used to inspect system state, monitor operations, and manage tenants rather than serve patients.
- Its api layer includes real/mock clients and auth state, which implies it can run against live backend endpoints or a mocked mode.
9. Hospital UI
- hospital/ui is the patient-facing front end.
- It centers on a ChatWidget and step-based components for renewal/continuity identity, OTP, and confirmation.
- It also includes health checks and booking-flow hooks, so the UI is tightly coupled to the backend conversation and scheduling APIs.
10. NLP lifecycle
- The backend ships an NLP model artifact under app/assets/nlp_models/distilbert-specialty.
- Training/evaluation scripts and a JSONL dataset are included, meaning model development is part of the repo, not an external dependency.
- Tooling under backend/tools validates model artifacts and startup readiness, so deployment depends on the packaged NLP assets being present and consistent.
11. Testing and quality gates
- There is broad coverage across unit, API, and integration tests in the backend.
- The frontend also has component and example tests via Vitest.
- tools/ci/check_strict_coverage.py and .github/workflows/ci.yml show CI enforces quality gates, likely including coverage and runtime checks.
12. Local/dev and deployment topology
- Each app has its own Dockerfile, and there are compose files for combined local stacks.
- Repository-level tools support backend-only local runs, a hybrid backend-with-hospital-UI mode, and offline dependency preparation.
- This suggests the intended deployment model is a containerized backend with separately built frontends, connected through the backend API and external FHIR systems.
Main entry points: routes Routes · orchestration Orchestration · main.py API app · db Database
Components 19
Backend
Python API, domain modules, persistence, and integrations
- API app · Wires routes, middleware, dependencies, and error handling.
company/backend/app/main.py - Routes · Auth, OTP, chat, scheduling, portal, integrations, and health endpoints.
company/backend/app/api/routes - Schemas · Request and response models for core backend APIs.
company/backend/app/api/schemas - Core · Config, security, rate limiting, logging, and correlation context.
company/backend/app/core - Database · Relational models, engine, session management, seed data, and migrations.
company/backend/app/db - Orchestration · Coordinates multi-step assistant flows and state transitions.
company/backend/app/modules/orchestration - Scheduling · Provider/slot selection, booking rules, idempotency, and reason-code mapping.
company/backend/app/modules/scheduling - OTP · One-time-password validation and verification service.
company/backend/app/modules/otp - NLP · Specialty/intent inference plus training and evaluation assets.
company/backend/app/modules/nlp - FHIR gateway · Normalizes external EMR/FHIR interaction through clients, mappers, schemas, and seeds.
company/backend/app/modules/fhir_gateway - Notifications · Sends email notifications from backend workflows.
company/backend/app/modules/notification - Observability · Emits operational events and traces for monitoring.
company/backend/app/modules/observability
Portal UI
Operations dashboard for monitoring and management
- Portal app · Vite/React/TypeScript admin console for operations and monitoring.
company/portal-ui/src/main.tsx - Portal API · Real and mock backend clients plus auth state management.
company/portal-ui/src/api - Portal pages · Sessions, bookings, tenants, traces, audit, and NLP monitoring screens.
company/portal-ui/src/pages
Hospital UI
Patient-facing chat and booking experience
- Hospital app · Patient-facing chat and booking front end.
hospital/ui/src/main.tsx - Chat widget · Guided assistant interface for consent, continuity, identity, OTP, and confirmation.
hospital/ui/src/components/ChatWidget.tsx - Chat steps · Step-based renewal and continuity identity, OTP, and confirm screens.
hospital/ui/src/components/steps - Booking hooks · Widget state, booking flow, API client, and health-check hooks.
hospital/ui/src/hooks
Connections 25
- API app → Routes: registers · Application startup attaches route groups.
- API app → Core: uses · Applies config, logging, security, and middleware.
- API app → Database: connects · Initializes persistence layer and session handling.
- Routes → Schemas: validates with · Routes exchange typed request/response contracts.
- Routes → OTP: calls · OTP endpoints delegate to verification logic.
- Routes → Scheduling: calls · Scheduling endpoints delegate to booking logic.
- Routes → Orchestration: calls · Chat and assistant flows are coordinated here.
- Routes → FHIR gateway: integrates via · Integration routes expose external-system interactions.
- Orchestration → NLP: infers · Uses NLP output for intent and specialty decisions.
- Orchestration → Scheduling: drives · Orchestration advances booking and slot-selection steps.
- Orchestration → OTP: verifies · Identity checks gate workflow progress.
- Scheduling → FHIR gateway: books through · Scheduling requests are translated to external FHIR operations.
- Scheduling → Database: persists · Stores booking state, idempotency, and related records.
- NLP → Database: stores training data · Model lifecycle uses local datasets and artifacts.
- FHIR gateway → Database: reads seed/state · Gateway relies on seeded mappings and stored normalized state.
- Notifications → Database: reads recipients · Notification delivery uses persisted application data.
- Observability → Core: hooks into · Telemetry is part of the request/runtime infrastructure.
- Portal app → Portal API: uses · UI relies on the client layer for backend access.
- Portal app → Portal pages: renders · Dashboard pages compose the visible admin workflows.
- Portal API → API app: calls · Portal client talks to backend APIs.
- Hospital app → Chat widget: contains · Main patient experience centers on the chat widget.
- Hospital app → Chat steps: renders · Workflow steps implement guided conversational screens.
- Hospital app → Booking hooks: uses · UI state and backend interaction are driven by hooks.
- Booking hooks → API app: calls · Patient UI exchanges data with backend APIs.
- Chat widget → Orchestration: drives · Conversation UI maps to orchestration-managed workflows.