# xcapaldi/whyknot architecture

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

- Interactive diagram: https://gitdiagram.com/xcapaldi/whyknot
- Repository: https://github.com/xcapaldi/whyknot

## Overview

##### Main Components of the System
- User Interface (GUI) Component:
– This is the graphical canvas (using Python’s Tkinter) where users interact. The main file (whyknot.py) is likely the entry point.
- Knot Analysis Component:
– The core functionality for analysis is delegated to the pyknotid backend. The module whyknot_identify.py appears responsible for preparing and sending drawn knot data for analysis.
- File/Data Management Component:
– The application writes output from the analysis to storage as CSV (storing knot parameters) and JSON files (storing raw knot coordinates). This file I/O is an essential back-end process.
- Optional/Alternate Interfaces:
– A file like whyknot-big-boys.py could be an alternative entry point or feature variant, perhaps meant for more advanced or batch operations.

##### Relationships and Data Flow
- The GUI module (whyknot.py) captures user input (mouse clicks to plot nodes) and displays feedback (e.g., closure lines, intersection indicators).
- When a knot is drawn, the captured coordinates are passed to the Knot Analysis Component (likely mediated by whyknot_identify.py) to perform parameter extraction using pyknotid.
- Once analyzed, the results (Gauss code, crossing number, Alexander polynomial) are written to a CSV file and the raw drawing data to JSON files. There is also a file-management aspect for creating/opening and saving knot data files.
- External Dependencies: pyknotid (an external library) is a key service for the knot analysis stage.

##### Architectural Design and Patterns
- The application follows a layered design:
- Presentation Layer: The Tkinter-based GUI.
- Application/Business Logic Layer: Knot drawing logic, event handling, and interfacing with the analysis module.
- Data Persistence Layer: Responsible for file I/O (CSV and JSON saving procedures).
- Design principles include separation of concerns and reusability. The GUI is kept separate from the analytical logic, which in turn is decoupled from data storage mechanics.

##### Technologies, Frameworks, and External Libraries
- Programming Language: Python 3.
- GUI Toolkit: Tkinter.
- External Library: pyknotid for knot parameter analysis.
- Packaging: Use of requirements.txt to manage dependencies.
- Additional tools: The project uses “black” for code styling, reinforcing code consistency.

- Another for processing/logic modules.
- A distinct style for external dependencies/services.
- Interactions like user inputs triggering analysis and subsequent data saving.

- Be as detailed as possible by noting not only the main components, but also the specific functionalities or roles:
- That the GUI handles drawing, zooming/panning, and event processing.
- That the analysis component invokes pyknotid functions to compute knot invariants.
- File operations (saving CSV and JSON outputs) and tie them to the corresponding action within the application.
- While avoiding over-complication, ensure that every file or module from the file tree that has a distinct responsibility is represented.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        A["GUI - Tkinter Canvas"]:::presentation
        A2["User Event Handlers"]:::presentation
        D["Alternate Interface"]:::presentation
    end

    %% Application/Business Logic Layer
    subgraph "Application Logic Layer"
        B["Knot Analysis Module"]:::logic
    end

    %% Data Persistence Layer
    subgraph "Data Persistence Layer"
        C1["CSV File Store"]:::persistence
        C2["JSON File Store"]:::persistence
    end

    %% External Dependency
    E["pyknotid Library"]:::external

    %% Connections
    A -->|"captures"| A2
    A2 -->|"sendsData"| B
    D -->|"alternateInput"| B
    B -->|"writeCSV"| C1
    B -->|"writeJSON"| C2
    B -->|"invoke"| E

    %% Click Events
    click A "https://github.com/xcapaldi/whyknot/blob/master/whyknot.py"
    click B "https://github.com/xcapaldi/whyknot/blob/master/whyknot_identify.py"
    click D "https://github.com/xcapaldi/whyknot/blob/master/whyknot-big-boys.py"

    %% Styles
    classDef presentation fill:#ADD8E6,stroke:#000,stroke-width:2px
    classDef logic fill:#90EE90,stroke:#000,stroke-width:2px
    classDef persistence fill:#FFFFCC,stroke:#000,stroke-width:2px
    classDef external fill:#D3D3D3,stroke:#000,stroke-width:2px
```
