# syedaejazahmed/clinicsynapse architecture

> Architecture diagram of the GitHub repository syedaejazahmed/clinicsynapse, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/syedaejazahmed/clinicsynapse
- Repository: https://github.com/syedaejazahmed/clinicsynapse

## Overview

#### Purpose and Entry Points
Trial Screening Copilot is an MVP for evidence-backed clinical-trial eligibility screening. It evaluates synthetic patient records against trial protocols and returns deterministic Eligible, Needs Review, or Ineligible decisions with criterion-level evidence. The backend starts at `app/main.py` as a FastAPI service; the separate Vite/React client starts at `Frontend/src/main.tsx` and composes the application in `Frontend/src/App.tsx`.

#### Shared Domain and Seed Data
Backend request, response, patient, trial, criteria, and matching schemas are centralized in `app/models.py`; these form the contract for API consumers and matching logic. The default offline dataset is JSON-backed, with synthetic records in `app/data/patients.json`, `app/data/trials.json`, and `app/data/studies.json`. This permits the core workflow without live model access or real PHI.

#### Eligibility Extraction Pipeline
Protocol text is converted into structured eligibility criteria by `app/extraction.py`. It can use an Anthropic-backed LLM path when `ANTHROPIC_API_KEY` is configured, but falls back to pre-extracted criteria in `app/data/trials.json`, preserving application functionality offline. Rule-oriented extraction support is separated into `app/extract_rules.py`.

#### Deterministic Matching Core
`app/matching_engine.py` is the product’s decision boundary: it compares structured patient attributes and trial criteria without relying on an LLM for eligibility decisions. Its output carries individual criterion outcomes and supporting evidence, allowing API and UI layers to explain the final status rather than merely expose a score. API orchestration and report generation are exposed through `app/main.py`.

#### Backend API and Reporting Flow
Clients retrieve patients and trials, submit a patient/trial match request, or request a patient-wide screening report. FastAPI in `app/main.py` loads domain data, invokes extraction or matching as needed, and serializes model-defined responses from `app/models.py`. Interactive backend documentation is available through FastAPI’s `/docs`; the service is intended to run under Uvicorn with Python dependencies from `requirements.txt`.

#### Frontend Clinical Workflow
The React frontend organizes operational views around patient, trial, study, matching, report, audit, and research-assistant workflows, including `Frontend/src/pages/Patients.tsx`, `Frontend/src/pages/Matching.tsx`, and `Frontend/src/pages/Reports.tsx`. Typed HTTP client modules such as `Frontend/src/services/patientApi.ts`, `Frontend/src/services/matchingApi.ts`, and `Frontend/src/services/reportApi.ts` isolate backend communication from UI pages. Reusable evidence-oriented presentation components include `Frontend/src/components/EligibilityCard.tsx`, `Frontend/src/components/CriteriaTable.tsx`, and `Frontend/src/components/EvidencePanel.tsx`.

#### Research and PDF RAG Boundary
A distinct research-assistant capability exists outside deterministic screening, implemented in `app/research_assistant.py` and `app/rag_pdf.py`. Its retrieval pipeline includes PDF conversion, cleaning, chunking, index construction, and querying under `app/utils/pdf_to_text.py`, `app/utils/build_index.py`, and `app/utils/query_index.py`. Sample protocol PDFs reside in `dataset/`; this subsystem may use LLM-provider abstraction in `app/utils/llm_provider.py` and should remain separate from the authoritative deterministic eligibility decision path.

Main entry points: [`app/main.py`](https://github.com/syedaejazahmed/clinicsynapse/blob/main/app/main.py) (FastAPI API & reports), [`app/rag_pdf.py`](https://github.com/syedaejazahmed/clinicsynapse/blob/main/app/rag_pdf.py) (PDF RAG orchestration), [`app/extraction.py`](https://github.com/syedaejazahmed/clinicsynapse/blob/main/app/extraction.py) (Eligibility extraction), [`app/matching_engine.py`](https://github.com/syedaejazahmed/clinicsynapse/blob/main/app/matching_engine.py) (Deterministic matcher)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_backend["Deterministic Screening Backend"]
  node_api["FastAPI API &amp; reports<br/>Python service<br/>[main.py]"]
  node_models["Shared domain models<br/>Pydantic schemas<br/>[models.py]"]
  node_patients_data[("Synthetic patients<br/>JSON data<br/>[patients.json]")]
  node_trials_data[("Trials &amp; extracted criteria<br/>JSON data<br/>[trials.json]")]
  node_studies_data[("Studies data<br/>JSON data<br/>[studies.json]")]
  node_extraction["Eligibility extraction<br/>protocol parser<br/>[extraction.py]"]
  node_extract_rules["Rule extraction support<br/>rule parser<br/>[extract_rules.py]"]
  node_matching{{"Deterministic matcher<br/>decision engine<br/>[matching_engine.py]"}}
end

subgraph group_frontend["React Clinical Client"]
  node_frontend_app["React app composition<br/>React shell<br/>[App.tsx]"]
  node_frontend_entry["Vite entry point<br/>React bootstrap<br/>[main.tsx]"]
  node_clinical_pages["Clinical workflow pages<br/>React views<br/>[Matching.tsx]"]
  node_api_clients["Typed API clients<br/>HTTP client layer<br/>[matchingApi.ts]"]
  node_evidence_ui["Evidence presentation<br/>React components<br/>[EvidencePanel.tsx]"]
end

subgraph group_research["Research PDF RAG"]
  node_research_assistant["Research assistant<br/>research service"]
  node_pdf_rag["PDF RAG orchestration<br/>retrieval pipeline<br/>[rag_pdf.py]"]
  node_protocol_pdfs["Sample protocol PDFs<br/>PDF corpus"]
  node_pdf_text["PDF conversion &amp; cleaning<br/>document processing<br/>[pdf_to_text.py]"]
  node_index_build["Chunking &amp; index build<br/>indexing<br/>[build_index.py]"]
  node_index_query["Index querying<br/>retrieval<br/>[query_index.py]"]
  node_llm_provider["LLM provider abstraction<br/>provider adapter<br/>[llm_provider.py]"]
end

node_frontend_entry -->|"mounts"| node_frontend_app
node_frontend_app -->|"composes"| node_clinical_pages
node_clinical_pages -->|"uses"| node_api_clients
node_clinical_pages -->|"renders"| node_evidence_ui
node_api_clients -->|"HTTP requests"| node_api
node_api -->|"serializes contract"| node_models
node_api -->|"loads"| node_patients_data
node_api -->|"loads"| node_trials_data
node_api -->|"loads"| node_studies_data
node_api -->|"extracts criteria as needed"| node_extraction
node_api -->|"submits patient-trial match"| node_matching
node_extraction -->|"uses rules"| node_extract_rules
node_extraction -.->|"offline criteria fallback"| node_trials_data
node_matching -->|"reads structured inputs and emits outcomes"| node_models
node_matching -->|"evaluates criteria"| node_trials_data
node_research_assistant -->|"uses retrieval"| node_pdf_rag
node_pdf_rag -->|"converts and cleans"| node_pdf_text
node_pdf_text -->|"reads"| node_protocol_pdfs
node_pdf_rag -->|"builds index"| node_index_build
node_pdf_rag -->|"queries index"| node_index_query
node_pdf_rag -.->|"optional LLM access"| node_llm_provider

click node_api "https://github.com/syedaejazahmed/clinicsynapse/blob/main/app/main.py"
click node_models "https://github.com/syedaejazahmed/clinicsynapse/blob/main/app/models.py"
click node_patients_data "https://github.com/syedaejazahmed/clinicsynapse/blob/main/app/data/patients.json"
click node_trials_data "https://github.com/syedaejazahmed/clinicsynapse/blob/main/app/data/trials.json"
click node_studies_data "https://github.com/syedaejazahmed/clinicsynapse/blob/main/app/data/studies.json"
click node_extraction "https://github.com/syedaejazahmed/clinicsynapse/blob/main/app/extraction.py"
click node_extract_rules "https://github.com/syedaejazahmed/clinicsynapse/blob/main/app/extract_rules.py"
click node_matching "https://github.com/syedaejazahmed/clinicsynapse/blob/main/app/matching_engine.py"
click node_frontend_app "https://github.com/syedaejazahmed/clinicsynapse/blob/main/Frontend/src/App.tsx"
click node_frontend_entry "https://github.com/syedaejazahmed/clinicsynapse/blob/main/Frontend/src/main.tsx"
click node_clinical_pages "https://github.com/syedaejazahmed/clinicsynapse/blob/main/Frontend/src/pages/Matching.tsx"
click node_api_clients "https://github.com/syedaejazahmed/clinicsynapse/blob/main/Frontend/src/services/matchingApi.ts"
click node_evidence_ui "https://github.com/syedaejazahmed/clinicsynapse/blob/main/Frontend/src/components/EvidencePanel.tsx"
click node_research_assistant "https://github.com/syedaejazahmed/clinicsynapse/blob/main/app/research_assistant.py"
click node_pdf_rag "https://github.com/syedaejazahmed/clinicsynapse/blob/main/app/rag_pdf.py"
click node_pdf_text "https://github.com/syedaejazahmed/clinicsynapse/blob/main/app/utils/pdf_to_text.py"
click node_index_build "https://github.com/syedaejazahmed/clinicsynapse/blob/main/app/utils/build_index.py"
click node_index_query "https://github.com/syedaejazahmed/clinicsynapse/blob/main/app/utils/query_index.py"
click node_llm_provider "https://github.com/syedaejazahmed/clinicsynapse/blob/main/app/utils/llm_provider.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_api,node_models,node_patients_data,node_trials_data,node_studies_data,node_extraction,node_extract_rules,node_matching toneBlue
class node_frontend_app,node_frontend_entry,node_clinical_pages,node_api_clients,node_evidence_ui toneAmber
class node_research_assistant,node_pdf_rag,node_protocol_pdfs,node_pdf_text,node_index_build,node_index_query,node_llm_provider toneMint
```

## Components

### Deterministic Screening Backend

Authoritative eligibility API and decision flow.

- [FastAPI API & reports](https://github.com/syedaejazahmed/clinicsynapse/blob/main/app/main.py): Python service · Orchestrates retrieval, matching, and patient-wide reports. · `app/main.py`
- [Shared domain models](https://github.com/syedaejazahmed/clinicsynapse/blob/main/app/models.py): Pydantic schemas · API contract for patients, trials, criteria, matches, and responses. · `app/models.py`
- [Synthetic patients](https://github.com/syedaejazahmed/clinicsynapse/blob/main/app/data/patients.json): JSON data · `app/data/patients.json`
- [Trials & extracted criteria](https://github.com/syedaejazahmed/clinicsynapse/blob/main/app/data/trials.json): JSON data · Offline trial source and extraction fallback. · `app/data/trials.json`
- [Studies data](https://github.com/syedaejazahmed/clinicsynapse/blob/main/app/data/studies.json): JSON data · `app/data/studies.json`
- [Eligibility extraction](https://github.com/syedaejazahmed/clinicsynapse/blob/main/app/extraction.py): protocol parser · Uses Anthropic when configured or stored criteria offline. · `app/extraction.py`
- [Rule extraction support](https://github.com/syedaejazahmed/clinicsynapse/blob/main/app/extract_rules.py): rule parser · `app/extract_rules.py`
- [Deterministic matcher](https://github.com/syedaejazahmed/clinicsynapse/blob/main/app/matching_engine.py): decision engine · Produces status, criterion outcomes, and evidence without LLM decisions. · `app/matching_engine.py`

### React Clinical Client

Operational screening and evidence views.

- [React app composition](https://github.com/syedaejazahmed/clinicsynapse/blob/main/Frontend/src/App.tsx): React shell · `Frontend/src/App.tsx`
- [Vite entry point](https://github.com/syedaejazahmed/clinicsynapse/blob/main/Frontend/src/main.tsx): React bootstrap · `Frontend/src/main.tsx`
- [Clinical workflow pages](https://github.com/syedaejazahmed/clinicsynapse/blob/main/Frontend/src/pages/Matching.tsx): React views · Patient, matching, and report workflows. · `Frontend/src/pages/Matching.tsx`
- [Typed API clients](https://github.com/syedaejazahmed/clinicsynapse/blob/main/Frontend/src/services/matchingApi.ts): HTTP client layer · Isolates patient, matching, and report API calls. · `Frontend/src/services/matchingApi.ts`
- [Evidence presentation](https://github.com/syedaejazahmed/clinicsynapse/blob/main/Frontend/src/components/EvidencePanel.tsx): React components · Renders eligibility outcomes, criteria, and supporting evidence. · `Frontend/src/components/EvidencePanel.tsx`

### Research PDF RAG

Separate, non-authoritative protocol research capability.

- [Research assistant](https://github.com/syedaejazahmed/clinicsynapse/blob/main/app/research_assistant.py): research service · Separate from authoritative screening decisions. · `app/research_assistant.py`
- [PDF RAG orchestration](https://github.com/syedaejazahmed/clinicsynapse/blob/main/app/rag_pdf.py): retrieval pipeline · `app/rag_pdf.py`
- **Sample protocol PDFs**: PDF corpus
- [PDF conversion & cleaning](https://github.com/syedaejazahmed/clinicsynapse/blob/main/app/utils/pdf_to_text.py): document processing · `app/utils/pdf_to_text.py`
- [Chunking & index build](https://github.com/syedaejazahmed/clinicsynapse/blob/main/app/utils/build_index.py): indexing · `app/utils/build_index.py`
- [Index querying](https://github.com/syedaejazahmed/clinicsynapse/blob/main/app/utils/query_index.py): retrieval · `app/utils/query_index.py`
- [LLM provider abstraction](https://github.com/syedaejazahmed/clinicsynapse/blob/main/app/utils/llm_provider.py): provider adapter · `app/utils/llm_provider.py`

## Connections

- Vite entry point → React app composition: mounts
- React app composition → Clinical workflow pages: composes
- Clinical workflow pages → Typed API clients: uses
- Clinical workflow pages → Evidence presentation: renders
- Typed API clients → FastAPI API & reports: HTTP requests
- FastAPI API & reports → Shared domain models: serializes contract
- FastAPI API & reports → Synthetic patients: loads
- FastAPI API & reports → Trials & extracted criteria: loads
- FastAPI API & reports → Studies data: loads
- FastAPI API & reports → Eligibility extraction: extracts criteria as needed
- FastAPI API & reports → Deterministic matcher: submits patient-trial match
- Eligibility extraction → Rule extraction support: uses rules
- Eligibility extraction → Trials & extracted criteria: offline criteria fallback
- Deterministic matcher → Shared domain models: reads structured inputs and emits outcomes
- Deterministic matcher → Trials & extracted criteria: evaluates criteria
- Research assistant → PDF RAG orchestration: uses retrieval
- PDF RAG orchestration → PDF conversion & cleaning: converts and cleans
- PDF conversion & cleaning → Sample protocol PDFs: reads
- PDF RAG orchestration → Chunking & index build: builds index
- PDF RAG orchestration → Index querying: queries index
- PDF RAG orchestration → LLM provider abstraction: optional LLM access
