# meetmendapara09/llm-council architecture

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

- Interactive diagram: https://gitdiagram.com/meetmendapara09/llm-council
- Repository: https://github.com/meetmendapara09/llm-council

## Overview

#### Purpose and entry points
LLM Council is a local, browser-based multi-model deliberation system. A user prompt is sent through OpenRouter to several LLMs, then through peer review/ranking, and finally to a chairman model for synthesis. Backend startup is `backend/main.py` (also reachable via root `main.py`); the React/Vite client boots at `frontend/src/main.jsx` and composes the app in `frontend/src/App.jsx`.

#### Backend API and orchestration
FastAPI owns the application boundary, request lifecycle, and routes in `backend/main.py`. Council workflow coordination belongs in `backend/council.py`, separating multi-stage LLM prompting from HTTP handling. Runtime model selection and chairman designation are centralized in `backend/config.py`, making the council membership an application-level policy rather than a frontend concern.

#### Three-stage council pipeline
1. **First opinions:** fan out the user question to configured council models and collect independent answers.
2. **Review:** redistribute peer outputs with model identities anonymized; each model evaluates/ranks the others.
3. **Chairman synthesis:** send accumulated opinions and reviews to the designated chairman model for the final response.

The core workflow boundary is `backend/council.py`; model settings are in `backend/config.py`; external completion requests are delegated to `backend/openrouter.py`.

#### External LLM integration
`backend/openrouter.py` is the adapter to the OpenRouter API, using async HTTP calls and the root `OPENROUTER_API_KEY` environment configuration. This isolates provider transport/authentication from council prompts and orchestration. The configured model IDs in `backend/config.py` may represent different underlying providers, but OpenRouter is the single upstream service boundary.

#### Conversation state and persistence
Conversation/session memory is managed separately from orchestration in `backend/memory.py`. Persistent conversation data is handled by `backend/storage.py` and stored as local JSON files under the documented `data/conversations/` location. This provides local durability without a database and forms the boundary between in-process state and filesystem persistence.

#### Frontend interaction model
The React client calls backend endpoints through `frontend/src/api.js`. `frontend/src/components/ChatInterface.jsx` is the primary prompt/chat interaction surface; `frontend/src/components/Stage1.jsx`, `frontend/src/components/Stage2.jsx`, and `frontend/src/components/Stage3.jsx` render the progressively available council outputs. `frontend/src/components/Sidebar.jsx` supports conversation navigation/state selection. Markdown-oriented response display is part of the frontend runtime.

#### Deployment/runtime shape
The system is intended for local development: Python 3.10+ with FastAPI and uv-managed dependencies, plus a Vite-served React frontend using npm. `start.sh` coordinates the two-process development setup. The frontend runs at Vite’s localhost endpoint and communicates with the Python backend; the backend in turn accesses OpenRouter over the network and local JSON storage on disk.

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["React client"]
  node_app_boot["React bootstrap<br/>Vite entry<br/>[main.jsx]"]
  node_app_shell["Application shell<br/>React composition<br/>[App.jsx]"]
  node_api_client["Backend API client<br/>HTTP client<br/>[api.js]"]
  node_chat["Prompt chat<br/>React component<br/>[ChatInterface.jsx]"]
  node_stages["Council stage views<br/>React components<br/>[Stage1.jsx]"]
  node_sidebar["Conversation sidebar<br/>React component<br/>[Sidebar.jsx]"]
end

subgraph group_backend["FastAPI backend"]
  node_api{{"FastAPI application<br/>HTTP API<br/>[main.py]"}}
  node_memory["Session memory<br/>conversation state<br/>[memory.py]"]
  node_storage["Conversation storage<br/>JSON persistence<br/>[storage.py]"]
  node_model_policy["Council model policy<br/>runtime configuration<br/>[config.py]"]
  node_openrouter_adapter["OpenRouter adapter<br/>LLM provider adapter<br/>[openrouter.py]"]
end

subgraph group_pipeline["Council pipeline"]
  node_workflow{{"Council coordinator<br/>workflow orchestration<br/>[council.py]"}}
  node_first_opinions["First opinions<br/>pipeline stage<br/>[council.py]"]
  node_peer_review["Anonymous peer review<br/>pipeline stage<br/>[council.py]"]
  node_synthesis["Chairman synthesis<br/>pipeline stage<br/>[council.py]"]
end

subgraph group_external["External and local services"]
  node_json_files[("Conversation JSON files<br/>local filesystem")]
  node_openrouter{{"OpenRouter API<br/>external LLM gateway"}}
  node_api_key["OPENROUTER_API_KEY<br/>environment configuration"]
end

node_dev_start["Local dev launcher<br/>shell launcher<br/>[start.sh]"]

node_dev_start -->|"starts"| node_app_boot
node_dev_start -->|"starts"| node_api
node_app_boot -->|"mounts"| node_app_shell
node_app_shell -->|"composes"| node_chat
node_app_shell -->|"composes"| node_stages
node_app_shell -->|"composes"| node_sidebar
node_chat -->|"submits prompt"| node_api_client
node_sidebar -->|"selects conversation"| node_api_client
node_api_client -->|"HTTP requests"| node_api
node_api -->|"runs deliberation"| node_workflow
node_api -->|"manages sessions"| node_memory
node_memory -->|"persists conversations"| node_storage
node_storage -->|"reads and writes"| node_json_files
node_workflow -->|"stage 1"| node_first_opinions
node_first_opinions -->|"opinions"| node_peer_review
node_peer_review -->|"reviews"| node_synthesis
node_workflow -->|"uses configured models"| node_model_policy
node_first_opinions -->|"completion requests"| node_openrouter_adapter
node_peer_review -->|"completion requests"| node_openrouter_adapter
node_synthesis -->|"completion request"| node_openrouter_adapter
node_openrouter_adapter -->|"async API calls"| node_openrouter
node_api_key -.->|"authenticates"| node_openrouter_adapter

click node_dev_start "https://github.com/meetmendapara09/llm-council/blob/main/start.sh"
click node_app_boot "https://github.com/meetmendapara09/llm-council/blob/main/frontend/src/main.jsx"
click node_app_shell "https://github.com/meetmendapara09/llm-council/blob/main/frontend/src/App.jsx"
click node_api_client "https://github.com/meetmendapara09/llm-council/blob/main/frontend/src/api.js"
click node_chat "https://github.com/meetmendapara09/llm-council/blob/main/frontend/src/components/ChatInterface.jsx"
click node_stages "https://github.com/meetmendapara09/llm-council/blob/main/frontend/src/components/Stage1.jsx"
click node_sidebar "https://github.com/meetmendapara09/llm-council/blob/main/frontend/src/components/Sidebar.jsx"
click node_api "https://github.com/meetmendapara09/llm-council/blob/main/backend/main.py"
click node_memory "https://github.com/meetmendapara09/llm-council/blob/main/backend/memory.py"
click node_storage "https://github.com/meetmendapara09/llm-council/blob/main/backend/storage.py"
click node_workflow "https://github.com/meetmendapara09/llm-council/blob/main/backend/council.py"
click node_first_opinions "https://github.com/meetmendapara09/llm-council/blob/main/backend/council.py"
click node_peer_review "https://github.com/meetmendapara09/llm-council/blob/main/backend/council.py"
click node_synthesis "https://github.com/meetmendapara09/llm-council/blob/main/backend/council.py"
click node_model_policy "https://github.com/meetmendapara09/llm-council/blob/main/backend/config.py"
click node_openrouter_adapter "https://github.com/meetmendapara09/llm-council/blob/main/backend/openrouter.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_app_boot,node_app_shell,node_api_client,node_chat,node_stages,node_sidebar toneBlue
class node_api,node_memory,node_storage,node_model_policy,node_openrouter_adapter toneAmber
class node_workflow,node_first_opinions,node_peer_review,node_synthesis toneMint
class node_json_files,node_openrouter,node_api_key toneRose
class node_dev_start toneNeutral
```

## Components

### React client

- [React bootstrap](https://github.com/meetmendapara09/llm-council/blob/main/frontend/src/main.jsx): Vite entry · `frontend/src/main.jsx`
- [Application shell](https://github.com/meetmendapara09/llm-council/blob/main/frontend/src/App.jsx): React composition · `frontend/src/App.jsx`
- [Backend API client](https://github.com/meetmendapara09/llm-council/blob/main/frontend/src/api.js): HTTP client · `frontend/src/api.js`
- [Prompt chat](https://github.com/meetmendapara09/llm-council/blob/main/frontend/src/components/ChatInterface.jsx): React component · `frontend/src/components/ChatInterface.jsx`
- [Council stage views](https://github.com/meetmendapara09/llm-council/blob/main/frontend/src/components/Stage1.jsx): React components · Renders progressively available opinions, reviews, and synthesis. · `frontend/src/components/Stage1.jsx`
- [Conversation sidebar](https://github.com/meetmendapara09/llm-council/blob/main/frontend/src/components/Sidebar.jsx): React component · `frontend/src/components/Sidebar.jsx`

### FastAPI backend

- [FastAPI application](https://github.com/meetmendapara09/llm-council/blob/main/backend/main.py): HTTP API · Owns request lifecycle and routes. · `backend/main.py`
- [Session memory](https://github.com/meetmendapara09/llm-council/blob/main/backend/memory.py): conversation state · `backend/memory.py`
- [Conversation storage](https://github.com/meetmendapara09/llm-council/blob/main/backend/storage.py): JSON persistence · `backend/storage.py`
- [Council model policy](https://github.com/meetmendapara09/llm-council/blob/main/backend/config.py): runtime configuration · Defines council membership and chairman designation. · `backend/config.py`
- [OpenRouter adapter](https://github.com/meetmendapara09/llm-council/blob/main/backend/openrouter.py): LLM provider adapter · Isolates async completion transport and authentication. · `backend/openrouter.py`

### Council pipeline

- [Council coordinator](https://github.com/meetmendapara09/llm-council/blob/main/backend/council.py): workflow orchestration · Coordinates the three-stage deliberation workflow. · `backend/council.py`
- [First opinions](https://github.com/meetmendapara09/llm-council/blob/main/backend/council.py): pipeline stage · Fans out the prompt for independent answers. · `backend/council.py`
- [Anonymous peer review](https://github.com/meetmendapara09/llm-council/blob/main/backend/council.py): pipeline stage · Redistributes anonymized outputs for ranking. · `backend/council.py`
- [Chairman synthesis](https://github.com/meetmendapara09/llm-council/blob/main/backend/council.py): pipeline stage · Produces the final answer from opinions and reviews. · `backend/council.py`

### External and local services

- **Conversation JSON files**: local filesystem
- **OpenRouter API**: external LLM gateway · Single upstream completion boundary.
- **OPENROUTER_API_KEY**: environment configuration

### Other components

- [Local dev launcher](https://github.com/meetmendapara09/llm-council/blob/main/start.sh): shell launcher · Starts the frontend and backend processes. · `start.sh`

## Connections

- Local dev launcher → React bootstrap: starts
- Local dev launcher → FastAPI application: starts
- React bootstrap → Application shell: mounts
- Application shell → Prompt chat: composes
- Application shell → Council stage views: composes
- Application shell → Conversation sidebar: composes
- Prompt chat → Backend API client: submits prompt
- Conversation sidebar → Backend API client: selects conversation
- Backend API client → FastAPI application: HTTP requests
- FastAPI application → Council coordinator: runs deliberation
- FastAPI application → Session memory: manages sessions
- Session memory → Conversation storage: persists conversations
- Conversation storage → Conversation JSON files: reads and writes
- Council coordinator → First opinions: stage 1
- First opinions → Anonymous peer review: opinions
- Anonymous peer review → Chairman synthesis: reviews
- Council coordinator → Council model policy: uses configured models
- First opinions → OpenRouter adapter: completion requests
- Anonymous peer review → OpenRouter adapter: completion requests
- Chairman synthesis → OpenRouter adapter: completion request
- OpenRouter adapter → OpenRouter API: async API calls
- OPENROUTER_API_KEY → OpenRouter adapter: authenticates
