# lanchiang/strudel architecture

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

- Interactive diagram: https://gitdiagram.com/lanchiang/strudel
- Repository: https://github.com/lanchiang/strudel

## Overview

1. **What this repo is**
   Strudel is a **Python 3.7 command-line ML pipeline** for detecting structure in verbose CSV files. The architecture is centered on **loading labeled CSV-like datasets, classifying lines/cells, deriving structure from those predictions, and writing results to CSV**.

2. **Entry point and orchestration**
   `run_strudel.py` is the main executable. It accepts dataset and output arguments (`-d`, `-t`, `-f`, `-o`) and decides whether to run **training + evaluation on a test set** or **cross-validation on the training set** when no test set is supplied. This script is the top-level coordinator for the whole pipeline.

3. **Data and benchmark assets**
   The `data/` directory contains compressed `.jl.gz` files (`cius`, `deex`, `saus`, `troy`), which appear to be **JSON Lines-style datasets** used for experiments. These files are the main repository boundary between the code and the benchmark corpora.

4. **Dataset loading and representation**
   `strudel/data.py` is the likely ingestion layer. It is responsible for reading the compressed training/test data, turning raw records into internal examples, and exposing them to the rest of the pipeline. This is the boundary where raw file formats become model-ready data.

5. **Feature and utility layer**
   `strudel/utility.py` and `strudel/block_size_calculator.py` provide shared support logic. From the names and project goal, this layer likely contains **feature extraction helpers, normalization, formatting helpers, and heuristics for estimating block sizes or table structure**. These helpers sit below the classifiers and above raw data access.

6. **Classification subsystem**
   `strudel/classification.py` is the core predictive layer. It likely contains the model training, prediction, and evaluation logic used to classify CSV lines or cells. This is the main ML boundary: input examples in, class labels or scores out.

7. **Two Strudel variants**
   `strudel/lstrudel.py` and `strudel/cstrudel.py` suggest two related detection pipelines or model variants, probably split along **line-level** and **cell-level** structure detection. Architecturally, these look like specialized wrappers around the shared classification and feature layers.

8. **Post-processing and structure derivation**
   `strudel/derived_detector.py` appears to take raw classifier outputs and convert them into **higher-level structural decisions**. In an architecture diagram, this is the post-processing stage that turns independent predictions into a coherent CSV structure estimate.

9. **Overall data flow**
   The pipeline is: **dataset files in `data/` → load/normalize examples → extract features → train or apply classifiers → derive structural blocks/labels → write evaluation/output CSV**. The important boundary is between **prediction** and **structure reconstruction**, since the repo is not just classifying rows but inferring CSV structure from those classifications.

10. **Operational characteristics**
   The project is **local and batch-oriented**: no server, no database, and no external runtime service are indicated. Execution is file-based, with results emitted as CSV. Dependencies are managed through `requirements.txt`, and the repo is designed to be run directly from the command line.

11. **How to think about the architecture diagram**
   A good diagram should show three main layers: **input datasets**, **ML/feature/classification pipeline**, and **structure derivation/output**. The central control plane is `run_strudel.py`, while `classification.py`, `derived_detector.py`, and the `lstrudel`/`cstrudel` modules form the core processing subsystem.

Main entry points: [`run_strudel.py`](https://github.com/lanchiang/strudel/blob/main/run_strudel.py) (run_strudel.py), [`strudel/data.py`](https://github.com/lanchiang/strudel/blob/main/strudel/data.py) (Data loader), [`strudel/classification.py`](https://github.com/lanchiang/strudel/blob/main/strudel/classification.py) (Classifier), [`strudel/lstrudel.py`](https://github.com/lanchiang/strudel/blob/main/strudel/lstrudel.py) (LStrudel)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_inputs["Inputs"]
  node_datasets[("Data files<br/>benchmark corpora")]
end

subgraph group_core["Core Pipeline"]
  node_run_strudel["run_strudel.py<br/>CLI orchestrator<br/>[run_strudel.py]"]
  node_data_loader["Data loader<br/>ingestion<br/>[data.py]"]
  node_utility["Utility<br/>shared helpers<br/>[utility.py]"]
  node_block_calc["Block sizing<br/>heuristics"]
  node_classification{{"Classifier<br/>ML model<br/>[classification.py]"}}
  node_lstrudel["LStrudel<br/>line-level variant<br/>[lstrudel.py]"]
  node_cstrudel["CStrudel<br/>cell-level variant<br/>[cstrudel.py]"]
  node_derived_detector{{"Derived detector<br/>post-processing"}}
  node_train_eval(("Train/eval<br/>execution mode"))
  node_crossval(("Cross-validation<br/>execution mode"))
  node_feature_building["Features<br/>feature extraction"]
  node_label_prediction{{"Predictions<br/>scoring"}}
  node_structure_recon["Structure<br/>reconstruction"]
end

subgraph group_outputs["Outputs"]
  node_results["CSV output<br/>artifacts"]
end

node_datasets -->|"read"| node_data_loader
node_run_strudel -->|"select"| node_train_eval
node_run_strudel -->|"select"| node_crossval
node_train_eval -->|"load"| node_data_loader
node_crossval -->|"load"| node_data_loader
node_data_loader -->|"prepare"| node_feature_building
node_feature_building -->|"use"| node_utility
node_feature_building -->|"use"| node_block_calc
node_feature_building -->|"feed"| node_classification
node_classification -->|"emit"| node_label_prediction
node_run_strudel -->|"invoke"| node_lstrudel
node_run_strudel -->|"invoke"| node_cstrudel
node_lstrudel -->|"wraps"| node_classification
node_cstrudel -->|"wraps"| node_classification
node_label_prediction -->|"refine"| node_derived_detector
node_derived_detector -->|"derive"| node_structure_recon
node_structure_recon -->|"write"| node_results
node_train_eval -->|"save"| node_results
node_crossval -->|"save"| node_results

click node_run_strudel "https://github.com/lanchiang/strudel/blob/main/run_strudel.py"
click node_datasets "https://github.com/lanchiang/strudel/tree/main/data"
click node_data_loader "https://github.com/lanchiang/strudel/blob/main/strudel/data.py"
click node_utility "https://github.com/lanchiang/strudel/blob/main/strudel/utility.py"
click node_block_calc "https://github.com/lanchiang/strudel/blob/main/strudel/block_size_calculator.py"
click node_classification "https://github.com/lanchiang/strudel/blob/main/strudel/classification.py"
click node_lstrudel "https://github.com/lanchiang/strudel/blob/main/strudel/lstrudel.py"
click node_cstrudel "https://github.com/lanchiang/strudel/blob/main/strudel/cstrudel.py"
click node_derived_detector "https://github.com/lanchiang/strudel/blob/main/strudel/derived_detector.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_datasets toneBlue
class node_run_strudel,node_data_loader,node_utility,node_block_calc,node_classification,node_lstrudel,node_cstrudel,node_derived_detector,node_train_eval,node_crossval,node_feature_building,node_label_prediction,node_structure_recon toneAmber
class node_results toneMint
```

## Components

### Inputs

Benchmark datasets and command-line entrypoint

- [Data files](https://github.com/lanchiang/strudel/tree/main/data): benchmark corpora · Compressed JSON-lines style datasets used for experiments · `data`

### Core Pipeline

Loading, feature work, classification, and structure derivation

- [run_strudel.py](https://github.com/lanchiang/strudel/blob/main/run_strudel.py): CLI orchestrator · Main command-line entrypoint that chooses training, evaluation, or cross-validation runs · `run_strudel.py`
- [Data loader](https://github.com/lanchiang/strudel/blob/main/strudel/data.py): ingestion · Reads compressed training and test data into internal examples · `strudel/data.py`
- [Utility](https://github.com/lanchiang/strudel/blob/main/strudel/utility.py): shared helpers · Common helper layer for feature support and formatting · `strudel/utility.py`
- [Block sizing](https://github.com/lanchiang/strudel/blob/main/strudel/block_size_calculator.py): heuristics · Estimates block sizes or structural spans used by the pipeline · `strudel/block_size_calculator.py`
- [Classifier](https://github.com/lanchiang/strudel/blob/main/strudel/classification.py): ML model · Training, prediction, and evaluation logic for structure labels · `strudel/classification.py`
- [LStrudel](https://github.com/lanchiang/strudel/blob/main/strudel/lstrudel.py): line-level variant · Specialized variant focused on line-level structure detection · `strudel/lstrudel.py`
- [CStrudel](https://github.com/lanchiang/strudel/blob/main/strudel/cstrudel.py): cell-level variant · Specialized variant focused on cell-level structure detection · `strudel/cstrudel.py`
- [Derived detector](https://github.com/lanchiang/strudel/blob/main/strudel/derived_detector.py): post-processing · Converts raw predictions into higher-level structural decisions · `strudel/derived_detector.py`
- **Train/eval**: execution mode · Run mode that trains on a dataset and evaluates against a test set
- **Cross-validation**: execution mode · Fallback run mode when no test set is supplied
- **Features**: feature extraction · Turns loaded examples into model inputs and shared signals
- **Predictions**: scoring · Classifier outputs for lines or cells
- **Structure**: reconstruction · Combines predictions into CSV structure estimates

### Outputs

Evaluation and CSV results

- **CSV output**: artifacts · Written evaluation and inference results

## Connections

- Data files → Data loader: read · Compressed benchmark files are ingested into internal examples
- run_strudel.py → Train/eval: select · Chooses training plus evaluation when a test set is provided
- run_strudel.py → Cross-validation: select · Runs cross-validation when no test set is supplied
- Train/eval → Data loader: load · Loads training and test examples
- Cross-validation → Data loader: load · Loads the training corpus for validation folds
- Data loader → Features: prepare · Converts raw records into model-ready inputs
- Features → Utility: use · Shares normalization and helper logic
- Features → Block sizing: use · Uses block-size and structure heuristics
- Features → Classifier: feed · Supplies features to the model layer
- Classifier → Predictions: emit · Produces class labels or scores
- run_strudel.py → LStrudel: invoke · May route work through the line-level variant
- run_strudel.py → CStrudel: invoke · May route work through the cell-level variant
- LStrudel → Classifier: wraps · Builds on the shared classifier
- CStrudel → Classifier: wraps · Builds on the shared classifier
- Predictions → Derived detector: refine · Raw predictions are post-processed into structure
- Derived detector → Structure: derive · Produces higher-level CSV structure decisions
- Structure → CSV output: write · Outputs evaluation or inferred CSV artifacts
- Train/eval → CSV output: save · Stores evaluation outputs
- Cross-validation → CSV output: save · Stores cross-validation outputs
