# abdalsattar-sys/ai-neural-networks-project architecture

> Architecture diagram of the GitHub repository abdalsattar-sys/ai-neural-networks-project, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-09-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/abdalsattar-sys/ai-neural-networks-project
- Repository: https://github.com/abdalsattar-sys/ai-neural-networks-project

## Overview

##### Project Type and Purpose
- This is a hybrid educational toolkit:
- A set of CLI Python modules implementing various neural networks (simple feedforward, advanced, CNN).
- A Flask-based web interface exposing model training and inference to end users in a browser.

##### File Structure
- Top‐level Python scripts:
- neural_network.py – simple feedforward NN
- advanced_neural_network.py – enhanced NN with multiple activations, logging, model persistence
- cnn_image_classifier.py – simple CNN example
- ai_web_interface.py – Flask server driving the web UI
- templates/ – holds the Flask HTML views (index.html)
- JSON files (cnn_model.json, trained_model.json, cnn_model.json) – serialized model weights/config
- requirements.txt – lists numpy, matplotlib, flask

##### Extract Additional Architecture Insights from README
- All neural-network modules share a common dependency on NumPy for numerical ops.
- Matplotlib is used by the web interface for plotting training loss/accuracy graphs.
- Web interface provides endpoints to:
- instantiate/train models (XOR, random data, CNN)
- perform predictions
- Plots of loss/accuracy over epochs
- save/load model JSON

##### Main Components and Their Interactions
a. Components:
1. Browser (Client UI)
2. Flask App (ai_web_interface.py)
3. Neural-Network Library – Python modules:
– SimpleNN (neural_network.py)
– AdvancedNN (advanced_neural_network.py)
– CNNClassifier (cnn_image_classifier.py)
4. Model Storage (JSON files)
5. Visualization (Matplotlib inside Flask)
b. Relationships:
– Browser → HTTP requests → Flask App
– Flask App:
- calls into NN modules to train/predict
- uses Matplotlib to generate plot images (PNG)
- reads/writes model JSON files for persistence
– Flask App → returns HTML + images + prediction results → Browser
c. Architectural Patterns:
– Monolithic server with clear separation between:
- Presentation Layer (Flask + HTML templates)
- Business Logic Layer (NN modules)
- Persistence Layer (JSON model files)
– Single process / single codebase (no microservices)
d. Key Technologies:
– Python 3.6+
– Flask (web framework)
– NumPy (linear algebra)
– Matplotlib (plotting)
– JSON (model serialization)

##### Detailed Elements
- In-memory objects: model instances during runtime
- Library dependencies: annotate Flask and NN modules with “+NumPy”, “+Matplotlib”
- Data flows labeled: “Training data (XOR, random, images)”, “Model weights JSON”, “Plot image”

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Layer"
        Browser["Browser"]:::ui
    end

    %% Backend Layer
    subgraph "Backend Layer"
        FlaskApp["Flask Application\n(ai_web_interface.py)"]:::backend
        subgraph "Neural Models"
            SimpleNN["SimpleNN Module\n(neural_network.py)"]:::backend
            AdvancedNN["AdvancedNN Module\n(advanced_neural_network.py)"]:::backend
            CNN["CNN Classifier Module\n(cnn_image_classifier.py)"]:::backend
        end
        Templates["HTML Templates\n(templates/)"]:::ui
        Index["index.html"]:::ui
    end

    %% Persistence Layer
    subgraph "Persistence Layer"
        ModelJSON1["Model Storage\n(cnn_model.json)"]:::storage
        ModelJSON2["Model Storage\n(trained_model.json)"]:::storage
    end

    %% Libraries
    subgraph "External Libraries"
        NumPy["NumPy"]:::lib
        Matplotlib["Matplotlib"]:::lib
    end

    %% Documentation
    subgraph "Documentation"
        Requirements["requirements.txt"]:::doc
        Readme["README.md"]:::doc
    end

    %% Data Flows
    Browser -->|HTTP GET/POST| FlaskApp
    FlaskApp -->|renders index.html| Templates
    Templates --> Index
    FlaskApp --> SimpleNN
    FlaskApp --> AdvancedNN
    FlaskApp --> CNN
    SimpleNN -->|read/write weights JSON| ModelJSON2
    AdvancedNN -->|read/write weights JSON| ModelJSON2
    CNN -->|read/write CNN JSON| ModelJSON1
    FlaskApp -->|generate plot image| Matplotlib
    FlaskApp -->|uses arrays| NumPy
    SimpleNN -->|uses arrays| NumPy
    AdvancedNN -->|uses arrays| NumPy
    CNN -->|uses arrays| NumPy
    FlaskApp -->|returns HTML + plot| Browser

    %% Click Events
    click FlaskApp "https://github.com/abdalsattar-sys/ai-neural-networks-project/blob/main/ai_web_interface.py"
    click SimpleNN "https://github.com/abdalsattar-sys/ai-neural-networks-project/blob/main/neural_network.py"
    click AdvancedNN "https://github.com/abdalsattar-sys/ai-neural-networks-project/blob/main/advanced_neural_network.py"
    click CNN "https://github.com/abdalsattar-sys/ai-neural-networks-project/blob/main/cnn_image_classifier.py"
    click Templates "https://github.com/abdalsattar-sys/ai-neural-networks-project/tree/main/templates/"
    click Index "https://github.com/abdalsattar-sys/ai-neural-networks-project/blob/main/templates/index.html"
    click ModelJSON1 "https://github.com/abdalsattar-sys/ai-neural-networks-project/blob/main/cnn_model.json"
    click ModelJSON2 "https://github.com/abdalsattar-sys/ai-neural-networks-project/blob/main/trained_model.json"
    click Requirements "https://github.com/abdalsattar-sys/ai-neural-networks-project/blob/main/requirements.txt"
    click Readme "https://github.com/abdalsattar-sys/ai-neural-networks-project/blob/main/README.md"

    %% Styles
    classDef ui fill:#CCE5FF,stroke:#005B99,color:#000;
    classDef backend fill:#D5F5E3,stroke:#27AE60,color:#000;
    classDef storage fill:#FCF3CF,stroke:#F1C40F,color:#000;
    classDef lib fill:#FADBD8,stroke:#C0392B,color:#000;
    classDef doc fill:#E8DAEF,stroke:#8E44AD,color:#000;
```
