Solace-AI is an enterprise-grade backend platform designed to provide evidence-based, clinically grounded, and personalized digital mental health support. Built as a distributed microservice system orchestrated via LangGraph, Solace-AI adheres to strict clinical safety guardrails, continuous personality adaptation, multi-tier cognitive memory, and zero-trust PHI privacy standards.
- π Core Clinical Capabilities
- ποΈ System Architecture
- π Project Structure
- π§ Technology Stack
- π Getting Started & Local Development
- π§ͺ Testing & Quality Assurance
- π CI/CD Pipelines
- π‘οΈ Security, Privacy & Compliance
- π Documentation Hub
β οΈ Clinical Disclaimer
- Evidence-Based Interventions: Dynamic therapeutic planning and delivery covering Cognitive Behavioral Therapy (CBT), Dialectical Behavior Therapy (DBT), Acceptance and Commitment Therapy (ACT), Motivational Interviewing (MI), and Mindfulness. Implements Stepped Care (Levels 0β4) tailored to validated screener outcomes (PHQ-9, GAD-7).
-
AMIE-Inspired Diagnostic Reasoning: A 4-step Chain-of-Reasoning (Analyze
$\rightarrow$ Hypothesize$\rightarrow$ Challenge$\rightarrow$ Synthesize) referencing DSM-5-TR and HiTOP dimensional models. Employs a dedicated Devil's Advocate agent to actively counter sycophancy and diagnostic confirmation bias. -
Personality & Empathy Adaptation: Real-time continuous Big Five (OCEAN) trait scoring combined with a Mixture of Empathetic Listeners (MoEL across 32 emotion states) to dynamically align communication style (
$r > 0.85$ ). -
5-Tier Cognitive Memory Hierarchy: Seamless transition from working memory to long-term semantic context (Input Buffer
$\rightarrow$ Working Memory [Redis]$\rightarrow$ Session Memory [Redis + PostgreSQL]$\rightarrow$ Episodic Memory [PostgreSQL + Weaviate]$\rightarrow$ Semantic Memory). Memory follows Ebbinghaus decay with a critical safety override: crisis disclosures and risk factors never decay. - Always-Active 4-Layer Crisis Shield: Continuous risk screening mapped to the Columbia-Suicide Severity Rating Scale (C-SSRS). High and critical disclosures immediately provide verified local crisis resources (e.g., 988 Lifeline) bypassing generative LLM latency, alert on-call clinicians via Amazon SES, and commit durable records to a transactional outbox.
Solace-AI is structured into 10 decoupled FastAPI microservices communicating via asynchronous Kafka event streams and REST/WebSocket APIs, with edge TLS terminated by Caddy.
flowchart TD
Client["Client Applications<br/>(Web / Mobile Frontend)"]
subgraph Edge ["Edge Layer (Ports 80 / 443)"]
Caddy["Caddy Reverse Proxy<br/>(TLS Termination, Path Routing)"]
end
subgraph Services ["Microservices Layer"]
Orchestrator["orchestrator_service<br/>(LangGraph 1.0 Orchestration)"]
Safety["safety_service<br/>(4-Layer Crisis Shield)"]
Therapy["therapy_service<br/>(CBT/DBT/ACT Stepped Care)"]
Diagnosis["diagnosis_service<br/>(AMIE 4-Step Clinical Chain)"]
Personality["personality_service<br/>(Big Five OCEAN & MoEL)"]
Memory["memory_service<br/>(5-Tier Cognitive Memory)"]
User["user-service<br/>(Auth, MFA, Consent, GDPR)"]
Notification["notification-service<br/>(Clinician SES Paging)"]
Analytics["analytics-service<br/>(Clinical Outcomes Tracking)"]
end
subgraph DataPlane ["Data & Event Plane"]
Postgres[("PostgreSQL 16<br/>(FORCE Row-Level Security)")]
Redis[("Redis 7<br/>(Session Cache & Rate Limiting)")]
Kafka[("Apache Kafka<br/>(Transactional Outbox & Events)")]
Weaviate[("Weaviate<br/>(Vector & Hybrid Search)")]
end
Client --> Caddy
Caddy --> Orchestrator
Caddy --> User
Orchestrator <--> Safety
Orchestrator <--> Therapy
Orchestrator <--> Diagnosis
Orchestrator <--> Personality
Orchestrator <--> Memory
Services <--> Postgres
Services <--> Redis
Services <--> Kafka
Memory <--> Weaviate
Notification --> Kafka
.
βββ services/ # FastAPI Microservices
β βββ orchestrator_service/ # Multi-agent LangGraph workflow, REST & WS APIs
β βββ safety_service/ # Crisis keyword matching, guardrails, contraindications
β βββ therapy_service/ # Clinical unit selection, intervention planning
β βββ diagnosis_service/ # Symptom extraction, differential assessment
β βββ memory_service/ # Vector and episodic cognitive retrieval
β βββ personality_service/ # OCEAN trait detection and style adaptation
β βββ user-service/ # User accounts, OAuth (Google PKCE), JWT, MFA, GDPR erasure
β βββ notification-service/ # Clinician paging, alert delivery, SES notifications
β βββ analytics-service/ # Outcome measures tracking (PHQ-9, GAD-7, SRS)
β βββ config_service/ # (Frozen under D-19)
β βββ shared/ # Service-level shared modules
βββ src/ # Shared Foundation Packages
β βββ solace_common/ # Core data models, schemas, shared interfaces
β βββ solace_events/ # Kafka event schemas, transactional outbox contracts
β βββ solace_infrastructure/ # IF-01 service runtime, ConnectionPoolManager, health probes
β βββ solace_security/ # IF-04 Service tokens, AES-256-GCM PHI codec, RLS context
β βββ solace_testing/ # Test fixtures, mock providers, testcontainers harness
βββ deploy/ # Deployment Configuration
β βββ env/ # env-contract.yaml and strict environment schema readers
β βββ secrets/ # SOPS + age encrypted secret templates
βββ docker/ # Base Docker files and database migration entrypoint
βββ infrastructure/ # Caddy reverse proxy, Prometheus, Grafana, init-db
βββ migrations/ # Alembic database migration chain (Slots 001β021)
βββ scripts/ # Maintenance, test runners, and DB tooling
β βββ ci/ # CI suite runner, image builder, clean checkout, secret scan
β βββ db/ # Database migration runner and TLS certificate generator
βββ system-design/ # Detailed architectural specifications and diagrams
βββ docs/ # Documentation hub, API handoff, and MVP remediation plans
βββ tests/ # Complete test suite (unit, realinfra, security, e2e)
| Layer | Component | Description |
|---|---|---|
| Runtime & Framework | Python 3.12, FastAPI, Uvicorn | Async microservices with Pydantic v2 validation. |
| Agent Orchestration | LangGraph 1.0, PostgreSQL Saver | Directed cyclic graph coordinating clinical and safety agents. |
| Relational Storage | PostgreSQL 16 | Enforced Row-Level Security (FORCE RLS) via unprivileged solace_app role. |
| Event Streaming | Apache Kafka | Event-driven microservice integration with a transactional outbox. |
| Cache & Ephemeral Data | Redis 7 | Sub-10ms session working memory, token revocation, rate limiting. |
| Vector Database | Weaviate | Hybrid BM25 and semantic vector search for long-term memory. |
| Edge & Proxy | Caddy v2 | Automatic HTTPS, TLS termination, internal port isolation. |
| Secrets Management | SOPS + age (D-07) | Version-controlled, zero-plaintext encrypted configuration. |
| Package Management | uv (Hash-Pinned) |
Deterministic lockfiles (requirements.lock, requirements-dev.lock). |
- Python 3.12
- Docker Engine & Docker Compose v2 (with at least 8 GB RAM allocated)
uvpackage manager:pip install "uv==0.8.2"
Create a local Python virtual environment and synchronize dependencies from the hash-pinned lockfile:
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\Activate.ps1
uv pip sync --require-hashes requirements-dev.lockCopy the development environment template:
cp .env.example .envLaunch the backing infrastructure (Postgres, Redis, Kafka, Weaviate, and Caddy) with Docker Compose:
docker compose up -dApply database migrations:
make migrate
# or: python -m scripts.db.migrate upgrade headVerify service health:
curl http://localhost:8000/health # Orchestrator
curl http://localhost:8001/health # User Service
curl http://localhost:8002/health # Safety ServiceSolace-AI enforces strict Test-Driven Development (TDD). All suites run under process-level isolation to prevent cross-test contamination.
# Run unit test suites
make test-unit
# Run real-infrastructure tests (Postgres, Kafka, Weaviate testcontainers)
make test-realinfra
# Run on-demand End-to-End suite
make test-e2e PROFILE=dev
# Run repository secret scan (SOPS + age hygiene)
python scripts/ci/secret_scan.py
# Run critical lint check
make lintThe repository features comprehensive automation powered by GitHub Actions:
-
Continuous Integration (.github/workflows/ci.yml):
- Dynamic Matrix Planning: Discovers all 28+ test suites and 10 container images dynamically.
- Process-Isolated Execution: Runs unit tests, real-infrastructure suites, and syntax checks concurrently.
- In-Container Module Probing: Builds images from repository root context and verifies startup and import resolution inside the container.
- Fast Caching & Path Filtering: Leverages
actions/cache@v4on~/.cache/uvand skips runner dispatch on docs-only changes. - On-Demand E2E: End-to-end tests run on manual dispatch across
devorstrictprofiles.
-
Continuous Delivery (.github/workflows/cd.yml):
- Triggers on release tags (
v*.*.*) or manual deployment workflow dispatch. - Builds and publishes container images to GitHub Container Registry (
ghcr.io) tagged with semantic release versions, commit SHAs, andlatest.
- Triggers on release tags (
- Zero-Trust PHI Protection: Personal Health Information (PHI) is encrypted at rest using AES-256-GCM via phi_codec.py with user ID as Additional Authenticated Data (AAD).
- PostgreSQL FORCE RLS: All application queries connect as
solace_appwith Row-Level Security enforced. No user can read or modify another user's records. Work operates strictly withinacting_as_user(user_id). - Inter-Service Authentication (IF-04): Microservices communicate using short-lived cryptographically signed service tokens (
ServiceTokenManager) with on-behalf-of (obo) claims. User credentials never enter LangGraph state. - Fail-Closed Strict Environments: In
stagingorproduction, missing secrets, loopback database addresses, or unverified TLS connections immediately abort startup.
- API Handoff & Frontend Guide: REST & WebSocket endpoints, Google OAuth PKCE flows, and message contracts.
- System Design Blueprint: In-depth technical specifications and Mermaid diagrams for all 5 core modules.
- Staging Bring-Up Runbook: Instructions for deploying strict single-host staging and production stacks.
- MVP Remediation Hub: Tracking hub for the MVP program, including decisions (DECISIONS.md), task tracker (TRACKER.md), and open items (OPEN-ITEMS.md).
Solace-AI is designed as an AI-powered conversational support companion and mental health screening aid. It is not an FDA-cleared medical device, nor a substitute for professional clinical diagnosis or medical care. Individuals experiencing acute psychological distress or suicidal ideation are immediately routed to emergency services and crisis helplines (such as 988 Suicide & Crisis Lifeline).