# hnx07/handwritten-digit-recognition architecture

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

- Interactive diagram: https://gitdiagram.com/hnx07/handwritten-digit-recognition
- Repository: https://github.com/hnx07/handwritten-digit-recognition

## Overview

This repository is a NumPy-based handwritten-digit recognizer with an OpenCV drawing interface. The primary user workflow is to draw a digit, trigger prediction, and see the predicted class printed; the app loads saved weights, preprocesses the drawing, and calls the model. A separate training script loads CSV data and uses the same model implementation for gradient descent. The tree includes the app’s weight file, but the training script saves to a different filename, so no training-to-included-weights link is shown.

Main entry points: [`app.py`](https://github.com/hnx07/handwritten-digit-recognition/blob/main/app.py) (Drawing and prediction app), [`train.py`](https://github.com/hnx07/handwritten-digit-recognition/blob/main/train.py) (Training workflow), [`model.py`](https://github.com/hnx07/handwritten-digit-recognition/blob/main/model.py) (Neural network), [`weights/best_weight.npz`](https://github.com/hnx07/handwritten-digit-recognition/blob/main/weights/best_weight.npz) (Saved model weights)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["Recognition interface"]
  node_app["Drawing and prediction app<br/>[app.py]"]
  node_prediction["Printed prediction"]
end

subgraph group_learning["Model and training"]
  node_training["Training workflow<br/>[train.py]"]
  node_model["Neural network<br/>[model.py]"]
end

subgraph group_artifacts["Model artifacts"]
  node_weights[("Saved model weights<br/>[best_weight.npz]")]
end

node_user(("User"))
node_dataset["MNIST CSV data"]

node_user -->|"draws and predicts"| node_app
node_app -->|"loads weights"| node_weights
node_app -->|"calls inference"| node_model
node_app -->|"prints class"| node_prediction
node_training -->|"loads data"| node_dataset
node_training -->|"runs training"| node_model

click node_app "https://github.com/hnx07/handwritten-digit-recognition/blob/main/app.py"
click node_training "https://github.com/hnx07/handwritten-digit-recognition/blob/main/train.py"
click node_model "https://github.com/hnx07/handwritten-digit-recognition/blob/main/model.py"
click node_weights "https://github.com/hnx07/handwritten-digit-recognition/blob/main/weights/best_weight.npz"

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_app,node_prediction,node_user toneBlue
class node_training,node_model toneAmber
class node_weights toneMint
class node_dataset toneIndigo
```

## Components

### Recognition interface

- [Drawing and prediction app](https://github.com/hnx07/handwritten-digit-recognition/blob/main/app.py): `app.py`
- **Printed prediction**

### Model and training

- [Training workflow](https://github.com/hnx07/handwritten-digit-recognition/blob/main/train.py): `train.py`
- [Neural network](https://github.com/hnx07/handwritten-digit-recognition/blob/main/model.py): `model.py`

### Model artifacts

- [Saved model weights](https://github.com/hnx07/handwritten-digit-recognition/blob/main/weights/best_weight.npz): `weights/best_weight.npz`

### Other components

- **User**
- **MNIST CSV data**

## Connections

- User → Drawing and prediction app: draws and predicts (evidence: `README.md`)
- Drawing and prediction app → Saved model weights: loads weights (evidence: `app.py`)
- Drawing and prediction app → Neural network: calls inference (evidence: `app.py`)
- Drawing and prediction app → Printed prediction: prints class (evidence: `app.py`)
- Training workflow → MNIST CSV data: loads data (evidence: `train.py`)
- Training workflow → Neural network: runs training (evidence: `train.py`)
