# sanjanb/bio-pipeline architecture

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

- Interactive diagram: https://gitdiagram.com/sanjanb/bio-pipeline
- Repository: https://github.com/sanjanb/bio-pipeline

## Overview

#### Purpose and entry points
Protein Intelligence Platform is a FastAPI web service for retrieving AlphaFold structures and enriching them with confidence, sequence, domain, and homology analysis. The ASGI entry point is `app.py` (`uvicorn app:app`). Browser routes submit jobs, expose status/results/downloads, and serve Jinja2 pages from `templates/`.

#### Web/API and job lifecycle
`app.py` owns request handling: `POST /predict` creates a job and launches background processing; status pages/API poll persisted state; result, raw-PDB, report, and download routes read generated artifacts. This is an in-process FastAPI background-task model, not a durable worker queue, so execution is coupled to the application process.
- `app.py`
- `templates/status.html`
- `templates/result.html`

#### Persistent job boundary
Job identity, lifecycle state/current pipeline step, and job-history access are modeled separately from protein-analysis data. SQLite is the system of record for progress; generated PDB/report/PyMOL assets remain local filesystem files under the configured output directory. This boundary enables browser polling but does not provide distributed storage or queue recovery.
- `models/job.py`
- `models/protein.py`
- `data_sources/cache.py`

#### Enrichment orchestration
The async data-source pipeline normalizes user input and composes a canonical protein profile from remote services. It resolves UniProt metadata/sequence, potentially gene and homolog information from Ensembl, NCBI-derived annotations, and BLAST homology; source failures such as BLAST timeouts are best-effort rather than necessarily blocking final output.
- `data_sources/pipeline.py`
- `data_sources/uniprot_client.py`
- `data_sources/blast_client.py`

#### Structure acquisition and analysis
Structure prediction here means AlphaFold DB lookup/download rather than local model inference. The AlphaFold client obtains a PDB for an accession/eligible sequence; the analyzer parses PDB content with Biopython and derives per-residue pLDDT/confidence summaries used downstream. Sequence input is limited by the AlphaFold DB constraint described in the README.
- `alphafold_client.py`
- `pdb_analyzer.py`
- `models/protein.py`

#### External-service integration layer
Remote API concerns are split by provider: AlphaFold DB for predicted structures; UniProt for protein metadata/features; Ensembl REST for gene/homology; NCBI E-utilities/CDD for annotations; and NCBI BLAST for similarity searches. File caching reduces repeated source requests; organism normalization supports cross-provider query consistency.
- `data_sources/ensembl_client.py`
- `data_sources/ncbi_client.py`
- `data_sources/organism.py`

#### Presentation and artifact generation
Analysis results produce three delivery forms: interactive server-rendered pages, a standalone HTML report, and a PyMOL script. Browser pages use 3Dmol.js to fetch raw PDB via the API and Chart.js for confidence visualization; templates render domains and BLAST findings from the assembled profile.
- `report_generator.py`
- `pymol_generator.py`
- `templates/report.html`

#### Runtime and deployment
The runtime is Python 3.11+ with FastAPI, Jinja2, and Biopython; dependencies are managed by uv. Container packaging is provided by `Dockerfile`, with Render deployment configuration in `render.yaml`. Required state is local SQLite plus writable local output storage, making horizontal scaling or ephemeral-container restarts material operational constraints.
- `Dockerfile`
- `render.yaml`
- `pyproject.toml`

Main entry points: [`data_sources/pipeline.py`](https://github.com/sanjanb/bio-pipeline/blob/main/data_sources/pipeline.py) (Enrichment pipeline), [`app.py`](https://github.com/sanjanb/bio-pipeline/blob/main/app.py) (In-process job runner), [`models/protein.py`](https://github.com/sanjanb/bio-pipeline/blob/main/models/protein.py) (Protein profile), [`report_generator.py`](https://github.com/sanjanb/bio-pipeline/blob/main/report_generator.py) (HTML report generator)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web application"]
  node_app["FastAPI app<br/>ASGI routes<br/>[app.py]"]
  node_browser_pages["Browser pages<br/>Jinja2 + 3Dmol.js<br/>[status.html]"]
  node_background_job["In-process job runner<br/>FastAPI background task<br/>[app.py]"]
end

subgraph group_pipeline["Analysis pipeline"]
  node_protein_model["Protein profile<br/>domain model<br/>[protein.py]"]
  node_enrichment_pipeline["Enrichment pipeline<br/>async orchestrator<br/>[pipeline.py]"]
  node_alphafold_client["AlphaFold client<br/>structure client"]
  node_pdb_analyzer["PDB confidence analysis<br/>Biopython analyzer<br/>[pdb_analyzer.py]"]
end

subgraph group_state["State and artifacts"]
  node_job_model[("Job lifecycle<br/>job model<br/>[job.py]")]
  node_source_cache[("Source cache<br/>file cache<br/>[cache.py]")]
  node_job_database[("SQLite job state<br/>persistent state<br/>[job.py]")]
  node_output_storage[("Local output storage<br/>filesystem artifacts")]
  node_report_generator["HTML report generator<br/>artifact generator"]
  node_pymol_generator["PyMOL generator<br/>artifact generator<br/>[pymol_generator.py]"]
  node_standalone_report["Standalone report template<br/>Jinja2 template<br/>[report.html]"]
end

subgraph group_external["External providers"]
  node_uniprot["UniProt<br/>metadata provider<br/>[uniprot_client.py]"]
  node_ensembl["Ensembl REST<br/>gene and homology provider<br/>[ensembl_client.py]"]
  node_ncbi["NCBI E-utilities/CDD<br/>annotation provider<br/>[ncbi_client.py]"]
  node_blast["NCBI BLAST<br/>homology provider<br/>[blast_client.py]"]
end

node_container_runtime{{"Container deployment<br/>Docker + Render"}}

node_browser_pages -->|"submits and polls"| node_app
node_app -->|"launches"| node_background_job
node_app -->|"reads status and history"| node_job_database
node_background_job -->|"updates lifecycle"| node_job_model
node_job_model -->|"persists"| node_job_database
node_background_job -->|"runs"| node_enrichment_pipeline
node_enrichment_pipeline -->|"assembles"| node_protein_model
node_enrichment_pipeline -->|"queries"| node_uniprot
node_enrichment_pipeline -->|"queries"| node_ensembl
node_enrichment_pipeline -->|"queries"| node_ncbi
node_enrichment_pipeline -.->|"queries"| node_blast
node_enrichment_pipeline -->|"uses"| node_source_cache
node_background_job -->|"acquires structure"| node_alphafold_client
node_alphafold_client -->|"provides PDB"| node_pdb_analyzer
node_pdb_analyzer -->|"adds confidence"| node_protein_model
node_background_job -->|"writes generated assets"| node_output_storage
node_protein_model -->|"supplies results"| node_report_generator
node_report_generator -->|"renders"| node_standalone_report
node_report_generator -->|"writes HTML"| node_output_storage
node_protein_model -->|"supplies analysis"| node_pymol_generator
node_pymol_generator -->|"writes script"| node_output_storage
node_app -->|"serves downloads and raw PDB"| node_output_storage
node_container_runtime -->|"packages runtime"| node_app

click node_app "https://github.com/sanjanb/bio-pipeline/blob/main/app.py"
click node_browser_pages "https://github.com/sanjanb/bio-pipeline/blob/main/templates/status.html"
click node_job_model "https://github.com/sanjanb/bio-pipeline/blob/main/models/job.py"
click node_protein_model "https://github.com/sanjanb/bio-pipeline/blob/main/models/protein.py"
click node_background_job "https://github.com/sanjanb/bio-pipeline/blob/main/app.py"
click node_enrichment_pipeline "https://github.com/sanjanb/bio-pipeline/blob/main/data_sources/pipeline.py"
click node_alphafold_client "https://github.com/sanjanb/bio-pipeline/blob/main/alphafold_client.py"
click node_pdb_analyzer "https://github.com/sanjanb/bio-pipeline/blob/main/pdb_analyzer.py"
click node_uniprot "https://github.com/sanjanb/bio-pipeline/blob/main/data_sources/uniprot_client.py"
click node_ensembl "https://github.com/sanjanb/bio-pipeline/blob/main/data_sources/ensembl_client.py"
click node_ncbi "https://github.com/sanjanb/bio-pipeline/blob/main/data_sources/ncbi_client.py"
click node_blast "https://github.com/sanjanb/bio-pipeline/blob/main/data_sources/blast_client.py"
click node_source_cache "https://github.com/sanjanb/bio-pipeline/blob/main/data_sources/cache.py"
click node_job_database "https://github.com/sanjanb/bio-pipeline/blob/main/models/job.py"
click node_report_generator "https://github.com/sanjanb/bio-pipeline/blob/main/report_generator.py"
click node_pymol_generator "https://github.com/sanjanb/bio-pipeline/blob/main/pymol_generator.py"
click node_standalone_report "https://github.com/sanjanb/bio-pipeline/blob/main/templates/report.html"
click node_container_runtime "https://github.com/sanjanb/bio-pipeline/blob/main/Dockerfile"

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_app,node_browser_pages,node_background_job toneBlue
class node_protein_model,node_enrichment_pipeline,node_alphafold_client,node_pdb_analyzer toneAmber
class node_job_model,node_source_cache,node_job_database,node_output_storage,node_report_generator,node_pymol_generator,node_standalone_report toneMint
class node_uniprot,node_ensembl,node_ncbi,node_blast toneRose
class node_container_runtime toneNeutral
```

## Components

### Web application

- [FastAPI app](https://github.com/sanjanb/bio-pipeline/blob/main/app.py): ASGI routes · Creates jobs, serves polling, results, artifacts, and pages. · `app.py`
- [Browser pages](https://github.com/sanjanb/bio-pipeline/blob/main/templates/status.html): Jinja2 + 3Dmol.js · Status and result pages poll jobs and visualize PDB confidence. · `templates/status.html`
- [In-process job runner](https://github.com/sanjanb/bio-pipeline/blob/main/app.py): FastAPI background task · Execution is coupled to the application process rather than a durable queue. · `app.py`

### Analysis pipeline

- [Protein profile](https://github.com/sanjanb/bio-pipeline/blob/main/models/protein.py): domain model · Canonical enriched protein data used by analysis and presentation. · `models/protein.py`
- [Enrichment pipeline](https://github.com/sanjanb/bio-pipeline/blob/main/data_sources/pipeline.py): async orchestrator · Normalizes input and assembles the protein profile with best-effort sources. · `data_sources/pipeline.py`
- [AlphaFold client](https://github.com/sanjanb/bio-pipeline/blob/main/alphafold_client.py): structure client · Looks up and downloads AlphaFold DB PDB structures. · `alphafold_client.py`
- [PDB confidence analysis](https://github.com/sanjanb/bio-pipeline/blob/main/pdb_analyzer.py): Biopython analyzer · Parses PDB residues and derives pLDDT confidence summaries. · `pdb_analyzer.py`

### State and artifacts

- [Job lifecycle](https://github.com/sanjanb/bio-pipeline/blob/main/models/job.py): job model · Tracks job identity, current step, state, and history. · `models/job.py`
- [Source cache](https://github.com/sanjanb/bio-pipeline/blob/main/data_sources/cache.py): file cache · Reduces repeated remote-source requests. · `data_sources/cache.py`
- [SQLite job state](https://github.com/sanjanb/bio-pipeline/blob/main/models/job.py): persistent state · System of record for progress and polling state. · `models/job.py`
- **Local output storage**: filesystem artifacts · Stores generated PDB, reports, and PyMOL files.
- [HTML report generator](https://github.com/sanjanb/bio-pipeline/blob/main/report_generator.py): artifact generator · `report_generator.py`
- [PyMOL generator](https://github.com/sanjanb/bio-pipeline/blob/main/pymol_generator.py): artifact generator · `pymol_generator.py`
- [Standalone report template](https://github.com/sanjanb/bio-pipeline/blob/main/templates/report.html): Jinja2 template · Renders domains and BLAST findings. · `templates/report.html`

### External providers

- [UniProt](https://github.com/sanjanb/bio-pipeline/blob/main/data_sources/uniprot_client.py): metadata provider · Supplies protein metadata, sequence, and features. · `data_sources/uniprot_client.py`
- [Ensembl REST](https://github.com/sanjanb/bio-pipeline/blob/main/data_sources/ensembl_client.py): gene and homology provider · `data_sources/ensembl_client.py`
- [NCBI E-utilities/CDD](https://github.com/sanjanb/bio-pipeline/blob/main/data_sources/ncbi_client.py): annotation provider · `data_sources/ncbi_client.py`
- [NCBI BLAST](https://github.com/sanjanb/bio-pipeline/blob/main/data_sources/blast_client.py): homology provider · Timeouts and source failures can be non-blocking. · `data_sources/blast_client.py`

### Other components

- [Container deployment](https://github.com/sanjanb/bio-pipeline/blob/main/Dockerfile): Docker + Render · Requires writable local SQLite and output storage. · `Dockerfile`

## Connections

- Browser pages → FastAPI app: submits and polls
- FastAPI app → In-process job runner: launches
- FastAPI app → SQLite job state: reads status and history
- In-process job runner → Job lifecycle: updates lifecycle
- Job lifecycle → SQLite job state: persists
- In-process job runner → Enrichment pipeline: runs
- Enrichment pipeline → Protein profile: assembles
- Enrichment pipeline → UniProt: queries
- Enrichment pipeline → Ensembl REST: queries
- Enrichment pipeline → NCBI E-utilities/CDD: queries
- Enrichment pipeline → NCBI BLAST: queries
- Enrichment pipeline → Source cache: uses
- In-process job runner → AlphaFold client: acquires structure
- AlphaFold client → PDB confidence analysis: provides PDB
- PDB confidence analysis → Protein profile: adds confidence
- In-process job runner → Local output storage: writes generated assets
- Protein profile → HTML report generator: supplies results
- HTML report generator → Standalone report template: renders
- HTML report generator → Local output storage: writes HTML
- Protein profile → PyMOL generator: supplies analysis
- PyMOL generator → Local output storage: writes script
- FastAPI app → Local output storage: serves downloads and raw PDB
- Container deployment → FastAPI app: packages runtime
