# ankan00v/verdikt architecture

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

- Interactive diagram: https://gitdiagram.com/ankan00v/verdikt
- Repository: https://github.com/ankan00v/verdikt

## Overview

#### Purpose and Entry Points
Verdikt is a Next.js investment-research agent. A user submits a company name and receives a traceable INVEST/PASS recommendation derived from financial, news, and web research. The UI entry points are the landing page at `src/app/page.tsx` and research console at `src/app/research/page.tsx`; execution enters through the SSE API route `src/app/api/research/route.ts`.

#### Client Research Console
The research page starts and monitors a run through the SSE-consuming hook `src/lib/useResearch.ts`. It renders progress and structured node results in the console components, principally `src/components/verdikt/NodeTracker.tsx`, `src/components/verdikt/FindingsFeed.tsx`, and `src/components/verdikt/DetailPane.tsx`. This is a streaming visualization layer, not the source of decision logic; frontend types are shared through `src/lib/researchTypes.ts`.

#### Agent Graph Orchestration
The core backend is a LangGraph StateGraph defined in `src/lib/agent/graph.ts`, with typed shared state in `src/lib/agent/state.ts`. The graph controls ordering, parallel fan-out/fan-in, and progression from request input to final verdict. `src/lib/agent/nodes/gather-data.ts` is the synchronization boundary between independent data retrieval and analysis stages.

#### Identity Resolution and Data Acquisition
The pipeline first maps a company query to a tradable ticker using `src/lib/agent/nodes/resolve-ticker.ts`. It then runs three retrieval branches concurrently:
- Financial/company data from Yahoo Finance: `src/lib/agent/nodes/fetch-financials.ts`
- Recent news from Tavily: `src/lib/agent/nodes/fetch-news.ts`
- Competitive/web research from Tavily: `src/lib/agent/nodes/fetch-web-research.ts`

Yahoo requests may use a configured proxy to work from Vercel infrastructure. These external-data nodes establish the boundary between live source material and downstream LLM interpretation.

#### Structured Analysis and Decisioning
After fan-in, specialized LLM nodes independently interpret each evidence domain: `src/lib/agent/nodes/analyze-fundamentals.ts`, `src/lib/agent/nodes/analyze-sentiment.ts`, and `src/lib/agent/nodes/analyze-competitive.ts`. A final synthesis node, `src/lib/agent/nodes/synthesize-decision.ts`, combines those outputs into the INVEST/PASS verdict, confidence, strengths, risks, and rationale. Output contracts live in `src/lib/agent/schemas.ts`, using Zod-enforced structured responses rather than free-form parsing.

#### LLM and Failure Boundaries
`src/lib/agent/llm.ts` centralizes NVIDIA NIM/Llama inference, structured-output invocation, timeout handling, retry/backoff, and optional fallback-key rotation. This keeps model-provider resilience outside individual analysis nodes. Failures in retrieval or analysis are represented in graph state and surfaced to the streaming console rather than silently hidden.

#### Durability, Caching, and Runtime
The application runs as Next.js App Router/serverless code, intended for Vercel. Redis integration in `src/lib/redis.ts` provides per-node result caching; `src/lib/agent/upstash-saver.ts` persists LangGraph checkpoints to Upstash Redis so an SSE reconnect after a serverless timeout can resume work. Required external services are NVIDIA NIM, Tavily, Yahoo Finance, and optionally Upstash Redis plus a Yahoo proxy.

Main entry points: [`src/lib/agent/nodes/gather-data.ts`](https://github.com/ankan00v/verdikt/blob/main/src/lib/agent/nodes/gather-data.ts) (Gather data), [`src/lib/agent/llm.ts`](https://github.com/ankan00v/verdikt/blob/main/src/lib/agent/llm.ts) (LLM gateway), [`src/lib/agent/nodes/synthesize-decision.ts`](https://github.com/ankan00v/verdikt/blob/main/src/lib/agent/nodes/synthesize-decision.ts) (Synthesize decision), [`src/lib/agent/graph.ts`](https://github.com/ankan00v/verdikt/blob/main/src/lib/agent/graph.ts) (Research StateGraph)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Research UI"]
  node_landing["Landing page<br/>Next.js page<br/>[page.tsx]"]
  node_console["Research console<br/>Next.js page<br/>[page.tsx]"]
  node_research_hook["SSE research hook<br/>client stream hook<br/>[useResearch.ts]"]
  node_console_views["Result views<br/>console components<br/>[NodeTracker.tsx]"]
  node_client_types["Research types<br/>shared frontend types<br/>[researchTypes.ts]"]
end

subgraph group_api["Server Runtime"]
  node_research_api{{"Research SSE route<br/>Next.js API route<br/>[route.ts]"}}
  node_redis_cache[("Redis cache<br/>result cache<br/>[redis.ts]")]
  node_checkpoint_saver[("Upstash checkpoint saver<br/>LangGraph persistence<br/>[upstash-saver.ts]")]
end

subgraph group_pipeline["Agent Pipeline"]
  node_graph{{"Research StateGraph<br/>LangGraph orchestration<br/>[graph.ts]"}}
  node_state["Shared graph state<br/>typed state<br/>[state.ts]"]
  node_resolve_ticker["Resolve ticker<br/>agent node<br/>[resolve-ticker.ts]"]
  node_financials["Fetch financials<br/>retrieval node"]
  node_news["Fetch news<br/>retrieval node<br/>[fetch-news.ts]"]
  node_web_research["Fetch web research<br/>retrieval node"]
  node_gather{{"Gather data<br/>fan-in node<br/>[gather-data.ts]"}}
  node_fundamentals["Analyze fundamentals<br/>LLM analysis node"]
  node_sentiment["Analyze sentiment<br/>LLM analysis node"]
  node_competitive["Analyze competitive<br/>LLM analysis node"]
  node_decision{{"Synthesize decision<br/>LLM synthesis node"}}
  node_schemas["Output schemas<br/>Zod contracts<br/>[schemas.ts]"]
  node_llm["LLM gateway<br/>resilient inference client<br/>[llm.ts]"]
end

subgraph group_services["External Services"]
  node_market_sources["Yahoo Finance<br/>market data service"]
  node_tavily["Tavily<br/>search service"]
  node_nim["NVIDIA NIM / Llama<br/>model provider"]
end

node_landing -->|"opens research"| node_console
node_console -->|"starts and monitors run"| node_research_hook
node_research_hook -->|"SSE request"| node_research_api
node_research_hook -->|"streamed updates"| node_console_views
node_client_types -.->|"types"| node_research_hook
node_client_types -.->|"types"| node_console_views
node_research_api -->|"execute or resume"| node_graph
node_research_api -->|"load/save checkpoints"| node_checkpoint_saver
node_graph -->|"reads and updates"| node_state
node_graph -->|"first stage"| node_resolve_ticker
node_resolve_ticker -->|"ticker fan-out"| node_financials
node_resolve_ticker -->|"ticker fan-out"| node_news
node_resolve_ticker -->|"ticker fan-out"| node_web_research
node_financials -->|"live company data"| node_market_sources
node_news -->|"recent news search"| node_tavily
node_web_research -->|"competitive web search"| node_tavily
node_financials -->|"financial evidence"| node_gather
node_news -->|"news evidence"| node_gather
node_web_research -->|"web evidence"| node_gather
node_gather -->|"analyze"| node_fundamentals
node_gather -->|"analyze"| node_sentiment
node_gather -->|"analyze"| node_competitive
node_fundamentals -->|"fundamental assessment"| node_decision
node_sentiment -->|"sentiment assessment"| node_decision
node_competitive -->|"competitive assessment"| node_decision
node_fundamentals -->|"structured inference"| node_llm
node_sentiment -->|"structured inference"| node_llm
node_competitive -->|"structured inference"| node_llm
node_decision -->|"structured synthesis"| node_llm
node_llm -->|"model invocation"| node_nim
node_llm -->|"validates outputs"| node_schemas
node_graph -.->|"cache node results"| node_redis_cache
node_decision -->|"verdict and state events"| node_research_api

click node_landing "https://github.com/ankan00v/verdikt/blob/main/src/app/page.tsx"
click node_console "https://github.com/ankan00v/verdikt/blob/main/src/app/research/page.tsx"
click node_research_hook "https://github.com/ankan00v/verdikt/blob/main/src/lib/useResearch.ts"
click node_console_views "https://github.com/ankan00v/verdikt/blob/main/src/components/verdikt/NodeTracker.tsx"
click node_client_types "https://github.com/ankan00v/verdikt/blob/main/src/lib/researchTypes.ts"
click node_research_api "https://github.com/ankan00v/verdikt/blob/main/src/app/api/research/route.ts"
click node_graph "https://github.com/ankan00v/verdikt/blob/main/src/lib/agent/graph.ts"
click node_state "https://github.com/ankan00v/verdikt/blob/main/src/lib/agent/state.ts"
click node_resolve_ticker "https://github.com/ankan00v/verdikt/blob/main/src/lib/agent/nodes/resolve-ticker.ts"
click node_financials "https://github.com/ankan00v/verdikt/blob/main/src/lib/agent/nodes/fetch-financials.ts"
click node_news "https://github.com/ankan00v/verdikt/blob/main/src/lib/agent/nodes/fetch-news.ts"
click node_web_research "https://github.com/ankan00v/verdikt/blob/main/src/lib/agent/nodes/fetch-web-research.ts"
click node_gather "https://github.com/ankan00v/verdikt/blob/main/src/lib/agent/nodes/gather-data.ts"
click node_fundamentals "https://github.com/ankan00v/verdikt/blob/main/src/lib/agent/nodes/analyze-fundamentals.ts"
click node_sentiment "https://github.com/ankan00v/verdikt/blob/main/src/lib/agent/nodes/analyze-sentiment.ts"
click node_competitive "https://github.com/ankan00v/verdikt/blob/main/src/lib/agent/nodes/analyze-competitive.ts"
click node_decision "https://github.com/ankan00v/verdikt/blob/main/src/lib/agent/nodes/synthesize-decision.ts"
click node_schemas "https://github.com/ankan00v/verdikt/blob/main/src/lib/agent/schemas.ts"
click node_llm "https://github.com/ankan00v/verdikt/blob/main/src/lib/agent/llm.ts"
click node_redis_cache "https://github.com/ankan00v/verdikt/blob/main/src/lib/redis.ts"
click node_checkpoint_saver "https://github.com/ankan00v/verdikt/blob/main/src/lib/agent/upstash-saver.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_landing,node_console,node_research_hook,node_console_views,node_client_types toneBlue
class node_research_api,node_redis_cache,node_checkpoint_saver toneAmber
class node_graph,node_state,node_resolve_ticker,node_financials,node_news,node_web_research,node_gather,node_fundamentals,node_sentiment,node_competitive,node_decision,node_schemas,node_llm toneMint
class node_market_sources,node_tavily,node_nim toneRose
```

## Components

### Research UI

- [Landing page](https://github.com/ankan00v/verdikt/blob/main/src/app/page.tsx): Next.js page · `src/app/page.tsx`
- [Research console](https://github.com/ankan00v/verdikt/blob/main/src/app/research/page.tsx): Next.js page · Displays streaming run progress and results. · `src/app/research/page.tsx`
- [SSE research hook](https://github.com/ankan00v/verdikt/blob/main/src/lib/useResearch.ts): client stream hook · `src/lib/useResearch.ts`
- [Result views](https://github.com/ankan00v/verdikt/blob/main/src/components/verdikt/NodeTracker.tsx): console components · Progress tracker, findings feed, and detail pane. · `src/components/verdikt/NodeTracker.tsx`
- [Research types](https://github.com/ankan00v/verdikt/blob/main/src/lib/researchTypes.ts): shared frontend types · `src/lib/researchTypes.ts`

### Server Runtime

- [Research SSE route](https://github.com/ankan00v/verdikt/blob/main/src/app/api/research/route.ts): Next.js API route · Starts or resumes graph execution and streams state updates. · `src/app/api/research/route.ts`
- [Redis cache](https://github.com/ankan00v/verdikt/blob/main/src/lib/redis.ts): result cache · Caches per-node results. · `src/lib/redis.ts`
- [Upstash checkpoint saver](https://github.com/ankan00v/verdikt/blob/main/src/lib/agent/upstash-saver.ts): LangGraph persistence · Allows reconnects to resume serverless runs. · `src/lib/agent/upstash-saver.ts`

### Agent Pipeline

- [Research StateGraph](https://github.com/ankan00v/verdikt/blob/main/src/lib/agent/graph.ts): LangGraph orchestration · Controls fan-out, fan-in, and verdict progression. · `src/lib/agent/graph.ts`
- [Shared graph state](https://github.com/ankan00v/verdikt/blob/main/src/lib/agent/state.ts): typed state · Carries evidence, failures, progress, and outputs between nodes. · `src/lib/agent/state.ts`
- [Resolve ticker](https://github.com/ankan00v/verdikt/blob/main/src/lib/agent/nodes/resolve-ticker.ts): agent node · `src/lib/agent/nodes/resolve-ticker.ts`
- [Fetch financials](https://github.com/ankan00v/verdikt/blob/main/src/lib/agent/nodes/fetch-financials.ts): retrieval node · `src/lib/agent/nodes/fetch-financials.ts`
- [Fetch news](https://github.com/ankan00v/verdikt/blob/main/src/lib/agent/nodes/fetch-news.ts): retrieval node · `src/lib/agent/nodes/fetch-news.ts`
- [Fetch web research](https://github.com/ankan00v/verdikt/blob/main/src/lib/agent/nodes/fetch-web-research.ts): retrieval node · `src/lib/agent/nodes/fetch-web-research.ts`
- [Gather data](https://github.com/ankan00v/verdikt/blob/main/src/lib/agent/nodes/gather-data.ts): fan-in node · Synchronization boundary before analysis. · `src/lib/agent/nodes/gather-data.ts`
- [Analyze fundamentals](https://github.com/ankan00v/verdikt/blob/main/src/lib/agent/nodes/analyze-fundamentals.ts): LLM analysis node · `src/lib/agent/nodes/analyze-fundamentals.ts`
- [Analyze sentiment](https://github.com/ankan00v/verdikt/blob/main/src/lib/agent/nodes/analyze-sentiment.ts): LLM analysis node · `src/lib/agent/nodes/analyze-sentiment.ts`
- [Analyze competitive](https://github.com/ankan00v/verdikt/blob/main/src/lib/agent/nodes/analyze-competitive.ts): LLM analysis node · `src/lib/agent/nodes/analyze-competitive.ts`
- [Synthesize decision](https://github.com/ankan00v/verdikt/blob/main/src/lib/agent/nodes/synthesize-decision.ts): LLM synthesis node · Produces INVEST/PASS, confidence, strengths, risks, and rationale. · `src/lib/agent/nodes/synthesize-decision.ts`
- [Output schemas](https://github.com/ankan00v/verdikt/blob/main/src/lib/agent/schemas.ts): Zod contracts · Enforces structured LLM responses. · `src/lib/agent/schemas.ts`
- [LLM gateway](https://github.com/ankan00v/verdikt/blob/main/src/lib/agent/llm.ts): resilient inference client · Centralizes structured calls, retries, timeouts, and key fallback. · `src/lib/agent/llm.ts`

### External Services

- **Yahoo Finance**: market data service · May be reached through a configured proxy.
- **Tavily**: search service
- **NVIDIA NIM / Llama**: model provider

## Connections

- Landing page → Research console: opens research
- Research console → SSE research hook: starts and monitors run
- SSE research hook → Research SSE route: SSE request
- SSE research hook → Result views: streamed updates
- Research types → SSE research hook: types
- Research types → Result views: types
- Research SSE route → Research StateGraph: execute or resume
- Research SSE route → Upstash checkpoint saver: load/save checkpoints
- Research StateGraph → Shared graph state: reads and updates
- Research StateGraph → Resolve ticker: first stage
- Resolve ticker → Fetch financials: ticker fan-out
- Resolve ticker → Fetch news: ticker fan-out
- Resolve ticker → Fetch web research: ticker fan-out
- Fetch financials → Yahoo Finance: live company data
- Fetch news → Tavily: recent news search
- Fetch web research → Tavily: competitive web search
- Fetch financials → Gather data: financial evidence
- Fetch news → Gather data: news evidence
- Fetch web research → Gather data: web evidence
- Gather data → Analyze fundamentals: analyze
- Gather data → Analyze sentiment: analyze
- Gather data → Analyze competitive: analyze
- Analyze fundamentals → Synthesize decision: fundamental assessment
- Analyze sentiment → Synthesize decision: sentiment assessment
- Analyze competitive → Synthesize decision: competitive assessment
- Analyze fundamentals → LLM gateway: structured inference
- Analyze sentiment → LLM gateway: structured inference
- Analyze competitive → LLM gateway: structured inference
- Synthesize decision → LLM gateway: structured synthesis
- LLM gateway → NVIDIA NIM / Llama: model invocation
- LLM gateway → Output schemas: validates outputs
- Research StateGraph → Redis cache: cache node results
- Synthesize decision → Research SSE route: verdict and state events
