# anandhakumar123456/genai architecture

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

- Interactive diagram: https://gitdiagram.com/anandhakumar123456/genai
- Repository: https://github.com/anandhakumar123456/genai

## Overview

#### Purpose and entry points

TradeTalks AI is a single-user, conversational financial-education assistant. It provides beginner-oriented investing and trading explanations while avoiding personalized buy/sell advice.

- Backend ASGI entry point: `main.py` (`uvicorn main:app --reload`)
- Browser client: `index.html`
- Conversational/LLM orchestration: `agent.py`

#### FastAPI chat boundary

`main.py` owns the HTTP application and exposes `POST /chat`, accepting a `user_question` query parameter. The endpoint streams plain-text model output back to the caller rather than waiting for a complete response.

This is the primary frontend/backend boundary: `index.html` submits questions to the FastAPI service and consumes the response incrementally.

Paths: `main.py`, `index.html`

#### Agent orchestration and conversation state

`agent.py` implements the chat agent layer between the API and Groq-hosted LLM. It is responsible for maintaining in-memory conversation history so later turns can be interpreted in the context of the active discussion.

Because history is memory-resident, conversations are process-local and are not durable across server restarts or naturally shared across multiple backend instances.

Paths: `agent.py`, `main.py`

#### Prompt and safety policy layer

`prompts.py` centralizes instructions supplied to the model. This layer defines the assistant’s educational tone, expected explanatory structure, and financial-safety constraints, including avoiding direct trading recommendations.

Prompting is the key behavioral boundary: application code delegates domain framing and response policy to model instructions rather than implementing financial analysis logic locally.

Paths: `prompts.py`, `agent.py`

#### Structured interaction schemas

`schemas.py` contains Pydantic models used to represent structured application/LLM interaction data, including cases where the assistant needs to present topic choices or clarification-oriented responses.

These schemas form the contract between orchestration logic and structured response handling, while the public `/chat` API remains a streamed text interface.

Paths: `schemas.py`, `agent.py`, `main.py`

#### Model and external-service integration

The runtime uses LangChain and LangChain-Groq to invoke a Groq-hosted language model. Authentication is supplied through the `GROQ_API_KEY` environment variable, expected in a local `.env` file.

The model provider is an external dependency and the source of generated educational content; no market-data service, database, or persistent message store is represented in the repository.

Paths: `agent.py`, `pyproject.toml`, `uv.lock`

#### Runtime and deployment shape

The application is a lightweight Python 3.13+ service using FastAPI and Uvicorn, paired with a standalone static HTML/CSS/JavaScript client. The frontend is opened directly in a browser rather than being represented as a separately built or served web application.

Paths: `pyproject.toml`, `main.py`, `index.html`

Main entry points: [`agent.py`](https://github.com/anandhakumar123456/genai/blob/main/agent.py) (Chat agent), [`pyproject.toml`](https://github.com/anandhakumar123456/genai/blob/main/pyproject.toml) (Python runtime dependencies), [`main.py`](https://github.com/anandhakumar123456/genai/blob/main/main.py) (POST /chat), [`index.html`](https://github.com/anandhakumar123456/genai/blob/main/index.html) (Static chat client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Browser Client"]
  node_browser["Static chat client<br/>HTML/JS client<br/>[index.html]"]
end

subgraph group_backend["Python Service"]
  node_chat["POST /chat<br/>FastAPI endpoint<br/>[main.py]"]
  node_streaming["Response streaming<br/>ASGI stream<br/>[main.py]"]
  node_schemas["Structured interactions<br/>Pydantic schemas<br/>[schemas.py]"]
  node_runtime["Python runtime dependencies<br/>Python 3.13+ project<br/>[pyproject.toml]"]
  node_lockfile["Locked dependencies<br/>dependency lockfile<br/>[uv.lock]"]
end

subgraph group_ai["AI Integration"]
  node_agent["Chat agent<br/>orchestrator<br/>[agent.py]"]
  node_history["Conversation history<br/>in-memory state<br/>[agent.py]"]
  node_prompts["Educational safety policy<br/>prompt instructions<br/>[prompts.py]"]
  node_langchain["LangChain integration<br/>LLM client<br/>[agent.py]"]
  node_api_key["GROQ_API_KEY<br/>environment credential"]
end

node_groq{{"Groq-hosted LLM<br/>external model provider"}}

node_browser -->|"submits question"| node_chat
node_chat -->|"invokes"| node_agent
node_agent -->|"reads and updates"| node_history
node_agent -->|"applies policy"| node_prompts
node_agent -->|"uses structured contracts"| node_schemas
node_agent -->|"calls through"| node_langchain
node_langchain -->|"model request"| node_groq
node_api_key -.->|"authenticates"| node_langchain
node_agent -->|"generated text"| node_streaming
node_streaming -->|"incremental plain text"| node_browser
node_runtime -.->|"runs with FastAPI/Uvicorn"| node_chat
node_runtime -.->|"provides dependencies"| node_langchain
node_lockfile -.->|"pins versions"| node_runtime

click node_browser "https://github.com/anandhakumar123456/genai/blob/main/index.html"
click node_chat "https://github.com/anandhakumar123456/genai/blob/main/main.py"
click node_streaming "https://github.com/anandhakumar123456/genai/blob/main/main.py"
click node_agent "https://github.com/anandhakumar123456/genai/blob/main/agent.py"
click node_history "https://github.com/anandhakumar123456/genai/blob/main/agent.py"
click node_prompts "https://github.com/anandhakumar123456/genai/blob/main/prompts.py"
click node_schemas "https://github.com/anandhakumar123456/genai/blob/main/schemas.py"
click node_langchain "https://github.com/anandhakumar123456/genai/blob/main/agent.py"
click node_runtime "https://github.com/anandhakumar123456/genai/blob/main/pyproject.toml"
click node_lockfile "https://github.com/anandhakumar123456/genai/blob/main/uv.lock"

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_browser toneBlue
class node_chat,node_streaming,node_schemas,node_runtime,node_lockfile toneAmber
class node_agent,node_history,node_prompts,node_langchain,node_api_key toneMint
class node_groq toneNeutral
```

## Components

### Browser Client

- [Static chat client](https://github.com/anandhakumar123456/genai/blob/main/index.html): HTML/JS client · Opened directly in the browser. · `index.html`

### Python Service

- [POST /chat](https://github.com/anandhakumar123456/genai/blob/main/main.py): FastAPI endpoint · Accepts user_question and streams plain text. · `main.py`
- [Response streaming](https://github.com/anandhakumar123456/genai/blob/main/main.py): ASGI stream · `main.py`
- [Structured interactions](https://github.com/anandhakumar123456/genai/blob/main/schemas.py): Pydantic schemas · Models topic-choice and clarification responses. · `schemas.py`
- [Python runtime dependencies](https://github.com/anandhakumar123456/genai/blob/main/pyproject.toml): Python 3.13+ project · Defines FastAPI, Uvicorn, LangChain, and LangChain-Groq dependencies. · `pyproject.toml`
- [Locked dependencies](https://github.com/anandhakumar123456/genai/blob/main/uv.lock): dependency lockfile · `uv.lock`

### AI Integration

- [Chat agent](https://github.com/anandhakumar123456/genai/blob/main/agent.py): orchestrator · Coordinates conversation and model calls. · `agent.py`
- [Conversation history](https://github.com/anandhakumar123456/genai/blob/main/agent.py): in-memory state · Process-local and lost on restart. · `agent.py`
- [Educational safety policy](https://github.com/anandhakumar123456/genai/blob/main/prompts.py): prompt instructions · Defines explanatory tone and avoids direct trading recommendations. · `prompts.py`
- [LangChain integration](https://github.com/anandhakumar123456/genai/blob/main/agent.py): LLM client · `agent.py`
- **GROQ_API_KEY**: environment credential

### Other components

- **Groq-hosted LLM**: external model provider · Generates educational responses.

## Connections

- Static chat client → POST /chat: submits question
- POST /chat → Chat agent: invokes
- Chat agent → Conversation history: reads and updates
- Chat agent → Educational safety policy: applies policy
- Chat agent → Structured interactions: uses structured contracts
- Chat agent → LangChain integration: calls through
- LangChain integration → Groq-hosted LLM: model request
- GROQ_API_KEY → LangChain integration: authenticates
- Chat agent → Response streaming: generated text
- Response streaming → Static chat client: incremental plain text
- Python runtime dependencies → POST /chat: runs with FastAPI/Uvicorn
- Python runtime dependencies → LangChain integration: provides dependencies
- Locked dependencies → Python runtime dependencies: pins versions
