# lberdy/microtensorgrad architecture

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

- Interactive diagram: https://gitdiagram.com/lberdy/microtensorgrad
- Repository: https://github.com/lberdy/microtensorgrad

## Overview

MicroTensorGrad is a small tensor-based automatic-differentiation library for constructing and training neural networks. The principal workflow is to compose layers into a Module, run a forward pass, attach an MSE or cross-entropy loss to its topology, backpropagate, and update the model with SGD or Adam. MicroTensor provides tensor operations, activation and normalization behavior, and loss calculations; utilities also provide dataset batching. The README describes MNIST training, but the notebook is not treated as runtime architecture evidence, so user-to-training links are shown as unverified.

Main entry points: [`MicroTensorGrad/Module.py`](https://github.com/lberdy/microtensorgrad/blob/main/MicroTensorGrad/Module.py) (Model Module), [`MicroTensorGrad/nn.py`](https://github.com/lberdy/microtensorgrad/blob/main/MicroTensorGrad/nn.py) (Neural layers), [`MicroTensorGrad/Loss.py`](https://github.com/lberdy/microtensorgrad/blob/main/MicroTensorGrad/Loss.py) (Loss functions), [`MicroTensorGrad/Optimizers.py`](https://github.com/lberdy/microtensorgrad/blob/main/MicroTensorGrad/Optimizers.py) (SGD and Adam)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_modeling["Modeling"]
  node_module["Model Module<br/>[Module.py]"]
  node_layers["Neural layers<br/>[nn.py]"]
  node_tensor["Autograd tensor<br/>[Engine.py]"]
end

subgraph group_training["Training"]
  node_loss["Loss functions<br/>[Loss.py]"]
  node_optimizers["SGD and Adam<br/>[Optimizers.py]"]
end

subgraph group_data["Data utilities"]
  node_batches["Batch creation<br/>[utils.py]"]
end

node_user(("Library user"))

node_user -.->|"assembles model"| node_module
node_module -->|"runs forward"| node_layers
node_layers -->|"uses operations"| node_tensor
node_loss -->|"builds loss and backpropagates"| node_tensor
node_optimizers -->|"reads model weights"| node_module
node_user -.->|"computes training loss"| node_loss
node_user -.->|"updates weights"| node_optimizers

click node_module "https://github.com/lberdy/microtensorgrad/blob/main/MicroTensorGrad/Module.py"
click node_layers "https://github.com/lberdy/microtensorgrad/blob/main/MicroTensorGrad/nn.py"
click node_tensor "https://github.com/lberdy/microtensorgrad/blob/main/MicroTensorGrad/Engine.py"
click node_loss "https://github.com/lberdy/microtensorgrad/blob/main/MicroTensorGrad/Loss.py"
click node_optimizers "https://github.com/lberdy/microtensorgrad/blob/main/MicroTensorGrad/Optimizers.py"
click node_batches "https://github.com/lberdy/microtensorgrad/blob/main/MicroTensorGrad/utils.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_module,node_layers,node_tensor,node_user toneBlue
class node_loss,node_optimizers toneAmber
class node_batches toneMint
```

## Components

### Modeling

- [Model Module](https://github.com/lberdy/microtensorgrad/blob/main/MicroTensorGrad/Module.py): `MicroTensorGrad/Module.py`
- [Neural layers](https://github.com/lberdy/microtensorgrad/blob/main/MicroTensorGrad/nn.py): `MicroTensorGrad/nn.py`
- [Autograd tensor](https://github.com/lberdy/microtensorgrad/blob/main/MicroTensorGrad/Engine.py): `MicroTensorGrad/Engine.py`

### Training

- [Loss functions](https://github.com/lberdy/microtensorgrad/blob/main/MicroTensorGrad/Loss.py): `MicroTensorGrad/Loss.py`
- [SGD and Adam](https://github.com/lberdy/microtensorgrad/blob/main/MicroTensorGrad/Optimizers.py): `MicroTensorGrad/Optimizers.py`

### Data utilities

- [Batch creation](https://github.com/lberdy/microtensorgrad/blob/main/MicroTensorGrad/utils.py): `MicroTensorGrad/utils.py`

### Other components

- **Library user**

## Connections

- Library user → Model Module: assembles model
- Model Module → Neural layers: runs forward (evidence: `MicroTensorGrad/Module.py`)
- Neural layers → Autograd tensor: uses operations (evidence: `MicroTensorGrad/nn.py`)
- Loss functions → Autograd tensor: builds loss and backpropagates (evidence: `MicroTensorGrad/Loss.py`)
- SGD and Adam → Model Module: reads model weights (evidence: `MicroTensorGrad/Optimizers.py`)
- Library user → Loss functions: computes training loss
- Library user → SGD and Adam: updates weights
