# healers-second-look/athena architecture

> Architecture diagram of the GitHub repository healers-second-look/athena, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/healers-second-look/athena
- Repository: https://github.com/healers-second-look/athena

## Overview

#### Purpose and Entry Points
Athena/SecondLook is an evidence-grounded oncology decision-support engine: it stores evolving patient cases, retrieves cited cancer evidence, synthesizes answers, and exposes clinical-data views. Primary runtime entry points are the FastAPI service at `src/secondlook/api/__main__.py`, read-only MCP service at `src/secondlook/mcp_server/__main__.py`, and React client at `web/src/main.jsx`. The legacy structural-biology orchestrator is `src/secondlook/pipeline.py`.

#### Case Memory and Read Model
Append-only case events are the clinical system of record; findings and changes are derived by folding event history rather than mutating prior events. Persistence, state transitions, evidence state, invalidation diffs, and alerts are centered in `src/secondlook/case/store.py`, `src/secondlook/case/state.py`, and `src/secondlook/case/evidence_diff.py`. A dedicated query layer supplies case summaries, findings, queues, research, and trial-access views to transport adapters: `src/secondlook/query/contracts.py`, `src/secondlook/query/case_summary.py`, `src/secondlook/query/evidence_search.py`.

#### Evidence Graph Ingestion and Retrieval
Tier 1 loads CIViC, PubMed, ClinicalTrials.gov, guidelines, and regional access pathways into/queryable through FalkorDB. Graph shape and connection boundaries reside in `src/secondlook/tier1/graph_schema.py` and `src/secondlook/tier1/graph_connection.py`; source ingestion is represented by `src/secondlook/tier1/civic_loader.py`, `src/secondlook/tier1/pubmed_loader.py`, and `src/secondlook/tier1/ctgov_loader.py`. Retrieval combines exact/relaxed graph lookup and semantic search in `src/secondlook/tier1/retrieval.py` and `src/secondlook/tier1/semantic_retrieval.py`; cited-source eligibility is a key evidence boundary.

#### Signals, Trials, and Access
The target architecture is converging sources into typed signals rather than treating structural prediction solely as a fallback. Signal generators cover genomics, literature, pharmacology, trials, and matching in `src/secondlook/signals/genomics.py`, `src/secondlook/signals/trial_matching.py`, and `src/secondlook/signals/registry.py`. Access-pathway registry data is maintained under `access_pathways/us.yaml` and `access_pathways/india.yaml`, queried through `src/secondlook/tier1/access_pathway_query.py`.

#### Synthesis, Chat, and Intake
Chat retrieves evidence, separates it from plugin annotations, constructs prompts, and invokes interchangeable offline, hosted, or OpenAI-compatible model clients. This boundary is implemented by `src/secondlook/chat/engine.py`, `src/secondlook/chat/knowledge.py`, and `src/secondlook/synthesis/llm_client.py`; citation-gated generation is in `src/secondlook/synthesis/citation_gate.py`. Intake converts documents to human-confirmable case events via `src/secondlook/intake/extraction.py`.

#### Delivery Surfaces and Infrastructure
FastAPI routes expose cases, findings, chat, and timeline through `src/secondlook/api/app.py`, `src/secondlook/api/routes/cases.py`, and `src/secondlook/api/routes/chat.py`. The frontend’s principal workflows are case dashboard, research queue, chat, and timeline at `web/src/routes/CaseDashboard.jsx`, `web/src/routes/ResearchQueue.jsx`, and `web/src/routes/ChatInterface.jsx`. Docker Compose provisions the API, web client, FalkorDB graph, and case database via `docker-compose.yml`; SQLAlchemy/Alembic schema evolution begins at `migrations/versions/0001_initial_case_schema.py`. MCP exposes read-only case/evidence/trial/access tools from `src/secondlook/mcp_server/tools.py`.

#### Structural-Biology Path and Constraints
When used, the older Tier 2 path validates mutations, resolves structures, discovers drugs, and evaluates noncovalent binding candidates. Core stages are `src/secondlook/mutation_validation.py`, `src/secondlook/structure.py`, `src/secondlook/candidates.py`, and `src/secondlook/binding.py`; external sources include UniProt, RCSB, AlphaFold, ESM Atlas, AlphaMissense, DGIdb, Open Targets, ChEMBL, mCSM-lig, and Vina. This path is explicitly not validated as a clinical prediction claim and is being demoted/re-wired into the signal-graph direction.

Main entry points: [`src/secondlook/signals/registry.py`](https://github.com/healers-second-look/athena/blob/main/src/secondlook/signals/registry.py) (Typed signal registry), [`src/secondlook/api/app.py`](https://github.com/healers-second-look/athena/blob/main/src/secondlook/api/app.py) (Case and chat routes), [`src/secondlook/case/store.py`](https://github.com/healers-second-look/athena/blob/main/src/secondlook/case/store.py) (Append-only case store), [`src/secondlook/tier1/graph_connection.py`](https://github.com/healers-second-look/athena/blob/main/src/secondlook/tier1/graph_connection.py) (FalkorDB)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_delivery["Delivery surfaces"]
  node_web["React client<br/>frontend<br/>[main.jsx]"]
  node_api["FastAPI service<br/>API runtime<br/>[__main__.py]"]
  node_mcp["Read-only MCP service<br/>MCP runtime<br/>[__main__.py]"]
  node_case_routes["Case and chat routes<br/>transport adapters<br/>[app.py]"]
end

subgraph group_case["Case memory"]
  node_case_store[("Append-only case store<br/>system of record<br/>[store.py]")]
  node_case_state["Folded case state<br/>derived state<br/>[state.py]"]
  node_query["Case query layer<br/>read model<br/>[contracts.py]"]
  node_case_db[("Case database<br/>relational database")]
  node_intake["Document intake<br/>event extraction<br/>[extraction.py]"]
end

subgraph group_evidence["Evidence graph"]
  node_graph_schema["Evidence graph schema<br/>graph boundary<br/>[graph_schema.py]"]
  node_ingestion["Tier 1 source ingestion<br/>ingestion pipeline<br/>[civic_loader.py]"]
  node_falkordb[("FalkorDB<br/>evidence graph database")]
  node_retrieval["Evidence retrieval<br/>graph and semantic retrieval<br/>[retrieval.py]"]
  node_access["Access pathway lookup<br/>registry query"]
end

subgraph group_reasoning["Signals and synthesis"]
  node_signals["Typed signal registry<br/>signal generation<br/>[registry.py]"]
  node_chat["Chat engine<br/>evidence-grounded orchestration<br/>[engine.py]"]
  node_citation_gate{{"Citation gate<br/>generation policy<br/>[citation_gate.py]"}}
  node_llm["Interchangeable LLM clients<br/>model boundary<br/>[llm_client.py]"]
end

subgraph group_legacy["Legacy Tier 2"]
  node_tier2["Structural-biology pipeline<br/>legacy orchestrator<br/>[pipeline.py]"]
  node_external_sources(("Structural data sources<br/>external services"))
end

node_web -->|"clinical workflows"| node_api
node_api -->|"routes requests"| node_case_routes
node_mcp -->|"read-only tools"| node_query
node_case_routes -->|"writes events"| node_case_store
node_case_routes -->|"reads views"| node_query
node_case_routes -->|"chat requests"| node_chat
node_intake -->|"confirmable events"| node_case_store
node_case_store -->|"persists"| node_case_db
node_case_store -->|"folds history"| node_case_state
node_case_state -->|"derived findings"| node_query
node_ingestion -->|"loads evidence"| node_falkordb
node_graph_schema -->|"defines graph"| node_falkordb
node_falkordb -->|"graph lookup"| node_retrieval
node_access -->|"access evidence"| node_falkordb
node_retrieval -->|"cited evidence"| node_signals
node_access -->|"regional access"| node_signals
node_case_state -->|"case context"| node_signals
node_retrieval -->|"retrieved sources"| node_chat
node_signals -->|"plugin annotations"| node_chat
node_chat -->|"draft answer"| node_citation_gate
node_citation_gate -->|"citation-gated prompt"| node_llm
node_external_sources -->|"protein, drug, docking data"| node_tier2
node_tier2 -.->|"rewired as signals"| node_signals

click node_web "https://github.com/healers-second-look/athena/blob/main/web/src/main.jsx"
click node_api "https://github.com/healers-second-look/athena/blob/main/src/secondlook/api/__main__.py"
click node_mcp "https://github.com/healers-second-look/athena/blob/main/src/secondlook/mcp_server/__main__.py"
click node_case_routes "https://github.com/healers-second-look/athena/blob/main/src/secondlook/api/app.py"
click node_case_store "https://github.com/healers-second-look/athena/blob/main/src/secondlook/case/store.py"
click node_case_state "https://github.com/healers-second-look/athena/blob/main/src/secondlook/case/state.py"
click node_query "https://github.com/healers-second-look/athena/blob/main/src/secondlook/query/contracts.py"
click node_case_db "https://github.com/healers-second-look/athena/blob/main/migrations/versions/0001_initial_case_schema.py"
click node_intake "https://github.com/healers-second-look/athena/blob/main/src/secondlook/intake/extraction.py"
click node_graph_schema "https://github.com/healers-second-look/athena/blob/main/src/secondlook/tier1/graph_schema.py"
click node_ingestion "https://github.com/healers-second-look/athena/blob/main/src/secondlook/tier1/civic_loader.py"
click node_falkordb "https://github.com/healers-second-look/athena/blob/main/src/secondlook/tier1/graph_connection.py"
click node_retrieval "https://github.com/healers-second-look/athena/blob/main/src/secondlook/tier1/retrieval.py"
click node_access "https://github.com/healers-second-look/athena/blob/main/src/secondlook/tier1/access_pathway_query.py"
click node_signals "https://github.com/healers-second-look/athena/blob/main/src/secondlook/signals/registry.py"
click node_chat "https://github.com/healers-second-look/athena/blob/main/src/secondlook/chat/engine.py"
click node_citation_gate "https://github.com/healers-second-look/athena/blob/main/src/secondlook/synthesis/citation_gate.py"
click node_llm "https://github.com/healers-second-look/athena/blob/main/src/secondlook/synthesis/llm_client.py"
click node_tier2 "https://github.com/healers-second-look/athena/blob/main/src/secondlook/pipeline.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_web,node_api,node_mcp,node_case_routes toneBlue
class node_case_store,node_case_state,node_query,node_case_db,node_intake toneAmber
class node_graph_schema,node_ingestion,node_falkordb,node_retrieval,node_access toneMint
class node_signals,node_chat,node_citation_gate,node_llm toneRose
class node_tier2,node_external_sources toneIndigo
```

## Components

### Delivery surfaces

- [React client](https://github.com/healers-second-look/athena/blob/main/web/src/main.jsx): frontend · `web/src/main.jsx`
- [FastAPI service](https://github.com/healers-second-look/athena/blob/main/src/secondlook/api/__main__.py): API runtime · `src/secondlook/api/__main__.py`
- [Read-only MCP service](https://github.com/healers-second-look/athena/blob/main/src/secondlook/mcp_server/__main__.py): MCP runtime · `src/secondlook/mcp_server/__main__.py`
- [Case and chat routes](https://github.com/healers-second-look/athena/blob/main/src/secondlook/api/app.py): transport adapters · `src/secondlook/api/app.py`

### Case memory

- [Append-only case store](https://github.com/healers-second-look/athena/blob/main/src/secondlook/case/store.py): system of record · Persists events, evidence state, transitions, diffs, and alerts. · `src/secondlook/case/store.py`
- [Folded case state](https://github.com/healers-second-look/athena/blob/main/src/secondlook/case/state.py): derived state · Findings and changes are derived from event history. · `src/secondlook/case/state.py`
- [Case query layer](https://github.com/healers-second-look/athena/blob/main/src/secondlook/query/contracts.py): read model · Serves summaries, findings, queues, research, and trial access. · `src/secondlook/query/contracts.py`
- [Case database](https://github.com/healers-second-look/athena/blob/main/migrations/versions/0001_initial_case_schema.py): relational database · Schema evolution begins in Alembic. · `migrations/versions/0001_initial_case_schema.py`
- [Document intake](https://github.com/healers-second-look/athena/blob/main/src/secondlook/intake/extraction.py): event extraction · Converts documents into human-confirmable case events. · `src/secondlook/intake/extraction.py`

### Evidence graph

- [Evidence graph schema](https://github.com/healers-second-look/athena/blob/main/src/secondlook/tier1/graph_schema.py): graph boundary · `src/secondlook/tier1/graph_schema.py`
- [Tier 1 source ingestion](https://github.com/healers-second-look/athena/blob/main/src/secondlook/tier1/civic_loader.py): ingestion pipeline · Loads CIViC, PubMed, and ClinicalTrials.gov evidence. · `src/secondlook/tier1/civic_loader.py`
- [FalkorDB](https://github.com/healers-second-look/athena/blob/main/src/secondlook/tier1/graph_connection.py): evidence graph database · `src/secondlook/tier1/graph_connection.py`
- [Evidence retrieval](https://github.com/healers-second-look/athena/blob/main/src/secondlook/tier1/retrieval.py): graph and semantic retrieval · Combines exact, relaxed, and semantic lookup with cited-source eligibility. · `src/secondlook/tier1/retrieval.py`
- [Access pathway lookup](https://github.com/healers-second-look/athena/blob/main/src/secondlook/tier1/access_pathway_query.py): registry query · Queries regional access pathways. · `src/secondlook/tier1/access_pathway_query.py`

### Signals and synthesis

- [Typed signal registry](https://github.com/healers-second-look/athena/blob/main/src/secondlook/signals/registry.py): signal generation · Converges genomic, literature, pharmacology, trial, and matching signals. · `src/secondlook/signals/registry.py`
- [Chat engine](https://github.com/healers-second-look/athena/blob/main/src/secondlook/chat/engine.py): evidence-grounded orchestration · Separates retrieved evidence from plugin annotations. · `src/secondlook/chat/engine.py`
- [Citation gate](https://github.com/healers-second-look/athena/blob/main/src/secondlook/synthesis/citation_gate.py): generation policy · Gates synthesized output on citations. · `src/secondlook/synthesis/citation_gate.py`
- [Interchangeable LLM clients](https://github.com/healers-second-look/athena/blob/main/src/secondlook/synthesis/llm_client.py): model boundary · Supports offline, hosted, and OpenAI-compatible clients. · `src/secondlook/synthesis/llm_client.py`

### Legacy Tier 2

Demoted structural-biology path.

- [Structural-biology pipeline](https://github.com/healers-second-look/athena/blob/main/src/secondlook/pipeline.py): legacy orchestrator · Validates mutations, resolves structures, finds drugs, and evaluates binding candidates. · `src/secondlook/pipeline.py`
- **Structural data sources**: external services · Includes protein, structure, variant, drug, and docking sources.

## Connections

- React client → FastAPI service: clinical workflows
- FastAPI service → Case and chat routes: routes requests
- Read-only MCP service → Case query layer: read-only tools
- Case and chat routes → Append-only case store: writes events
- Case and chat routes → Case query layer: reads views
- Case and chat routes → Chat engine: chat requests
- Document intake → Append-only case store: confirmable events
- Append-only case store → Case database: persists
- Append-only case store → Folded case state: folds history
- Folded case state → Case query layer: derived findings
- Tier 1 source ingestion → FalkorDB: loads evidence
- Evidence graph schema → FalkorDB: defines graph
- FalkorDB → Evidence retrieval: graph lookup
- Access pathway lookup → FalkorDB: access evidence
- Evidence retrieval → Typed signal registry: cited evidence
- Access pathway lookup → Typed signal registry: regional access
- Folded case state → Typed signal registry: case context
- Evidence retrieval → Chat engine: retrieved sources
- Typed signal registry → Chat engine: plugin annotations
- Chat engine → Citation gate: draft answer
- Citation gate → Interchangeable LLM clients: citation-gated prompt
- Structural data sources → Structural-biology pipeline: protein, drug, docking data
- Structural-biology pipeline → Typed signal registry: rewired as signals
