# hassanzadehmahdi/and-or-gates-using-neural-networks architecture

> Architecture diagram of the GitHub repository hassanzadehmahdi/and-or-gates-using-neural-networks, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hassanzadehmahdi/and-or-gates-using-neural-networks
- Repository: https://github.com/hassanzadehmahdi/and-or-gates-using-neural-networks

## Overview

1. **Project shape**
   - This is a very small, self-contained Python repository.
   - There is no evidence of a multi-package application, web stack, or external service integration.
   - The entire functional architecture appears to live in a single script, `and-or.py`, with `README.md` providing the conceptual overview and usage example.

2. **Primary purpose**
   - The repo is an educational demonstration of how three classic single-layer learning rules can realize simple binary logic gates:
     - AND
     - OR
   - The algorithms named in the README are:
     - Hebbian learning
     - Perceptron learning
     - Adaline

3. **Core runtime boundary**
   - The main runtime boundary is the standalone Python script.
   - Inputs are not coming from a network, database, or UI layer; they are most likely hardcoded training examples for the truth tables of the AND/OR gates.
   - Output is likely printed to the console, as suggested by the README screenshot.

4. **Algorithm subsystems**
   - The script conceptually contains three parallel model implementations or training routines:
     - **Hebbian**: updates weights from observed input-output associations.
     - **Perceptron**: performs supervised binary classification with thresholded linear prediction.
     - **Adaline**: uses linear activation and error minimization over multiple epochs.
   - These are not separate services; they are algorithmic modules inside one script.

5. **Shared data flow**
   - The data flow is simple and likely repeated for each gate/algorithm combination:
     - define binary input patterns for the truth table
     - feed the patterns into a training routine
     - update weights and bias according to the chosen rule
     - evaluate the learned model on the same gate inputs
     - display the resulting outputs
   - This creates a small in-memory pipeline from fixed dataset to learned parameters to predicted gate behavior.

6. **Model state**
   - The key state held by the program is the learned parameter set:
     - weights
     - bias/threshold
   - For Adaline, training likely runs for a fixed number of epochs, explicitly called out in the README as 10 epochs.
   - The state is ephemeral and exists only during script execution.

7. **Behavioral separation**
   - The repo’s main separation is between:
     - **learning rule logic** and
     - **gate demonstration output**
   - In architectural terms, the code likely has small function-level boundaries rather than class-based or service-based boundaries.

8. **User-facing surface**
   - The only documented interface is command-line execution of `and-or.py`.
   - The README image shows that the program produces a visible result set, probably comparing predicted outputs for AND and OR across the three methods.

9. **Technology and infrastructure**
   - The only material technology implied is **Python**.
   - There is no indication of frameworks, ML libraries, containerization, tests, or deployment infrastructure.
   - This is a teaching/demo repo, not an operational system.

10. **What to show in an architecture diagram**
   - A useful diagram would be very simple:
     - one executable Python script
     - a small fixed truth-table dataset
     - three learning-rule branches
     - learned weights/biases
     - console output of AND/OR results
   - The important architectural fact is that all computation is local, synchronous, and in-process.

11. **Repository boundary**
   - `LICENSE` is legal metadata.
   - `README.md` is documentation.
   - `and-or.py` is the only implementation artifact.
   - So the repository boundary and the runtime boundary are essentially the same.

12. **Overall characterization**
   - Architecturally, this is a single-node, single-process educational program demonstrating classic neural network learning rules on a tiny binary classification problem.
   - The design emphasis is on algorithm comparison rather than modular system integration.

Main entry points: [`and-or.py`](https://github.com/hassanzadehmahdi/and-or-gates-using-neural-networks/blob/main/and-or.py) (and-or.py), [`README.md`](https://github.com/hassanzadehmahdi/and-or-gates-using-neural-networks/blob/main/README.md) (README)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["Core demo"]
  node_script["and-or.py<br/>python demo<br/>[and-or.py]"]
  node_truth_data[("Truth table<br/>fixed dataset")]
  node_hebbian(("Hebbian<br/>learning rule"))
  node_perceptron(("Perceptron<br/>learning rule"))
  node_adaline(("Adaline<br/>learning rule"))
  node_params{{"Model state<br/>weights/bias"}}
  node_outputs["Console output<br/>result display"]
end

node_readme["README<br/>documentation<br/>[README.md]"]

node_readme -->|"documents"| node_script
node_script -->|"uses"| node_truth_data
node_script -->|"runs"| node_hebbian
node_script -->|"runs"| node_perceptron
node_script -->|"runs"| node_adaline
node_truth_data -->|"trains"| node_hebbian
node_truth_data -->|"trains"| node_perceptron
node_truth_data -->|"trains"| node_adaline
node_hebbian -->|"produces"| node_params
node_perceptron -->|"produces"| node_params
node_adaline -->|"produces"| node_params
node_params -->|"prints"| node_outputs
node_script -->|"emits"| node_outputs

click node_readme "https://github.com/hassanzadehmahdi/and-or-gates-using-neural-networks/blob/main/README.md"
click node_script "https://github.com/hassanzadehmahdi/and-or-gates-using-neural-networks/blob/main/and-or.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_script,node_truth_data,node_hebbian,node_perceptron,node_adaline,node_params,node_outputs toneBlue
class node_readme toneNeutral
```

## Components

### Core demo

Single-script Python demo that trains simple logic gates with three learning rules.

- [and-or.py](https://github.com/hassanzadehmahdi/and-or-gates-using-neural-networks/blob/main/and-or.py): python demo · Standalone executable that runs the training and comparison flow. · `and-or.py`
- **Truth table**: fixed dataset · Hardcoded binary input/output patterns for AND and OR.
- **Hebbian**: learning rule · Updates weights from input-output associations.
- **Perceptron**: learning rule · Thresholded supervised classification routine.
- **Adaline**: learning rule · Linear activation trained over multiple epochs.
- **Model state**: weights/bias · Learned weights and bias or threshold produced by training.
- **Console output**: result display · Printed learned gate behavior for AND and OR.

### Other components

- [README](https://github.com/hassanzadehmahdi/and-or-gates-using-neural-networks/blob/main/README.md): documentation · Conceptual overview and usage example for the gate-learning demo. · `README.md`

## Connections

- README → and-or.py: documents · README explains how to run the demonstration.
- and-or.py → Truth table: uses · The script feeds fixed gate examples into the learning routines.
- and-or.py → Hebbian: runs · Executes the Hebbian learning path.
- and-or.py → Perceptron: runs · Executes the perceptron learning path.
- and-or.py → Adaline: runs · Executes the Adaline training path.
- Truth table → Hebbian: trains · Truth-table samples drive Hebbian updates.
- Truth table → Perceptron: trains · Truth-table samples drive perceptron updates.
- Truth table → Adaline: trains · Truth-table samples drive Adaline epochs.
- Hebbian → Model state: produces · Hebbian learning yields a parameter set.
- Perceptron → Model state: produces · Perceptron learning yields a parameter set.
- Adaline → Model state: produces · Adaline training yields a parameter set.
- Model state → Console output: prints · Learned parameters are evaluated and shown in the console.
- and-or.py → Console output: emits · The script renders the comparison output.
