# dantubhavyasree/token-tracker architecture

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

- Interactive diagram: https://gitdiagram.com/dantubhavyasree/token-tracker
- Repository: https://github.com/dantubhavyasree/token-tracker

## Overview

LLM Prompt Analyzer predicts expected output-token usage and prompt quality before a prompt is sent to an LLM. Its main user flow starts in the Streamlit dashboard or browser extension, passes through prediction and feature extraction, and returns scores and suggestions. A separate preparation and training workflow builds the models used at inference. The README also describes interaction collection and retraining as intended workflow, but those capabilities are not implemented in the sampled runtime. The root-level CSVs do not match the data paths used by the merger, so their connection is left out.

Main entry points: [`inference/predictor.py`](https://github.com/dantubhavyasree/token-tracker/blob/main/inference/predictor.py) (Prediction coordinator), [`extension/popup.js`](https://github.com/dantubhavyasree/token-tracker/blob/main/extension/popup.js) (Browser extension popup), [`inference/api.py`](https://github.com/dantubhavyasree/token-tracker/blob/main/inference/api.py) (Prediction API), [`data_collection/merge_datasets.py`](https://github.com/dantubhavyasree/token-tracker/blob/main/data_collection/merge_datasets.py) (Dataset merger)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interfaces["User interfaces"]
  node_dashboard["Streamlit dashboard<br/>[app.py]"]
  node_extension["Browser extension popup<br/>[popup.js]"]
end

subgraph group_inference["Prediction"]
  node_api["Prediction API<br/>[api.py]"]
  node_predictor["Prediction coordinator<br/>[predictor.py]"]
  node_extractor["Prompt feature extractor<br/>[extractor.py]"]
  node_results["Scores and suggestions<br/>[predictor.py]"]
end

subgraph group_preparation["Data preparation"]
  node_raw_data["Prompt-response datasets"]
  node_merger["Dataset merger<br/>[merge_datasets.py]"]
  node_feature_data["Processed feature dataset<br/>[merge_datasets.py]"]
end

subgraph group_training["Model training"]
  node_token_training["Token model training"]
  node_quality_training["Quality model training"]
  node_model_files[("Trained model files")]
end

node_prompt_author(("Prompt author"))
node_llm_page["LLM page"]

node_prompt_author -->|"enters prompt"| node_dashboard
node_dashboard -->|"requests prediction"| node_predictor
node_prompt_author -->|"enters prompt"| node_extension
node_llm_page -->|"provides prompt text"| node_extension
node_extension -->|"posts prompt"| node_api
node_api -->|"calls prediction"| node_predictor
node_predictor -->|"extracts features"| node_extractor
node_predictor -->|"loads models"| node_model_files
node_predictor -->|"returns predictions"| node_results
node_results -->|"renders results"| node_dashboard
node_api -->|"returns response"| node_extension
node_raw_data -->|"loads CSVs"| node_merger
node_merger -->|"extracts dataset features"| node_extractor
node_merger -->|"writes features"| node_feature_data
node_feature_data -->|"provides training data"| node_token_training
node_feature_data -->|"provides training data"| node_quality_training
node_token_training -->|"saves token model"| node_model_files
node_quality_training -->|"saves quality model"| node_model_files

click node_dashboard "https://github.com/dantubhavyasree/token-tracker/blob/main/dashboard/app.py"
click node_extension "https://github.com/dantubhavyasree/token-tracker/blob/main/extension/popup.js"
click node_api "https://github.com/dantubhavyasree/token-tracker/blob/main/inference/api.py"
click node_predictor "https://github.com/dantubhavyasree/token-tracker/blob/main/inference/predictor.py"
click node_extractor "https://github.com/dantubhavyasree/token-tracker/blob/main/feature_engineering/extractor.py"
click node_results "https://github.com/dantubhavyasree/token-tracker/blob/main/inference/predictor.py"
click node_merger "https://github.com/dantubhavyasree/token-tracker/blob/main/data_collection/merge_datasets.py"
click node_feature_data "https://github.com/dantubhavyasree/token-tracker/blob/main/data_collection/merge_datasets.py"
click node_token_training "https://github.com/dantubhavyasree/token-tracker/blob/main/training/train_token_model.py"
click node_quality_training "https://github.com/dantubhavyasree/token-tracker/blob/main/training/train_quality_model.py"
click node_model_files "https://github.com/dantubhavyasree/token-tracker/tree/main/models"

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_dashboard,node_extension toneBlue
class node_api,node_predictor,node_extractor,node_results toneAmber
class node_raw_data,node_merger,node_feature_data toneMint
class node_token_training,node_quality_training,node_model_files toneRose
class node_prompt_author,node_llm_page toneIndigo
```

## Components

### User interfaces

- [Streamlit dashboard](https://github.com/dantubhavyasree/token-tracker/blob/main/dashboard/app.py): `dashboard/app.py`
- [Browser extension popup](https://github.com/dantubhavyasree/token-tracker/blob/main/extension/popup.js): `extension/popup.js`

### Prediction

- [Prediction API](https://github.com/dantubhavyasree/token-tracker/blob/main/inference/api.py): `inference/api.py`
- [Prediction coordinator](https://github.com/dantubhavyasree/token-tracker/blob/main/inference/predictor.py): `inference/predictor.py`
- [Prompt feature extractor](https://github.com/dantubhavyasree/token-tracker/blob/main/feature_engineering/extractor.py): `feature_engineering/extractor.py`
- [Scores and suggestions](https://github.com/dantubhavyasree/token-tracker/blob/main/inference/predictor.py): `inference/predictor.py`

### Data preparation

- **Prompt-response datasets**
- [Dataset merger](https://github.com/dantubhavyasree/token-tracker/blob/main/data_collection/merge_datasets.py): `data_collection/merge_datasets.py`
- [Processed feature dataset](https://github.com/dantubhavyasree/token-tracker/blob/main/data_collection/merge_datasets.py): `data_collection/merge_datasets.py`

### Model training

- [Token model training](https://github.com/dantubhavyasree/token-tracker/blob/main/training/train_token_model.py): `training/train_token_model.py`
- [Quality model training](https://github.com/dantubhavyasree/token-tracker/blob/main/training/train_quality_model.py): `training/train_quality_model.py`
- [Trained model files](https://github.com/dantubhavyasree/token-tracker/tree/main/models): `models`

### Other components

- **Prompt author**
- **LLM page**

## Connections

- Prompt author → Streamlit dashboard: enters prompt (evidence: `dashboard/app.py`)
- Streamlit dashboard → Prediction coordinator: requests prediction (evidence: `dashboard/app.py`)
- Prompt author → Browser extension popup: enters prompt (evidence: `extension/popup.js`)
- LLM page → Browser extension popup: provides prompt text (evidence: `extension/popup.js`)
- Browser extension popup → Prediction API: posts prompt (evidence: `extension/popup.js`)
- Prediction API → Prediction coordinator: calls prediction (evidence: `inference/api.py`)
- Prediction coordinator → Prompt feature extractor: extracts features (evidence: `inference/predictor.py`)
- Prediction coordinator → Trained model files: loads models (evidence: `inference/predictor.py`)
- Prediction coordinator → Scores and suggestions: returns predictions (evidence: `inference/predictor.py`)
- Scores and suggestions → Streamlit dashboard: renders results (evidence: `dashboard/app.py`)
- Prediction API → Browser extension popup: returns response (evidence: `extension/popup.js`)
- Prompt-response datasets → Dataset merger: loads CSVs (evidence: `data_collection/merge_datasets.py`)
- Dataset merger → Prompt feature extractor: extracts dataset features (evidence: `data_collection/merge_datasets.py`)
- Dataset merger → Processed feature dataset: writes features (evidence: `data_collection/merge_datasets.py`)
- Processed feature dataset → Token model training: provides training data (evidence: `training/train_token_model.py`)
- Processed feature dataset → Quality model training: provides training data (evidence: `training/train_quality_model.py`)
- Token model training → Trained model files: saves token model (evidence: `training/train_token_model.py`)
- Quality model training → Trained model files: saves quality model (evidence: `training/train_quality_model.py`)
