# nnboru/mathbot architecture

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

- Interactive diagram: https://gitdiagram.com/nnboru/mathbot
- Repository: https://github.com/nnboru/mathbot

## Overview

##### Project Type & Purpose
- Mathbot is a full-stack, Flask-based web application.
- Purpose: provide an interactive chatbot in the CS domain, plus two external utilities (CSV Analyser and Equation Plotter hosted separately).

##### File Structure
- Top-level files:
- app.py – Flask application entrypoint and request router
- scrap.py – web-scraping logic
- nn/ – scripted-bot logic (neural-net or rule-based responses)
- requirements.txt, Procfile, run.bat – deployment/build configs
- Front-end assets:
- static/ – CSS & JS (botbase.css/js, index.css/js)
- templates/ – HTML views (index.html, update.html)

##### Key Architecture Insights from README
- Three logical “layers” inside the backend:
1. Scripted bot layer (handles basic chat & updates)
2. Math evaluator layer (parses/calculates expressions)
3. Scraper layer (search & scrape from Google, GeeksforGeeks, CP-Algorithms)

##### Main Components & Interactions
a. Frontend
- Browser: HTML/JS/CSS delivered from static/ & templates/
- Two views: Chat interface (index.html) and Update interface (update.html)
b. Backend (Flask app.py)
- Routes requests to the correct layer based on input type
c. Core Processing Layers
1. Scripted Bot (nn/ folder)
2. Math Evaluator (in app.py or a helper module)
3. Scraper (scrap.py using requests & BeautifulSoup)
d. External Services
- Google search (HTTP API by scraping search results)
- GeeksforGeeks & CP-Algorithms (scrape sub-sites)
- Separate micro-apps: CSV Analyser & Equation Plotter (hosted externally)

##### Architectural Patterns & Tech
- Layered architecture: Presentation → Business Logic → Integration
- MVC-style separation:
- Views (templates/)
- Controllers (Flask routes in app.py)
- Models/Services (nn/, math parser, scrap.py)
- Technologies: Python 3.x, Flask, requests, BeautifulSoup, HTML/CSS/JS

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User Layer
    Browser["User Browser"]:::frontend

    %% Frontend Layer
    subgraph "Frontend"
        direction TB
        StaticAssets["Static Assets"]:::frontend
        Templates["Templates"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend"
        direction TB
        App["Flask App (app.py)"]:::backend
        subgraph "Business Logic"
            direction TB
            BotModule["Scripted Bot Module (nn/)"]:::backend
            MathEvaluator["Math Evaluator Module"]:::backend
            ScraperModule["Scraper Module (scrap.py)"]:::backend
        end
    end

    %% External Services Layer
    subgraph "External Services"
        direction TB
        Google["Google Search"]:::external
        G4G["GeeksforGeeks & CP-Algorithms"]:::external
        CSVAnalyser["CSV Analyser (External)"]:::external
        EquationPlotter["Equation Plotter (External)"]:::external
    end

    %% Connections
    Browser -->|"HTTP GET/POST"| App
    Browser --> StaticAssets
    Browser --> Templates

    App -->|"invoke"| BotModule
    App -->|"invoke"| MathEvaluator
    App -->|"invoke"| ScraperModule

    ScraperModule -->|"scrape"| Google
    ScraperModule -->|"scrape"| G4G
    Google -->|"results"| ScraperModule
    G4G -->|"results"| ScraperModule

    App -->|"links to"| CSVAnalyser
    App -->|"links to"| EquationPlotter

    %% Click Events
    click StaticAssets "https://github.com/nnboru/mathbot/tree/master/static/"
    click Templates "https://github.com/nnboru/mathbot/tree/master/templates/"
    click App "https://github.com/nnboru/mathbot/blob/master/app.py"
    click BotModule "https://github.com/nnboru/mathbot/tree/master/nn/"
    click ScraperModule "https://github.com/nnboru/mathbot/blob/master/scrap.py"

    %% Styles
    classDef frontend fill:#D0E6F8,stroke:#0366D6;
    classDef backend fill:#DFF2BF,stroke:#4F8A10;
    classDef external fill:#E0E0E0,stroke:#888888;
```
