# malavika-suresh/ai-chatbot architecture

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

- Interactive diagram: https://gitdiagram.com/malavika-suresh/ai-chatbot
- Repository: https://github.com/malavika-suresh/ai-chatbot

## Overview

This is a Django chatbot: a visitor opens the web interface, submits a question, and receives a response selected from the configured intents. The request routes to the chatbot view, which invokes intent matching and renders the result. Inside the inference layer, text is tokenized and lemmatized, converted to a bag of words, and scored by the trained model before response selection. The README also documents responsive UI, CSRF-protected handling, and customizable intents. Asset loading uses hard-coded paths in the sampled view; no database-backed chatbot behavior is shown.

Main entry points: [`chatbot/views.py`](https://github.com/malavika-suresh/ai-chatbot/blob/main/chatbot/views.py) (Intent predictor), [`chat/urls.py`](https://github.com/malavika-suresh/ai-chatbot/blob/main/chat/urls.py) (Project routes), [`chatbot/urls.py`](https://github.com/malavika-suresh/ai-chatbot/blob/main/chatbot/urls.py) (Chat routes), [`chatbot/templates/webbot/index.html`](https://github.com/malavika-suresh/ai-chatbot/blob/main/chatbot/templates/webbot/index.html) (Chat page)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web interface"]
  node_project_routes["Project routes<br/>[urls.py]"]
  node_chat_routes["Chat routes<br/>[urls.py]"]
  node_request_views["Request views<br/>[views.py]"]
  node_chat_page["Chat page<br/>[index.html]"]
end

subgraph group_inference["Intent inference"]
  node_response_selector["Response selector<br/>[views.py]"]
  node_intent_predictor["Intent predictor<br/>[views.py]"]
  node_text_vectorizer["Text vectorizer<br/>[views.py]"]
  node_sentence_cleaner["Sentence cleaner<br/>[views.py]"]
end

subgraph group_assets["Chatbot assets"]
  node_trained_model["Trained model<br/>[model_new.h5]"]
  node_intent_data["Intent responses<br/>[new_intent.json]"]
  node_word_list["Word list<br/>[words.pkl]"]
  node_intent_classes["Intent classes<br/>[classes.pkl]"]
end

node_visitor(("Visitor"))

node_visitor -->|"sends request"| node_project_routes
node_project_routes -->|"includes routes"| node_chat_routes
node_chat_routes -->|"routes requests"| node_request_views
node_request_views -->|"renders page"| node_chat_page
node_request_views -->|"gets response"| node_response_selector
node_response_selector -->|"predicts intent"| node_intent_predictor
node_intent_predictor -->|"vectorizes text"| node_text_vectorizer
node_text_vectorizer -->|"cleans sentence"| node_sentence_cleaner
node_intent_predictor -->|"scores vector"| node_trained_model
node_intent_predictor -->|"uses vocabulary"| node_word_list
node_intent_predictor -->|"maps classes"| node_intent_classes
node_response_selector -->|"selects response"| node_intent_data

click node_project_routes "https://github.com/malavika-suresh/ai-chatbot/blob/main/chat/urls.py"
click node_chat_routes "https://github.com/malavika-suresh/ai-chatbot/blob/main/chatbot/urls.py"
click node_request_views "https://github.com/malavika-suresh/ai-chatbot/blob/main/chatbot/views.py"
click node_chat_page "https://github.com/malavika-suresh/ai-chatbot/blob/main/chatbot/templates/webbot/index.html"
click node_response_selector "https://github.com/malavika-suresh/ai-chatbot/blob/main/chatbot/views.py"
click node_intent_predictor "https://github.com/malavika-suresh/ai-chatbot/blob/main/chatbot/views.py"
click node_text_vectorizer "https://github.com/malavika-suresh/ai-chatbot/blob/main/chatbot/views.py"
click node_sentence_cleaner "https://github.com/malavika-suresh/ai-chatbot/blob/main/chatbot/views.py"
click node_trained_model "https://github.com/malavika-suresh/ai-chatbot/blob/main/files/model_new.h5"
click node_intent_data "https://github.com/malavika-suresh/ai-chatbot/blob/main/files/new_intent.json"
click node_word_list "https://github.com/malavika-suresh/ai-chatbot/blob/main/files/words.pkl"
click node_intent_classes "https://github.com/malavika-suresh/ai-chatbot/blob/main/files/classes.pkl"

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_project_routes,node_chat_routes,node_request_views,node_chat_page toneBlue
class node_response_selector,node_intent_predictor,node_text_vectorizer,node_sentence_cleaner toneAmber
class node_trained_model,node_intent_data,node_word_list,node_intent_classes toneMint
class node_visitor toneIndigo
```

## Components

### Web interface

- [Project routes](https://github.com/malavika-suresh/ai-chatbot/blob/main/chat/urls.py): `chat/urls.py`
- [Chat routes](https://github.com/malavika-suresh/ai-chatbot/blob/main/chatbot/urls.py): `chatbot/urls.py`
- [Request views](https://github.com/malavika-suresh/ai-chatbot/blob/main/chatbot/views.py): `chatbot/views.py`
- [Chat page](https://github.com/malavika-suresh/ai-chatbot/blob/main/chatbot/templates/webbot/index.html): `chatbot/templates/webbot/index.html`

### Intent inference

- [Response selector](https://github.com/malavika-suresh/ai-chatbot/blob/main/chatbot/views.py): `chatbot/views.py`
- [Intent predictor](https://github.com/malavika-suresh/ai-chatbot/blob/main/chatbot/views.py): `chatbot/views.py`
- [Text vectorizer](https://github.com/malavika-suresh/ai-chatbot/blob/main/chatbot/views.py): `chatbot/views.py`
- [Sentence cleaner](https://github.com/malavika-suresh/ai-chatbot/blob/main/chatbot/views.py): `chatbot/views.py`

### Chatbot assets

- [Trained model](https://github.com/malavika-suresh/ai-chatbot/blob/main/files/model_new.h5): `files/model_new.h5`
- [Intent responses](https://github.com/malavika-suresh/ai-chatbot/blob/main/files/new_intent.json): `files/new_intent.json`
- [Word list](https://github.com/malavika-suresh/ai-chatbot/blob/main/files/words.pkl): `files/words.pkl`
- [Intent classes](https://github.com/malavika-suresh/ai-chatbot/blob/main/files/classes.pkl): `files/classes.pkl`

### Other components

- **Visitor**

## Connections

- Visitor → Project routes: sends request (evidence: `chat/urls.py`)
- Project routes → Chat routes: includes routes (evidence: `chat/urls.py`)
- Chat routes → Request views: routes requests (evidence: `chatbot/urls.py`)
- Request views → Chat page: renders page (evidence: `chatbot/views.py`)
- Request views → Response selector: gets response (evidence: `chatbot/views.py`)
- Response selector → Intent predictor: predicts intent (evidence: `chatbot/views.py`)
- Intent predictor → Text vectorizer: vectorizes text (evidence: `chatbot/views.py`)
- Text vectorizer → Sentence cleaner: cleans sentence (evidence: `chatbot/views.py`)
- Intent predictor → Trained model: scores vector (evidence: `chatbot/views.py`)
- Intent predictor → Word list: uses vocabulary (evidence: `chatbot/views.py`)
- Intent predictor → Intent classes: maps classes (evidence: `chatbot/views.py`)
- Response selector → Intent responses: selects response (evidence: `chatbot/views.py`)
