# rasbt/ai-detector-from-scratch architecture

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

- Interactive diagram: https://gitdiagram.com/rasbt/ai-detector-from-scratch
- Repository: https://github.com/rasbt/ai-detector-from-scratch

## Overview

This repository builds and evaluates an AI-text detector, then exposes trained classifiers for local scoring. The documented workflow runs from licensed human-text collection and AI/AI-assisted generation through dataset construction, model training, evaluation, and inference. The inference library selects and loads model artifacts, computes probabilities, and formats scores; CLI, browser, and Substack workflows use that capability. Additional branches cover resource/latency benchmarking and reinforcement-learning verifier experiments. Several training and analysis stages are documented but absent from the supplied tree, so those nodes use null paths; relationships are limited to README statements or shown calls.

Main entry points: [`src/ai_detector/classifiers.py`](https://github.com/rasbt/ai-detector-from-scratch/blob/main/src/ai_detector/classifiers.py) (Classifier loaders), [`scripts/01_human-data/01_collect_licensed_human_text.py`](https://github.com/rasbt/ai-detector-from-scratch/blob/main/scripts/01_human-data/01_collect_licensed_human_text.py) (Human collection), [`scripts/02_ai-data/_generate_ai_texts.py`](https://github.com/rasbt/ai-detector-from-scratch/blob/main/scripts/02_ai-data/_generate_ai_texts.py) (AI generation), [`scripts/03_ai-assisted-data/_generate_assisted_texts.py`](https://github.com/rasbt/ai-detector-from-scratch/blob/main/scripts/03_ai-assisted-data/_generate_assisted_texts.py) (Assisted edits)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Data construction"]
  node_human_collection["Human collection"]
  node_ai_generation["AI generation"]
  node_assisted_generation["Assisted edits"]
  node_pangram_checks["Pangram checks<br/>[run_check.py]"]
  node_dataset_build["Dataset assembly"]
end

subgraph group_models["Model development"]
  node_training["Classifier training"]
  node_resource_benchmarks["Resource benchmarks"]
end

subgraph group_runtime["Inference runtime"]
  node_model_registry["Model registry<br/>[registry.py]"]
  node_classifier_loaders["Classifier loaders<br/>[classifiers.py]"]
  node_score_format["Score validation<br/>[scoring.py]"]
  node_artifact_download["Artifact download<br/>[download-models.py]"]
end

subgraph group_products["Scoring applications"]
  node_cli["Scoring CLI<br/>[classify.py]"]
  node_api_server["Browser API<br/>[app.py]"]
  node_browser_ui["Browser interface<br/>[App.jsx]"]
end

subgraph group_research["Research workflows"]
  node_substack_eval["Substack evaluation"]
  node_rl_experiments["Verifier RL"]
end

node_human_writer(("Licensed text sources"))
node_model_providers(("Model providers"))

node_human_writer -->|"collects text"| node_human_collection
node_human_collection -.->|"seeds generation"| node_ai_generation
node_model_providers -.->|"generate samples"| node_ai_generation
node_model_providers -.->|"edit samples"| node_assisted_generation
node_human_collection -.->|"source texts"| node_assisted_generation
node_ai_generation -.->|"check samples"| node_pangram_checks
node_assisted_generation -.->|"check edits"| node_pangram_checks
node_human_collection -.->|"assemble data"| node_dataset_build
node_ai_generation -.->|"assemble data"| node_dataset_build
node_assisted_generation -.->|"assemble data"| node_dataset_build
node_dataset_build -.->|"provides dataset"| node_training
node_training -.->|"exports classifiers"| node_model_registry
node_model_registry -->|"supplies model specs"| node_classifier_loaders
node_classifier_loaders -->|"validates text"| node_score_format
node_artifact_download -.->|"uses model registry"| node_model_registry
node_cli -.->|"loads classifier"| node_classifier_loaders
node_cli -.->|"formats score"| node_score_format
node_browser_ui -->|"requests scores"| node_api_server
node_api_server -->|"scores text"| node_classifier_loaders
node_api_server -.->|"formats score"| node_score_format
node_substack_eval -->|"loads classifiers"| node_classifier_loaders
node_substack_eval -->|"formats scores"| node_score_format
node_training -.->|"benchmark models"| node_resource_benchmarks
node_classifier_loaders -.->|"verifies generations"| node_rl_experiments

click node_human_collection "https://github.com/rasbt/ai-detector-from-scratch/blob/main/scripts/01_human-data/01_collect_licensed_human_text.py"
click node_ai_generation "https://github.com/rasbt/ai-detector-from-scratch/blob/main/scripts/02_ai-data/_generate_ai_texts.py"
click node_assisted_generation "https://github.com/rasbt/ai-detector-from-scratch/blob/main/scripts/03_ai-assisted-data/_generate_assisted_texts.py"
click node_pangram_checks "https://github.com/rasbt/ai-detector-from-scratch/blob/main/scripts/02_ai-data/pangram-check/run_check.py"
click node_dataset_build "https://github.com/rasbt/ai-detector-from-scratch/blob/main/scripts/04_hf-dataset/04_build_hf_dataset.py"
click node_resource_benchmarks "https://github.com/rasbt/ai-detector-from-scratch/blob/main/scripts/14_resource-latency/_benchmark_model.py"
click node_model_registry "https://github.com/rasbt/ai-detector-from-scratch/blob/main/src/ai_detector/registry.py"
click node_classifier_loaders "https://github.com/rasbt/ai-detector-from-scratch/blob/main/src/ai_detector/classifiers.py"
click node_score_format "https://github.com/rasbt/ai-detector-from-scratch/blob/main/src/ai_detector/scoring.py"
click node_artifact_download "https://github.com/rasbt/ai-detector-from-scratch/blob/main/scripts/15_classifier-api/download-models.py"
click node_cli "https://github.com/rasbt/ai-detector-from-scratch/blob/main/scripts/15_classifier-api/classify.py"
click node_api_server "https://github.com/rasbt/ai-detector-from-scratch/blob/main/scripts/17_browser-ui/app.py"
click node_browser_ui "https://github.com/rasbt/ai-detector-from-scratch/blob/main/scripts/17_browser-ui/frontend/src/App.jsx"
click node_substack_eval "https://github.com/rasbt/ai-detector-from-scratch/blob/main/scripts/16_case-study-substack/predict_substack_notes.py"
click node_rl_experiments "https://github.com/rasbt/ai-detector-from-scratch/blob/main/scripts/18_reinforcement-learning/05_train_grpo_human_writing.py"

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_human_collection,node_ai_generation,node_assisted_generation,node_pangram_checks,node_dataset_build toneBlue
class node_training,node_resource_benchmarks toneAmber
class node_model_registry,node_classifier_loaders,node_score_format,node_artifact_download toneMint
class node_cli,node_api_server,node_browser_ui toneRose
class node_substack_eval,node_rl_experiments,node_human_writer,node_model_providers toneIndigo
```

## Components

### Data construction

- [Human collection](https://github.com/rasbt/ai-detector-from-scratch/blob/main/scripts/01_human-data/01_collect_licensed_human_text.py): `scripts/01_human-data/01_collect_licensed_human_text.py`
- [AI generation](https://github.com/rasbt/ai-detector-from-scratch/blob/main/scripts/02_ai-data/_generate_ai_texts.py): `scripts/02_ai-data/_generate_ai_texts.py`
- [Assisted edits](https://github.com/rasbt/ai-detector-from-scratch/blob/main/scripts/03_ai-assisted-data/_generate_assisted_texts.py): `scripts/03_ai-assisted-data/_generate_assisted_texts.py`
- [Pangram checks](https://github.com/rasbt/ai-detector-from-scratch/blob/main/scripts/02_ai-data/pangram-check/run_check.py): `scripts/02_ai-data/pangram-check/run_check.py`
- [Dataset assembly](https://github.com/rasbt/ai-detector-from-scratch/blob/main/scripts/04_hf-dataset/04_build_hf_dataset.py): `scripts/04_hf-dataset/04_build_hf_dataset.py`

### Model development

- **Classifier training**
- [Resource benchmarks](https://github.com/rasbt/ai-detector-from-scratch/blob/main/scripts/14_resource-latency/_benchmark_model.py): `scripts/14_resource-latency/_benchmark_model.py`

### Inference runtime

- [Model registry](https://github.com/rasbt/ai-detector-from-scratch/blob/main/src/ai_detector/registry.py): `src/ai_detector/registry.py`
- [Classifier loaders](https://github.com/rasbt/ai-detector-from-scratch/blob/main/src/ai_detector/classifiers.py): `src/ai_detector/classifiers.py`
- [Score validation](https://github.com/rasbt/ai-detector-from-scratch/blob/main/src/ai_detector/scoring.py): `src/ai_detector/scoring.py`
- [Artifact download](https://github.com/rasbt/ai-detector-from-scratch/blob/main/scripts/15_classifier-api/download-models.py): `scripts/15_classifier-api/download-models.py`

### Scoring applications

- [Scoring CLI](https://github.com/rasbt/ai-detector-from-scratch/blob/main/scripts/15_classifier-api/classify.py): `scripts/15_classifier-api/classify.py`
- [Browser API](https://github.com/rasbt/ai-detector-from-scratch/blob/main/scripts/17_browser-ui/app.py): `scripts/17_browser-ui/app.py`
- [Browser interface](https://github.com/rasbt/ai-detector-from-scratch/blob/main/scripts/17_browser-ui/frontend/src/App.jsx): `scripts/17_browser-ui/frontend/src/App.jsx`

### Research workflows

- [Substack evaluation](https://github.com/rasbt/ai-detector-from-scratch/blob/main/scripts/16_case-study-substack/predict_substack_notes.py): `scripts/16_case-study-substack/predict_substack_notes.py`
- [Verifier RL](https://github.com/rasbt/ai-detector-from-scratch/blob/main/scripts/18_reinforcement-learning/05_train_grpo_human_writing.py): `scripts/18_reinforcement-learning/05_train_grpo_human_writing.py`

### Other components

- **Licensed text sources**
- **Model providers**

## Connections

- Licensed text sources → Human collection: collects text (evidence: `scripts/01_human-data/01_collect_licensed_human_text.py`)
- Human collection → AI generation: seeds generation (evidence: `README.md`)
- Model providers → AI generation: generate samples (evidence: `README.md`)
- Model providers → Assisted edits: edit samples (evidence: `README.md`)
- Human collection → Assisted edits: source texts (evidence: `README.md`)
- AI generation → Pangram checks: check samples (evidence: `README.md`)
- Assisted edits → Pangram checks: check edits (evidence: `README.md`)
- Human collection → Dataset assembly: assemble data (evidence: `README.md`)
- AI generation → Dataset assembly: assemble data (evidence: `README.md`)
- Assisted edits → Dataset assembly: assemble data (evidence: `README.md`)
- Dataset assembly → Classifier training: provides dataset (evidence: `README.md`)
- Classifier training → Model registry: exports classifiers (evidence: `README.md`)
- Model registry → Classifier loaders: supplies model specs (evidence: `src/ai_detector/classifiers.py`)
- Classifier loaders → Score validation: validates text (evidence: `src/ai_detector/classifiers.py`)
- Artifact download → Model registry: uses model registry
- Scoring CLI → Classifier loaders: loads classifier (evidence: `README.md`)
- Scoring CLI → Score validation: formats score (evidence: `README.md`)
- Browser interface → Browser API: requests scores (evidence: `scripts/17_browser-ui/frontend/src/App.jsx`)
- Browser API → Classifier loaders: scores text (evidence: `scripts/17_browser-ui/app.py`)
- Browser API → Score validation: formats score (evidence: `README.md`)
- Substack evaluation → Classifier loaders: loads classifiers (evidence: `scripts/16_case-study-substack/predict_substack_notes.py`)
- Substack evaluation → Score validation: formats scores (evidence: `scripts/16_case-study-substack/predict_substack_notes.py`)
- Classifier training → Resource benchmarks: benchmark models (evidence: `README.md`)
- Classifier loaders → Verifier RL: verifies generations (evidence: `README.md`)
