# krishna-dhawangale/astro-ai-chatbot architecture

> Architecture diagram of the GitHub repository krishna-dhawangale/astro-ai-chatbot, 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/krishna-dhawangale/astro-ai-chatbot
- Repository: https://github.com/krishna-dhawangale/astro-ai-chatbot

## Overview

Astro AI Chatbot accepts a question and birth details, applies safety boundaries, and returns either an educational/direct answer or chart-grounded guidance. Its documented path combines query classification, chart calculation and normalization, deterministic Vedic rules and timing, then selects local synthesis or constrained LLM rendering. The graph preserves the documented domain-rule breadth; unsampled implementation details are represented only where the README or source index supports the relationship.

Main entry points: [`backend/main.py`](https://github.com/krishna-dhawangale/astro-ai-chatbot/blob/main/backend/main.py) (Chat API), [`backend/reasoning/mode_selector.py`](https://github.com/krishna-dhawangale/astro-ai-chatbot/blob/main/backend/reasoning/mode_selector.py) (Mode Selector), [`backend/normalize.py`](https://github.com/krishna-dhawangale/astro-ai-chatbot/blob/main/backend/normalize.py) (Chart Normalizer), [`frontend/script.js`](https://github.com/krishna-dhawangale/astro-ai-chatbot/blob/main/frontend/script.js) (Frontend Client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Safety and Entry"]
  node_api["Chat API<br/>[main.py]"]
  node_guard["Abuse Guardrail<br/>[abuse_guardrail.py]"]
  node_boundary["Domain Filter<br/>[domain_filter.py]"]
end

subgraph group_classify["Query Classification"]
  node_faq["Educational FAQ<br/>[faq_engine.py]"]
  node_classifier["Domain Intent Ensemble<br/>[model_selector.py]"]
  node_router["Question Pipeline<br/>[pipeline.py]"]
  node_complexity["Complexity Prediction<br/>[complexity.py]"]
  node_intent["Intent Prediction<br/>[intent.py]"]
end

subgraph group_chart["Chart and Ephemeris"]
  node_ephemeris["Swiss Ephemeris<br/>[ephemeris.py]"]
  node_normalize["Chart Normalizer<br/>[normalize.py]"]
  node_astrology["Dasha and Transit"]
end

subgraph group_reason["Astrological Reasoning"]
  node_direct["Direct Fact Engine"]
  node_rules["Domain Rules"]
  node_timing["Dasha Transit Timing"]
  node_stage8["Stage 8 Pipeline<br/>[stage8_pipeline.py]"]
  node_coverage["Rule Coverage<br/>[rule_coverage.py]"]
end

subgraph group_answer["Answer Generation"]
  node_mode["Mode Selector<br/>[mode_selector.py]"]
  node_evidence["Structured Evidence"]
  node_synth["Local Synthesizer"]
  node_renderer["LLM Renderer<br/>[llm_renderer.py]"]
  node_llm_router["LLM Provider Router<br/>[llm_router.py]"]
end

node_user(("User"))
node_astro_api["FreeAstrologyAPI"]
node_llm["LLM Providers"]
node_client["Frontend Client<br/>[script.js]"]

node_user -->|"submits query"| node_api
node_api -->|"checks safety"| node_guard
node_api -->|"filters scope"| node_boundary
node_api -->|"checks FAQ"| node_faq
node_api -->|"classifies query"| node_classifier
node_router -->|"predicts complexity"| node_complexity
node_router -->|"predicts intent"| node_intent
node_api -->|"requests chart"| node_astro_api
node_api -->|"fallback calculation"| node_ephemeris
node_astro_api -->|"returns chart"| node_normalize
node_ephemeris -->|"returns chart"| node_normalize
node_api -->|"normalizes chart"| node_normalize
node_normalize -->|"provides chart facts"| node_direct
node_api -->|"checks direct facts"| node_direct
node_api -->|"evaluates domains"| node_rules
node_rules -->|"evaluates timing"| node_timing
node_timing -->|"supplies timing"| node_stage8
node_stage8 -->|"combines domain results"| node_rules
node_api -->|"selects answer mode"| node_mode
node_mode -->|"checks rule coverage"| node_coverage
node_mode -->|"checks direct path"| node_direct
node_api -->|"builds evidence"| node_evidence
node_evidence -->|"supplies evidence"| node_synth
node_mode -->|"selects local answer"| node_synth
node_mode -->|"selects LLM path"| node_renderer
node_renderer -->|"routes prompt"| node_llm_router
node_llm_router -->|"calls providers"| node_llm
node_api -->|"returns answer"| node_client
node_faq -->|"returns FAQ"| node_client
node_synth -->|"returns local answer"| node_client
node_llm -->|"returns response"| node_client

click node_api "https://github.com/krishna-dhawangale/astro-ai-chatbot/blob/main/backend/main.py"
click node_guard "https://github.com/krishna-dhawangale/astro-ai-chatbot/blob/main/backend/abuse_guardrail.py"
click node_boundary "https://github.com/krishna-dhawangale/astro-ai-chatbot/blob/main/backend/domain_filter.py"
click node_faq "https://github.com/krishna-dhawangale/astro-ai-chatbot/blob/main/backend/faq_engine.py"
click node_classifier "https://github.com/krishna-dhawangale/astro-ai-chatbot/blob/main/backend/router/model_selector.py"
click node_router "https://github.com/krishna-dhawangale/astro-ai-chatbot/blob/main/backend/router/pipeline.py"
click node_complexity "https://github.com/krishna-dhawangale/astro-ai-chatbot/blob/main/backend/router/complexity.py"
click node_intent "https://github.com/krishna-dhawangale/astro-ai-chatbot/blob/main/backend/router/intent.py"
click node_ephemeris "https://github.com/krishna-dhawangale/astro-ai-chatbot/blob/main/backend/ephemeris.py"
click node_normalize "https://github.com/krishna-dhawangale/astro-ai-chatbot/blob/main/backend/normalize.py"
click node_astrology "https://github.com/krishna-dhawangale/astro-ai-chatbot/tree/main/backend/astrology"
click node_direct "https://github.com/krishna-dhawangale/astro-ai-chatbot/blob/main/backend/reasoning/direct_fact_engine.py"
click node_rules "https://github.com/krishna-dhawangale/astro-ai-chatbot/tree/main/backend/reasoning"
click node_timing "https://github.com/krishna-dhawangale/astro-ai-chatbot/tree/main/backend/reasoning"
click node_stage8 "https://github.com/krishna-dhawangale/astro-ai-chatbot/blob/main/backend/reasoning/stage8_pipeline.py"
click node_coverage "https://github.com/krishna-dhawangale/astro-ai-chatbot/blob/main/backend/reasoning/rule_coverage.py"
click node_mode "https://github.com/krishna-dhawangale/astro-ai-chatbot/blob/main/backend/reasoning/mode_selector.py"
click node_evidence "https://github.com/krishna-dhawangale/astro-ai-chatbot/blob/main/backend/reasoning/structured_evidence.py"
click node_synth "https://github.com/krishna-dhawangale/astro-ai-chatbot/blob/main/backend/reasoning/answer_synthesizer.py"
click node_renderer "https://github.com/krishna-dhawangale/astro-ai-chatbot/blob/main/backend/reasoning/llm_renderer.py"
click node_llm_router "https://github.com/krishna-dhawangale/astro-ai-chatbot/blob/main/backend/llm_router.py"
click node_client "https://github.com/krishna-dhawangale/astro-ai-chatbot/blob/main/frontend/script.js"

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_api,node_guard,node_boundary,node_user,node_client toneBlue
class node_faq,node_classifier,node_router,node_complexity,node_intent toneAmber
class node_ephemeris,node_normalize,node_astrology,node_astro_api toneMint
class node_direct,node_rules,node_timing,node_stage8,node_coverage toneRose
class node_mode,node_evidence,node_synth,node_renderer,node_llm_router,node_llm toneIndigo
```

## Components

### Safety and Entry

- [Chat API](https://github.com/krishna-dhawangale/astro-ai-chatbot/blob/main/backend/main.py): `backend/main.py`
- [Abuse Guardrail](https://github.com/krishna-dhawangale/astro-ai-chatbot/blob/main/backend/abuse_guardrail.py): `backend/abuse_guardrail.py`
- [Domain Filter](https://github.com/krishna-dhawangale/astro-ai-chatbot/blob/main/backend/domain_filter.py): `backend/domain_filter.py`

### Query Classification

- [Educational FAQ](https://github.com/krishna-dhawangale/astro-ai-chatbot/blob/main/backend/faq_engine.py): `backend/faq_engine.py`
- [Domain Intent Ensemble](https://github.com/krishna-dhawangale/astro-ai-chatbot/blob/main/backend/router/model_selector.py): `backend/router/model_selector.py`
- [Question Pipeline](https://github.com/krishna-dhawangale/astro-ai-chatbot/blob/main/backend/router/pipeline.py): `backend/router/pipeline.py`
- [Complexity Prediction](https://github.com/krishna-dhawangale/astro-ai-chatbot/blob/main/backend/router/complexity.py): `backend/router/complexity.py`
- [Intent Prediction](https://github.com/krishna-dhawangale/astro-ai-chatbot/blob/main/backend/router/intent.py): `backend/router/intent.py`

### Chart and Ephemeris

- [Swiss Ephemeris](https://github.com/krishna-dhawangale/astro-ai-chatbot/blob/main/backend/ephemeris.py): `backend/ephemeris.py`
- [Chart Normalizer](https://github.com/krishna-dhawangale/astro-ai-chatbot/blob/main/backend/normalize.py): `backend/normalize.py`
- [Dasha and Transit](https://github.com/krishna-dhawangale/astro-ai-chatbot/tree/main/backend/astrology): `backend/astrology`

### Astrological Reasoning

- [Direct Fact Engine](https://github.com/krishna-dhawangale/astro-ai-chatbot/blob/main/backend/reasoning/direct_fact_engine.py): `backend/reasoning/direct_fact_engine.py`
- [Domain Rules](https://github.com/krishna-dhawangale/astro-ai-chatbot/tree/main/backend/reasoning): `backend/reasoning`
- [Dasha Transit Timing](https://github.com/krishna-dhawangale/astro-ai-chatbot/tree/main/backend/reasoning): `backend/reasoning`
- [Stage 8 Pipeline](https://github.com/krishna-dhawangale/astro-ai-chatbot/blob/main/backend/reasoning/stage8_pipeline.py): `backend/reasoning/stage8_pipeline.py`
- [Rule Coverage](https://github.com/krishna-dhawangale/astro-ai-chatbot/blob/main/backend/reasoning/rule_coverage.py): `backend/reasoning/rule_coverage.py`

### Answer Generation

- [Mode Selector](https://github.com/krishna-dhawangale/astro-ai-chatbot/blob/main/backend/reasoning/mode_selector.py): `backend/reasoning/mode_selector.py`
- [Structured Evidence](https://github.com/krishna-dhawangale/astro-ai-chatbot/blob/main/backend/reasoning/structured_evidence.py): `backend/reasoning/structured_evidence.py`
- [Local Synthesizer](https://github.com/krishna-dhawangale/astro-ai-chatbot/blob/main/backend/reasoning/answer_synthesizer.py): `backend/reasoning/answer_synthesizer.py`
- [LLM Renderer](https://github.com/krishna-dhawangale/astro-ai-chatbot/blob/main/backend/reasoning/llm_renderer.py): `backend/reasoning/llm_renderer.py`
- [LLM Provider Router](https://github.com/krishna-dhawangale/astro-ai-chatbot/blob/main/backend/llm_router.py): `backend/llm_router.py`

### Other components

- **User**
- **FreeAstrologyAPI**
- **LLM Providers**
- [Frontend Client](https://github.com/krishna-dhawangale/astro-ai-chatbot/blob/main/frontend/script.js): `frontend/script.js`

## Connections

- User → Chat API: submits query
- Chat API → Abuse Guardrail: checks safety (evidence: `backend/main.py`)
- Chat API → Domain Filter: filters scope (evidence: `backend/main.py`)
- Chat API → Educational FAQ: checks FAQ (evidence: `backend/main.py`)
- Chat API → Domain Intent Ensemble: classifies query
- Question Pipeline → Complexity Prediction: predicts complexity (evidence: `backend/router/pipeline.py`)
- Question Pipeline → Intent Prediction: predicts intent (evidence: `backend/router/pipeline.py`)
- Chat API → FreeAstrologyAPI: requests chart
- Chat API → Swiss Ephemeris: fallback calculation (evidence: `backend/main.py`)
- FreeAstrologyAPI → Chart Normalizer: returns chart
- Swiss Ephemeris → Chart Normalizer: returns chart
- Chat API → Chart Normalizer: normalizes chart (evidence: `backend/main.py`)
- Chart Normalizer → Direct Fact Engine: provides chart facts
- Chat API → Direct Fact Engine: checks direct facts (evidence: `backend/main.py`)
- Chat API → Domain Rules: evaluates domains (evidence: `backend/main.py`)
- Domain Rules → Dasha Transit Timing: evaluates timing
- Dasha Transit Timing → Stage 8 Pipeline: supplies timing (evidence: `backend/reasoning/stage8_pipeline.py`)
- Stage 8 Pipeline → Domain Rules: combines domain results (evidence: `backend/reasoning/stage8_pipeline.py`)
- Chat API → Mode Selector: selects answer mode (evidence: `backend/main.py`)
- Mode Selector → Rule Coverage: checks rule coverage (evidence: `backend/reasoning/mode_selector.py`)
- Mode Selector → Direct Fact Engine: checks direct path (evidence: `backend/reasoning/mode_selector.py`)
- Chat API → Structured Evidence: builds evidence (evidence: `backend/main.py`)
- Structured Evidence → Local Synthesizer: supplies evidence (evidence: `backend/reasoning/answer_synthesizer.py`)
- Mode Selector → Local Synthesizer: selects local answer
- Mode Selector → LLM Renderer: selects LLM path
- LLM Renderer → LLM Provider Router: routes prompt
- LLM Provider Router → LLM Providers: calls providers
- Chat API → Frontend Client: returns answer
- Educational FAQ → Frontend Client: returns FAQ
- Local Synthesizer → Frontend Client: returns local answer
- LLM Providers → Frontend Client: returns response
