# charanms0125/the-negotiator architecture

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

- Interactive diagram: https://gitdiagram.com/charanms0125/the-negotiator
- Repository: https://github.com/charanms0125/the-negotiator

## Overview

The Negotiator is a full-stack application for configuring and running budget-bounded merchant negotiations, then comparing offers and auditing evidence. Buyers use the Streamlit dashboard to manage retailers, create and monitor sessions, and review recommendations and history. The FastAPI API launches session orchestration; the session manager coordinates negotiation strategy, AI dialogue, voice calls, evidence extraction, and persistence. Offer scoring produces normalized comparisons for the frontend. README capabilities are included, though several page and service implementations were not sampled; their connections are shown only where the excerpts, SOURCE INDEX, or README support them.

Main entry points: [`frontend/app.py`](https://github.com/charanms0125/the-negotiator/blob/main/frontend/app.py) (Streamlit Navigation), [`frontend/services/api_client.py`](https://github.com/charanms0125/the-negotiator/blob/main/frontend/services/api_client.py) (HTTP API Client), [`backend/app/services/session_manager.py`](https://github.com/charanms0125/the-negotiator/blob/main/backend/app/services/session_manager.py) (Session Orchestrator), [`backend/app/api/routes.py`](https://github.com/charanms0125/the-negotiator/blob/main/backend/app/api/routes.py) (FastAPI Routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["Buyer Dashboard"]
  node_frontend["Streamlit Navigation<br/>[app.py]"]
  node_config_page["Negotiation Setup<br/>[new_negotiation.py]"]
  node_business_page["Retailer Directory"]
  node_live_page["Live Control Room"]
  node_dashboard_page["Dashboard and History<br/>[dashboard.py]"]
  node_history_page["Session Archives<br/>[history.py]"]
  node_comparison_page["Offer Comparison"]
  node_recommend_page["Recommendation View<br/>[recommendation.py]"]
  node_api_client["HTTP API Client<br/>[api_client.py]"]
end

subgraph group_api["API and Contracts"]
  node_api["FastAPI Routes<br/>[routes.py]"]
  node_contracts["Request and Result Schemas<br/>[schemas.py]"]
end

subgraph group_runtime["Negotiation Runtime"]
  node_orchestrator["Session Orchestrator<br/>[session_manager.py]"]
  node_strategy["Negotiation State Machine"]
  node_llm["Dialogue and Extraction AI<br/>[llm_service.py]"]
  node_voice["Voice Provider<br/>[voice_service.py]"]
end

subgraph group_results["Evidence and Results"]
  node_evidence["Evidence Audit"]
  node_scoring["Offer Normalization"]
end

subgraph group_state["Persistence"]
  node_store[("Session and Offer Store<br/>[db.py]")]
end

node_buyer(("Buyer"))
node_merchant(("Authorized Retailer"))
node_gemini["Gemini API"]
node_twilio["Twilio Telephony"]

node_buyer -->|"uses"| node_frontend
node_frontend -->|"routes to"| node_config_page
node_frontend -->|"routes to"| node_business_page
node_frontend -->|"routes to"| node_live_page
node_frontend -->|"routes to"| node_dashboard_page
node_frontend -->|"routes to"| node_history_page
node_frontend -->|"routes to"| node_comparison_page
node_frontend -->|"routes to"| node_recommend_page
node_config_page -->|"submits through"| node_api_client
node_business_page -->|"manages through"| node_api_client
node_live_page -->|"controls through"| node_api_client
node_dashboard_page -->|"fetches through"| node_api_client
node_history_page -->|"fetches through"| node_api_client
node_comparison_page -->|"fetches through"| node_api_client
node_recommend_page -->|"fetches through"| node_api_client
node_api_client -->|"sends HTTP"| node_api
node_api -->|"validates with"| node_contracts
node_api -->|"reads and writes"| node_store
node_api -->|"starts sessions"| node_orchestrator
node_api -->|"scores offers"| node_scoring
node_orchestrator -->|"chooses counters"| node_strategy
node_orchestrator -->|"generates dialogue"| node_llm
node_orchestrator -->|"audits transcripts"| node_evidence
node_orchestrator -->|"runs calls"| node_voice
node_orchestrator -->|"persists session data"| node_store
node_voice -.->|"conducts call"| node_merchant
node_voice -.->|"can use"| node_twilio
node_llm -->|"can query"| node_gemini
node_scoring -.->|"scores stored offers"| node_store

click node_frontend "https://github.com/charanms0125/the-negotiator/blob/main/frontend/app.py"
click node_config_page "https://github.com/charanms0125/the-negotiator/blob/main/frontend/pages/new_negotiation.py"
click node_business_page "https://github.com/charanms0125/the-negotiator/blob/main/frontend/pages/business_management.py"
click node_live_page "https://github.com/charanms0125/the-negotiator/blob/main/frontend/pages/live_negotiation.py"
click node_dashboard_page "https://github.com/charanms0125/the-negotiator/blob/main/frontend/pages/dashboard.py"
click node_history_page "https://github.com/charanms0125/the-negotiator/blob/main/frontend/pages/history.py"
click node_comparison_page "https://github.com/charanms0125/the-negotiator/blob/main/frontend/pages/offer_comparison.py"
click node_recommend_page "https://github.com/charanms0125/the-negotiator/blob/main/frontend/pages/recommendation.py"
click node_api_client "https://github.com/charanms0125/the-negotiator/blob/main/frontend/services/api_client.py"
click node_api "https://github.com/charanms0125/the-negotiator/blob/main/backend/app/api/routes.py"
click node_contracts "https://github.com/charanms0125/the-negotiator/blob/main/backend/app/schemas/schemas.py"
click node_orchestrator "https://github.com/charanms0125/the-negotiator/blob/main/backend/app/services/session_manager.py"
click node_strategy "https://github.com/charanms0125/the-negotiator/blob/main/backend/app/services/negotiation_engine.py"
click node_llm "https://github.com/charanms0125/the-negotiator/blob/main/backend/app/services/llm_service.py"
click node_voice "https://github.com/charanms0125/the-negotiator/blob/main/backend/app/services/voice_service.py"
click node_evidence "https://github.com/charanms0125/the-negotiator/blob/main/backend/app/services/evidence_service.py"
click node_scoring "https://github.com/charanms0125/the-negotiator/blob/main/backend/app/services/recommendation_engine.py"
click node_store "https://github.com/charanms0125/the-negotiator/blob/main/backend/app/database/db.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_frontend,node_config_page,node_business_page,node_live_page,node_dashboard_page,node_history_page,node_comparison_page,node_recommend_page,node_api_client toneBlue
class node_api,node_contracts toneAmber
class node_orchestrator,node_strategy,node_llm,node_voice,node_gemini toneMint
class node_evidence,node_scoring toneRose
class node_store,node_buyer,node_merchant,node_twilio toneIndigo
```

## Components

### Buyer Dashboard

- [Streamlit Navigation](https://github.com/charanms0125/the-negotiator/blob/main/frontend/app.py): `frontend/app.py`
- [Negotiation Setup](https://github.com/charanms0125/the-negotiator/blob/main/frontend/pages/new_negotiation.py): `frontend/pages/new_negotiation.py`
- [Retailer Directory](https://github.com/charanms0125/the-negotiator/blob/main/frontend/pages/business_management.py): `frontend/pages/business_management.py`
- [Live Control Room](https://github.com/charanms0125/the-negotiator/blob/main/frontend/pages/live_negotiation.py): `frontend/pages/live_negotiation.py`
- [Dashboard and History](https://github.com/charanms0125/the-negotiator/blob/main/frontend/pages/dashboard.py): `frontend/pages/dashboard.py`
- [Session Archives](https://github.com/charanms0125/the-negotiator/blob/main/frontend/pages/history.py): `frontend/pages/history.py`
- [Offer Comparison](https://github.com/charanms0125/the-negotiator/blob/main/frontend/pages/offer_comparison.py): `frontend/pages/offer_comparison.py`
- [Recommendation View](https://github.com/charanms0125/the-negotiator/blob/main/frontend/pages/recommendation.py): `frontend/pages/recommendation.py`
- [HTTP API Client](https://github.com/charanms0125/the-negotiator/blob/main/frontend/services/api_client.py): `frontend/services/api_client.py`

### API and Contracts

- [FastAPI Routes](https://github.com/charanms0125/the-negotiator/blob/main/backend/app/api/routes.py): `backend/app/api/routes.py`
- [Request and Result Schemas](https://github.com/charanms0125/the-negotiator/blob/main/backend/app/schemas/schemas.py): `backend/app/schemas/schemas.py`

### Negotiation Runtime

- [Session Orchestrator](https://github.com/charanms0125/the-negotiator/blob/main/backend/app/services/session_manager.py): `backend/app/services/session_manager.py`
- [Negotiation State Machine](https://github.com/charanms0125/the-negotiator/blob/main/backend/app/services/negotiation_engine.py): `backend/app/services/negotiation_engine.py`
- [Dialogue and Extraction AI](https://github.com/charanms0125/the-negotiator/blob/main/backend/app/services/llm_service.py): `backend/app/services/llm_service.py`
- [Voice Provider](https://github.com/charanms0125/the-negotiator/blob/main/backend/app/services/voice_service.py): `backend/app/services/voice_service.py`

### Evidence and Results

- [Evidence Audit](https://github.com/charanms0125/the-negotiator/blob/main/backend/app/services/evidence_service.py): `backend/app/services/evidence_service.py`
- [Offer Normalization](https://github.com/charanms0125/the-negotiator/blob/main/backend/app/services/recommendation_engine.py): `backend/app/services/recommendation_engine.py`

### Persistence

- [Session and Offer Store](https://github.com/charanms0125/the-negotiator/blob/main/backend/app/database/db.py): `backend/app/database/db.py`

### Other components

- **Buyer**
- **Authorized Retailer**
- **Gemini API**
- **Twilio Telephony**

## Connections

- Buyer → Streamlit Navigation: uses (evidence: `frontend/app.py`)
- Streamlit Navigation → Negotiation Setup: routes to (evidence: `frontend/app.py`)
- Streamlit Navigation → Retailer Directory: routes to (evidence: `frontend/app.py`)
- Streamlit Navigation → Live Control Room: routes to (evidence: `frontend/app.py`)
- Streamlit Navigation → Dashboard and History: routes to (evidence: `frontend/app.py`)
- Streamlit Navigation → Session Archives: routes to (evidence: `frontend/app.py`)
- Streamlit Navigation → Offer Comparison: routes to (evidence: `frontend/app.py`)
- Streamlit Navigation → Recommendation View: routes to (evidence: `frontend/app.py`)
- Negotiation Setup → HTTP API Client: submits through (evidence: `frontend/pages/new_negotiation.py`)
- Retailer Directory → HTTP API Client: manages through (evidence: `frontend/pages/business_management.py`)
- Live Control Room → HTTP API Client: controls through (evidence: `frontend/pages/live_negotiation.py`)
- Dashboard and History → HTTP API Client: fetches through (evidence: `frontend/pages/dashboard.py`)
- Session Archives → HTTP API Client: fetches through (evidence: `frontend/pages/history.py`)
- Offer Comparison → HTTP API Client: fetches through (evidence: `frontend/pages/offer_comparison.py`)
- Recommendation View → HTTP API Client: fetches through (evidence: `frontend/pages/recommendation.py`)
- HTTP API Client → FastAPI Routes: sends HTTP (evidence: `frontend/services/api_client.py`)
- FastAPI Routes → Request and Result Schemas: validates with (evidence: `backend/app/api/routes.py`)
- FastAPI Routes → Session and Offer Store: reads and writes (evidence: `backend/app/api/routes.py`)
- FastAPI Routes → Session Orchestrator: starts sessions (evidence: `backend/app/api/routes.py`)
- FastAPI Routes → Offer Normalization: scores offers (evidence: `backend/app/api/routes.py`)
- Session Orchestrator → Negotiation State Machine: chooses counters (evidence: `backend/app/services/session_manager.py`)
- Session Orchestrator → Dialogue and Extraction AI: generates dialogue (evidence: `backend/app/services/session_manager.py`)
- Session Orchestrator → Evidence Audit: audits transcripts (evidence: `backend/app/services/session_manager.py`)
- Session Orchestrator → Voice Provider: runs calls (evidence: `backend/app/services/session_manager.py`)
- Session Orchestrator → Session and Offer Store: persists session data (evidence: `backend/app/services/session_manager.py`)
- Voice Provider → Authorized Retailer: conducts call (evidence: `README.md`)
- Voice Provider → Twilio Telephony: can use (evidence: `README.md`)
- Dialogue and Extraction AI → Gemini API: can query (evidence: `backend/app/services/llm_service.py`)
- Offer Normalization → Session and Offer Store: scores stored offers
