# findtharun/railway_bot architecture

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

- Interactive diagram: https://gitdiagram.com/findtharun/railway_bot
- Repository: https://github.com/findtharun/railway_bot

## Overview

##### Project Type and Purpose
- This is an AI/NLP prototype chatbot built in Python (Jupyter notebooks), intended to handle railway‐ticket booking queries via text or speech.
- Major features: intent classification (TensorFlow), speech recognition, sentiment analysis, custom thresholding, and a feedback loop.

##### File Structure
Top level:
- Chatbot use cases..pdf – design/use‐case documentation
- RailwayBot.ipynb – main chatbot pipeline (input → model → response)
- RailwayBot_SpeechRecognition.ipynb – notebook extension showing speech→text integration
- sentiment Analysis.ipynb – notebook demonstrating feedback sentiment module
- intents.json – the corpus of user intents/patterns + responses
- feedback.xlsx – storage for user feedback data

##### Key Architecture Components
a. User Interface Layer
- Text input (CLI or GUI)
- Speech input (microphone) → Speech Recognition module (e.g., Python speech_recognition)
b. Preprocessing / NLU Layer
- Punkt Sentence Tokenizer (NLTK)
- Text Normalization: lowercasing, punctuation removal
- Stemming & Lemmatization (NLTK or custom)
- Vocabulary & feature engineering (TF‑IDF from scratch)
c. Intent Classification Module
- Features → Neural Network (TensorFlow)
- Custom thresholding to filter low‑confidence predictions
- intents.json as knowledge base (patterns → intent tags → responses)
d. Response Generation
- Predicted intent to canned response templates
- Optionally slot‑fill or prompt for missing info (source, destination, date)
e. Feedback & Sentiment Analysis
- User feedback post‑conversation → store in feedback.xlsx
- Sentiment Analysis notebook (NLTK/Vader or custom) to gauge satisfaction
- Sentiment scores feed back into model re‑training or threshold adjustment
f. Model Training / Offline Batch
- Shuffle & vectorize documents → np.array features
- Train TensorFlow model using gradient descent
- Export trained model weights for runtime inference

##### Architectural Patterns & Tech Stack
- Pipeline pattern: a linear sequence of processing stages
- Batch training vs. real‑time inference separation
- Key libraries: TensorFlow, NLTK, speech_recognition, JSON for intents, pandas/xlsx for feedback

##### Essential Elements
- Data stores: intents.json (knowledge base), feedback.xlsx
- Clear labels and notes (e.g., “Threshold filter applied here,” “TensorFlow neural network”)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Input Layer
    subgraph "Input Layer"
        style InputLayer fill:none,stroke:none
        User["User"]:::input
        TextInput["Text Input"]:::input
        SpeechRecognizer["Speech Recognizer"]:::input
    end

    User -->|"text or speech"| TextInput
    User -->|"speech"| SpeechRecognizer

    %% Preprocessing Layer
    subgraph "Preprocessing & NLU" 
        style PreprocLayer fill:none,stroke:none
        Preprocessor["Text Preprocessor<br/>(tokenize, normalize,<br/>stem/lemmatize, TF‑IDF)"]:::preprocess
    end

    TextInput -->|"raw text"| Preprocessor
    SpeechRecognizer -->|"transcribed text"| Preprocessor

    %% ML Layer
    subgraph "ML & Classification" 
        style MLLayer fill:none,stroke:none
        Classifier["Intent Classification Module<br/>(TensorFlow NN,<br/>threshold filter)"]:::ml
        ResponseGenerator["Response Generator<br/>(map intent to<br/>templates/slot‑filling)"]:::ml
    end

    Preprocessor -->|"tokens & features"| Classifier
    Classifier -->|"predicted intent"| ResponseGenerator

    %% Data Store: Intents KB
    IntentsDB[(intents.json)]:::datastore
    IntentsDB -.->|knowledge base| Classifier
    IntentsDB -.->|templates| ResponseGenerator

    %% Output
    ResponseGenerator -->|"response text"| User

    %% Feedback Loop
    subgraph "Feedback & Retraining Loop"
        style FeedbackLoop fill:none,stroke:none
        FeedbackCollector[(feedback.xlsx)]:::datastore
        SentimentAnalyzer["Sentiment Analyzer"]:::feedback
        ModelTrainer["Model Trainer<br/>(shuffle, vectorize,<br/>train, export weights)"]:::feedback
    end

    User -->|"feedback"| FeedbackCollector
    FeedbackCollector -->|"feedback data"| SentimentAnalyzer
    SentimentAnalyzer -->|"sentiment scores"| FeedbackCollector
    FeedbackCollector -->|"feedback dataset"| ModelTrainer
    IntentsDB -.->|training data| ModelTrainer
    ModelTrainer -->|"updated model"| Classifier

    %% Documentation Links
    subgraph "Project Docs & Diagrams"
        ChatbotDocs["Use‑Case & Design Doc"]:::notebook
        Readme["README & Overview"]:::notebook
        ImagesFolder["Flowcharts & Diagrams"]:::notebook
    end

    %% Click Events
    click SpeechRecognizer "https://github.com/findtharun/railway_bot/blob/master/RailwayBot_SpeechRecognition.ipynb"
    click Preprocessor "https://github.com/findtharun/railway_bot/blob/master/RailwayBot.ipynb"
    click Classifier "https://github.com/findtharun/railway_bot/blob/master/RailwayBot.ipynb"
    click ResponseGenerator "https://github.com/findtharun/railway_bot/blob/master/RailwayBot.ipynb"
    click ModelTrainer "https://github.com/findtharun/railway_bot/blob/master/RailwayBot.ipynb"
    click SentimentAnalyzer "https://github.com/findtharun/railway_bot/blob/master/sentiment Analysis.ipynb"
    click FeedbackCollector "https://github.com/findtharun/railway_bot/blob/master/feedback.xlsx"
    click IntentsDB "https://github.com/findtharun/railway_bot/blob/master/intents.json"
    click ChatbotDocs "https://github.com/findtharun/railway_bot/blob/master/Chatbot use cases..pdf"
    click Readme "https://github.com/findtharun/railway_bot/blob/master/Readme.md"
    click ImagesFolder "https://github.com/findtharun/railway_bot/tree/master/Images/"

    %% Styles
    classDef input fill:#ADD8E6,stroke:#000,color:#000
    classDef preprocess fill:#90EE90,stroke:#000,color:#000
    classDef ml fill:#FFA500,stroke:#000,color:#000
    classDef feedback fill:#DDA0DD,stroke:#000,color:#000
    classDef datastore fill:#F0E68C,stroke:#000,color:#000
    classDef notebook fill:#E0FFFF,stroke:#000,color:#000
```
