# yasser392/papertrail-ai architecture

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

- Interactive diagram: https://gitdiagram.com/yasser392/papertrail-ai
- Repository: https://github.com/yasser392/papertrail-ai

## Overview

PaperTrail AI turns a researcher’s profile and saved papers into a traceable scientific corpus, then supports search, graph exploration, clustering, recommendations, serendipitous discovery, and research-opportunity analysis. The documented main path is profile → background corpus build from federated sources and citation expansion → embeddings → graph and clusters → discovery outputs. The graph also shows the frontend/API boundary and the shared persistence and retrieval layers. Some route and subsystem implementations were not excerpted, so those documented links cite the README rather than implying source inspection.

Main entry points: [`backend/app/services/pipelines.py`](https://github.com/yasser392/papertrail-ai/blob/main/backend/app/services/pipelines.py) (Corpus pipelines), [`frontend/src/App.tsx`](https://github.com/yasser392/papertrail-ai/blob/main/frontend/src/App.tsx) (Web application), [`backend/app/api/routes`](https://github.com/yasser392/papertrail-ai/tree/main/backend/app/api/routes) (REST API routes), [`backend/app/services/corpus.py`](https://github.com/yasser392/papertrail-ai/blob/main/backend/app/services/corpus.py) (Corpus lifecycle)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Researcher interface"]
  node_webapp["Web application<br/>[App.tsx]"]
  node_profile_ui["Research profile<br/>[Profile.tsx]"]
  node_discover_ui["Search and discovery<br/>[Discover.tsx]"]
  node_map_ui["Knowledge map<br/>[KnowledgeMap.tsx]"]
  node_clusters_ui["Cluster explorer<br/>[Clusters.tsx]"]
  node_opportunity_ui["Discovery outputs<br/>[Opportunities.tsx]"]
end

subgraph group_api["API and jobs"]
  node_api_routes["REST API routes"]
  node_job_worker["Background jobs<br/>[jobs.py]"]
  node_pipeline["Corpus pipelines<br/>[pipelines.py]"]
end

subgraph group_ingest["Corpus and retrieval"]
  node_federation["Federated source adapters<br/>[aggregator.py]"]
  node_corpus["Corpus lifecycle<br/>[corpus.py]"]
  node_embeddings["Paper embeddings<br/>[encoder.py]"]
  node_vector_index[("Vector retrieval<br/>[vector_index.py]")]
  node_hybrid_search["Hybrid search<br/>[hybrid.py]"]
end

subgraph group_analysis["Discovery analytics"]
  node_graph_builder["Knowledge graph<br/>[builder.py]"]
  node_cluster_engine["Research clusters<br/>[engine.py]"]
  node_recommendations["Recommendations<br/>[engine.py]"]
  node_serendipity["Serendipity discovery<br/>[engine.py]"]
  node_opportunities["Research opportunities<br/>[analyzer.py]"]
  node_evaluation["Evaluation<br/>[metrics.py]"]
  node_llm["LLM explanations<br/>[llm.py]"]
end

subgraph group_state["Persistence and integrations"]
  node_paper_store[("Paper repository<br/>[papers.py]")]
  node_sql_db[("Relational database<br/>[db.py]")]
  node_neo4j[("Optional Neo4j mirror<br/>[neo4j_store.py]")]
end

node_researcher(("Researcher"))
node_sources{{"Publication services"}}

node_researcher -->|"uses"| node_webapp
node_webapp -->|"offers profile"| node_profile_ui
node_webapp -->|"offers discovery"| node_discover_ui
node_webapp -->|"offers graph"| node_map_ui
node_webapp -->|"offers clusters"| node_clusters_ui
node_webapp -->|"shows opportunities"| node_opportunity_ui
node_webapp -->|"requests API"| node_api_routes
node_api_routes -->|"queues work"| node_job_worker
node_job_worker -.->|"dispatches pipeline"| node_pipeline
node_pipeline -->|"searches sources"| node_federation
node_sources -->|"returns records"| node_federation
node_pipeline -->|"ingests records"| node_paper_store
node_pipeline -->|"embeds corpus"| node_corpus
node_corpus -->|"encodes papers"| node_embeddings
node_corpus -->|"refreshes index"| node_vector_index
node_discover_ui -->|"searches corpus"| node_hybrid_search
node_pipeline -->|"builds graph"| node_graph_builder
node_pipeline -->|"runs clustering"| node_cluster_engine
node_pipeline -->|"generates results"| node_recommendations
node_pipeline -->|"runs benchmark"| node_evaluation
node_graph_builder -.->|"syncs optionally"| node_neo4j
node_recommendations -.->|"explains optionally"| node_llm
node_api_routes -.->|"serves discovery"| node_serendipity
node_api_routes -.->|"serves analysis"| node_opportunities
node_cluster_engine -->|"labels optionally"| node_llm
node_corpus -->|"reads and writes"| node_paper_store
node_hybrid_search -->|"retrieves vectors"| node_vector_index
node_api_routes -->|"accesses records"| node_sql_db

click node_webapp "https://github.com/yasser392/papertrail-ai/blob/main/frontend/src/App.tsx"
click node_profile_ui "https://github.com/yasser392/papertrail-ai/blob/main/frontend/src/pages/Profile.tsx"
click node_discover_ui "https://github.com/yasser392/papertrail-ai/blob/main/frontend/src/pages/Discover.tsx"
click node_map_ui "https://github.com/yasser392/papertrail-ai/blob/main/frontend/src/pages/KnowledgeMap.tsx"
click node_clusters_ui "https://github.com/yasser392/papertrail-ai/blob/main/frontend/src/pages/Clusters.tsx"
click node_opportunity_ui "https://github.com/yasser392/papertrail-ai/blob/main/frontend/src/pages/Opportunities.tsx"
click node_api_routes "https://github.com/yasser392/papertrail-ai/tree/main/backend/app/api/routes"
click node_job_worker "https://github.com/yasser392/papertrail-ai/blob/main/backend/app/workers/jobs.py"
click node_pipeline "https://github.com/yasser392/papertrail-ai/blob/main/backend/app/services/pipelines.py"
click node_federation "https://github.com/yasser392/papertrail-ai/blob/main/backend/app/integrations/aggregator.py"
click node_paper_store "https://github.com/yasser392/papertrail-ai/blob/main/backend/app/repositories/papers.py"
click node_corpus "https://github.com/yasser392/papertrail-ai/blob/main/backend/app/services/corpus.py"
click node_embeddings "https://github.com/yasser392/papertrail-ai/blob/main/backend/app/ml/embeddings/encoder.py"
click node_vector_index "https://github.com/yasser392/papertrail-ai/blob/main/backend/app/ml/retrieval/vector_index.py"
click node_hybrid_search "https://github.com/yasser392/papertrail-ai/blob/main/backend/app/ml/retrieval/hybrid.py"
click node_graph_builder "https://github.com/yasser392/papertrail-ai/blob/main/backend/app/ml/knowledge_graph/builder.py"
click node_cluster_engine "https://github.com/yasser392/papertrail-ai/blob/main/backend/app/ml/clustering/engine.py"
click node_recommendations "https://github.com/yasser392/papertrail-ai/blob/main/backend/app/ml/recommendation/engine.py"
click node_serendipity "https://github.com/yasser392/papertrail-ai/blob/main/backend/app/ml/serendipity/engine.py"
click node_opportunities "https://github.com/yasser392/papertrail-ai/blob/main/backend/app/ml/research_gaps/analyzer.py"
click node_evaluation "https://github.com/yasser392/papertrail-ai/blob/main/backend/app/ml/evaluation/metrics.py"
click node_llm "https://github.com/yasser392/papertrail-ai/blob/main/backend/app/services/llm.py"
click node_sql_db "https://github.com/yasser392/papertrail-ai/blob/main/backend/app/core/db.py"
click node_neo4j "https://github.com/yasser392/papertrail-ai/blob/main/backend/app/ml/knowledge_graph/neo4j_store.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_webapp,node_profile_ui,node_discover_ui,node_map_ui,node_clusters_ui,node_opportunity_ui toneBlue
class node_api_routes,node_job_worker,node_pipeline toneAmber
class node_federation,node_corpus,node_embeddings,node_vector_index,node_hybrid_search toneMint
class node_graph_builder,node_cluster_engine,node_recommendations,node_serendipity,node_opportunities,node_evaluation,node_llm toneRose
class node_paper_store,node_sql_db,node_neo4j,node_researcher,node_sources toneIndigo
```

## Components

### Researcher interface

- [Web application](https://github.com/yasser392/papertrail-ai/blob/main/frontend/src/App.tsx): `frontend/src/App.tsx`
- [Research profile](https://github.com/yasser392/papertrail-ai/blob/main/frontend/src/pages/Profile.tsx): `frontend/src/pages/Profile.tsx`
- [Search and discovery](https://github.com/yasser392/papertrail-ai/blob/main/frontend/src/pages/Discover.tsx): `frontend/src/pages/Discover.tsx`
- [Knowledge map](https://github.com/yasser392/papertrail-ai/blob/main/frontend/src/pages/KnowledgeMap.tsx): `frontend/src/pages/KnowledgeMap.tsx`
- [Cluster explorer](https://github.com/yasser392/papertrail-ai/blob/main/frontend/src/pages/Clusters.tsx): `frontend/src/pages/Clusters.tsx`
- [Discovery outputs](https://github.com/yasser392/papertrail-ai/blob/main/frontend/src/pages/Opportunities.tsx): `frontend/src/pages/Opportunities.tsx`

### API and jobs

- [REST API routes](https://github.com/yasser392/papertrail-ai/tree/main/backend/app/api/routes): `backend/app/api/routes`
- [Background jobs](https://github.com/yasser392/papertrail-ai/blob/main/backend/app/workers/jobs.py): `backend/app/workers/jobs.py`
- [Corpus pipelines](https://github.com/yasser392/papertrail-ai/blob/main/backend/app/services/pipelines.py): `backend/app/services/pipelines.py`

### Corpus and retrieval

- [Federated source adapters](https://github.com/yasser392/papertrail-ai/blob/main/backend/app/integrations/aggregator.py): `backend/app/integrations/aggregator.py`
- [Corpus lifecycle](https://github.com/yasser392/papertrail-ai/blob/main/backend/app/services/corpus.py): `backend/app/services/corpus.py`
- [Paper embeddings](https://github.com/yasser392/papertrail-ai/blob/main/backend/app/ml/embeddings/encoder.py): `backend/app/ml/embeddings/encoder.py`
- [Vector retrieval](https://github.com/yasser392/papertrail-ai/blob/main/backend/app/ml/retrieval/vector_index.py): `backend/app/ml/retrieval/vector_index.py`
- [Hybrid search](https://github.com/yasser392/papertrail-ai/blob/main/backend/app/ml/retrieval/hybrid.py): `backend/app/ml/retrieval/hybrid.py`

### Discovery analytics

- [Knowledge graph](https://github.com/yasser392/papertrail-ai/blob/main/backend/app/ml/knowledge_graph/builder.py): `backend/app/ml/knowledge_graph/builder.py`
- [Research clusters](https://github.com/yasser392/papertrail-ai/blob/main/backend/app/ml/clustering/engine.py): `backend/app/ml/clustering/engine.py`
- [Recommendations](https://github.com/yasser392/papertrail-ai/blob/main/backend/app/ml/recommendation/engine.py): `backend/app/ml/recommendation/engine.py`
- [Serendipity discovery](https://github.com/yasser392/papertrail-ai/blob/main/backend/app/ml/serendipity/engine.py): `backend/app/ml/serendipity/engine.py`
- [Research opportunities](https://github.com/yasser392/papertrail-ai/blob/main/backend/app/ml/research_gaps/analyzer.py): `backend/app/ml/research_gaps/analyzer.py`
- [Evaluation](https://github.com/yasser392/papertrail-ai/blob/main/backend/app/ml/evaluation/metrics.py): `backend/app/ml/evaluation/metrics.py`
- [LLM explanations](https://github.com/yasser392/papertrail-ai/blob/main/backend/app/services/llm.py): `backend/app/services/llm.py`

### Persistence and integrations

- [Paper repository](https://github.com/yasser392/papertrail-ai/blob/main/backend/app/repositories/papers.py): `backend/app/repositories/papers.py`
- [Relational database](https://github.com/yasser392/papertrail-ai/blob/main/backend/app/core/db.py): `backend/app/core/db.py`
- [Optional Neo4j mirror](https://github.com/yasser392/papertrail-ai/blob/main/backend/app/ml/knowledge_graph/neo4j_store.py): `backend/app/ml/knowledge_graph/neo4j_store.py`

### Other components

- **Researcher**
- **Publication services**

## Connections

- Researcher → Web application: uses (evidence: `README.md`)
- Web application → Research profile: offers profile (evidence: `README.md`)
- Web application → Search and discovery: offers discovery (evidence: `README.md`)
- Web application → Knowledge map: offers graph (evidence: `README.md`)
- Web application → Cluster explorer: offers clusters (evidence: `README.md`)
- Web application → Discovery outputs: shows opportunities (evidence: `README.md`)
- Web application → REST API routes: requests API (evidence: `README.md`)
- REST API routes → Background jobs: queues work (evidence: `backend/app/api/routes/clusters.py`)
- Background jobs → Corpus pipelines: dispatches pipeline
- Corpus pipelines → Federated source adapters: searches sources (evidence: `backend/app/services/pipelines.py`)
- Publication services → Federated source adapters: returns records (evidence: `README.md`)
- Corpus pipelines → Paper repository: ingests records
- Corpus pipelines → Corpus lifecycle: embeds corpus (evidence: `backend/app/services/pipelines.py`)
- Corpus lifecycle → Paper embeddings: encodes papers (evidence: `backend/app/services/corpus.py`)
- Corpus lifecycle → Vector retrieval: refreshes index (evidence: `backend/app/services/corpus.py`)
- Search and discovery → Hybrid search: searches corpus (evidence: `README.md`)
- Corpus pipelines → Knowledge graph: builds graph (evidence: `backend/app/services/pipelines.py`)
- Corpus pipelines → Research clusters: runs clustering (evidence: `backend/app/services/pipelines.py`)
- Corpus pipelines → Recommendations: generates results (evidence: `backend/app/services/pipelines.py`)
- Corpus pipelines → Evaluation: runs benchmark (evidence: `backend/app/services/pipelines.py`)
- Knowledge graph → Optional Neo4j mirror: syncs optionally (evidence: `README.md`)
- Recommendations → LLM explanations: explains optionally (evidence: `README.md`)
- REST API routes → Serendipity discovery: serves discovery
- REST API routes → Research opportunities: serves analysis
- Research clusters → LLM explanations: labels optionally (evidence: `backend/app/ml/clustering/engine.py`)
- Corpus lifecycle → Paper repository: reads and writes (evidence: `backend/app/services/corpus.py`)
- Hybrid search → Vector retrieval: retrieves vectors (evidence: `backend/app/ml/retrieval/hybrid.py`)
- REST API routes → Relational database: accesses records (evidence: `backend/app/api/routes/clusters.py`)
