# vishalla/mathai-prototype architecture

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

- Interactive diagram: https://gitdiagram.com/vishalla/mathai-prototype
- Repository: https://github.com/vishalla/mathai-prototype

## Overview

##### Project type and purpose
- From the file tree and README ("MathAI"), this is a desktop‐based, PyQt-driven whiteboard application with an integrated convolutional neural network (CNN) for math expression recognition. The system consists of a front-end drawing UI, a networked server component, and a CNN inference pipeline.

##### File structure
- Top-level files:
- app.py, main.py: entry points for the application
- requirements.txt: Python dependencies (likely PyQt5, PyTorch, NumPy, etc.)
- weights.txt and model_parameters_for_CNN.pth: serialized model weights
- CNN_Model directory:
- Covonutional_neural_network/: core CNN training/inference code (CNNnetwork.py, model_pipeline.py) and utilities (augment_dataset.py, loaddataset.py, model_utils.py)
- Utils/: preprocessing, contour detection, prediction wrappers
- IPython notebooks: exploratory analysis (confusion_matrix.ipynb, pca.ipynb)
- Whiteboard directory:
- UI/: boardscene.py, mainwindow.py, board.ui form definitions
- Server/: TCPServer sub-module handling network sockets and invoking predictions, plus helpers (getip.py, netManage.py, tcpServerNet.py)
- board.py: client-side canvas logic

##### README for additional insights
- The README is minimal; project name “MathAI” implies a focus on mathematical handwriting recognition. All other context comes from directory naming and file content.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Application Layer
    subgraph "Client Application" 
        direction TB
        mwGUI["main_window.py<br>(PyQt Main Window)"]:::frontend
        gc["graphics_components.py<br>(Graphics Components)"]:::frontend
        bs["boardscene.py<br>(UI Controller)"]:::frontend
        mwUI["mainwindow.py<br>(UI Forms Controller)"]:::frontend
        boardClient["board.py<br>(Canvas & TCP Client)"]:::frontend
        boardUI["board.ui<br>(UI Form Definition)"]:::frontend
    end

    %% Entry Points
    app["app.py<br>(Entry Point)"]:::frontend
    main["main.py<br>(Entry Point)"]:::frontend

    %% Networking Layer (Client)
    nm["netManage.py<br>(Network Manager)"]:::frontend
    gip["getip.py<br>(IP Utility)"]:::frontend
    tcpClient["tcpServerNet.py<br>(Client TCP Handler)"]:::frontend

    %% Server Application Layer
    subgraph "Server Application"
        direction TB
        subgraph "TCPServer Core" 
            direction TB
            bsTCP["boardscenetcp.py<br>(TCP UI Controller)"]:::server
            mwTCP["mainwindowtcp.py<br>(TCP Main Window)"]:::server
            zv["zoomableview.py<br>(TCP Zoomable View)"]:::server
        end
        subgraph "Prediction Orchestrator"
            direction TB
            pred["prediction.py<br>(Prediction Orchestrator)"]:::server
            tools["tools.py<br>(Utility Tools)"]:::server
            utsp["usertsp.py<br>(User Session)"]:::server
        end
    end

    %% ML Inference Module
    subgraph "Machine Learning Module"
        direction TB
        subgraph "CNN Pipeline"
            direction TB
            cnnNet["CNNnetwork.py<br>(CNN Definition)"]:::ml
            modelPipe["model_pipeline.py<br>(Inference Pipeline)"]:::ml
            reqVars["required_variables.py<br>(Model Config)"]:::ml
        end
        subgraph "Preprocessing & Utilities"
            direction TB
            pre["pre_process.py<br>(Image Preprocessor)"]:::ml
            cont["contour.py<br>(Contour Detection)"]:::ml
            predUtil["pred.py<br>(Prediction Wrapper)"]:::ml
            evalExpr["Evaluate_expression.py<br>(Expression Evaluator)"]:::ml
        end
        subgraph "Dataset & Model Utils"
            direction TB
            aug["augment_dataset.py<br>(Data Augmentation)"]:::ml
            ld["loaddataset.py<br>(Dataset Loader)"]:::ml
            mu["model_utils.py<br>(Model Utilities)"]:::ml
        end
    end

    %% Data Stores
    subgraph "Data Stores"
        direction TB
        weightsFile["model_parameters_for_CNN.pth"]:::datastore
        weightsTxt["weights.txt"]:::datastore
    end

    %% Data Flows
    bs -->|"User Draw Event"| boardClient
    boardClient -->|"Serialize Strokes"| tcpClient
    tcpClient -->|"Send over TCP"| bsTCP
    bsTCP -->|"Raw Stroke Data"| pred
    pred -->|"Preprocess Image"| pre
    pre --> cont
    cont --> predUtil
    predUtil --> cnnNet
    cnnNet --> modelPipe
    modelPipe --> evalExpr
    evalExpr --> pred
    pred --> tools
    tools --> utsp
    utsp -->|"Inference Result JSON"| bsTCP
    bsTCP -->|"Send Response"| tcpClient
    tcpClient -->|"Receive Result"| boardClient
    boardClient -->|"Update UI Overlay"| bs

    %% Click Events for Client Application
    click mwGUI "https://github.com/vishalla/mathai-prototype/blob/main/Whiteboard/GUI/main_window.py"
    click gc "https://github.com/vishalla/mathai-prototype/blob/main/Whiteboard/GUI/graphics_componets.py"
    click bs "https://github.com/vishalla/mathai-prototype/blob/main/Whiteboard/UI/boardscene.py"
    click mwUI "https://github.com/vishalla/mathai-prototype/blob/main/Whiteboard/UI/mainwindow.py"
    click boardClient "https://github.com/vishalla/mathai-prototype/blob/main/Whiteboard/board.py"
    click boardUI "https://github.com/vishalla/mathai-prototype/blob/main/Whiteboard/board.ui"

    %% Click Events for Entry Points
    click app "https://github.com/vishalla/mathai-prototype/blob/main/app.py"
    click main "https://github.com/vishalla/mathai-prototype/blob/main/main.py"

    %% Click Events for Networking Layer
    click nm "https://github.com/vishalla/mathai-prototype/blob/main/Whiteboard/Server/netManage.py"
    click gip "https://github.com/vishalla/mathai-prototype/blob/main/Whiteboard/Server/getip.py"
    click tcpClient "https://github.com/vishalla/mathai-prototype/blob/main/Whiteboard/Server/tcpServerNet.py"

    %% Click Events for Server Application
    click bsTCP "https://github.com/vishalla/mathai-prototype/blob/main/Whiteboard/Server/TCPServer/boardscenetcp.py"
    click mwTCP "https://github.com/vishalla/mathai-prototype/blob/main/Whiteboard/Server/TCPServer/mainwindowtcp.py"
    click zv "https://github.com/vishalla/mathai-prototype/blob/main/Whiteboard/Server/TCPServer/zoomableview.py"
    click pred "https://github.com/vishalla/mathai-prototype/blob/main/Whiteboard/Server/TCPServer/prediction.py"
    click tools "https://github.com/vishalla/mathai-prototype/blob/main/Whiteboard/Server/TCPServer/tools.py"
    click utsp "https://github.com/vishalla/mathai-prototype/blob/main/Whiteboard/Server/TCPServer/usertsp.py"

    %% Click Events for ML Module
    click cnnNet "https://github.com/vishalla/mathai-prototype/blob/main/CNN_Model/Covonutional_neural_network/CNNnetwork.py"
    click modelPipe "https://github.com/vishalla/mathai-prototype/blob/main/CNN_Model/Covonutional_neural_network/model_pipleine.py"
    click reqVars "https://github.com/vishalla/mathai-prototype/blob/main/CNN_Model/Covonutional_neural_network/required_variables.py"
    click pre "https://github.com/vishalla/mathai-prototype/blob/main/CNN_Model/Utils/pre_process.py"
    click cont "https://github.com/vishalla/mathai-prototype/blob/main/CNN_Model/Utils/contour.py"
    click predUtil "https://github.com/vishalla/mathai-prototype/blob/main/CNN_Model/Utils/pred.py"
    click evalExpr "https://github.com/vishalla/mathai-prototype/blob/main/CNN_Model/Utils/Evaluate_expression.py"
    click aug "https://github.com/vishalla/mathai-prototype/blob/main/CNN_Model/Covonutional_neural_network/modelUttils/augment_dataset.py"
    click ld "https://github.com/vishalla/mathai-prototype/blob/main/CNN_Model/Covonutional_neural_network/modelUttils/loaddataset.py"
    click mu "https://github.com/vishalla/mathai-prototype/blob/main/CNN_Model/Covonutional_neural_network/modelUttils/model_utils.py"

    %% Click Events for Data Stores
    click weightsFile "https://github.com/vishalla/mathai-prototype/blob/main/CNN_Model/model_parameters_for_CNN.pth"
    click weightsTxt "https://github.com/vishalla/mathai-prototype/blob/main/weights.txt"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#333,stroke-width:1px
    classDef server fill:#d4edda,stroke:#333,stroke-width:1px
    classDef ml fill:#ffe5b4,stroke:#333,stroke-width:1px
    classDef datastore fill:#f8d7da,stroke:#333,stroke-width:1px
```
