# wajih1234/enstab_bot architecture

> Architecture diagram of the GitHub repository wajih1234/enstab_bot, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/wajih1234/enstab_bot
- Repository: https://github.com/wajih1234/enstab_bot

## Overview

ENSTAB Chatbot combines a Node/Express authentication and message API with a Flask chatbot service. Students log in or sign up, open the chatbot, send a message for intent-based prediction, and receive a response; conversation messages are stored for history. The trained PyTorch model uses intent data and French NLP preprocessing. The sampled client also posts user messages to the Node API, while Flask independently stores user and bot turns. Some documented history behavior is represented by the Node message API; the excerpts do not show the client loading that history.

Main entry points: [`logpfa2/server.js`](https://github.com/wajih1234/enstab_bot/blob/master/logpfa2/server.js) (Auth and message API), [`ENSTA_BOT1/train.py`](https://github.com/wajih1234/enstab_bot/blob/master/ENSTA_BOT1/train.py) (Model trainer), [`ENSTA_BOT1/static/app.js`](https://github.com/wajih1234/enstab_bot/blob/master/ENSTA_BOT1/static/app.js) (Chat interface), [`ENSTA_BOT1/chat.py`](https://github.com/wajih1234/enstab_bot/blob/master/ENSTA_BOT1/chat.py) (Intent response)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web experience"]
  node_login_ui["Login form<br/>[login.js]"]
  node_chat_ui["Chat interface<br/>[app.js]"]
  node_chat_page["Chat page<br/>[base.html]"]
end

subgraph group_identity["Identity and history"]
  node_auth_api["Auth and message API<br/>[server.js]"]
  node_user_store[("User records<br/>[server.js]")]
  node_message_store[("Message records<br/>[server.js]")]
end

subgraph group_inference["Chat inference"]
  node_flask_api["Chatbot API<br/>[app.py]"]
  node_chat_logic["Intent response<br/>[chat.py]"]
  node_nlp["NLP preprocessing<br/>[nltk_utils.py]"]
  node_network["Neural network<br/>[model.py]"]
  node_chat_store[("Chat messages<br/>[app.py]")]
end

subgraph group_training["Model training"]
  node_intents["Intent definitions<br/>[intents.json]"]
  node_trainer["Model trainer<br/>[train.py]"]
  node_model_artifact["Trained weights<br/>[data.pth]"]
end

node_student(("Student"))

node_student -->|"enters credentials"| node_login_ui
node_login_ui -->|"submits login"| node_auth_api
node_auth_api -->|"checks or saves"| node_user_store
node_auth_api -->|"returns token"| node_student
node_student -->|"opens chatbot"| node_chat_page
node_chat_page -.->|"loads script"| node_chat_ui
node_chat_ui -->|"renders messages"| node_student
node_chat_ui -->|"posts user message"| node_auth_api
node_chat_ui -->|"requests prediction"| node_flask_api
node_flask_api -->|"requests response"| node_chat_logic
node_chat_logic -->|"tokenizes and vectors"| node_nlp
node_chat_logic -->|"runs classification"| node_network
node_chat_logic -->|"loads weights"| node_model_artifact
node_flask_api -->|"saves both turns"| node_chat_store
node_auth_api -->|"saves and retrieves"| node_message_store
node_student -->|"trains intents model"| node_trainer
node_intents -->|"provides patterns"| node_trainer
node_trainer -->|"preprocesses text"| node_nlp
node_trainer -->|"trains network"| node_network
node_trainer -->|"saves weights"| node_model_artifact

click node_login_ui "https://github.com/wajih1234/enstab_bot/blob/master/logpfa2/public/login.js"
click node_chat_ui "https://github.com/wajih1234/enstab_bot/blob/master/ENSTA_BOT1/static/app.js"
click node_chat_page "https://github.com/wajih1234/enstab_bot/blob/master/ENSTA_BOT1/templates/base.html"
click node_auth_api "https://github.com/wajih1234/enstab_bot/blob/master/logpfa2/server.js"
click node_user_store "https://github.com/wajih1234/enstab_bot/blob/master/logpfa2/server.js"
click node_message_store "https://github.com/wajih1234/enstab_bot/blob/master/logpfa2/server.js"
click node_flask_api "https://github.com/wajih1234/enstab_bot/blob/master/ENSTA_BOT1/app.py"
click node_chat_logic "https://github.com/wajih1234/enstab_bot/blob/master/ENSTA_BOT1/chat.py"
click node_nlp "https://github.com/wajih1234/enstab_bot/blob/master/ENSTA_BOT1/nltk_utils.py"
click node_network "https://github.com/wajih1234/enstab_bot/blob/master/ENSTA_BOT1/model.py"
click node_chat_store "https://github.com/wajih1234/enstab_bot/blob/master/ENSTA_BOT1/app.py"
click node_intents "https://github.com/wajih1234/enstab_bot/blob/master/ENSTA_BOT1/intents.json"
click node_trainer "https://github.com/wajih1234/enstab_bot/blob/master/ENSTA_BOT1/train.py"
click node_model_artifact "https://github.com/wajih1234/enstab_bot/blob/master/data.pth"

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_login_ui,node_chat_ui,node_chat_page toneBlue
class node_auth_api,node_user_store,node_message_store toneAmber
class node_flask_api,node_chat_logic,node_nlp,node_network,node_chat_store toneMint
class node_intents,node_trainer,node_model_artifact toneRose
class node_student toneIndigo
```

## Components

### Web experience

- [Login form](https://github.com/wajih1234/enstab_bot/blob/master/logpfa2/public/login.js): `logpfa2/public/login.js`
- [Chat interface](https://github.com/wajih1234/enstab_bot/blob/master/ENSTA_BOT1/static/app.js): `ENSTA_BOT1/static/app.js`
- [Chat page](https://github.com/wajih1234/enstab_bot/blob/master/ENSTA_BOT1/templates/base.html): `ENSTA_BOT1/templates/base.html`

### Identity and history

- [Auth and message API](https://github.com/wajih1234/enstab_bot/blob/master/logpfa2/server.js): `logpfa2/server.js`
- [User records](https://github.com/wajih1234/enstab_bot/blob/master/logpfa2/server.js): `logpfa2/server.js`
- [Message records](https://github.com/wajih1234/enstab_bot/blob/master/logpfa2/server.js): `logpfa2/server.js`

### Chat inference

- [Chatbot API](https://github.com/wajih1234/enstab_bot/blob/master/ENSTA_BOT1/app.py): `ENSTA_BOT1/app.py`
- [Intent response](https://github.com/wajih1234/enstab_bot/blob/master/ENSTA_BOT1/chat.py): `ENSTA_BOT1/chat.py`
- [NLP preprocessing](https://github.com/wajih1234/enstab_bot/blob/master/ENSTA_BOT1/nltk_utils.py): `ENSTA_BOT1/nltk_utils.py`
- [Neural network](https://github.com/wajih1234/enstab_bot/blob/master/ENSTA_BOT1/model.py): `ENSTA_BOT1/model.py`
- [Chat messages](https://github.com/wajih1234/enstab_bot/blob/master/ENSTA_BOT1/app.py): `ENSTA_BOT1/app.py`

### Model training

- [Intent definitions](https://github.com/wajih1234/enstab_bot/blob/master/ENSTA_BOT1/intents.json): `ENSTA_BOT1/intents.json`
- [Model trainer](https://github.com/wajih1234/enstab_bot/blob/master/ENSTA_BOT1/train.py): `ENSTA_BOT1/train.py`
- [Trained weights](https://github.com/wajih1234/enstab_bot/blob/master/data.pth): `data.pth`

### Other components

- **Student**

## Connections

- Student → Login form: enters credentials (evidence: `logpfa2/public/login.js`)
- Login form → Auth and message API: submits login (evidence: `logpfa2/public/login.js`)
- Auth and message API → User records: checks or saves (evidence: `logpfa2/server.js`)
- Auth and message API → Student: returns token (evidence: `logpfa2/server.js`)
- Student → Chat page: opens chatbot
- Chat page → Chat interface: loads script
- Chat interface → Student: renders messages (evidence: `ENSTA_BOT1/static/app.js`)
- Chat interface → Auth and message API: posts user message (evidence: `ENSTA_BOT1/static/app.js`)
- Chat interface → Chatbot API: requests prediction (evidence: `ENSTA_BOT1/static/app.js`)
- Chatbot API → Intent response: requests response (evidence: `ENSTA_BOT1/app.py`)
- Intent response → NLP preprocessing: tokenizes and vectors (evidence: `ENSTA_BOT1/chat.py`)
- Intent response → Neural network: runs classification (evidence: `ENSTA_BOT1/chat.py`)
- Intent response → Trained weights: loads weights (evidence: `ENSTA_BOT1/chat.py`)
- Chatbot API → Chat messages: saves both turns (evidence: `ENSTA_BOT1/app.py`)
- Auth and message API → Message records: saves and retrieves (evidence: `logpfa2/server.js`)
- Student → Model trainer: trains intents model (evidence: `README.md`)
- Intent definitions → Model trainer: provides patterns (evidence: `ENSTA_BOT1/train.py`)
- Model trainer → NLP preprocessing: preprocesses text (evidence: `ENSTA_BOT1/train.py`)
- Model trainer → Neural network: trains network (evidence: `ENSTA_BOT1/train.py`)
- Model trainer → Trained weights: saves weights (evidence: `ENSTA_BOT1/train.py`)
