# tejas-952007/bhasa2code architecture

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

- Interactive diagram: https://gitdiagram.com/tejas-952007/bhasa2code
- Repository: https://github.com/tejas-952007/bhasa2code

## Overview

Bhasha2Code is an offline-first multilingual assistant for code generation, debugging, execution, and learning. A user submits a prompt through the browser; the backend manages session context, classifies language/tone/intent, builds a prompt, and requests local LLM generation. Generated code can be validated and run in an isolated sandbox, while the UI presents study explanations and manages saved work. The README documents the major tiers; several internal route-to-service connections are not shown in sampled source, so those links are documented rather than inferred from module names.

Main entry points: [`backend/app/api/routes/chat_stream.py`](https://github.com/tejas-952007/bhasa2code/blob/main/backend/app/api/routes/chat_stream.py) (Chat endpoints), [`backend/app/nlp/pipeline/nlp_pipeline.py`](https://github.com/tejas-952007/bhasa2code/blob/main/backend/app/nlp/pipeline/nlp_pipeline.py) (NLP pipeline), [`frontend/src/services/api.js`](https://github.com/tejas-952007/bhasa2code/blob/main/frontend/src/services/api.js) (API client), [`backend/app/api/routes/code.py`](https://github.com/tejas-952007/bhasa2code/blob/main/backend/app/api/routes/code.py) (Code endpoints)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Browser experience"]
  node_app["Workspace app<br/>[App.jsx]"]
  node_response["Response renderer"]
  node_artifact["Code workspace<br/>[CodeArtifact.jsx]"]
  node_study["Study flowcharts"]
  node_api_client["API client<br/>[api.js]"]
end

subgraph group_api["Backend API"]
  node_chat_routes["Chat endpoints<br/>[chat_stream.py]"]
  node_code_routes["Code endpoints<br/>[code.py]"]
  node_session_routes["Session endpoints<br/>[sessions.py]"]
end

subgraph group_language["Language and generation"]
  node_nlp["NLP pipeline<br/>[nlp_pipeline.py]"]
  node_language_detection["Language detection"]
  node_preprocessing["Text preprocessing"]
  node_tone["Tone classification<br/>[tone_classifier.py]"]
  node_intent["Intent classification"]
  node_context["Conversation context<br/>[context_manager.py]"]
  node_prompt["Prompt builder<br/>[prompt_builder.py]"]
  node_llm["LLM service<br/>[llm_service.py]"]
end

subgraph group_runtime["Code verification"]
  node_validator["Response validator"]
  node_sandbox["Sandbox runner<br/>[sandbox_runner.py]"]
end

subgraph group_data["Local persistence"]
  node_repositories["Data repositories"]
  node_database[("Local database<br/>[engine.py]")]
end

node_user(("Learner"))
node_ollama["Local Ollama"]
node_docker["Docker runtime"]

node_user -->|"submits prompt"| node_app
node_app -->|"requests data"| node_api_client
node_api_client -->|"streams chat"| node_chat_routes
node_chat_routes -.->|"analyzes input"| node_nlp
node_nlp -->|"preprocesses text"| node_preprocessing
node_nlp -->|"detects language"| node_language_detection
node_nlp -->|"classifies tone"| node_tone
node_nlp -->|"classifies intent"| node_intent
node_chat_routes -.->|"builds context"| node_context
node_context -->|"retrieves history"| node_repositories
node_chat_routes -.->|"compiles prompt"| node_prompt
node_prompt -->|"provides specification"| node_llm
node_llm -->|"generates locally"| node_ollama
node_ollama -->|"returns generated text"| node_validator
node_validator -->|"returns validated output"| node_chat_routes
node_chat_routes -->|"streams response"| node_response
node_response -->|"renders code"| node_artifact
node_response -->|"renders study content"| node_study
node_artifact -->|"validates and runs"| node_api_client
node_api_client -->|"requests validation"| node_code_routes
node_code_routes -->|"validates code"| node_validator
node_code_routes -->|"runs code"| node_sandbox
node_sandbox -->|"executes isolated"| node_docker
node_code_routes -->|"returns execution result"| node_artifact
node_api_client -->|"manages sessions"| node_session_routes
node_session_routes -->|"reads and writes"| node_repositories
node_repositories -->|"persists records"| node_database

click node_app "https://github.com/tejas-952007/bhasa2code/blob/main/frontend/src/App.jsx"
click node_response "https://github.com/tejas-952007/bhasa2code/blob/main/frontend/src/components/response/ResponseRenderer.jsx"
click node_artifact "https://github.com/tejas-952007/bhasa2code/blob/main/frontend/src/components/code/CodeArtifact.jsx"
click node_study "https://github.com/tejas-952007/bhasa2code/blob/main/frontend/src/components/study/VisualFlowchart.jsx"
click node_api_client "https://github.com/tejas-952007/bhasa2code/blob/main/frontend/src/services/api.js"
click node_chat_routes "https://github.com/tejas-952007/bhasa2code/blob/main/backend/app/api/routes/chat_stream.py"
click node_code_routes "https://github.com/tejas-952007/bhasa2code/blob/main/backend/app/api/routes/code.py"
click node_session_routes "https://github.com/tejas-952007/bhasa2code/blob/main/backend/app/api/routes/sessions.py"
click node_nlp "https://github.com/tejas-952007/bhasa2code/blob/main/backend/app/nlp/pipeline/nlp_pipeline.py"
click node_language_detection "https://github.com/tejas-952007/bhasa2code/blob/main/backend/app/nlp/language_detection/language_detector.py"
click node_preprocessing "https://github.com/tejas-952007/bhasa2code/blob/main/backend/app/nlp/preprocessing/text_preprocessor.py"
click node_tone "https://github.com/tejas-952007/bhasa2code/blob/main/backend/app/nlp/tone_classification/tone_classifier.py"
click node_intent "https://github.com/tejas-952007/bhasa2code/blob/main/backend/app/nlp/intent_classification/intent_classifier.py"
click node_context "https://github.com/tejas-952007/bhasa2code/blob/main/backend/app/context/context_manager.py"
click node_prompt "https://github.com/tejas-952007/bhasa2code/blob/main/backend/app/prompt/prompt_builder.py"
click node_llm "https://github.com/tejas-952007/bhasa2code/blob/main/backend/app/llm/llm_service.py"
click node_validator "https://github.com/tejas-952007/bhasa2code/blob/main/backend/app/validation/response_validator.py"
click node_sandbox "https://github.com/tejas-952007/bhasa2code/blob/main/backend/app/sandbox/sandbox_runner.py"
click node_repositories "https://github.com/tejas-952007/bhasa2code/tree/main/backend/app/database/repositories"
click node_database "https://github.com/tejas-952007/bhasa2code/blob/main/backend/app/database/engine.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,node_response,node_artifact,node_study,node_api_client toneBlue
class node_chat_routes,node_code_routes,node_session_routes toneAmber
class node_nlp,node_language_detection,node_preprocessing,node_tone,node_intent,node_context,node_prompt,node_llm toneMint
class node_validator,node_sandbox toneRose
class node_repositories,node_database,node_user,node_ollama,node_docker toneIndigo
```

## Components

### Browser experience

- [Workspace app](https://github.com/tejas-952007/bhasa2code/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`
- [Response renderer](https://github.com/tejas-952007/bhasa2code/blob/main/frontend/src/components/response/ResponseRenderer.jsx): `frontend/src/components/response/ResponseRenderer.jsx`
- [Code workspace](https://github.com/tejas-952007/bhasa2code/blob/main/frontend/src/components/code/CodeArtifact.jsx): `frontend/src/components/code/CodeArtifact.jsx`
- [Study flowcharts](https://github.com/tejas-952007/bhasa2code/blob/main/frontend/src/components/study/VisualFlowchart.jsx): `frontend/src/components/study/VisualFlowchart.jsx`
- [API client](https://github.com/tejas-952007/bhasa2code/blob/main/frontend/src/services/api.js): `frontend/src/services/api.js`

### Backend API

- [Chat endpoints](https://github.com/tejas-952007/bhasa2code/blob/main/backend/app/api/routes/chat_stream.py): `backend/app/api/routes/chat_stream.py`
- [Code endpoints](https://github.com/tejas-952007/bhasa2code/blob/main/backend/app/api/routes/code.py): `backend/app/api/routes/code.py`
- [Session endpoints](https://github.com/tejas-952007/bhasa2code/blob/main/backend/app/api/routes/sessions.py): `backend/app/api/routes/sessions.py`

### Language and generation

- [NLP pipeline](https://github.com/tejas-952007/bhasa2code/blob/main/backend/app/nlp/pipeline/nlp_pipeline.py): `backend/app/nlp/pipeline/nlp_pipeline.py`
- [Language detection](https://github.com/tejas-952007/bhasa2code/blob/main/backend/app/nlp/language_detection/language_detector.py): `backend/app/nlp/language_detection/language_detector.py`
- [Text preprocessing](https://github.com/tejas-952007/bhasa2code/blob/main/backend/app/nlp/preprocessing/text_preprocessor.py): `backend/app/nlp/preprocessing/text_preprocessor.py`
- [Tone classification](https://github.com/tejas-952007/bhasa2code/blob/main/backend/app/nlp/tone_classification/tone_classifier.py): `backend/app/nlp/tone_classification/tone_classifier.py`
- [Intent classification](https://github.com/tejas-952007/bhasa2code/blob/main/backend/app/nlp/intent_classification/intent_classifier.py): `backend/app/nlp/intent_classification/intent_classifier.py`
- [Conversation context](https://github.com/tejas-952007/bhasa2code/blob/main/backend/app/context/context_manager.py): `backend/app/context/context_manager.py`
- [Prompt builder](https://github.com/tejas-952007/bhasa2code/blob/main/backend/app/prompt/prompt_builder.py): `backend/app/prompt/prompt_builder.py`
- [LLM service](https://github.com/tejas-952007/bhasa2code/blob/main/backend/app/llm/llm_service.py): `backend/app/llm/llm_service.py`

### Code verification

- [Response validator](https://github.com/tejas-952007/bhasa2code/blob/main/backend/app/validation/response_validator.py): `backend/app/validation/response_validator.py`
- [Sandbox runner](https://github.com/tejas-952007/bhasa2code/blob/main/backend/app/sandbox/sandbox_runner.py): `backend/app/sandbox/sandbox_runner.py`

### Local persistence

- [Data repositories](https://github.com/tejas-952007/bhasa2code/tree/main/backend/app/database/repositories): `backend/app/database/repositories`
- [Local database](https://github.com/tejas-952007/bhasa2code/blob/main/backend/app/database/engine.py): `backend/app/database/engine.py`

### Other components

- **Learner**
- **Local Ollama**
- **Docker runtime**

## Connections

- Learner → Workspace app: submits prompt (evidence: `README.md`)
- Workspace app → API client: requests data (evidence: `frontend/src/App.jsx`)
- API client → Chat endpoints: streams chat (evidence: `README.md`)
- Chat endpoints → NLP pipeline: analyzes input
- NLP pipeline → Text preprocessing: preprocesses text (evidence: `backend/app/nlp/pipeline/nlp_pipeline.py`)
- NLP pipeline → Language detection: detects language (evidence: `backend/app/nlp/pipeline/nlp_pipeline.py`)
- NLP pipeline → Tone classification: classifies tone (evidence: `backend/app/nlp/pipeline/nlp_pipeline.py`)
- NLP pipeline → Intent classification: classifies intent (evidence: `backend/app/nlp/pipeline/nlp_pipeline.py`)
- Chat endpoints → Conversation context: builds context
- Conversation context → Data repositories: retrieves history (evidence: `backend/app/context/context_manager.py`)
- Chat endpoints → Prompt builder: compiles prompt
- Prompt builder → LLM service: provides specification (evidence: `backend/app/llm/llm_service.py`)
- LLM service → Local Ollama: generates locally (evidence: `README.md`)
- Local Ollama → Response validator: returns generated text (evidence: `README.md`)
- Response validator → Chat endpoints: returns validated output (evidence: `README.md`)
- Chat endpoints → Response renderer: streams response (evidence: `README.md`)
- Response renderer → Code workspace: renders code (evidence: `frontend/src/components/response/ResponseRenderer.jsx`)
- Response renderer → Study flowcharts: renders study content (evidence: `frontend/src/components/response/ResponseRenderer.jsx`)
- Code workspace → API client: validates and runs (evidence: `frontend/src/components/code/CodeArtifact.jsx`)
- API client → Code endpoints: requests validation (evidence: `README.md`)
- Code endpoints → Response validator: validates code (evidence: `README.md`)
- Code endpoints → Sandbox runner: runs code (evidence: `README.md`)
- Sandbox runner → Docker runtime: executes isolated (evidence: `README.md`)
- Code endpoints → Code workspace: returns execution result (evidence: `README.md`)
- API client → Session endpoints: manages sessions
- Session endpoints → Data repositories: reads and writes (evidence: `backend/app/api/routes/sessions.py`)
- Data repositories → Local database: persists records (evidence: `backend/app/database/engine.py`)
