# lynote-ai/ai-text-detector architecture

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

- Interactive diagram: https://gitdiagram.com/lynote-ai/ai-text-detector
- Repository: https://github.com/lynote-ai/ai-text-detector

## Overview

Lynote contains two distinct products: an explainable offline risk analyzer and a production document-and-sentence classifier. The local path reads text through the CLI and returns a scored report; the production path prepares data, trains and calibrates a joint model, evaluates it, and serves detection results. The production model offers ModernBERT and XLM-R variants. Some pipeline stages are represented by their exact enclosing directories because their implementation excerpts were not provided; edges are limited to relationships shown in excerpts or documented in the README.

Main entry points: [`detection-model-pipeline/code/j_train_hier_model.py`](https://github.com/lynote-ai/ai-text-detector/blob/main/detection-model-pipeline/code/j_train_hier_model.py) (Joint training), [`detection-model-pipeline/code/m_serve_hier_api.py`](https://github.com/lynote-ai/ai-text-detector/blob/main/detection-model-pipeline/code/m_serve_hier_api.py) (Detection API), [`detection-model-pipeline/model_entity/hier_model_factory.py`](https://github.com/lynote-ai/ai-text-detector/blob/main/detection-model-pipeline/model_entity/hier_model_factory.py) (Backbone factory), [`src/aidetect/cli.py`](https://github.com/lynote-ai/ai-text-detector/blob/main/src/aidetect/cli.py) (CLI input)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_local["Local Analyzer"]
  node_cli["CLI input<br/>[cli.py]"]
  node_analyzer["Risk analysis<br/>[core.py]"]
  node_report["Risk report<br/>[cli.py]"]
end

subgraph group_pipeline["Model Pipeline"]
  node_data_prep["Data preparation"]
  node_training["Joint training"]
  node_calibration["Calibration"]
  node_evaluation["Model evaluation"]
end

subgraph group_model["Joint Model"]
  node_factory["Backbone factory"]
  node_modernbert["ModernBERT model"]
  node_xlmr["XLM-R model<br/>[hier_xlmr_model.py]"]
end

subgraph group_service["Detection Service"]
  node_splitter["Sentence splitting"]
  node_serving["Detection API"]
end

node_user(("Text submitter"))
node_reviewer(("Human reviewer"))

node_user -->|"provides text"| node_cli
node_cli -->|"analyzes text"| node_analyzer
node_analyzer -->|"returns result"| node_report
node_data_prep -->|"prepares training data"| node_training
node_training -->|"loads model class"| node_factory
node_factory -->|"routes ModernBERT"| node_modernbert
node_factory -->|"routes XLM-R"| node_xlmr
node_training -->|"produces model"| node_calibration
node_calibration -->|"calibrates model"| node_evaluation
node_training -->|"evaluates model"| node_evaluation
node_user -->|"submits document"| node_serving
node_serving -->|"splits sentences"| node_splitter
node_serving -->|"loads model class"| node_factory
node_serving -->|"returns classifications"| node_reviewer

click node_cli "https://github.com/lynote-ai/ai-text-detector/blob/main/src/aidetect/cli.py"
click node_analyzer "https://github.com/lynote-ai/ai-text-detector/blob/main/src/aidetect/core.py"
click node_report "https://github.com/lynote-ai/ai-text-detector/blob/main/src/aidetect/cli.py"
click node_data_prep "https://github.com/lynote-ai/ai-text-detector/tree/main/detection-model-pipeline/code"
click node_training "https://github.com/lynote-ai/ai-text-detector/blob/main/detection-model-pipeline/code/j_train_hier_model.py"
click node_calibration "https://github.com/lynote-ai/ai-text-detector/blob/main/detection-model-pipeline/code/k_calibrate_hier_model.py"
click node_evaluation "https://github.com/lynote-ai/ai-text-detector/blob/main/detection-model-pipeline/code/l_eval_hier_model.py"
click node_factory "https://github.com/lynote-ai/ai-text-detector/blob/main/detection-model-pipeline/model_entity/hier_model_factory.py"
click node_modernbert "https://github.com/lynote-ai/ai-text-detector/blob/main/detection-model-pipeline/model_entity/hier_aidetect_model.py"
click node_xlmr "https://github.com/lynote-ai/ai-text-detector/blob/main/detection-model-pipeline/model_entity/hier_xlmr_model.py"
click node_splitter "https://github.com/lynote-ai/ai-text-detector/blob/main/detection-model-pipeline/code/sentence_splitter.py"
click node_serving "https://github.com/lynote-ai/ai-text-detector/blob/main/detection-model-pipeline/code/m_serve_hier_api.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_cli,node_analyzer,node_report,node_reviewer toneBlue
class node_data_prep,node_training,node_calibration,node_evaluation toneAmber
class node_factory,node_modernbert,node_xlmr toneMint
class node_splitter,node_serving toneRose
class node_user toneIndigo
```

## Components

### Local Analyzer

- [CLI input](https://github.com/lynote-ai/ai-text-detector/blob/main/src/aidetect/cli.py): `src/aidetect/cli.py`
- [Risk analysis](https://github.com/lynote-ai/ai-text-detector/blob/main/src/aidetect/core.py): `src/aidetect/core.py`
- [Risk report](https://github.com/lynote-ai/ai-text-detector/blob/main/src/aidetect/cli.py): `src/aidetect/cli.py`

### Model Pipeline

- [Data preparation](https://github.com/lynote-ai/ai-text-detector/tree/main/detection-model-pipeline/code): `detection-model-pipeline/code`
- [Joint training](https://github.com/lynote-ai/ai-text-detector/blob/main/detection-model-pipeline/code/j_train_hier_model.py): `detection-model-pipeline/code/j_train_hier_model.py`
- [Calibration](https://github.com/lynote-ai/ai-text-detector/blob/main/detection-model-pipeline/code/k_calibrate_hier_model.py): `detection-model-pipeline/code/k_calibrate_hier_model.py`
- [Model evaluation](https://github.com/lynote-ai/ai-text-detector/blob/main/detection-model-pipeline/code/l_eval_hier_model.py): `detection-model-pipeline/code/l_eval_hier_model.py`

### Joint Model

- [Backbone factory](https://github.com/lynote-ai/ai-text-detector/blob/main/detection-model-pipeline/model_entity/hier_model_factory.py): `detection-model-pipeline/model_entity/hier_model_factory.py`
- [ModernBERT model](https://github.com/lynote-ai/ai-text-detector/blob/main/detection-model-pipeline/model_entity/hier_aidetect_model.py): `detection-model-pipeline/model_entity/hier_aidetect_model.py`
- [XLM-R model](https://github.com/lynote-ai/ai-text-detector/blob/main/detection-model-pipeline/model_entity/hier_xlmr_model.py): `detection-model-pipeline/model_entity/hier_xlmr_model.py`

### Detection Service

- [Sentence splitting](https://github.com/lynote-ai/ai-text-detector/blob/main/detection-model-pipeline/code/sentence_splitter.py): `detection-model-pipeline/code/sentence_splitter.py`
- [Detection API](https://github.com/lynote-ai/ai-text-detector/blob/main/detection-model-pipeline/code/m_serve_hier_api.py): `detection-model-pipeline/code/m_serve_hier_api.py`

### Other components

- **Text submitter**
- **Human reviewer**

## Connections

- Text submitter → CLI input: provides text (evidence: `README.md`)
- CLI input → Risk analysis: analyzes text (evidence: `src/aidetect/cli.py`)
- Risk analysis → Risk report: returns result (evidence: `src/aidetect/cli.py`)
- Data preparation → Joint training: prepares training data (evidence: `README.md`)
- Joint training → Backbone factory: loads model class (evidence: `detection-model-pipeline/code/j_train_hier_model.py`)
- Backbone factory → ModernBERT model: routes ModernBERT (evidence: `detection-model-pipeline/model_entity/hier_model_factory.py`)
- Backbone factory → XLM-R model: routes XLM-R (evidence: `detection-model-pipeline/model_entity/hier_model_factory.py`)
- Joint training → Calibration: produces model (evidence: `README.md`)
- Calibration → Model evaluation: calibrates model (evidence: `README.md`)
- Joint training → Model evaluation: evaluates model (evidence: `README.md`)
- Text submitter → Detection API: submits document (evidence: `README.md`)
- Detection API → Sentence splitting: splits sentences (evidence: `detection-model-pipeline/code/m_serve_hier_api.py`)
- Detection API → Backbone factory: loads model class (evidence: `detection-model-pipeline/code/m_serve_hier_api.py`)
- Detection API → Human reviewer: returns classifications (evidence: `README.md`)
