# tom-hoinacki/longevity-intelligence architecture

> Architecture diagram of the GitHub repository tom-hoinacki/longevity-intelligence, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tom-hoinacki/longevity-intelligence
- Repository: https://github.com/tom-hoinacki/longevity-intelligence

## Overview

#### Purpose and Shape
Longevity Intelligence is a structured, source-backed longevity evidence platform: asset → claim → scientific source → evidence → score/verdict. It is a .NET backend with a separate TypeScript web shell, using Supabase-hosted PostgreSQL as the schema source of truth. Core solution: `Longevity.sln`, `src/Longevity.Api/Program.cs`, `supabase/migrations/`.

#### Entry Points and Runtime Composition
The ASP.NET Core API bootstraps dependency injection, HTTP endpoints, diagnostics, persistence, model providers, and a workflow background service in `src/Longevity.Api/Program.cs` and `src/Longevity.Api/DependencyInjection/ServiceCollectionExtensions.cs`. It exposes public evidence and human-review API surfaces through `src/Longevity.Api/PublicEvidence/PublicEvidenceEndpoints.cs` and `src/Longevity.Api/HumanReview/HumanReviewEndpoints.cs`. The frontend is a Vite/React TypeScript application entered at `src/Longevity.Web/src/main.tsx`; its current role appears to be a basic UI shell.

#### Layered Backend Boundary
The code follows a Domain / Application / Infrastructure / API separation. Workflow state and identifiers are domain-owned in `src/Longevity.Domain/Workflow/WorkflowState.cs` and `src/Longevity.Domain/Workflow/WorkflowIdentifiers.cs`. Application code defines contracts and use cases, isolating business flows from transport and provider implementations: `src/Longevity.Application/Contracts/IWorkflowRunProcessor.cs`, `src/Longevity.Application/Contracts/IClaimExtractionModel.cs`, and `src/Longevity.Application/Contracts/IWorkflowRunRepository.cs`. Infrastructure supplies PostgreSQL and OpenRouter implementations.

#### Workflow Orchestration
A hosted worker polls/processes workflow runs via `src/Longevity.Api/Workflow/WorkflowOrchestratorBackgroundService.cs`, delegating lifecycle coordination to `src/Longevity.Application/Orchestration/WorkflowRunProcessor.cs`. Phases are explicit: extraction in `src/Longevity.Application/Orchestration/ExtractingWorkflowRunPhaseHandler.cs`, deterministic validation in `src/Longevity.Application/Orchestration/ValidatingWorkflowRunPhaseHandler.cs`, and publication in `src/Longevity.Application/Publishing/PublishingWorkflowRunPhaseHandler.cs`. State transitions are controlled by domain workflow state, rather than endpoint request lifetimes.

#### AI Extraction and Source Processing
Claim extraction is provider-abstracted by application contracts and implemented through OpenRouter in `src/Longevity.Infrastructure/ModelProviders/OpenRouter/OpenRouterClaimExtractionModel.cs`. Extracted candidates are persisted under policies intended to preserve workflow semantics: `src/Longevity.Infrastructure/Persistence/PostgresClaimExtractionPersistence.cs` and `src/Longevity.Infrastructure/Persistence/ClaimExtractionPersistencePolicy.cs`. Scientific inputs are normalized before downstream use by `src/Longevity.Application/SourceNormalization/ScientificSourceNormalization.cs`.

#### Evidence, Review, and Publication
Evidence scoring is deterministic application logic, centered on `src/Longevity.Application/EvidenceScoring/EvidenceScoringEngine.cs` and `src/Longevity.Application/EvidenceScoring/ClaimEvidenceAggregator.cs`. Human decisions form a boundary before approval/publication, handled in `src/Longevity.Application/HumanReview/HumanReviewService.cs` with PostgreSQL persistence in `src/Longevity.Infrastructure/Persistence/PostgresHumanReviewPersistence.cs`. Published/public-facing reads use a catalog abstraction, backed by `src/Longevity.Infrastructure/PublicEvidence/PostgresPublicEvidenceCatalog.cs` (with a demo alternative).

#### Data and External Infrastructure
Supabase PostgreSQL holds the evidence registry and workflow schema, defined incrementally in `supabase/migrations/20260711000000_claim_evidence_registry.sql` and `supabase/migrations/20260711140000_workflow_schema_v1.sql`. Later migrations enforce workflow/source and human-decision integrity. API persistence is configured through `src/Longevity.Infrastructure/Persistence/PostgresServiceCollectionExtensions.cs` and `src/Longevity.Infrastructure/Persistence/PostgresWorkflowRunRepository.cs`. OpenRouter is the external LLM service; its configuration and registration live in `src/Longevity.Infrastructure/ModelProviders/OpenRouter/OpenRouterClaimExtractionServiceCollectionExtensions.cs`.

Main entry points: [`src/Longevity.Application/Orchestration/WorkflowRunProcessor.cs`](https://github.com/tom-hoinacki/longevity-intelligence/blob/main/src/Longevity.Application/Orchestration/WorkflowRunProcessor.cs) (Workflow processor), [`src/Longevity.Api/Program.cs`](https://github.com/tom-hoinacki/longevity-intelligence/blob/main/src/Longevity.Api/Program.cs) (API bootstrap), [`supabase/migrations/20260711140000_workflow_schema_v1.sql`](https://github.com/tom-hoinacki/longevity-intelligence/blob/main/supabase/migrations/20260711140000_workflow_schema_v1.sql) (Supabase PostgreSQL), [`src/Longevity.Application/Orchestration/ExtractingWorkflowRunPhaseHandler.cs`](https://github.com/tom-hoinacki/longevity-intelligence/blob/main/src/Longevity.Application/Orchestration/ExtractingWorkflowRunPhaseHandler.cs) (Extraction phase)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web client"]
  node_web_shell["React web shell<br/>Vite/React client<br/>[main.tsx]"]
end

subgraph group_api["API runtime"]
  node_api_bootstrap["API bootstrap<br/>ASP.NET Core composition<br/>[Program.cs]"]
  node_service_registration["Service registration<br/>DI extensions"]
  node_public_endpoints["Public evidence API<br/>HTTP endpoints"]
  node_review_endpoints["Human review API<br/>HTTP endpoints"]
  node_workflow_worker["Workflow worker<br/>hosted background service"]
end

subgraph group_core["Application core"]
  node_workflow_domain["Workflow state<br/>domain state model<br/>[WorkflowState.cs]"]
  node_workflow_processor["Workflow processor<br/>orchestration service"]
  node_extraction_phase["Extraction phase<br/>workflow phase handler"]
  node_validation_phase["Validation phase<br/>workflow phase handler"]
  node_source_normalization["Source normalization<br/>application service"]
  node_evidence_scoring["Evidence scoring<br/>deterministic scoring engine"]
  node_review_service["Human review service<br/>application service"]
  node_publication_phase["Publication phase<br/>workflow phase handler"]
end

subgraph group_infra["Infrastructure"]
  node_openrouter_model["OpenRouter extraction<br/>claim extraction provider"]
  node_extraction_persistence["Claim extraction persistence<br/>PostgreSQL persistence"]
  node_workflow_repository["Workflow repository<br/>PostgreSQL repository"]
  node_review_persistence["Human review persistence<br/>PostgreSQL persistence"]
  node_public_catalog["Public evidence catalog<br/>PostgreSQL read catalog"]
  node_postgres[("Supabase PostgreSQL<br/>evidence and workflow registry")]
end

node_web_shell -->|"HTTP"| node_api_bootstrap
node_api_bootstrap -->|"configures"| node_service_registration
node_api_bootstrap -->|"maps"| node_public_endpoints
node_api_bootstrap -->|"maps"| node_review_endpoints
node_api_bootstrap -->|"hosts"| node_workflow_worker
node_workflow_worker -->|"processes runs"| node_workflow_processor
node_workflow_processor -->|"applies transitions"| node_workflow_domain
node_workflow_processor -->|"loads and updates runs"| node_workflow_repository
node_workflow_processor -->|"runs"| node_extraction_phase
node_workflow_processor -->|"runs"| node_validation_phase
node_workflow_processor -->|"runs"| node_publication_phase
node_extraction_phase -->|"extracts claims"| node_openrouter_model
node_extraction_phase -->|"persists candidates"| node_extraction_persistence
node_validation_phase -->|"normalizes sources"| node_source_normalization
node_validation_phase -->|"scores evidence"| node_evidence_scoring
node_review_endpoints -->|"submits decisions"| node_review_service
node_review_service -->|"stores decisions"| node_review_persistence
node_review_service -->|"approves publication"| node_publication_phase
node_publication_phase -->|"publishes evidence"| node_public_catalog
node_public_endpoints -->|"reads catalog"| node_public_catalog
node_workflow_repository -->|"workflow data"| node_postgres
node_extraction_persistence -->|"claims and sources"| node_postgres
node_review_persistence -->|"decisions"| node_postgres
node_public_catalog -->|"published evidence"| node_postgres
node_openrouter_model -.->|"no direct access"| node_postgres

click node_web_shell "https://github.com/tom-hoinacki/longevity-intelligence/blob/main/src/Longevity.Web/src/main.tsx"
click node_api_bootstrap "https://github.com/tom-hoinacki/longevity-intelligence/blob/main/src/Longevity.Api/Program.cs"
click node_service_registration "https://github.com/tom-hoinacki/longevity-intelligence/blob/main/src/Longevity.Api/DependencyInjection/ServiceCollectionExtensions.cs"
click node_public_endpoints "https://github.com/tom-hoinacki/longevity-intelligence/blob/main/src/Longevity.Api/PublicEvidence/PublicEvidenceEndpoints.cs"
click node_review_endpoints "https://github.com/tom-hoinacki/longevity-intelligence/blob/main/src/Longevity.Api/HumanReview/HumanReviewEndpoints.cs"
click node_workflow_worker "https://github.com/tom-hoinacki/longevity-intelligence/blob/main/src/Longevity.Api/Workflow/WorkflowOrchestratorBackgroundService.cs"
click node_workflow_domain "https://github.com/tom-hoinacki/longevity-intelligence/blob/main/src/Longevity.Domain/Workflow/WorkflowState.cs"
click node_workflow_processor "https://github.com/tom-hoinacki/longevity-intelligence/blob/main/src/Longevity.Application/Orchestration/WorkflowRunProcessor.cs"
click node_extraction_phase "https://github.com/tom-hoinacki/longevity-intelligence/blob/main/src/Longevity.Application/Orchestration/ExtractingWorkflowRunPhaseHandler.cs"
click node_validation_phase "https://github.com/tom-hoinacki/longevity-intelligence/blob/main/src/Longevity.Application/Orchestration/ValidatingWorkflowRunPhaseHandler.cs"
click node_source_normalization "https://github.com/tom-hoinacki/longevity-intelligence/blob/main/src/Longevity.Application/SourceNormalization/ScientificSourceNormalization.cs"
click node_evidence_scoring "https://github.com/tom-hoinacki/longevity-intelligence/blob/main/src/Longevity.Application/EvidenceScoring/EvidenceScoringEngine.cs"
click node_review_service "https://github.com/tom-hoinacki/longevity-intelligence/blob/main/src/Longevity.Application/HumanReview/HumanReviewService.cs"
click node_publication_phase "https://github.com/tom-hoinacki/longevity-intelligence/blob/main/src/Longevity.Application/Publishing/PublishingWorkflowRunPhaseHandler.cs"
click node_openrouter_model "https://github.com/tom-hoinacki/longevity-intelligence/blob/main/src/Longevity.Infrastructure/ModelProviders/OpenRouter/OpenRouterClaimExtractionModel.cs"
click node_extraction_persistence "https://github.com/tom-hoinacki/longevity-intelligence/blob/main/src/Longevity.Infrastructure/Persistence/PostgresClaimExtractionPersistence.cs"
click node_workflow_repository "https://github.com/tom-hoinacki/longevity-intelligence/blob/main/src/Longevity.Infrastructure/Persistence/PostgresWorkflowRunRepository.cs"
click node_review_persistence "https://github.com/tom-hoinacki/longevity-intelligence/blob/main/src/Longevity.Infrastructure/Persistence/PostgresHumanReviewPersistence.cs"
click node_public_catalog "https://github.com/tom-hoinacki/longevity-intelligence/blob/main/src/Longevity.Infrastructure/PublicEvidence/PostgresPublicEvidenceCatalog.cs"
click node_postgres "https://github.com/tom-hoinacki/longevity-intelligence/blob/main/supabase/migrations/20260711140000_workflow_schema_v1.sql"

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_shell toneBlue
class node_api_bootstrap,node_service_registration,node_public_endpoints,node_review_endpoints,node_workflow_worker toneAmber
class node_workflow_domain,node_workflow_processor,node_extraction_phase,node_validation_phase,node_source_normalization,node_evidence_scoring,node_review_service,node_publication_phase toneMint
class node_openrouter_model,node_extraction_persistence,node_workflow_repository,node_review_persistence,node_public_catalog,node_postgres toneRose
```

## Components

### Web client

- [React web shell](https://github.com/tom-hoinacki/longevity-intelligence/blob/main/src/Longevity.Web/src/main.tsx): Vite/React client · Basic UI shell. · `src/Longevity.Web/src/main.tsx`

### API runtime

- [API bootstrap](https://github.com/tom-hoinacki/longevity-intelligence/blob/main/src/Longevity.Api/Program.cs): ASP.NET Core composition · Registers endpoints, providers, persistence, diagnostics, and worker. · `src/Longevity.Api/Program.cs`
- [Service registration](https://github.com/tom-hoinacki/longevity-intelligence/blob/main/src/Longevity.Api/DependencyInjection/ServiceCollectionExtensions.cs): DI extensions · `src/Longevity.Api/DependencyInjection/ServiceCollectionExtensions.cs`
- [Public evidence API](https://github.com/tom-hoinacki/longevity-intelligence/blob/main/src/Longevity.Api/PublicEvidence/PublicEvidenceEndpoints.cs): HTTP endpoints · `src/Longevity.Api/PublicEvidence/PublicEvidenceEndpoints.cs`
- [Human review API](https://github.com/tom-hoinacki/longevity-intelligence/blob/main/src/Longevity.Api/HumanReview/HumanReviewEndpoints.cs): HTTP endpoints · `src/Longevity.Api/HumanReview/HumanReviewEndpoints.cs`
- [Workflow worker](https://github.com/tom-hoinacki/longevity-intelligence/blob/main/src/Longevity.Api/Workflow/WorkflowOrchestratorBackgroundService.cs): hosted background service · Polls and processes workflow runs outside request lifetimes. · `src/Longevity.Api/Workflow/WorkflowOrchestratorBackgroundService.cs`

### Application core

- [Workflow state](https://github.com/tom-hoinacki/longevity-intelligence/blob/main/src/Longevity.Domain/Workflow/WorkflowState.cs): domain state model · Owns workflow states and identifiers. · `src/Longevity.Domain/Workflow/WorkflowState.cs`
- [Workflow processor](https://github.com/tom-hoinacki/longevity-intelligence/blob/main/src/Longevity.Application/Orchestration/WorkflowRunProcessor.cs): orchestration service · Coordinates lifecycle phases through application contracts. · `src/Longevity.Application/Orchestration/WorkflowRunProcessor.cs`
- [Extraction phase](https://github.com/tom-hoinacki/longevity-intelligence/blob/main/src/Longevity.Application/Orchestration/ExtractingWorkflowRunPhaseHandler.cs): workflow phase handler · `src/Longevity.Application/Orchestration/ExtractingWorkflowRunPhaseHandler.cs`
- [Validation phase](https://github.com/tom-hoinacki/longevity-intelligence/blob/main/src/Longevity.Application/Orchestration/ValidatingWorkflowRunPhaseHandler.cs): workflow phase handler · Performs deterministic validation. · `src/Longevity.Application/Orchestration/ValidatingWorkflowRunPhaseHandler.cs`
- [Source normalization](https://github.com/tom-hoinacki/longevity-intelligence/blob/main/src/Longevity.Application/SourceNormalization/ScientificSourceNormalization.cs): application service · `src/Longevity.Application/SourceNormalization/ScientificSourceNormalization.cs`
- [Evidence scoring](https://github.com/tom-hoinacki/longevity-intelligence/blob/main/src/Longevity.Application/EvidenceScoring/EvidenceScoringEngine.cs): deterministic scoring engine · `src/Longevity.Application/EvidenceScoring/EvidenceScoringEngine.cs`
- [Human review service](https://github.com/tom-hoinacki/longevity-intelligence/blob/main/src/Longevity.Application/HumanReview/HumanReviewService.cs): application service · Decision boundary before approval and publication. · `src/Longevity.Application/HumanReview/HumanReviewService.cs`
- [Publication phase](https://github.com/tom-hoinacki/longevity-intelligence/blob/main/src/Longevity.Application/Publishing/PublishingWorkflowRunPhaseHandler.cs): workflow phase handler · `src/Longevity.Application/Publishing/PublishingWorkflowRunPhaseHandler.cs`

### Infrastructure

- [OpenRouter extraction](https://github.com/tom-hoinacki/longevity-intelligence/blob/main/src/Longevity.Infrastructure/ModelProviders/OpenRouter/OpenRouterClaimExtractionModel.cs): claim extraction provider · `src/Longevity.Infrastructure/ModelProviders/OpenRouter/OpenRouterClaimExtractionModel.cs`
- [Claim extraction persistence](https://github.com/tom-hoinacki/longevity-intelligence/blob/main/src/Longevity.Infrastructure/Persistence/PostgresClaimExtractionPersistence.cs): PostgreSQL persistence · Persists candidates under workflow-preserving policies. · `src/Longevity.Infrastructure/Persistence/PostgresClaimExtractionPersistence.cs`
- [Workflow repository](https://github.com/tom-hoinacki/longevity-intelligence/blob/main/src/Longevity.Infrastructure/Persistence/PostgresWorkflowRunRepository.cs): PostgreSQL repository · `src/Longevity.Infrastructure/Persistence/PostgresWorkflowRunRepository.cs`
- [Human review persistence](https://github.com/tom-hoinacki/longevity-intelligence/blob/main/src/Longevity.Infrastructure/Persistence/PostgresHumanReviewPersistence.cs): PostgreSQL persistence · `src/Longevity.Infrastructure/Persistence/PostgresHumanReviewPersistence.cs`
- [Public evidence catalog](https://github.com/tom-hoinacki/longevity-intelligence/blob/main/src/Longevity.Infrastructure/PublicEvidence/PostgresPublicEvidenceCatalog.cs): PostgreSQL read catalog · `src/Longevity.Infrastructure/PublicEvidence/PostgresPublicEvidenceCatalog.cs`
- [Supabase PostgreSQL](https://github.com/tom-hoinacki/longevity-intelligence/blob/main/supabase/migrations/20260711140000_workflow_schema_v1.sql): evidence and workflow registry · Schema source of truth. · `supabase/migrations/20260711140000_workflow_schema_v1.sql`

## Connections

- React web shell → API bootstrap: HTTP
- API bootstrap → Service registration: configures
- API bootstrap → Public evidence API: maps
- API bootstrap → Human review API: maps
- API bootstrap → Workflow worker: hosts
- Workflow worker → Workflow processor: processes runs
- Workflow processor → Workflow state: applies transitions
- Workflow processor → Workflow repository: loads and updates runs
- Workflow processor → Extraction phase: runs
- Workflow processor → Validation phase: runs
- Workflow processor → Publication phase: runs
- Extraction phase → OpenRouter extraction: extracts claims
- Extraction phase → Claim extraction persistence: persists candidates
- Validation phase → Source normalization: normalizes sources
- Validation phase → Evidence scoring: scores evidence
- Human review API → Human review service: submits decisions
- Human review service → Human review persistence: stores decisions
- Human review service → Publication phase: approves publication
- Publication phase → Public evidence catalog: publishes evidence
- Public evidence API → Public evidence catalog: reads catalog
- Workflow repository → Supabase PostgreSQL: workflow data
- Claim extraction persistence → Supabase PostgreSQL: claims and sources
- Human review persistence → Supabase PostgreSQL: decisions
- Public evidence catalog → Supabase PostgreSQL: published evidence
- OpenRouter extraction → Supabase PostgreSQL: no direct access
