How aryamang1/synapse works
1. Repo purpose and runtime
- This is a single-purpose Java project that implements a neural network from scratch with no external libraries.
- The code is organized as a small in-memory training system that learns a function approximation task: predicting y = x².
2. Top-level architecture
- The repository has one application module (module-info.java) and one main package (NeuralNetwork/).
- There are no separate services, databases, web APIs, or persistence layers. Everything happens inside the Java process during training and evaluation.
3. Core domain model
- The main architectural building blocks are:
- Neuron for the basic compute unit
- Layer for grouping neurons
- NeuralNetwork for end-to-end orchestration
- activation function types for non-linear behavior
- This is a classic layered neural network structure, with data flowing forward and gradients flowing backward.
4. Activation function boundary
- ActivationFunction.java defines the shared contract for activation behavior.
- ReLU, LeakyReLU, Sigmoid, Tanh, and Linear are concrete activation variants.
- This is a clean polymorphic boundary: the network can swap activation behavior without changing the rest of the model logic.
5. Neuron subsystem
- Neuron.java is the lowest-level learnable unit.
- A neuron is expected to own its parameters, typically weights and bias, and compute a weighted sum followed by an activation.
- It also participates in gradient-based updates during backpropagation.
6. Layer subsystem
- Layer.java composes multiple neurons into a vectorized stage of the network.
- Its role is to manage forward propagation across all neurons in the layer and route gradient information backward during training.
- This is the key structural boundary between single-neuron behavior and network-wide behavior.
7. Network orchestration
- NeuralNetwork.java likely coordinates the full training loop:
- forward pass through all layers
- loss computation against the target
- backpropagation of error
- weight/bias updates
- This class is the main control plane of the model and likely owns the layer sequence and training hyperparameters.
8. Training data flow
- The README describes a simple supervised learning loop using input-target pairs such as 0.2 -> 0.04.
- Data flow is strictly feed-forward during prediction, then reverse-flow during learning:
- input value enters the first layer
- output is produced
- loss is measured
- gradients are propagated backward
- parameters are updated
- The sequence diagram mentioned in the README likely documents this exact flow.
9. Execution boundary
- NeuralNetworkTester.java is the entry point used to run training and observe results.
- It acts as the application harness rather than part of the model itself.
- The tester likely prints epoch loss and final predictions, serving as the only observable interface to the system.
10. Build and packaging
- The project is plain Java, modularized with module-info.java.
- package-info.java suggests the package is documented at the package level, but the architecture remains compact and single-package.
- There is no build tool visible in the tree, so the repository appears intended to compile directly with the JDK.
11. Repository documentation assets
- ClassDiagram.png and Sequence.png are architecture documentation artifacts, not runtime dependencies.
- They reinforce that the system is intentionally simple and centered on the relationship between neuron, layer, network, and training flow.
12. What is notably absent
- There is no indication of convolution, recurrent layers, data loaders, persistence, serialization, concurrency, or external ML frameworks.
- That means the architecture is best drawn as a small, self-contained learning engine: input sample in, prediction out, gradient updates back in.
13. Best diagram framing
- For an architecture diagram, the main boxes should be:
- NeuralNetworkTester as the runner
- NeuralNetwork as the orchestrator
- Layer as a composite stage
- Neuron as the compute/parameter unit
- ActivationFunction plus its implementations as a strategy family
- The arrows should show forward inference left-to-right and gradient/update flow right-to-left during training.
Main entry points: ActivationFunction.java Activation API · NeuralNetwork.java Network · Layer.java Layer · Neuron.java Neuron
Components 13
Runtime
In-memory training and inference flow
- Tester · Runs training and prints results
NeuralNetwork/NeuralNetworkTester.java - Network · Coordinates forward pass, loss, backprop, and updates
NeuralNetwork/NeuralNetwork.java - Layer · Groups neurons into a stage and routes signals
NeuralNetwork/Layer.java - Neuron · Computes weighted sum, activation, and parameter updates
NeuralNetwork/Neuron.java
Activation
Polymorphic nonlinearity boundary
- Activation API · Shared contract for activation behavior
NeuralNetwork/ActivationFunction.java - ReLU · Rectified linear activation
NeuralNetwork/ReLU.java - LeakyReLU · ReLU variant with small negative slope
NeuralNetwork/LeakyReLU.java - Sigmoid · Smooth bounded activation
NeuralNetwork/Sigmoid.java - Tanh · Centered smooth activation
NeuralNetwork/Tanh.java - Linear · Pass-through activation
NeuralNetwork/Linear.java
Docs
Repository documentation and guidance
- README · Describes the learning task and flow
README.md - Module Info · Java module declaration
module-info.java - Package Info · Package-level documentation
NeuralNetwork/package-info.java
Connections 15
- Tester → Network: runs training · Entry point invokes the model workflow
- README → Tester: describes · Documentation points to the execution harness
- Network → Layer: contains · Network owns an ordered stack of layers
- Layer → Neuron: contains · Layer composes multiple neurons
- Neuron → Activation API: uses · Neuron depends on the activation strategy boundary
- Activation API → ReLU: implemented by · Concrete activation variant
- Activation API → LeakyReLU: implemented by · Concrete activation variant
- Activation API → Sigmoid: implemented by · Concrete activation variant
- Activation API → Tanh: implemented by · Concrete activation variant
- Activation API → Linear: implemented by · Concrete activation variant
- Network → Neuron: trains · Backpropagation ultimately updates neuron parameters
- Layer → Network: returns gradients · Layer propagates error signals back upstream
- Neuron → Layer: propagates gradients · Neuron participates in layer-level backward flow
- Module Info → Network: packages · Module boundary includes the neural network package
- Package Info → Network: documents · Package-level notes for the main model package