# sahil-2005/amivre architecture

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

- Interactive diagram: https://gitdiagram.com/sahil-2005/amivre
- Repository: https://github.com/sahil-2005/amivre

## Overview

#### Purpose and entry points
AMIVRE is an asynchronous market-intelligence system that turns a submitted venture idea into an evidence-grounded risk and competitor report. The interactive entry point is the Next.js App Router UI; its API boundary is FastAPI, which delegates long-running analysis to Celery.
- `frontend/src/app/(dashboard)/new-analysis/page.tsx`
- `backend/app/main.py`
- `backend/app/api/routes/analysis.py`

#### Frontend application
The Next.js 14 frontend provides authentication, dashboard/history, analysis submission, and a job-specific report view. It calls the backend through a typed client and uses a WebSocket hook to render live agent progress; report tabs map to each specialist’s result.
- `frontend/src/lib/api-client.ts`
- `frontend/src/hooks/use-websocket-progress.ts`
- `frontend/src/app/(dashboard)/analysis/[jobId]/page.tsx`

#### API, identity, and persistence boundary
FastAPI exposes versioned analysis, authentication, health, and WebSocket endpoints. SQLAlchemy models represent users and durable analysis-job state/results; Alembic owns schema evolution. This layer should remain request-oriented: creation/status access at the API edge, execution in workers.
- `backend/app/api/routes/auth.py`
- `backend/app/api/websocket.py`
- `backend/app/models/analysis_job.py`

#### Asynchronous execution and infrastructure
Analysis requests enqueue Celery work rather than executing scraping/LLM calls in the API process. Redis is the Celery broker; PostgreSQL persists application data. Docker Compose provisions backend, worker, PostgreSQL, Redis, and Qdrant; Qdrant is reserved for future RAG-oriented capability.
- `backend/app/worker/celery_app.py`
- `docker/docker-compose.yml`
- `docker/Dockerfile.celery`

#### Orchestration graph and state
A LangGraph workflow coordinates the analysis lifecycle. The master-query stage first produces focused research queries, then specialized research agents operate, and the risk modeller synthesizes their outputs into the final venture risk score and mitigations. Shared graph state is the key contract between stages.
- `backend/app/orchestrator/graph.py`
- `backend/app/orchestrator/state.py`
- `backend/app/agents/master_query_node.py`

#### Specialized AI agents
Five focused agents implement market sizing, sentiment, competitor mapping, trend forecasting, and final risk synthesis. Prompt templates are externalized per research persona, enabling behavior changes without changing orchestration code. Gemini Pro 1.5 Flash is the LLM runtime.
- `backend/app/agents/market_scout.py`
- `backend/app/agents/sentiment_analyst.py`
- `backend/app/agents/risk_modeller.py`

#### Research and external-service boundary
Agents obtain live evidence through the research pipeline: Tavily provides search, while Crawl4AI/headless Chromium renders and extracts web content. Sources include Wikipedia, Hacker News, Reddit, Google Play, and Google Trends. Extracted Markdown is truncated before Gemini prompt injection, creating an explicit scrape-to-LLM size/safety boundary.
- `backend/app/scrapers/research_pipeline.py`
- `backend/app/scrapers/scraper_runner.py`
- `backend/app/config.py>

Main entry points: [`backend/app/scrapers/research_pipeline.py`](https://github.com/sahil-2005/amivre/blob/main/backend/app/scrapers/research_pipeline.py) (Evidence pipeline), [`backend/app/api/routes/analysis.py`](https://github.com/sahil-2005/amivre/blob/main/backend/app/api/routes/analysis.py) (Analysis routes), [`backend/app/models/analysis_job.py`](https://github.com/sahil-2005/amivre/blob/main/backend/app/models/analysis_job.py) (Analysis job state), [`backend/app/main.py`](https://github.com/sahil-2005/amivre/blob/main/backend/app/main.py) (FastAPI service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Next.js frontend"]
  node_new_analysis["New analysis UI<br/>Next.js page<br/>[page.tsx]"]
  node_report_view["Live report view<br/>Next.js page<br/>[page.tsx]"]
  node_api_client["Typed API client<br/>frontend client<br/>[api-client.ts]"]
  node_progress_hook["WebSocket progress hook<br/>frontend hook"]
end

subgraph group_api["API and data"]
  node_fastapi["FastAPI service<br/>API boundary<br/>[main.py]"]
  node_analysis_routes["Analysis routes<br/>FastAPI routes<br/>[analysis.py]"]
  node_auth_routes["Auth routes<br/>FastAPI routes<br/>[auth.py]"]
  node_websocket_endpoint["Progress WebSocket<br/>FastAPI WebSocket<br/>[websocket.py]"]
  node_job_model[("Analysis job state<br/>SQLAlchemy model<br/>[analysis_job.py]")]
  node_postgres[("PostgreSQL<br/>database<br/>[docker-compose.yml]")]
end

subgraph group_execution["Async analysis"]
  node_celery["Celery worker<br/>async worker<br/>[celery_app.py]"]
  node_redis["Redis broker<br/>Celery broker<br/>[docker-compose.yml]"]
  node_langgraph{{"Analysis workflow<br/>LangGraph orchestration<br/>[graph.py]"}}
  node_graph_state["Shared graph state<br/>workflow contract<br/>[state.py]"]
  node_master_query["Master query stage<br/>agent node"]
  node_specialist_agents["Research specialists<br/>AI agents<br/>[market_scout.py]"]
  node_risk_modeller["Risk synthesis<br/>AI agent<br/>[risk_modeller.py]"]
end

subgraph group_research["Research services"]
  node_research_pipeline["Evidence pipeline<br/>research pipeline"]
  node_scraper_runner["Web extraction<br/>Crawl4AI / Chromium<br/>[scraper_runner.py]"]
  node_external_sources(("Search and web sources<br/>external services"))
  node_gemini(("Gemini 1.5 Flash<br/>LLM runtime"))
  node_qdrant[("Qdrant<br/>future vector store<br/>[docker-compose.yml]")]
end

node_new_analysis -->|"submit idea"| node_api_client
node_api_client -->|"HTTP"| node_analysis_routes
node_report_view -->|"job and report"| node_api_client
node_report_view -->|"live status"| node_progress_hook
node_progress_hook -->|"WebSocket"| node_websocket_endpoint
node_fastapi -->|"serves"| node_analysis_routes
node_fastapi -->|"serves"| node_auth_routes
node_fastapi -->|"serves"| node_websocket_endpoint
node_analysis_routes -->|"create/read jobs"| node_job_model
node_job_model -->|"persist"| node_postgres
node_analysis_routes -->|"enqueue"| node_redis
node_celery -->|"consume tasks"| node_redis
node_celery -->|"run workflow"| node_langgraph
node_langgraph -->|"reads/writes"| node_graph_state
node_langgraph -->|"first stage"| node_master_query
node_master_query -->|"focused queries"| node_specialist_agents
node_specialist_agents -->|"gather evidence"| node_research_pipeline
node_research_pipeline -->|"search and fetch"| node_external_sources
node_research_pipeline -->|"render/extract"| node_scraper_runner
node_research_pipeline -->|"truncated Markdown"| node_gemini
node_specialist_agents -->|"research outputs"| node_risk_modeller
node_risk_modeller -->|"synthesize"| node_gemini
node_risk_modeller -->|"final report"| node_job_model
node_celery -->|"update progress"| node_job_model

click node_new_analysis "https://github.com/sahil-2005/amivre/blob/main/frontend/src/app/(dashboard)/new-analysis/page.tsx"
click node_report_view "https://github.com/sahil-2005/amivre/blob/main/frontend/src/app/(dashboard)/analysis/%5BjobId%5D/page.tsx"
click node_api_client "https://github.com/sahil-2005/amivre/blob/main/frontend/src/lib/api-client.ts"
click node_progress_hook "https://github.com/sahil-2005/amivre/blob/main/frontend/src/hooks/use-websocket-progress.ts"
click node_fastapi "https://github.com/sahil-2005/amivre/blob/main/backend/app/main.py"
click node_analysis_routes "https://github.com/sahil-2005/amivre/blob/main/backend/app/api/routes/analysis.py"
click node_auth_routes "https://github.com/sahil-2005/amivre/blob/main/backend/app/api/routes/auth.py"
click node_websocket_endpoint "https://github.com/sahil-2005/amivre/blob/main/backend/app/api/websocket.py"
click node_job_model "https://github.com/sahil-2005/amivre/blob/main/backend/app/models/analysis_job.py"
click node_postgres "https://github.com/sahil-2005/amivre/blob/main/docker/docker-compose.yml"
click node_celery "https://github.com/sahil-2005/amivre/blob/main/backend/app/worker/celery_app.py"
click node_redis "https://github.com/sahil-2005/amivre/blob/main/docker/docker-compose.yml"
click node_langgraph "https://github.com/sahil-2005/amivre/blob/main/backend/app/orchestrator/graph.py"
click node_graph_state "https://github.com/sahil-2005/amivre/blob/main/backend/app/orchestrator/state.py"
click node_master_query "https://github.com/sahil-2005/amivre/blob/main/backend/app/agents/master_query_node.py"
click node_specialist_agents "https://github.com/sahil-2005/amivre/blob/main/backend/app/agents/market_scout.py"
click node_risk_modeller "https://github.com/sahil-2005/amivre/blob/main/backend/app/agents/risk_modeller.py"
click node_research_pipeline "https://github.com/sahil-2005/amivre/blob/main/backend/app/scrapers/research_pipeline.py"
click node_scraper_runner "https://github.com/sahil-2005/amivre/blob/main/backend/app/scrapers/scraper_runner.py"
click node_qdrant "https://github.com/sahil-2005/amivre/blob/main/docker/docker-compose.yml"

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_new_analysis,node_report_view,node_api_client,node_progress_hook toneBlue
class node_fastapi,node_analysis_routes,node_auth_routes,node_websocket_endpoint,node_job_model,node_postgres toneAmber
class node_celery,node_redis,node_langgraph,node_graph_state,node_master_query,node_specialist_agents,node_risk_modeller toneMint
class node_research_pipeline,node_scraper_runner,node_external_sources,node_gemini,node_qdrant toneRose
```

## Components

### Next.js frontend

- [New analysis UI](https://github.com/sahil-2005/amivre/blob/main/frontend/src/app/(dashboard)/new-analysis/page.tsx): Next.js page · Submits venture ideas. · `frontend/src/app/(dashboard)/new-analysis/page.tsx`
- [Live report view](https://github.com/sahil-2005/amivre/blob/main/frontend/src/app/(dashboard)/analysis/%5BjobId%5D/page.tsx): Next.js page · Renders specialist report tabs and progress. · `frontend/src/app/(dashboard)/analysis/[jobId]/page.tsx`
- [Typed API client](https://github.com/sahil-2005/amivre/blob/main/frontend/src/lib/api-client.ts): frontend client · `frontend/src/lib/api-client.ts`
- [WebSocket progress hook](https://github.com/sahil-2005/amivre/blob/main/frontend/src/hooks/use-websocket-progress.ts): frontend hook · `frontend/src/hooks/use-websocket-progress.ts`

### API and data

- [FastAPI service](https://github.com/sahil-2005/amivre/blob/main/backend/app/main.py): API boundary · Serves versioned analysis, auth, health, and WebSocket endpoints. · `backend/app/main.py`
- [Analysis routes](https://github.com/sahil-2005/amivre/blob/main/backend/app/api/routes/analysis.py): FastAPI routes · Creates and retrieves analysis jobs. · `backend/app/api/routes/analysis.py`
- [Auth routes](https://github.com/sahil-2005/amivre/blob/main/backend/app/api/routes/auth.py): FastAPI routes · `backend/app/api/routes/auth.py`
- [Progress WebSocket](https://github.com/sahil-2005/amivre/blob/main/backend/app/api/websocket.py): FastAPI WebSocket · `backend/app/api/websocket.py`
- [Analysis job state](https://github.com/sahil-2005/amivre/blob/main/backend/app/models/analysis_job.py): SQLAlchemy model · Durable job status and results contract. · `backend/app/models/analysis_job.py`
- [PostgreSQL](https://github.com/sahil-2005/amivre/blob/main/docker/docker-compose.yml): database · Persists users and analysis jobs. · `docker/docker-compose.yml`

### Async analysis

- [Celery worker](https://github.com/sahil-2005/amivre/blob/main/backend/app/worker/celery_app.py): async worker · Executes long-running analysis outside the API process. · `backend/app/worker/celery_app.py`
- [Redis broker](https://github.com/sahil-2005/amivre/blob/main/docker/docker-compose.yml): Celery broker · `docker/docker-compose.yml`
- [Analysis workflow](https://github.com/sahil-2005/amivre/blob/main/backend/app/orchestrator/graph.py): LangGraph orchestration · Coordinates the analysis lifecycle through shared state. · `backend/app/orchestrator/graph.py`
- [Shared graph state](https://github.com/sahil-2005/amivre/blob/main/backend/app/orchestrator/state.py): workflow contract · Carries queries, research outputs, and synthesis between stages. · `backend/app/orchestrator/state.py`
- [Master query stage](https://github.com/sahil-2005/amivre/blob/main/backend/app/agents/master_query_node.py): agent node · Generates focused research queries. · `backend/app/agents/master_query_node.py`
- [Research specialists](https://github.com/sahil-2005/amivre/blob/main/backend/app/agents/market_scout.py): AI agents · Market sizing, sentiment, competitor mapping, and trend forecasting. · `backend/app/agents/market_scout.py`
- [Risk synthesis](https://github.com/sahil-2005/amivre/blob/main/backend/app/agents/risk_modeller.py): AI agent · Produces risk score and mitigations from specialist outputs. · `backend/app/agents/risk_modeller.py`

### Research services

- [Evidence pipeline](https://github.com/sahil-2005/amivre/blob/main/backend/app/scrapers/research_pipeline.py): research pipeline · Searches, renders, extracts, and truncates evidence before prompting. · `backend/app/scrapers/research_pipeline.py`
- [Web extraction](https://github.com/sahil-2005/amivre/blob/main/backend/app/scrapers/scraper_runner.py): Crawl4AI / Chromium · `backend/app/scrapers/scraper_runner.py`
- **Search and web sources**: external services · Tavily search plus public web sources.
- **Gemini 1.5 Flash**: LLM runtime
- [Qdrant](https://github.com/sahil-2005/amivre/blob/main/docker/docker-compose.yml): future vector store · Reserved for future RAG capability. · `docker/docker-compose.yml`

## Connections

- New analysis UI → Typed API client: submit idea
- Typed API client → Analysis routes: HTTP
- Live report view → Typed API client: job and report
- Live report view → WebSocket progress hook: live status
- WebSocket progress hook → Progress WebSocket: WebSocket
- FastAPI service → Analysis routes: serves
- FastAPI service → Auth routes: serves
- FastAPI service → Progress WebSocket: serves
- Analysis routes → Analysis job state: create/read jobs
- Analysis job state → PostgreSQL: persist
- Analysis routes → Redis broker: enqueue
- Celery worker → Redis broker: consume tasks
- Celery worker → Analysis workflow: run workflow
- Analysis workflow → Shared graph state: reads/writes
- Analysis workflow → Master query stage: first stage
- Master query stage → Research specialists: focused queries
- Research specialists → Evidence pipeline: gather evidence
- Evidence pipeline → Search and web sources: search and fetch
- Evidence pipeline → Web extraction: render/extract
- Evidence pipeline → Gemini 1.5 Flash: truncated Markdown
- Research specialists → Risk synthesis: research outputs
- Risk synthesis → Gemini 1.5 Flash: synthesize
- Risk synthesis → Analysis job state: final report
- Celery worker → Analysis job state: update progress
