# naowalrahman/neural-network architecture

> Architecture diagram of the GitHub repository naowalrahman/neural-network, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/naowalrahman/neural-network
- Repository: https://github.com/naowalrahman/neural-network

## Overview

##### Project type and purpose
- This is a standalone C++ library/tool that implements a fully functional feedforward neural network, including weight initialization (Glorot uniform), multiple activation functions, stochastic gradient descent training via backpropagation, and example applications (XOR, MNIST).
- It is not a web app or microservice; it’s a compute-intensive command-line tool/library.

##### File structure
- Top‐level source files:
- Main.cpp – entry point; sets up network, loads data, runs training/evaluation
- NeuralNetwork.hpp/.cpp – orchestrates layers, forward pass, backpropagation
- Layer.hpp/.cpp – defines a single layer: neurons, weights, biases, activation
- Matrix.hpp/.cpp – lightweight matrix operations (vector/matrix math)
- Functions.hpp/.cpp – activation functions and derivatives
- Functions.cpp – contains sigmoid, ReLU, etc.
- backpropagation.md – theoretical reference
- mnist.txt – serialized pre-trained weights for example evaluation
- CMakeLists.txt, makefile, build.sh – build configuration/scripts
- There is no external dependency; everything lives in C++ STL modules.

##### README for insights
- Describes goals (pure C++ neural network), training setups (XOR, MNIST), build instructions, to-do list.

a. Main components
- Data Input/Loader
- Core Math Module (Matrix operations)
- Activation Module (Functions)
- Layer Module (Layer)
- Network Module (NeuralNetwork)
- Training Engine (drive forward+backprop loops, SGD)
- Application/CLI (Main.cpp)
- Build/Deployment (CMake, build.sh, makefile)
b. Relationships & interactions
- Application invokes Data Loader → provides training/test datasets
- Application instantiates NeuralNetwork → internally creates Layer objects
- NeuralNetwork uses Matrix and Functions modules for calculations
- Training Engine sits inside NeuralNetwork: repeats forward pass → compute loss → backpropagate → update weights
- NeuralNetwork outputs results → Application logs accuracy/loss or stores weights in mnist.txt
- Build tools compile all modules into an executable or library
c. Architectural patterns & principles
- Modular separation: math, activation, layers, network, application
- Single responsibility per module
- Data flow pipeline: Input → Forward → Loss → Backprop → Update → Output
- Dependency direction: high-level modules (Application, Training Engine) depend on low-level modules (Matrix, Functions)
d. Relevant technologies/frameworks
- C++17/20 (STL only)
- CMake, Make, custom shell script build.sh
- No third-party libraries

##### Detailed elements to capture
- Feedforward sequence: Input → Layer1 → … → LayerN → Output
- Feedback loop for backpropagation inside the Training Engine
- That activation functions and matrix multiplications are internal to each Layer
- Build pipeline: source files → CMake/Make → executable
- Call out that no external libraries are used, so all dependencies are internal modules.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Application Layer
    App["Application/CLI\nMain.cpp"]:::app
    click App "https://github.com/naowalrahman/neural-network/blob/main/Main.cpp"

    %% Data Modules
    DataLoader["Data Input/Loader"]:::data
    click DataLoader "https://github.com/naowalrahman/neural-network/blob/main/Main.cpp"
    Mnist["Serialized Weights\nmnist.txt"]:::data
    click Mnist "https://github.com/naowalrahman/neural-network/blob/main/mnist.txt"

    %% Core Library Modules
    subgraph "Core Library"
        direction TB
        Matrix["Matrix Module\n(Matrix.hpp/.cpp)"]:::core
        click Matrix "https://github.com/naowalrahman/neural-network/blob/main/Matrix.hpp"
        click Matrix "https://github.com/naowalrahman/neural-network/blob/main/Matrix.cpp"

        Functions["Activation Module\n(Functions.hpp/.cpp)"]:::core
        click Functions "https://github.com/naowalrahman/neural-network/blob/main/Functions.hpp"
        click Functions "https://github.com/naowalrahman/neural-network/blob/main/Functions.cpp"

        Layer["Layer Module\n(Layer.hpp/.cpp)"]:::core
        click Layer "https://github.com/naowalrahman/neural-network/blob/main/Layer.hpp"
        click Layer "https://github.com/naowalrahman/neural-network/blob/main/Layer.cpp"

        NeuralNet["Network Module\n(NeuralNetwork.hpp/.cpp)"]:::core
        click NeuralNet "https://github.com/naowalrahman/neural-network/blob/main/NeuralNetwork.hpp"
        click NeuralNet "https://github.com/naowalrahman/neural-network/blob/main/NeuralNetwork.cpp"

        %% Training Engine inside NeuralNet
        Training["Training Engine\n(forward/backprop & SGD)"]:::core
    end

    %% Build System
    subgraph "Build System"
        direction TB
        CMake["CMakeLists.txt"]:::build
        click CMake "https://github.com/naowalrahman/neural-network/blob/main/CMakeLists.txt"
        Makefile["makefile"]:::build
        click Makefile "https://github.com/naowalrahman/neural-network/tree/main/makefile"
        BuildSh["build.sh"]:::build
        click BuildSh "https://github.com/naowalrahman/neural-network/blob/main/build.sh"
    end

    %% Documentation
    subgraph "Documentation"
        direction TB
        Readme["README.md"]:::doc
        click Readme "https://github.com/naowalrahman/neural-network/blob/main/README.md"
        Backprop["backpropagation.md"]:::doc
        click Backprop "https://github.com/naowalrahman/neural-network/blob/main/backpropagation.md"
    end

    %% Connections
    App -->|invokes| DataLoader
    Mnist -->|provides weights| DataLoader
    App -->|instantiates| NeuralNet
    DataLoader -->|feeds data to| NeuralNet
    NeuralNet -->|creates| Layer
    Layer -->|uses| Matrix
    Layer -->|uses| Functions
    NeuralNet -->|contains| Training
    Training -->|updates weights in| NeuralNet
    NeuralNet -->|returns results to| App

    %% Styles
    classDef core fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef data fill:#90EE90,stroke:#333,stroke-width:1px
    classDef build fill:#FFA500,stroke:#333,stroke-width:1px
    classDef doc fill:#D3D3D3,stroke:#333,stroke-width:1px
    classDef app fill:#98FB98,stroke:#333,stroke-width:1px
```
