# atharva-ankad/voice_ai_agent architecture

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

- Interactive diagram: https://gitdiagram.com/atharva-ankad/voice_ai_agent
- Repository: https://github.com/atharva-ankad/voice_ai_agent

## Overview

1. **Project shape**
This is a small, single-process Python application with a browser UI. The runtime entry point is `app.py`, and the main behavior is split into three modules under `modules/`: audio transcription, intent classification, and tool execution.

2. **Top-level orchestration**
`app.py` acts as the controller for the whole pipeline. It receives audio from the Streamlit UI, passes it through transcription, sends the transcript to intent detection, then dispatches the result to the appropriate tool and displays all intermediate/final outputs in the page.

3. **User interface boundary**
The UI is Streamlit-based and is the only interactive surface. It supports two input paths: microphone capture and audio file upload. This means the app is not a network service or multi-user backend; it is a local desktop-style browser app.

4. **Audio ingestion and transcription**
`modules/audio.py` is responsible for converting raw audio into text using Faster-Whisper. The README indicates the Whisper `base` model runs locally, typically CPU-only with int8 quantization, so transcription is a local compute stage rather than an API call.

5. **Intent detection layer**
`modules/intent.py` classifies the transcript into one of four intents: `create_file`, `write_code`, `summarize_text`, or `general_chat`. It uses LangChain with a locally hosted Phi-3 model through Ollama, and the architecture depends on a strict prompt plus a fallback regex cleanup to normalize model output.

6. **Tool execution boundary**
`modules/tools.py` is the action layer. It maps the detected intent to concrete behavior: create an empty file, generate/write code, summarize text, or produce a general chat response. This module is the main place where intent becomes side effect or output.

7. **Sandboxed file system behavior**
All file-producing actions are constrained to the `output/` directory at the repository root. That directory is the project’s only persistent artifact store, and the design explicitly rejects path traversal attempts, which makes the file boundary a key security constraint in the architecture.

8. **Code-generation data flow**
For `write_code`, the tool layer can read the tail of an existing file before appending new content. That creates a narrow context-preservation flow: existing output file → truncated context → Phi-3 generation → append/write back into `output/`.

9. **Local model/runtime dependencies**
The architecture depends on two local model runtimes: Faster-Whisper for speech-to-text and Ollama for Phi-3 inference. No cloud APIs are involved, so the deployment model is “local app + local model servers/libraries,” with model weights downloaded on first run.

10. **State and persistence model**
There is essentially no application database and no conversation memory. The only durable state is whatever gets written into `output/`. Everything else is transient per command: audio input, transcript, detected intent, and generated response.

11. **Operational flow**
A typical run is: user records or uploads audio → Streamlit hands audio to `app.py` → transcription produces text → intent classification selects a route → tool execution runs → UI shows transcript, intent, action, and final output. That sequential pipeline is the main architecture to diagram.

12. **Repo-level structure**
The repository is intentionally compact: `app.py` for orchestration, `modules/` for logic, `assets/` for documentation imagery, and `output/` for generated artifacts. This suggests a tightly coupled but clearly layered prototype where most boundaries are functional rather than service-based.

Main entry points: [`app.py`](https://github.com/atharva-ankad/voice_ai_agent/blob/main/app.py) (app.py), [`modules/tools.py`](https://github.com/atharva-ankad/voice_ai_agent/blob/main/modules/tools.py) (Tool router), [`modules/audio.py`](https://github.com/atharva-ankad/voice_ai_agent/blob/main/modules/audio.py) (Audio transcribe), [`modules/intent.py`](https://github.com/atharva-ankad/voice_ai_agent/blob/main/modules/intent.py) (Intent classify)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_runtime["App runtime"]
  node_node_ui["Streamlit UI<br/>browser app"]
  node_node_app["app.py<br/>orchestrator<br/>[app.py]"]
  node_node_audio["Audio transcribe<br/>[audio.py]"]
  node_node_intent["Intent classify<br/>[intent.py]"]
  node_node_tools["Tool router<br/>[tools.py]"]
end

subgraph group_group_models["Local models"]
  node_node_whisper{{"Whisper base<br/>speech model"}}
  node_node_langchain["Prompt chain<br/>llm prompt"]
  node_node_ollama{{"Phi-3<br/>local llm"}}
end

subgraph group_group_actions["Tool actions"]
  node_node_create["Create file<br/>action"]
  node_node_write["Write code<br/>action"]
  node_node_sum["Summarize text<br/>action"]
  node_node_chat["General chat<br/>action"]
end

subgraph group_group_storage["Persistent storage"]
  node_node_output[("output/<br/>sandbox folder")]
end

node_node_ui -->|"input events"| node_node_app
node_node_app -->|"transcribe"| node_node_audio
node_node_audio -->|"run model"| node_node_whisper
node_node_whisper -->|"text"| node_node_audio
node_node_audio -->|"transcript"| node_node_app
node_node_app -->|"classify"| node_node_intent
node_node_intent -->|"prompting"| node_node_langchain
node_node_langchain -->|"infer"| node_node_ollama
node_node_ollama -->|"labels"| node_node_intent
node_node_intent -->|"intent"| node_node_app
node_node_app -->|"dispatch"| node_node_tools
node_node_tools -->|"route"| node_node_create
node_node_tools -->|"route"| node_node_write
node_node_tools -->|"route"| node_node_sum
node_node_tools -->|"route"| node_node_chat
node_node_create -->|"write file"| node_node_output
node_node_write -->|"append"| node_node_output
node_node_sum -->|"result"| node_node_app
node_node_chat -->|"result"| node_node_app
node_node_output -->|"read tail"| node_node_write
node_node_app -->|"render"| node_node_ui

click node_node_app "https://github.com/atharva-ankad/voice_ai_agent/blob/main/app.py"
click node_node_audio "https://github.com/atharva-ankad/voice_ai_agent/blob/main/modules/audio.py"
click node_node_intent "https://github.com/atharva-ankad/voice_ai_agent/blob/main/modules/intent.py"
click node_node_tools "https://github.com/atharva-ankad/voice_ai_agent/blob/main/modules/tools.py"
click node_node_output "https://github.com/atharva-ankad/voice_ai_agent/tree/main/output"

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_node_ui,node_node_app,node_node_audio,node_node_intent,node_node_tools toneBlue
class node_node_whisper,node_node_langchain,node_node_ollama toneAmber
class node_node_create,node_node_write,node_node_sum,node_node_chat toneMint
class node_node_output toneRose
```

## Components

### App runtime

Streamlit UI and orchestration pipeline

- **Streamlit UI**: browser app · Local interactive surface for microphone and file upload input
- [app.py](https://github.com/atharva-ankad/voice_ai_agent/blob/main/app.py): orchestrator · Main controller that coordinates transcription, intent detection, tool execution, and display · `app.py`
- [Audio transcribe](https://github.com/atharva-ankad/voice_ai_agent/blob/main/modules/audio.py): module · Converts uploaded or recorded audio into text · `modules/audio.py`
- [Intent classify](https://github.com/atharva-ankad/voice_ai_agent/blob/main/modules/intent.py): module · Maps transcript to create_file, write_code, summarize_text, or general_chat · `modules/intent.py`
- [Tool router](https://github.com/atharva-ankad/voice_ai_agent/blob/main/modules/tools.py): module · Dispatches detected intent to concrete actions · `modules/tools.py`

### Local models

Speech and intent inference run locally

- **Whisper base**: speech model · Local Faster-Whisper model used for speech-to-text
- **Prompt chain**: llm prompt · Strict intent prompt and output normalization logic
- **Phi-3**: local llm · Locally hosted model served through Ollama for intent and generation

### Tool actions

Intent routes that produce outputs or files

- **Create file**: action · Creates an empty file in the output sandbox
- **Write code**: action · Generates or appends code using existing file tail as context
- **Summarize text**: action · Produces a summary response from supplied text
- **General chat**: action · Produces a free-form conversational response

### Persistent storage

Only durable repository state

- [output/](https://github.com/atharva-ankad/voice_ai_agent/tree/main/output): sandbox folder · Only persistent artifact store for generated files · `output`

## Connections

- Streamlit UI → app.py: input events · Microphone capture or audio upload is handed to the controller
- app.py → Audio transcribe: transcribe · App sends raw audio for speech-to-text
- Audio transcribe → Whisper base: run model · Faster-Whisper performs local transcription
- Whisper base → Audio transcribe: text · Transcript returns to the audio module
- Audio transcribe → app.py: transcript · Transcript is returned for downstream routing
- app.py → Intent classify: classify · Transcript is sent for intent detection
- Intent classify → Prompt chain: prompting · Intent module applies the strict prompt and cleanup rules
- Prompt chain → Phi-3: infer · Ollama hosts Phi-3 for intent inference
- Phi-3 → Intent classify: labels · Model output is normalized into one of the supported intents
- Intent classify → app.py: intent · Detected intent is returned to the controller
- app.py → Tool router: dispatch · App forwards transcript and intent to the action layer
- Tool router → Create file: route · create_file intent triggers empty-file creation
- Tool router → Write code: route · write_code intent triggers code generation or append
- Tool router → Summarize text: route · summarize_text intent triggers summarization
- Tool router → General chat: route · general_chat intent triggers conversational response
- Create file → output/: write file · New file is created inside the sandboxed output directory
- Write code → output/: append · Generated code is written back into output/
- Summarize text → app.py: result · Summary is returned for UI display
- General chat → app.py: result · Chat response is returned for UI display
- output/ → Write code: read tail · Existing file tail can be read as context before appending
- app.py → Streamlit UI: render · Transcript, intent, action, and final output are shown to the user
