# tanishpoddar/neuralnexus architecture

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

- Interactive diagram: https://gitdiagram.com/tanishpoddar/neuralnexus
- Repository: https://github.com/tanishpoddar/neuralnexus

## Overview

##### Project Type and Purpose
- NeuralNexus is a full-stack AI chatbot application. It combines a Flask-based web server (backend) with a modern web interface (frontend), and an NLP/ML module that trains and serves a neural network model for conversational AI.

##### Top-Level Components
a. Frontend
- Browser/client running `templates/index.html` (HTML, CSS, JS)
- Sends user messages via HTTP (e.g., AJAX or Fetch) to the Flask API
b. Backend (Flask App)
- Entry point: `main-host.py` (Flask server)
- May import `main.py` (core logic: training & inference)
- Loads configuration from `.env` (via `python-dotenv`)
- Exposes REST endpoints for chat and possibly status/training
c. NLP/ML Module
- Data loader: reads `intents.json`
- Preprocessor: uses NLTK to tokenize, stem, bag-of-words
- Model trainer: TensorFlow-based network (layers, dropout)
- Inference engine: loads `model.weights.h5` & `data.pickle`, generates responses
d. Data Storage
- Static JSON: `intents.json` (training data)
- Binary artifacts: `model.weights.h5`, `data.pickle` (persisted in project root or storage folder)
e. External Dependencies
- TensorFlow, NLTK, NumPy, Flask, python-dotenv

##### Interactions and Data Flows
- 1) User opens the web page (`index.html`) in browser.
- 2) Browser sends user input via HTTP POST to Flask endpoint (e.g., `/chat`).
- 3) Flask app receives request in `main-host.py`, calls NLP module in `main.py`:
- If model not yet trained or weights missing, trigger training subroutine
- Otherwise load persisted model and data (from `model.weights.h5`, `data.pickle`)
- 4) NLP module preprocesses input, runs inference, selects a response tag and text.
- 5) Flask app returns JSON payload containing chatbot response.
- 6) Frontend JavaScript updates the UI with the chatbot reply.

##### Architectural Patterns and Principles
- Layered architecture:
- Presentation layer (frontend)
- API layer (Flask routes)
- Business logic layer (NLP pipeline, model training/inference)
- Data layer (intents JSON, trained artifacts)
- Separation of concerns: each layer handles a specific responsibility.
- Stateless request handling: each HTTP request is independent (model loading cached in memory).
- Extensibility: adding new intents via `intents.json` only requires editing the JSON file.

##### Diagramming Recommendations
- Client (Browser)
- Web UI (HTML/JS)
- Flask API (main-host.py)
- NLP Engine (main.py modules: Preprocessor, Trainer, Inference)
- Data Store (intents.json, model.weights.h5, data.pickle)
- Relationships:

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        Browser["Browser/Client"]:::infra
        UI["Web UI (templates/index.html)"]:::infra
    end

    %% API Layer
    subgraph "API Layer"
        API["Flask API (main-host.py)"]:::infra
    end

    %% Business Logic Layer
    subgraph "Business Logic Layer"
        subgraph "NLP Engine (main.py)"
            Pre["Preprocessor"]:::ml
            Train["Trainer"]:::ml
            Infer["Inference Engine"]:::ml
        end
    end

    %% Data Layer
    subgraph "Data Store"
        Intent["intents.json"]:::data
        Model["model.weights.h5"]:::data
        DataPickle["data.pickle"]:::data
    end

    %% External Dependencies
    External["requirements.txt"]:::data

    %% Data Flows
    Browser -->|"loads UI"| UI
    UI -->|"POST /chat"| API
    API -->|"invoke NLP pipeline"| Pre
    Pre -->|"uses intents definitions"| Intent
    Pre --> Infer
    Infer -->|"load artifacts"| Model
    Infer -->|"load artifacts"| DataPickle

    %% Optional Training Flow
    API -.->|"trigger training if missing"| Train
    Train -->|"reads intents"| Intent
    Train -->|"generates artifacts"| Model
    Train -->|"generates artifacts"| DataPickle

    %% Response Flow
    Infer -->|"response data"| API
    API -->|"HTTP 200 with reply"| UI
    UI -->|"renders reply"| Browser

    %% Dependencies
    API -.->|"uses"| External
    Pre -.->|"uses NLTK, TensorFlow"| External
    Train -.->|"uses TensorFlow"| External
    Infer -.->|"uses TensorFlow"| External

    %% Click Events
    click UI "https://github.com/tanishpoddar/neuralnexus/blob/main/templates/index.html"
    click API "https://github.com/tanishpoddar/neuralnexus/blob/main/main-host.py"
    click Pre "https://github.com/tanishpoddar/neuralnexus/blob/main/main.py"
    click Train "https://github.com/tanishpoddar/neuralnexus/blob/main/main.py"
    click Infer "https://github.com/tanishpoddar/neuralnexus/blob/main/main.py"
    click Intent "https://github.com/tanishpoddar/neuralnexus/blob/main/intents.json"
    click External "https://github.com/tanishpoddar/neuralnexus/blob/main/requirements.txt"

    %% Styles
    classDef infra fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef ml fill:#90EE90,stroke:#333,stroke-width:1px
    classDef data fill:#D3D3D3,stroke:#333,stroke-width:1px
```
