# roshenisr/s3231-mcq-sheet-reader architecture

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

- Interactive diagram: https://gitdiagram.com/roshenisr/s3231-mcq-sheet-reader
- Repository: https://github.com/roshenisr/s3231-mcq-sheet-reader

## Overview

S3231 MCQ answer-sheet reader is a CPU-only computer-vision application that turns a scan or photo into student-number and answer predictions in JSON. Its runtime path is CLI input, page registration, bubble scoring and thresholded decoding, then JSON output; an optional debug image annotates the registered page. The README also describes a separate training-time layout-learning stage. Registration details are shown in sampled source, but the robust registrar, layout learning and data loader were not excerpted, so their internal call relationships are not asserted.

Main entry points: [`predict.py`](https://github.com/roshenisr/s3231-mcq-sheet-reader/blob/main/predict.py) (Prediction CLI), [`src/robust.py`](https://github.com/roshenisr/s3231-mcq-sheet-reader/blob/main/src/robust.py) (Robust registration), [`src/register.py`](https://github.com/roshenisr/s3231-mcq-sheet-reader/blob/main/src/register.py) (SIFT registrar), [`src/bubbles.py`](https://github.com/roshenisr/s3231-mcq-sheet-reader/blob/main/src/bubbles.py) (Bubble scoring)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_input["Input and output"]
  node_cli["Prediction CLI<br/>[predict.py]"]
  node_image["Input image"]
  node_json["Prediction JSON"]
end

subgraph group_registration["Page registration"]
  node_robust["Robust registration<br/>[robust.py]"]
  node_sift["SIFT registrar<br/>[register.py]"]
  node_contour["Contour warp<br/>[align.py]"]
end

subgraph group_reading["Bubble reading"]
  node_scoring["Bubble scoring<br/>[bubbles.py]"]
  node_decoding["Thresholded decoding<br/>[bubbles.py]"]
  node_annotation["Debug annotation<br/>[bubbles.py]"]
end

subgraph group_training["Layout preparation"]
  node_layout["Learned layout<br/>[grid.py]"]
  node_data["Training data loader<br/>[s3231_data.py]"]
end

node_operator(("Operator"))

node_operator -->|"runs"| node_cli
node_operator -->|"provides"| node_image
node_cli -->|"reads"| node_image
node_cli -->|"registers with"| node_robust
node_robust -.->|"uses retries"| node_sift
node_robust -.->|"falls back"| node_contour
node_sift -->|"falls back"| node_contour
node_cli -->|"scores bubbles"| node_scoring
node_scoring -->|"uses layout"| node_layout
node_cli -->|"decodes scores"| node_decoding
node_cli -->|"writes"| node_json
node_cli -->|"optionally annotates"| node_annotation
node_data -.->|"supplies training pages"| node_layout

click node_cli "https://github.com/roshenisr/s3231-mcq-sheet-reader/blob/main/predict.py"
click node_robust "https://github.com/roshenisr/s3231-mcq-sheet-reader/blob/main/src/robust.py"
click node_sift "https://github.com/roshenisr/s3231-mcq-sheet-reader/blob/main/src/register.py"
click node_contour "https://github.com/roshenisr/s3231-mcq-sheet-reader/blob/main/src/align.py"
click node_layout "https://github.com/roshenisr/s3231-mcq-sheet-reader/blob/main/src/grid.py"
click node_data "https://github.com/roshenisr/s3231-mcq-sheet-reader/blob/main/src/s3231_data.py"
click node_scoring "https://github.com/roshenisr/s3231-mcq-sheet-reader/blob/main/src/bubbles.py"
click node_decoding "https://github.com/roshenisr/s3231-mcq-sheet-reader/blob/main/src/bubbles.py"
click node_annotation "https://github.com/roshenisr/s3231-mcq-sheet-reader/blob/main/src/bubbles.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_image,node_json toneBlue
class node_robust,node_sift,node_contour toneAmber
class node_scoring,node_decoding,node_annotation toneMint
class node_layout,node_data toneRose
class node_operator toneIndigo
```

## Components

### Input and output

- [Prediction CLI](https://github.com/roshenisr/s3231-mcq-sheet-reader/blob/main/predict.py): `predict.py`
- **Input image**
- **Prediction JSON**

### Page registration

- [Robust registration](https://github.com/roshenisr/s3231-mcq-sheet-reader/blob/main/src/robust.py): `src/robust.py`
- [SIFT registrar](https://github.com/roshenisr/s3231-mcq-sheet-reader/blob/main/src/register.py): `src/register.py`
- [Contour warp](https://github.com/roshenisr/s3231-mcq-sheet-reader/blob/main/src/align.py): `src/align.py`

### Bubble reading

- [Bubble scoring](https://github.com/roshenisr/s3231-mcq-sheet-reader/blob/main/src/bubbles.py): `src/bubbles.py`
- [Thresholded decoding](https://github.com/roshenisr/s3231-mcq-sheet-reader/blob/main/src/bubbles.py): `src/bubbles.py`
- [Debug annotation](https://github.com/roshenisr/s3231-mcq-sheet-reader/blob/main/src/bubbles.py): `src/bubbles.py`

### Layout preparation

- [Learned layout](https://github.com/roshenisr/s3231-mcq-sheet-reader/blob/main/src/grid.py): `src/grid.py`
- [Training data loader](https://github.com/roshenisr/s3231-mcq-sheet-reader/blob/main/src/s3231_data.py): `src/s3231_data.py`

### Other components

- **Operator**

## Connections

- Operator → Prediction CLI: runs (evidence: `README.md`)
- Operator → Input image: provides (evidence: `README.md`)
- Prediction CLI → Input image: reads (evidence: `predict.py`)
- Prediction CLI → Robust registration: registers with (evidence: `predict.py`)
- Robust registration → SIFT registrar: uses retries (evidence: `README.md`)
- Robust registration → Contour warp: falls back (evidence: `README.md`)
- SIFT registrar → Contour warp: falls back (evidence: `src/register.py`)
- Prediction CLI → Bubble scoring: scores bubbles (evidence: `predict.py`)
- Bubble scoring → Learned layout: uses layout (evidence: `README.md`)
- Prediction CLI → Thresholded decoding: decodes scores (evidence: `predict.py`)
- Prediction CLI → Prediction JSON: writes (evidence: `predict.py`)
- Prediction CLI → Debug annotation: optionally annotates (evidence: `predict.py`)
- Training data loader → Learned layout: supplies training pages
