# ahmedosama07/netsim architecture

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

- Interactive diagram: https://gitdiagram.com/ahmedosama07/netsim
- Repository: https://github.com/ahmedosama07/netsim

## Overview

##### File Structure Analysis
- Top-level files:
- main.py – application entry point, initializes MVC and starts the Qt event loop
- README.md, .gitignore
- Directories:
- model/ (network_model.py) – graph data structures, file I/O, Dijkstra’s algorithm
- view/  (network_view.py)  – PyQt5 GUI, Matplotlib-based topology rendering, user interaction
- controller/ (network_controller.py) – glue code: event handlers, command processing, mediates between model and view

##### README Insights
- Clearly calls out MVC architecture
- Lists external dependencies: PyQt5 (GUI), Matplotlib (drawing), NetworkX (graph utilities)
- Describes features (node/edge editing, forwarding-table viewing, file load/save) and algorithmic design (custom Dijkstra, priority queue optimization)

##### Main Components
a. Model Layer
- Graph Data Store
- File I/O Module (parser/serializer for .txt format)
- Dijkstra’s Algorithm Engine
b. View Layer
- PyQt5 Application Window & Widgets (buttons, dialogs, canvas)
- Matplotlib Canvas for Topology Rendering
- User Interaction Handlers (mouse clicks, dialog inputs)
c. Controller Layer
- Event Dispatcher (translates GUI actions into model/view updates)
- Command Logic (add/remove nodes/edges, compute paths, update forwarding tables)
d. Application Entry Point
- main.py: instantiates Model, View, Controller; wires signals/slots
e. External Libraries
- PyQt5, Matplotlib, NetworkX

##### Component Relationships and Data Flows
- The View emits UI events (e.g., “add node” click) → Controller receives event
- Controller invokes Model APIs (e.g., model.add_node())
- Model updates its graph, returns data (e.g., new node list, shortest paths)
- Controller pushes updated data into View’s rendering methods
- View redraws the topology, updates forwarding-table dialogs
- File operations: View → Controller → Model → disk I/O → Model → Controller → View

##### Architectural Patterns and Principles
- MVC: strict separation of concerns
- Event-driven design via Qt’s signals/slots
- Modular components (each folder encapsulates one responsibility)
- Algorithm module isolated from GUI concerns

- Under Model, list subcomponents: Graph Store, Dijkstra Engine
- Under View, list subcomponents: PyQt5 GUI, Matplotlib Canvas

- Optionally number the main sequence of interactions (1: user click, 2: controller call, 3: model update, 4: view redraw)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Application Bootstrap
    main["main.py\n(Application Entry Point)"]:::external
    click main "https://github.com/ahmedosama07/netsim/blob/master/main.py"

    %% MVC Container
    subgraph "Network Simulator App"
        direction TB

        %% Model Layer
        subgraph "Model Layer" 
            direction TB
            modelPkg["model/__init__.py"]:::model
            click modelPkg "https://github.com/ahmedosama07/netsim/blob/master/model/__init__.py"
            modelNode["NetworkModel\n(model/network_model.py)"]:::model
            click modelNode "https://github.com/ahmedosama07/netsim/blob/master/model/network_model.py"
            graphStore["Graph Data Store"]:::model
            fileIOModule["File I/O Module"]:::model
            dijkstraEngine["Dijkstra’s Algorithm Engine"]:::model
        end

        %% Controller Layer
        subgraph "Controller Layer"
            direction TB
            controllerPkg["controller/__init__.py"]:::controller
            click controllerPkg "https://github.com/ahmedosama07/netsim/blob/master/controller/__init__.py"
            controllerNode["NetworkController\n(controller/network_controller.py)"]:::controller
            click controllerNode "https://github.com/ahmedosama07/netsim/blob/master/controller/network_controller.py"
            eventDispatcher["Event Dispatcher"]:::controller
            cmdLogic["Command Logic"]:::controller
        end

        %% View Layer
        subgraph "View Layer"
            direction TB
            viewPkg["view/__init__.py"]:::view
            click viewPkg "https://github.com/ahmedosama07/netsim/blob/master/view/__init__.py"
            viewNode["NetworkView\n(view/network_view.py)"]:::view
            click viewNode "https://github.com/ahmedosama07/netsim/blob/master/view/network_view.py"
            pyqtGui["PyQt5 GUI"]:::view
            pltCanvas["Matplotlib Canvas"]:::view
            uiHandlers["User Interaction Handlers"]:::view
        end
    end

    %% External Libraries
    subgraph "External Libraries"
        direction TB
        extPyQt5["PyQt5"]:::external
        extMpl["Matplotlib"]:::external
        extNetX["NetworkX"]:::external
    end

    %% File System
    fs["Configuration Files\n(config.txt)"]:::file

    %% User
    user["User"]:::external

    %% Documentation
    doc1["README.md"]:::external
    click doc1 "https://github.com/ahmedosama07/netsim/blob/master/README.md"
    doc2[".gitignore"]:::external
    click doc2 "https://github.com/ahmedosama07/netsim/blob/master/.gitignore"

    %% Data Flows
    user -->|"onNodeClick()"| uiHandlers
    uiHandlers -->|"signal" | eventDispatcher
    eventDispatcher -->|"computeShortestPath()"| cmdLogic
    cmdLogic -->|"model.add_node()/compute()"| modelNode
    modelNode -->|returns data| cmdLogic
    cmdLogic -->|"renderTopology()"| pyqtGui
    pyqtGui -->|"update canvas"| pltCanvas

    %% File I/O Flow
    pyqtGui -->|"load/save" | eventDispatcher
    eventDispatcher -->|"invoke I/O" | fileIOModule
    fileIOModule -->|"read/write disk" | fs
    fs -->|"data" | fileIOModule
    fileIOModule -->|"data" | eventDispatcher
    eventDispatcher -->|"update view" | pyqtGui

    %% MVC Bootstrap
    main -->|"instantiates" | modelNode
    main -->|"instantiates" | controllerNode
    main -->|"instantiates" | viewNode

    %% Dependencies on External Libraries
    pyqtGui -->|"uses"| extPyQt5
    pltCanvas -->|"uses"| extMpl
    modelNode -->|"uses"| extNetX

    %% Legend (Optional)
    classDef model fill:#B0C4DE,stroke:#333,stroke-width:1px
    classDef view fill:#98FB98,stroke:#333,stroke-width:1px
    classDef controller fill:#FFA500,stroke:#333,stroke-width:1px
    classDef external fill:#D3D3D3,stroke:#333,stroke-width:1px
    classDef file fill:#FFEFD5,stroke:#333,stroke-width:1px
```
