CareBridge is a TypeScript fullstack monorepo. Its defining architectural idea is that all clinical data mutations flow through an event queue where the AI oversight layer evaluates the patient’s complete picture across specialties — not just the latest chart entry.

Data flow

Clinician enters data
        |
        v
   API Gateway (tRPC, Fastify)
        |
        v
 Clinical services (vitals, labs, meds, notes)
        |    saves to PostgreSQL
        |    emits to Redis queue
        v
  AI Oversight Worker (BullMQ)
        |
        +--> Deterministic rules (cross-specialty patterns, drug interactions, critical values)
        |         +--> Immediate critical flags
        |
        +--> LLM review (Claude API, full patient context)
                  +--> Nuanced clinical flags
        |
        v
 Notifications --> Clinician Portal (flags dashboard)

Decoupling data entry from AI processing is deliberate: clinicians never wait for the LLM, and BullMQ provides retries, rate limiting, and backpressure for free. See Design Decisions for the rationale.

Monorepo structure

carebridge/
|-- packages/    Shared libraries
|-- services/    Backend microservices
|-- apps/        Next.js frontends (clinician + patient portals)
|-- tooling/     Seed data + CLI scripts

Turborepo manages the build graph: packages/* -> services/* -> apps/*. Packages build before the services that depend on them, and services before apps.

Packages

PackageResponsibility
@carebridge/shared-typesCanonical TypeScript interfaces for the whole system (pure types, no runtime deps)
@carebridge/db-schemaDrizzle ORM schema, migrations, DB connection, PHI column encryption
@carebridge/validatorsZod schemas for every API input, shared by backend and frontend forms
@carebridge/medical-logicVital danger zones, lab validation, trend analysis
@carebridge/ai-promptsVersioned Claude prompts + context builder (see ai-oversight)
@carebridge/fhir-utilsFHIR R4 format converters

Services

ServicePortResponsibility
api-gateway4000tRPC entrypoint, JWT auth middleware, audit logging, CORS
clinical-dataVitals, labs, medications, procedures CRUD + event emission
clinical-notesSOAP / Progress note templates, versioning, signing
ai-oversightRules engine + LLM review + flag management (BullMQ worker)
authJWT authentication + session management
patient-recordsPatient demographics + care-team management
notificationsAlert delivery (in-app, email, SMS)
fhir-gatewayFHIR R4 import/export
schedulingAppointment scheduling

Worker health-check ports: ai-oversight 4001, notifications 4002, scheduling 4003.

Apps

  • clinician-portal (port 3000) — Next.js 15 app for physicians, nurses, and care coordinators. tRPC client + React Query. Surfaces the clinical flags dashboard.
  • patient-portal (port 3001) — Next.js 15 app for patients. Notably does not surface AI flags (a compliance requirement).

Tech stack

LayerTechnology
MonorepoTurborepo + pnpm workspaces
LanguageTypeScript (strict mode, ESM)
Backend frameworkFastify
API layertRPC (end-to-end types, no codegen)
FrontendNext.js 15 + React 19
Database ORMDrizzle ORM
DatabasePostgreSQL 16
Job queueBullMQ + Redis 7
ValidationZod
AI reviewClaude API (@anthropic-ai/sdk)

Source of truth

The authoritative architecture description is the README in the CareBridge repo. Service-specific designs live under docs/.

See also: AI Oversight Layer, Clinical Domain Model, Developer Guide.