# navinsreejithprep/pib-rag-agent architecture

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

- Interactive diagram: https://gitdiagram.com/navinsreejithprep/pib-rag-agent
- Repository: https://github.com/navinsreejithprep/pib-rag-agent

## Overview

The repository contains two user-facing products: Executive Media Intelligence, which turns a question into a verified, cited executive brief, and DocQuery, which indexes uploaded PDFs for document Q&A. The media product’s fixed pipeline and bounded autonomous research mode share downstream synthesis and verification; PDF evidence can also enter media research. The graph follows documented and indexed module relationships; some UI-to-endpoint and unsampled subsystem links rely on README descriptions rather than inspected route bodies.

Main entry points: [`lib/media/orchestrator.ts`](https://github.com/navinsreejithprep/pib-rag-agent/blob/main/lib/media/orchestrator.ts) (Fixed orchestrator), [`lib/media/agent/orchestrator.ts`](https://github.com/navinsreejithprep/pib-rag-agent/blob/main/lib/media/agent/orchestrator.ts) (Agent orchestrator), [`app/api/media/ingest-pib/route.ts`](https://github.com/navinsreejithprep/pib-rag-agent/blob/main/app/api/media/ingest-pib/route.ts) (PIB ingestion API), [`lib/rag.ts`](https://github.com/navinsreejithprep/pib-rag-agent/blob/main/lib/rag.ts) (Document retrieval and Q&A)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_media["Media intelligence"]
  node_dashboard["Media dashboard"]
  node_query_api["Media query API<br/>[route.ts]"]
  node_fixed["Fixed orchestrator<br/>[orchestrator.ts]"]
  node_intent["Query understanding<br/>[intent.ts]"]
  node_search["Evidence search<br/>[search.ts]"]
  node_cluster["Event clustering<br/>[cluster.ts]"]
  node_compare["Source comparison<br/>[compare.ts]"]
  node_impact["Impact analysis<br/>[impact.ts]"]
  node_brief["Brief generation<br/>[brief.ts]"]
  node_verify["Citation verification<br/>[verify.ts]"]
end

subgraph group_agent["Autonomous research"]
  node_autonomous_api["Agent API<br/>[route.ts]"]
  node_agent_orch["Agent orchestrator<br/>[orchestrator.ts]"]
  node_loop["Research loop<br/>[loop.ts]"]
end

subgraph group_ingest["Evidence ingestion"]
  node_media_store[("Media evidence store<br/>[store.ts]")]
  node_pib_source["PIB releases<br/>[pib.ts]"]
  node_pib_ingest["PIB ingestion API<br/>[route.ts]"]
end

subgraph group_docquery["DocQuery"]
  node_pdf_ui["DocQuery interface<br/>[rag-app.tsx]"]
  node_pdf_ingest["PDF ingestion API<br/>[route.ts]"]
  node_pdf_store[("Document store<br/>[store.ts]")]
  node_rag["Document retrieval and Q&amp;A<br/>[rag.ts]"]
end

subgraph group_services["Shared services"]
  node_openai["OpenAI client<br/>[openai.ts]"]
end

node_analyst(("Analyst"))
node_openai_service["OpenAI"]
node_executive["Executive brief"]

node_analyst -->|"asks question"| node_dashboard
node_dashboard -->|"submits query"| node_query_api
node_query_api -->|"runs pipeline"| node_fixed
node_fixed -->|"classifies query"| node_intent
node_fixed -->|"searches evidence"| node_search
node_fixed -->|"clusters results"| node_cluster
node_fixed -->|"compares sources"| node_compare
node_fixed -->|"analyzes impact"| node_impact
node_fixed -->|"generates brief"| node_brief
node_fixed -->|"verifies citations"| node_verify
node_fixed -->|"streams result"| node_executive
node_search -->|"searches items"| node_media_store
node_search -->|"searches PDFs"| node_rag
node_pib_ingest -->|"fetches releases"| node_pib_source
node_pib_ingest -->|"embeds text"| node_openai
node_pib_ingest -->|"seeds evidence"| node_media_store
node_dashboard -->|"triggers pull"| node_pib_ingest
node_analyst -.->|"requests research"| node_autonomous_api
node_autonomous_api -->|"runs agent flow"| node_agent_orch
node_agent_orch -->|"gathers evidence"| node_loop
node_agent_orch -->|"clusters results"| node_cluster
node_agent_orch -->|"compares sources"| node_compare
node_agent_orch -->|"analyzes impact"| node_impact
node_agent_orch -->|"generates brief"| node_brief
node_agent_orch -->|"verifies citations"| node_verify
node_pdf_ui -.->|"uploads PDF"| node_pdf_ingest
node_pdf_ingest -->|"embeds chunks"| node_openai
node_pdf_ingest -->|"stores chunks"| node_pdf_store
node_pdf_ui -.->|"asks document question"| node_rag
node_rag -->|"retrieves chunks"| node_pdf_store
node_rag -->|"embeds and answers"| node_openai
node_openai -->|"calls models"| node_openai_service

click node_dashboard "https://github.com/navinsreejithprep/pib-rag-agent/blob/main/components/media-dashboard.tsx"
click node_query_api "https://github.com/navinsreejithprep/pib-rag-agent/blob/main/app/api/media/query/route.ts"
click node_fixed "https://github.com/navinsreejithprep/pib-rag-agent/blob/main/lib/media/orchestrator.ts"
click node_intent "https://github.com/navinsreejithprep/pib-rag-agent/blob/main/lib/media/tools/intent.ts"
click node_search "https://github.com/navinsreejithprep/pib-rag-agent/blob/main/lib/media/tools/search.ts"
click node_cluster "https://github.com/navinsreejithprep/pib-rag-agent/blob/main/lib/media/tools/cluster.ts"
click node_compare "https://github.com/navinsreejithprep/pib-rag-agent/blob/main/lib/media/tools/compare.ts"
click node_impact "https://github.com/navinsreejithprep/pib-rag-agent/blob/main/lib/media/tools/impact.ts"
click node_brief "https://github.com/navinsreejithprep/pib-rag-agent/blob/main/lib/media/tools/brief.ts"
click node_verify "https://github.com/navinsreejithprep/pib-rag-agent/blob/main/lib/media/tools/verify.ts"
click node_media_store "https://github.com/navinsreejithprep/pib-rag-agent/blob/main/lib/media/store.ts"
click node_pib_source "https://github.com/navinsreejithprep/pib-rag-agent/blob/main/lib/media/sources/pib.ts"
click node_pib_ingest "https://github.com/navinsreejithprep/pib-rag-agent/blob/main/app/api/media/ingest-pib/route.ts"
click node_autonomous_api "https://github.com/navinsreejithprep/pib-rag-agent/blob/main/app/api/media/agent/route.ts"
click node_agent_orch "https://github.com/navinsreejithprep/pib-rag-agent/blob/main/lib/media/agent/orchestrator.ts"
click node_loop "https://github.com/navinsreejithprep/pib-rag-agent/blob/main/lib/media/agent/loop.ts"
click node_pdf_ui "https://github.com/navinsreejithprep/pib-rag-agent/blob/main/components/rag-app.tsx"
click node_pdf_ingest "https://github.com/navinsreejithprep/pib-rag-agent/blob/main/app/api/ingest/route.ts"
click node_pdf_store "https://github.com/navinsreejithprep/pib-rag-agent/blob/main/lib/store.ts"
click node_rag "https://github.com/navinsreejithprep/pib-rag-agent/blob/main/lib/rag.ts"
click node_openai "https://github.com/navinsreejithprep/pib-rag-agent/blob/main/lib/openai.ts"

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_dashboard,node_query_api,node_fixed,node_intent,node_search,node_cluster,node_compare,node_impact,node_brief,node_verify toneBlue
class node_autonomous_api,node_agent_orch,node_loop toneAmber
class node_media_store,node_pib_source,node_pib_ingest toneMint
class node_pdf_ui,node_pdf_ingest,node_pdf_store,node_rag toneRose
class node_openai,node_analyst,node_openai_service,node_executive toneIndigo
```

## Components

### Media intelligence

- [Media dashboard](https://github.com/navinsreejithprep/pib-rag-agent/blob/main/components/media-dashboard.tsx): `components/media-dashboard.tsx`
- [Media query API](https://github.com/navinsreejithprep/pib-rag-agent/blob/main/app/api/media/query/route.ts): `app/api/media/query/route.ts`
- [Fixed orchestrator](https://github.com/navinsreejithprep/pib-rag-agent/blob/main/lib/media/orchestrator.ts): `lib/media/orchestrator.ts`
- [Query understanding](https://github.com/navinsreejithprep/pib-rag-agent/blob/main/lib/media/tools/intent.ts): `lib/media/tools/intent.ts`
- [Evidence search](https://github.com/navinsreejithprep/pib-rag-agent/blob/main/lib/media/tools/search.ts): `lib/media/tools/search.ts`
- [Event clustering](https://github.com/navinsreejithprep/pib-rag-agent/blob/main/lib/media/tools/cluster.ts): `lib/media/tools/cluster.ts`
- [Source comparison](https://github.com/navinsreejithprep/pib-rag-agent/blob/main/lib/media/tools/compare.ts): `lib/media/tools/compare.ts`
- [Impact analysis](https://github.com/navinsreejithprep/pib-rag-agent/blob/main/lib/media/tools/impact.ts): `lib/media/tools/impact.ts`
- [Brief generation](https://github.com/navinsreejithprep/pib-rag-agent/blob/main/lib/media/tools/brief.ts): `lib/media/tools/brief.ts`
- [Citation verification](https://github.com/navinsreejithprep/pib-rag-agent/blob/main/lib/media/tools/verify.ts): `lib/media/tools/verify.ts`

### Autonomous research

- [Agent API](https://github.com/navinsreejithprep/pib-rag-agent/blob/main/app/api/media/agent/route.ts): `app/api/media/agent/route.ts`
- [Agent orchestrator](https://github.com/navinsreejithprep/pib-rag-agent/blob/main/lib/media/agent/orchestrator.ts): `lib/media/agent/orchestrator.ts`
- [Research loop](https://github.com/navinsreejithprep/pib-rag-agent/blob/main/lib/media/agent/loop.ts): `lib/media/agent/loop.ts`

### Evidence ingestion

- [Media evidence store](https://github.com/navinsreejithprep/pib-rag-agent/blob/main/lib/media/store.ts): `lib/media/store.ts`
- [PIB releases](https://github.com/navinsreejithprep/pib-rag-agent/blob/main/lib/media/sources/pib.ts): `lib/media/sources/pib.ts`
- [PIB ingestion API](https://github.com/navinsreejithprep/pib-rag-agent/blob/main/app/api/media/ingest-pib/route.ts): `app/api/media/ingest-pib/route.ts`

### DocQuery

- [DocQuery interface](https://github.com/navinsreejithprep/pib-rag-agent/blob/main/components/rag-app.tsx): `components/rag-app.tsx`
- [PDF ingestion API](https://github.com/navinsreejithprep/pib-rag-agent/blob/main/app/api/ingest/route.ts): `app/api/ingest/route.ts`
- [Document store](https://github.com/navinsreejithprep/pib-rag-agent/blob/main/lib/store.ts): `lib/store.ts`
- [Document retrieval and Q&A](https://github.com/navinsreejithprep/pib-rag-agent/blob/main/lib/rag.ts): `lib/rag.ts`

### Shared services

- [OpenAI client](https://github.com/navinsreejithprep/pib-rag-agent/blob/main/lib/openai.ts): `lib/openai.ts`

### Other components

- **Analyst**
- **OpenAI**
- **Executive brief**

## Connections

- Analyst → Media dashboard: asks question
- Media dashboard → Media query API: submits query
- Media query API → Fixed orchestrator: runs pipeline (evidence: `app/api/media/query/route.ts`)
- Fixed orchestrator → Query understanding: classifies query (evidence: `lib/media/orchestrator.ts`)
- Fixed orchestrator → Evidence search: searches evidence (evidence: `lib/media/orchestrator.ts`)
- Fixed orchestrator → Event clustering: clusters results (evidence: `lib/media/orchestrator.ts`)
- Fixed orchestrator → Source comparison: compares sources (evidence: `lib/media/orchestrator.ts`)
- Fixed orchestrator → Impact analysis: analyzes impact (evidence: `lib/media/orchestrator.ts`)
- Fixed orchestrator → Brief generation: generates brief (evidence: `lib/media/orchestrator.ts`)
- Fixed orchestrator → Citation verification: verifies citations (evidence: `lib/media/orchestrator.ts`)
- Fixed orchestrator → Executive brief: streams result
- Evidence search → Media evidence store: searches items (evidence: `lib/media/tools/search.ts`)
- Evidence search → Document retrieval and Q&A: searches PDFs (evidence: `lib/media/tools/search.ts`)
- PIB ingestion API → PIB releases: fetches releases (evidence: `app/api/media/ingest-pib/route.ts`)
- PIB ingestion API → OpenAI client: embeds text (evidence: `app/api/media/ingest-pib/route.ts`)
- PIB ingestion API → Media evidence store: seeds evidence (evidence: `app/api/media/ingest-pib/route.ts`)
- Media dashboard → PIB ingestion API: triggers pull (evidence: `app/api/media/ingest-pib/route.ts`)
- Analyst → Agent API: requests research
- Agent API → Agent orchestrator: runs agent flow (evidence: `app/api/media/agent/route.ts`)
- Agent orchestrator → Research loop: gathers evidence (evidence: `lib/media/agent/orchestrator.ts`)
- Agent orchestrator → Event clustering: clusters results (evidence: `lib/media/agent/orchestrator.ts`)
- Agent orchestrator → Source comparison: compares sources (evidence: `lib/media/agent/orchestrator.ts`)
- Agent orchestrator → Impact analysis: analyzes impact (evidence: `lib/media/agent/orchestrator.ts`)
- Agent orchestrator → Brief generation: generates brief (evidence: `lib/media/agent/orchestrator.ts`)
- Agent orchestrator → Citation verification: verifies citations (evidence: `lib/media/agent/orchestrator.ts`)
- DocQuery interface → PDF ingestion API: uploads PDF
- PDF ingestion API → OpenAI client: embeds chunks (evidence: `app/api/ingest/route.ts`)
- PDF ingestion API → Document store: stores chunks (evidence: `app/api/ingest/route.ts`)
- DocQuery interface → Document retrieval and Q&A: asks document question
- Document retrieval and Q&A → Document store: retrieves chunks (evidence: `lib/rag.ts`)
- Document retrieval and Q&A → OpenAI client: embeds and answers (evidence: `lib/rag.ts`)
- OpenAI client → OpenAI: calls models (evidence: `lib/openai.ts`)
