# thien-z3d3r/deep-learning-library-in-c-from-scratch architecture

> Architecture diagram of the GitHub repository thien-z3d3r/deep-learning-library-in-c-from-scratch, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/thien-z3d3r/deep-learning-library-in-c-from-scratch
- Repository: https://github.com/thien-z3d3r/deep-learning-library-in-c-from-scratch

## Overview

This is a self-contained C99 deep-learning library. Its principal workflow is to build tensors and trainable layers, compute a loss, run reverse-mode backpropagation, then update parameters with SGD or Adam. The README also documents XOR and classification benchmark examples. Source excerpts show tensor/autograd, layer/loss, and optimizer responsibilities; example-to-library links are based on README descriptions, not inspected example source.

Main entry points: [`examples/stress_tests.c`](https://github.com/thien-z3d3r/deep-learning-library-in-c-from-scratch/blob/main/examples/stress_tests.c) (Classification benchmarks), [`src/tensor.c`](https://github.com/thien-z3d3r/deep-learning-library-in-c-from-scratch/blob/main/src/tensor.c) (Tensor operations), [`src/nn.c`](https://github.com/thien-z3d3r/deep-learning-library-in-c-from-scratch/blob/main/src/nn.c) (Linear layer), [`src/autograd.c`](https://github.com/thien-z3d3r/deep-learning-library-in-c-from-scratch/blob/main/src/autograd.c) (Differentiable operations)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_tensor["Tensor engine"]
  node_tensor_ops["Tensor operations<br/>[tensor.c]"]
end

subgraph group_grad["Autograd engine"]
  node_autograd_ops["Differentiable operations<br/>[autograd.c]"]
  node_backward["Backward traversal<br/>[autograd.c]"]
end

subgraph group_model["Model training"]
  node_linear["Linear layer<br/>[nn.c]"]
  node_parameters["Parameter list<br/>[nn.c]"]
  node_losses["Loss functions<br/>[nn.c]"]
  node_sgd["SGD optimizer<br/>[optim.c]"]
  node_adam["Adam optimizer<br/>[optim.c]"]
  node_xor["XOR example<br/>[xor.c]"]
  node_benchmarks["Classification benchmarks<br/>[stress_tests.c]"]
end

node_training(("Training program"))

node_training -->|"runs"| node_xor
node_training -->|"runs"| node_benchmarks
node_xor -->|"trains with"| node_linear
node_xor -->|"updates with"| node_adam
node_linear -->|"computes with"| node_tensor_ops
node_linear -->|"collects"| node_parameters
node_losses -->|"computes with"| node_tensor_ops
node_losses -->|"records gradients"| node_autograd_ops
node_autograd_ops -->|"retains tensors"| node_tensor_ops
node_backward -->|"dispatches backward"| node_autograd_ops
node_backward -->|"accumulates gradients"| node_tensor_ops
node_tensor_ops -->|"frees contexts"| node_autograd_ops
node_sgd -->|"updates"| node_parameters
node_adam -->|"updates"| node_parameters
node_benchmarks -->|"trains with"| node_linear
node_benchmarks -->|"uses SGD"| node_sgd
node_benchmarks -->|"uses AdamW"| node_adam
node_benchmarks -->|"uses cross-entropy"| node_losses

click node_tensor_ops "https://github.com/thien-z3d3r/deep-learning-library-in-c-from-scratch/blob/main/src/tensor.c"
click node_autograd_ops "https://github.com/thien-z3d3r/deep-learning-library-in-c-from-scratch/blob/main/src/autograd.c"
click node_backward "https://github.com/thien-z3d3r/deep-learning-library-in-c-from-scratch/blob/main/src/autograd.c"
click node_linear "https://github.com/thien-z3d3r/deep-learning-library-in-c-from-scratch/blob/main/src/nn.c"
click node_parameters "https://github.com/thien-z3d3r/deep-learning-library-in-c-from-scratch/blob/main/src/nn.c"
click node_losses "https://github.com/thien-z3d3r/deep-learning-library-in-c-from-scratch/blob/main/src/nn.c"
click node_sgd "https://github.com/thien-z3d3r/deep-learning-library-in-c-from-scratch/blob/main/src/optim.c"
click node_adam "https://github.com/thien-z3d3r/deep-learning-library-in-c-from-scratch/blob/main/src/optim.c"
click node_xor "https://github.com/thien-z3d3r/deep-learning-library-in-c-from-scratch/blob/main/examples/xor.c"
click node_benchmarks "https://github.com/thien-z3d3r/deep-learning-library-in-c-from-scratch/blob/main/examples/stress_tests.c"

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_tensor_ops toneBlue
class node_autograd_ops,node_backward toneAmber
class node_linear,node_parameters,node_losses,node_sgd,node_adam,node_xor,node_benchmarks toneMint
class node_training toneIndigo
```

## Components

### Tensor engine

- [Tensor operations](https://github.com/thien-z3d3r/deep-learning-library-in-c-from-scratch/blob/main/src/tensor.c): `src/tensor.c`

### Autograd engine

- [Differentiable operations](https://github.com/thien-z3d3r/deep-learning-library-in-c-from-scratch/blob/main/src/autograd.c): `src/autograd.c`
- [Backward traversal](https://github.com/thien-z3d3r/deep-learning-library-in-c-from-scratch/blob/main/src/autograd.c): `src/autograd.c`

### Model training

- [Linear layer](https://github.com/thien-z3d3r/deep-learning-library-in-c-from-scratch/blob/main/src/nn.c): `src/nn.c`
- [Parameter list](https://github.com/thien-z3d3r/deep-learning-library-in-c-from-scratch/blob/main/src/nn.c): `src/nn.c`
- [Loss functions](https://github.com/thien-z3d3r/deep-learning-library-in-c-from-scratch/blob/main/src/nn.c): `src/nn.c`
- [SGD optimizer](https://github.com/thien-z3d3r/deep-learning-library-in-c-from-scratch/blob/main/src/optim.c): `src/optim.c`
- [Adam optimizer](https://github.com/thien-z3d3r/deep-learning-library-in-c-from-scratch/blob/main/src/optim.c): `src/optim.c`
- [XOR example](https://github.com/thien-z3d3r/deep-learning-library-in-c-from-scratch/blob/main/examples/xor.c): `examples/xor.c`
- [Classification benchmarks](https://github.com/thien-z3d3r/deep-learning-library-in-c-from-scratch/blob/main/examples/stress_tests.c): `examples/stress_tests.c`

### Other components

- **Training program**

## Connections

- Training program → XOR example: runs (evidence: `README.md`)
- Training program → Classification benchmarks: runs (evidence: `README.md`)
- XOR example → Linear layer: trains with (evidence: `README.md`)
- XOR example → Adam optimizer: updates with (evidence: `README.md`)
- Linear layer → Tensor operations: computes with (evidence: `src/nn.c`)
- Linear layer → Parameter list: collects (evidence: `src/nn.c`)
- Loss functions → Tensor operations: computes with (evidence: `src/nn.c`)
- Loss functions → Differentiable operations: records gradients (evidence: `src/nn.c`)
- Differentiable operations → Tensor operations: retains tensors (evidence: `src/autograd.c`)
- Backward traversal → Differentiable operations: dispatches backward (evidence: `src/autograd.c`)
- Backward traversal → Tensor operations: accumulates gradients (evidence: `src/autograd.c`)
- Tensor operations → Differentiable operations: frees contexts (evidence: `src/tensor.c`)
- SGD optimizer → Parameter list: updates (evidence: `src/optim.c`)
- Adam optimizer → Parameter list: updates (evidence: `src/optim.c`)
- Classification benchmarks → Linear layer: trains with (evidence: `README.md`)
- Classification benchmarks → SGD optimizer: uses SGD (evidence: `README.md`)
- Classification benchmarks → Adam optimizer: uses AdamW (evidence: `README.md`)
- Classification benchmarks → Loss functions: uses cross-entropy (evidence: `README.md`)
