# rupak-raut/nepse-lstm-gru architecture

> Architecture diagram of the GitHub repository rupak-raut/nepse-lstm-gru, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rupak-raut/nepse-lstm-gru
- Repository: https://github.com/rupak-raut/nepse-lstm-gru

## Overview

1. **Repository purpose**
   - This is a stock-prediction application for NEPSE securities, centered on pre-trained sequence models rather than live model training.

2. **Runtime shape**
   - The repo appears to be a small, self-contained Python application with one backend entrypoint: `nepse/app.py`.
   - There is no visible service decomposition; the likely architecture is a single-process server plus a static HTML frontend.

3. **User interface layer**
   - `nepse/frontend.html` is the client-facing page.
   - It likely provides the stock selection and displays prediction output, while delegating prediction requests to the Python backend over HTTP.

4. **Backend / API layer**
   - `app.py` is the orchestration point.
   - Its responsibilities are likely:
     - load the requested stock’s model and scaler,
     - accept input from the UI,
     - run inference,
     - return the predicted result to the frontend.

5. **Model inference subsystem**
   - `nepse/trained_models/` contains one model bundle per stock symbol.
   - Each stock has two artifacts:
     - `*_model_state_dict.pth` for the trained neural network weights,
     - `*_scaler.pkl` for feature normalization / inverse transformation.
   - This strongly suggests the prediction pipeline is stock-specific and depends on matching the correct scaler with the correct model.

6. **Model portfolio**
   - The included symbols show the app supports multiple NEPSE instruments, including banks, insurers, and other listed companies such as `ADBL`, `NABIL`, `NLIC`, `SCB`, `SBL`, `NTC`, and others.
   - Architecture-wise, this is not a single generic model; it is a collection of separate per-ticker models.

7. **Data dependency**
   - `nepse/NEPSE_STOCKS_DATASETS.csv` is the primary dataset artifact in the repo.
   - It is likely used for historical training, preprocessing, or validation, and not necessarily loaded at runtime except for analytics or feature preparation.

8. **Offline training vs. online prediction boundary**
   - The presence of the CSV plus many persisted model/scaler files indicates a clear split:
     - offline: data preparation and model training,
     - online: loading saved artifacts and generating predictions.
   - The runtime app depends on these precomputed artifacts and does not need to retrain models on each request.

9. **ML framework boundary**
   - The `.pth` files indicate PyTorch-based model storage.
   - The `.pkl` scalers suggest scikit-learn or compatible preprocessing objects.
   - In the architecture diagram, this is the core ML stack boundary between raw market data and predicted output.

10. **Packaging / distribution**
   - `nepse/trained_models.zip` is a bundled copy of the model artifacts, likely for easier distribution or deployment.
   - The repo already contains the extracted `trained_models/` directory, so deployment can use either the archive or the expanded folder.

11. **Dependencies**
   - `requirements.txt` defines the Python runtime dependencies needed by the app and model inference pipeline.
   - Those dependencies likely include the web framework and ML libraries required to deserialize scalers and run the neural network models.

12. **What is missing from the repo**
   - There is no separate database, message queue, or external API integration visible in the tree.
   - The architecture therefore looks local-file driven: static frontend + Python backend + model artifacts on disk.

13. **Diagram-ready summary**
   - A useful architecture diagram would show:
     - browser/user -> `frontend.html`,
     - frontend -> `app.py`,
     - `app.py` -> stock-specific model/scaler files in `trained_models/`,
     - optional offline arrow from `NEPSE_STOCKS_DATASETS.csv` to the model-training step that produced those artifacts.

14. **Primary architectural characteristic**
   - The key design choice is per-stock persisted ML inference inside a lightweight Python web app, with all prediction intelligence stored as local artifacts rather than in an external service.

Main entry points: [`nepse/app.py`](https://github.com/rupak-raut/nepse-lstm-gru/blob/main/nepse/app.py) (App), [`nepse/frontend.html`](https://github.com/rupak-raut/nepse-lstm-gru/blob/main/nepse/frontend.html) (Frontend), [`nepse/trained_models`](https://github.com/rupak-raut/nepse-lstm-gru/tree/main/nepse/trained_models) (Trained Models), [`nepse/trained_models.zip`](https://github.com/rupak-raut/nepse-lstm-gru/blob/main/nepse/trained_models.zip) (Model Bundle)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["Interface"]
  node_browser(("User<br/>client"))
  node_frontend["Frontend<br/>html-ui<br/>[frontend.html]"]
end

subgraph group_backend["Backend"]
  node_app["App<br/>python-server<br/>[app.py]"]
  node_api["Request API<br/>http-endpoint"]
  node_prep["Input Prep<br/>preprocess"]
  node_loader["Model Loader<br/>artifact-loader"]
  node_infer["Inference<br/>prediction-core"]
end

subgraph group_artifacts["Artifacts"]
  node_models[("Trained Models<br/>model-store")]
  node_zip["Model Bundle<br/>archive<br/>[trained_models.zip]"]
  node_stockset[("Ticker Bundles<br/>per-stock-artifacts")]
end

subgraph group_data["Data"]
  node_dataset["Market Data<br/>csv-dataset"]
  node_reqs["Dependencies<br/>python-reqs<br/>[requirements.txt]"]
end

node_browser -->|"uses"| node_frontend
node_frontend -->|"requests"| node_api
node_api -->|"handled by"| node_app
node_app -->|"prepares"| node_prep
node_prep -->|"selects"| node_loader
node_loader -->|"loads"| node_models
node_models -->|"contains"| node_stockset
node_loader -->|"supplies"| node_infer
node_infer -->|"returns"| node_app
node_app -->|"responds"| node_frontend
node_dataset -.->|"feeds offline"| node_stockset
node_zip -.->|"packages"| node_models
node_reqs -.->|"supports"| node_app

click node_frontend "https://github.com/rupak-raut/nepse-lstm-gru/blob/main/nepse/frontend.html"
click node_app "https://github.com/rupak-raut/nepse-lstm-gru/blob/main/nepse/app.py"
click node_models "https://github.com/rupak-raut/nepse-lstm-gru/tree/main/nepse/trained_models"
click node_zip "https://github.com/rupak-raut/nepse-lstm-gru/blob/main/nepse/trained_models.zip"
click node_dataset "https://github.com/rupak-raut/nepse-lstm-gru/blob/main/nepse/NEPSE_STOCKS_DATASETS.csv"
click node_reqs "https://github.com/rupak-raut/nepse-lstm-gru/blob/main/nepse/requirements.txt"

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_frontend toneBlue
class node_app,node_api,node_prep,node_loader,node_infer toneAmber
class node_models,node_zip,node_stockset toneMint
class node_dataset,node_reqs toneRose
```

## Components

### Interface

Client-facing presentation layer

- **User**: client · Person using the prediction interface
- [Frontend](https://github.com/rupak-raut/nepse-lstm-gru/blob/main/nepse/frontend.html): html-ui · Static page for symbol selection and prediction display · `nepse/frontend.html`

### Backend

Single-process Python server and request handling

- [App](https://github.com/rupak-raut/nepse-lstm-gru/blob/main/nepse/app.py): python-server · Backend entrypoint that orchestrates prediction requests · `nepse/app.py`
- **Request API**: http-endpoint · HTTP boundary between the page and the Python backend
- **Input Prep**: preprocess · Turns UI input into model-ready features
- **Model Loader**: artifact-loader · Selects the correct stock model and scaler bundle
- **Inference**: prediction-core · Runs the stored sequence model and returns the forecast

### Artifacts

Persisted ML bundles used for inference

- [Trained Models](https://github.com/rupak-raut/nepse-lstm-gru/tree/main/nepse/trained_models): model-store · Per-ticker PyTorch weights plus matching scalers · `nepse/trained_models`
- [Model Bundle](https://github.com/rupak-raut/nepse-lstm-gru/blob/main/nepse/trained_models.zip): archive · Packaged copy of the trained model artifacts · `nepse/trained_models.zip`
- **Ticker Bundles**: per-stock-artifacts · Individual model/scaler pairs for symbols such as ADBL, NABIL, NLIC, SCB, SBL, NTC, and others

### Data

Historical market data and packaging

- [Market Data](https://github.com/rupak-raut/nepse-lstm-gru/blob/main/nepse/NEPSE_STOCKS_DATASETS.csv): csv-dataset · Historical NEPSE dataset used for training and preparation · `nepse/NEPSE_STOCKS_DATASETS.csv`
- [Dependencies](https://github.com/rupak-raut/nepse-lstm-gru/blob/main/nepse/requirements.txt): python-reqs · Runtime and ML library requirements · `nepse/requirements.txt`

## Connections

- User → Frontend: uses · User interacts with the stock prediction page
- Frontend → Request API: requests · Page sends prediction requests to the backend
- Request API → App: handled by · HTTP requests are served by the Python application
- App → Input Prep: prepares · Backend shapes submitted inputs for inference
- Input Prep → Model Loader: selects · Prepared inputs determine which stock bundle to load
- Model Loader → Trained Models: loads · Model and scaler artifacts are read from disk
- Trained Models → Ticker Bundles: contains · Repository stores one bundle per supported ticker
- Model Loader → Inference: supplies · Loaded artifacts are passed into the prediction path
- Inference → App: returns · Predicted output is sent back to the application layer
- App → Frontend: responds · Backend returns prediction results for display
- Market Data → Ticker Bundles: feeds offline · Historical data is the source for training the persisted bundles
- Model Bundle → Trained Models: packages · Archive mirrors the extracted trained model directory
- Dependencies → App: supports · Dependencies enable the server and ML runtime
