# devit-tech/btl_tsr_dbds architecture

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

- Interactive diagram: https://gitdiagram.com/devit-tech/btl_tsr_dbds
- Repository: https://github.com/devit-tech/btl_tsr_dbds

## Overview

##### Project type and purpose
- This is a full-stack ML forecasting system (“BTL_TSR_DBDS”) that trains deep-learning (LSTM, Autoformer, DistilBERT) models on historical sales time-series and product metadata, exposes a Flask API for programmatic forecasting, and provides a Streamlit UI for interactive demo on a cloud server.

##### File structure
- Top-level directories:
- data/sales_history/ : raw CSV time-series per ASIN
- best_models/        : serialized PyTorch (.pt) model artifacts
- logs/               : TensorBoard training logs per ASIN
- src/                : source code
‣ model.py     : defines the neural architectures
‣ inference.py : loads models, runs forecasting routine
‣ api.py       : Flask REST API endpoints for prediction
‣ app.py       : Streamlit front-end application
- Config/dependencies: requirements.txt, README.md

##### Extract architectural clues from the README
- Two serving paths: Flask API (backend micro-service) and Streamlit UI (frontend demo)
- Training pipeline is implied but code lives in model.py and inference.py
- Data flows from CSV → training → model store; inference loads model → returns forecast

##### Main components & their interactions
a. Data Layer
- CSV Sales History in data/sales_history
- Product metadata (title, price, rating) either bundled or fetched at runtime
b. Training Pipeline
- Reads CSVs, invokes model architectures (model.py), logs training to logs/, saves best .pt in best_models/
c. Model Storage
- Repository of versioned .pt artifacts in best_models/
d. Inference Module
- inference.py loads chosen .pt, pre-processes input, returns next-day prediction
e. API Service (Flask)
- Exposes REST endpoint (/predict) that invokes inference.py and returns JSON forecast
f. Frontend (Streamlit)
- Renders product list, historical charts (matplotlib), calls either inference.py directly or the Flask API to display forecasts
g. Hosting / Infrastructure
- Cloud server hosting both the Flask service and the Streamlit app
h. Logging/Monitoring
- TensorBoard logs in logs/ for training metrics

##### Important architectural patterns & design principles
- Separation of Concerns: distinct training, storage, inference, API, and UI layers
- Modular ML pipeline: model definitions (model.py) abstracted from inference logic (inference.py)
- Micro-service style: the Flask API can be independently deployed and scaled
- Artifact versioning: best_models folder holds per-ASIN best checkpoints

2. Inside Training Pipeline, list sub-steps: load CSV, preprocess, train model (model.py), log metrics to “logs/”, save to “best_models/”.
a. direct to Inference Module (via inference.py import)
b. HTTP call to Flask API
6. Surround API & UI with a “Cloud Server” boundary.
7. Client symbol (browser) pointing to Streamlit UI and/or API.
8. “TensorBoard” component connected to logs/ for monitoring.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Layer
    subgraph "Data Layer"
        Data["CSV Sales History"]:::data
    end
    click Data "https://github.com/devit-tech/btl_tsr_dbds/tree/main/BTL_TSR_DBDS/data/sales_history/"

    %% Training Pipeline
    subgraph "Training Pipeline"
        ModelDefs["Model Definitions (model.py)"]:::compute
        TrainingProcess["Train & Save Checkpoints (inference.py)"]:::compute
    end
    click ModelDefs "https://github.com/devit-tech/btl_tsr_dbds/blob/main/BTL_TSR_DBDS/src/model.py"
    click TrainingProcess "https://github.com/devit-tech/btl_tsr_dbds/blob/main/BTL_TSR_DBDS/src/inference.py"

    Data -->|"raw CSV"| ModelDefs
    ModelDefs -->|"preprocessed tensors"| TrainingProcess
    TrainingProcess -->|"training metrics"| LogsComp["TensorBoard Logs"]:::logs
    click LogsComp "https://github.com/devit-tech/btl_tsr_dbds/tree/main/BTL_TSR_DBDS/logs/"
    TrainingProcess -->|"serialized .pt"| ModelStore["Model Artifacts"]:::data_store
    click ModelStore "https://github.com/devit-tech/btl_tsr_dbds/tree/main/BTL_TSR_DBDS/best_models/"

    %% TensorBoard Monitoring
    TB["TensorBoard"]:::logs
    LogsComp --> TB

    %% Inference Module
    Inference["Inference Module (inference.py)"]:::compute
    click Inference "https://github.com/devit-tech/btl_tsr_dbds/blob/main/BTL_TSR_DBDS/src/inference.py"
    ModelStore -->|"load .pt"| Inference

    %% Cloud Hosted Services
    subgraph "Cloud Server"
        API["Flask API Service (/predict)"]:::service
        UI["Streamlit UI"]:::service
    end
    click API "https://github.com/devit-tech/btl_tsr_dbds/blob/main/BTL_TSR_DBDS/src/api.py"
    click UI "https://github.com/devit-tech/btl_tsr_dbds/blob/main/BTL_TSR_DBDS/src/app.py"

    Inference -->|"provides predictions"| API
    Inference -->|"provides predictions"| UI

    %% Client Interaction
    Client["User (Browser)"]:::external
    Client --> UI
    Client -->|"/predict" HTTP| API
    UI -->|HTTP /predict| API
    API -->|"JSON forecast"| Client
    UI -->|"renders charts & forecast"| Client
    UI -->|direct import| Inference

    %% Documentation
    Docs["README & requirements"]:::docs
    click Docs "https://github.com/devit-tech/btl_tsr_dbds/blob/main/README.md"
    click Docs "https://github.com/devit-tech/btl_tsr_dbds/blob/main/requirements.txt"

    %% Styles
    classDef data fill:#D6E9F8,stroke:#3A8CCF,color:#0F3C6E;
    classDef data_store fill:#D6E9F8,stroke:#3A8CCF,color:#0F3C6E,stroke-dasharray: 5 5;
    classDef compute fill:#E2F7E1,stroke:#31A234,color:#184F19;
    classDef service fill:#FFE5B4,stroke:#FF8C00,color:#663C00;
    classDef logs fill:#F2F2F2,stroke:#A0A0A0,color:#505050,stroke-dasharray: 2 2;
    classDef external fill:#F9E3FF,stroke:#C75FD5,color:#541160;
    classDef docs fill:#F0E0FF,stroke:#A060C0,color:#502060;
```
