# pbaniket/nagavisha architecture

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

- Interactive diagram: https://gitdiagram.com/pbaniket/nagavisha
- Repository: https://github.com/pbaniket/nagavisha

## Overview

1. **Repository purpose**
   - This is a compact machine-learning web app for classifying snake photos into **Venomous** or **Non Venomous**.
   - The repo combines a **trained TensorFlow/Keras model** with a **Flask** server and simple HTML/CSS templates.

2. **User-facing layer**
   - The browser-facing UI lives in `templates/` and `static/`.
   - `templates/home.html` is likely the landing page, while `templates/classify.html` is the upload/prediction page.
   - `static/style.css` provides the presentation layer; there is no frontend framework or client-side app bundle.

3. **Web application boundary**
   - `app.py` is the main runtime entry point.
   - It likely defines Flask routes for:
     - rendering the home page,
     - showing the classifier form,
     - handling image upload and returning a prediction result.
   - This is the boundary between HTTP requests and model inference.

4. **Inference and preprocessing layer**
   - `classifier.py` is the natural place for image loading, resizing, normalization, label mapping, and model prediction logic.
   - This file likely isolates ML-specific logic away from Flask route handlers, so the app layer stays thin and the model workflow stays reusable.

5. **Model artifact**
   - `snake_classifier_model.h5` is the persisted trained model used at prediction time.
   - The README indicates it is based on **MobileNetV2** with a small classification head on top, suggesting transfer learning and a lightweight inference path.
   - At runtime, the app probably loads this file once and reuses it for each upload.

6. **Training data layout**
   - `dataset/train/` and `dataset/test/` contain the class directories:
     - `Venomous`
     - `Non Venomous`
   - This is a standard image-classification folder structure, useful for both training and validation/testing.
   - The dataset is part of the repo, so the project is self-contained for retraining or experimentation.

7. **Model training workflow implied by the repo**
   - Even though no standalone training script is visible in the tree, the presence of the dataset plus `.h5` artifact implies an offline training process happened separately.
   - The README says training used `ImageDataGenerator` and a fine-tuned MobileNetV2 backbone, which means the training pipeline likely performed data augmentation and then saved the final model to the `.h5` file.

8. **Request-to-result data flow**
   - A user uploads a snake image in the browser.
   - Flask receives the request in `app.py`.
   - The image is passed to the classifier logic in `classifier.py`.
   - That logic preprocesses the image and calls the loaded Keras model.
   - The predicted class and confidence are returned to the template for display.

9. **System boundaries and dependencies**
   - The application is self-hosted and does not appear to depend on external APIs, databases, queues, or cloud services.
   - Runtime dependencies are local Python libraries listed in `requirements.txt`, primarily Flask, TensorFlow/Keras, and image-processing support.
   - This makes the architecture simple: UI + web server + local model inference.

10. **What an architecture diagram should show**
   - A browser/client on the left.
   - A Flask application in the middle with two responsibilities: page rendering and prediction handling.
   - A separate inference/model component backed by `classifier.py`.
   - The persisted model file `snake_classifier_model.h5` as the model source.
   - The training dataset as an offline artifact feeding the model-building process, not the live request path.

11. **Operational characteristics**
   - The app is lightweight and likely suitable for local or small-server deployment.
   - Because the model is a single `.h5` file and the UI is server-rendered, the deployment footprint is small and simple.
   - There is no evidence of asynchronous processing or batch jobs; prediction appears synchronous per upload.

12. **Overall architecture summary**
   - This repository is a classic **server-rendered ML inference app**: Flask serves pages, a local Keras model performs classification, and a stored dataset supports training/retraining.
   - The main architectural separation is between **presentation**, **request handling**, **ML preprocessing/inference**, and **offline training assets**.

Main entry points: [`app.py`](https://github.com/pbaniket/nagavisha/blob/main/app.py) (Flask app), [`classifier.py`](https://github.com/pbaniket/nagavisha/blob/main/classifier.py) (Classifier), [`snake_classifier_model.h5`](https://github.com/pbaniket/nagavisha/blob/main/snake_classifier_model.h5) (Keras model), [`dataset/train`](https://github.com/pbaniket/nagavisha/tree/main/dataset/train) (Train set)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["Presentation"]
  node_browser(("Browser<br/>client"))
  node_home_page["Home page<br/>template<br/>[home.html]"]
  node_classify_page["Classify page<br/>template<br/>[classify.html]"]
  node_style["Styles<br/>css<br/>[style.css]"]
end

subgraph group_web["Flask App"]
  node_app["Flask app<br/>server<br/>[app.py]"]
  node_deps["Requirements<br/>manifest<br/>[requirements.txt]"]
end

subgraph group_ml["Inference"]
  node_classifier["Classifier<br/>ml logic<br/>[classifier.py]"]
  node_model[("Keras model<br/>artifact")]
end

subgraph group_data["Training Assets"]
  node_train_data[("Train set<br/>image data")]
  node_test_data[("Test set<br/>image data")]
  node_venomous["Venomous<br/>class"]
  node_non_venomous["Non Venomous<br/>class"]
end

node_browser -->|"HTTP requests"| node_app
node_app -->|"renders"| node_home_page
node_app -->|"renders"| node_classify_page
node_app -->|"predicts via"| node_classifier
node_classifier -->|"loads"| node_model
node_classifier -->|"prediction result"| node_app
node_home_page -->|"uses"| node_style
node_classify_page -->|"uses"| node_style
node_app -.->|"depends on"| node_deps
node_model -.->|"trained from"| node_train_data
node_model -.->|"validated with"| node_test_data
node_train_data -.->|"contains"| node_venomous
node_train_data -.->|"contains"| node_non_venomous
node_test_data -.->|"contains"| node_venomous
node_test_data -.->|"contains"| node_non_venomous

click node_home_page "https://github.com/pbaniket/nagavisha/blob/main/templates/home.html"
click node_classify_page "https://github.com/pbaniket/nagavisha/blob/main/templates/classify.html"
click node_style "https://github.com/pbaniket/nagavisha/blob/main/static/style.css"
click node_app "https://github.com/pbaniket/nagavisha/blob/main/app.py"
click node_classifier "https://github.com/pbaniket/nagavisha/blob/main/classifier.py"
click node_model "https://github.com/pbaniket/nagavisha/blob/main/snake_classifier_model.h5"
click node_deps "https://github.com/pbaniket/nagavisha/blob/main/requirements.txt"
click node_train_data "https://github.com/pbaniket/nagavisha/tree/main/dataset/train"
click node_test_data "https://github.com/pbaniket/nagavisha/tree/main/dataset/test"
click node_venomous "https://github.com/pbaniket/nagavisha/tree/main/dataset/train/Venomous"
click node_non_venomous "https://github.com/pbaniket/nagavisha/tree/main/dataset/train/Non Venomous"

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_browser,node_home_page,node_classify_page,node_style toneBlue
class node_app,node_deps toneAmber
class node_classifier,node_model toneMint
class node_train_data,node_test_data,node_venomous,node_non_venomous toneRose
```

## Components

### Presentation

Server-rendered pages and static styling for the browser UI.

- **Browser**: client · User uploads snake images and views results.
- [Home page](https://github.com/pbaniket/nagavisha/blob/main/templates/home.html): template · Landing page rendered by Flask. · `templates/home.html`
- [Classify page](https://github.com/pbaniket/nagavisha/blob/main/templates/classify.html): template · Upload and prediction result page. · `templates/classify.html`
- [Styles](https://github.com/pbaniket/nagavisha/blob/main/static/style.css): css · Global presentation styles for the templates. · `static/style.css`

### Flask App

HTTP entrypoint and request handling for classification.

- [Flask app](https://github.com/pbaniket/nagavisha/blob/main/app.py): server · Main HTTP runtime and route handlers. · `app.py`
- [Requirements](https://github.com/pbaniket/nagavisha/blob/main/requirements.txt): manifest · Python package dependencies for the app and model runtime. · `requirements.txt`

### Inference

Image preprocessing, prediction, and the saved model artifact.

- [Classifier](https://github.com/pbaniket/nagavisha/blob/main/classifier.py): ml logic · Preprocesses images and runs model inference. · `classifier.py`
- [Keras model](https://github.com/pbaniket/nagavisha/blob/main/snake_classifier_model.h5): artifact · Saved TensorFlow/Keras model used for predictions. · `snake_classifier_model.h5`

### Training Assets

Offline dataset used to build or retrain the classifier.

- [Train set](https://github.com/pbaniket/nagavisha/tree/main/dataset/train): image data · Class-organized training images. · `dataset/train`
- [Test set](https://github.com/pbaniket/nagavisha/tree/main/dataset/test): image data · Class-organized evaluation images. · `dataset/test`
- [Venomous](https://github.com/pbaniket/nagavisha/tree/main/dataset/train/Venomous): class · Positive class in the dataset. · `dataset/train/Venomous`
- [Non Venomous](https://github.com/pbaniket/nagavisha/tree/HEAD/dataset/train/Non%20Venomous): class · Negative class in the dataset. · `dataset/train/Non Venomous`

## Connections

- Browser → Flask app: HTTP requests · Users submit page loads and image uploads to Flask.
- Flask app → Home page: renders · Flask serves the landing page template.
- Flask app → Classify page: renders · Flask serves the upload and result page.
- Flask app → Classifier: predicts via · Route handlers delegate image classification to the ML layer.
- Classifier → Keras model: loads · Inference code uses the saved .h5 model artifact.
- Classifier → Flask app: prediction result · Predicted class and confidence return to the web layer.
- Home page → Styles: uses · The page is styled by the shared CSS file.
- Classify page → Styles: uses · The classifier page is styled by the shared CSS file.
- Flask app → Requirements: depends on · The Flask runtime relies on the declared Python packages.
- Keras model → Train set: trained from · The stored classifier was produced from the training images.
- Keras model → Test set: validated with · Evaluation data supports model checking and tuning.
- Train set → Venomous: contains · Training images include the Venomous class.
- Train set → Non Venomous: contains · Training images include the Non Venomous class.
- Test set → Venomous: contains · Test images include the Venomous class.
- Test set → Non Venomous: contains · Test images include the Non Venomous class.
