# bgrawi/jsflap architecture

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

- Interactive diagram: https://gitdiagram.com/bgrawi/jsflap
- Repository: https://github.com/bgrawi/jsflap

## Overview

##### Project type and purpose
- This is a front-end, full-stack-style open-source visualization tool for Formal Languages and Automata Theory, named jsflap.
- It provides an embeddable web component (index.html + Angular + D3) plus a core TypeScript library (src/) to model and render finite automata, Turing machines, etc.

##### File structure
- Top-level artifacts:
- Gulpfile.js, package.json, bower.json, tsconfig.json, karma.conf.js: build/test configuration
- index.html, assets/, templates/: runtime HTML/CSS assets and Angular partials
- bower_components/: third-party front-end deps (Angular, D3)
- src/: core TypeScript modules
- dist/: compiled output (jsflap.js, css)
- test/: unit tests (Karma + Jasmine)
- src/ is further subdivided into logical namespaces:
- Board (canvas, mouse events, command pattern for undo/redo)
- Graph (abstract graph interfaces, FA/TM graph implementations)
- Machine (state machines built on top of graphs)
- Transition, Node, Edge classes & lists, Utils (UUID), Point modules
- Visualization (D3/DOM wrappers, Angular directives for nodes/edges)

##### README for additional insights
- Confirmed: “JS Implementation for visualizing Formal Languages and Automata Theory.”

##### Final recommendations
- Interfaces (IGraph, IMachine, ICommand) and concrete implementations (FAGraph, FAMachine, AddNodeAtPointCommand).
- Architectural elements (build, dependencies, runtime, testing) appear to give a holistic system view.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Build & Test Tools
    subgraph "Build & Test Tools"
        Gulp["Gulpfile.js"]:::build
        NPM["package.json / tsconfig.json"]:::build
        BOWER["bower.json"]:::build
        KARMA["karma.conf.js"]:::build
    end

    %% External Libraries
    subgraph "External Libraries"
        ANG["AngularJS"]:::external
        D3["D3.js"]:::external
    end

    %% Core Library
    subgraph "Core Library" 
        direction TB
        subgraph "Model Layer"
            direction TB
            IGRAPH["IGraph"]:::core
            FAGRAPH["FAGraph"]:::core
            TMGRAPH["TMGraph"]:::core
            IMACHINE["IMachine"]:::core
            FAMACHINE["FAMachine"]:::core
            TMACHINE["TMachine"]:::core
            IMACHSTATE["IMachineState"]:::core
            FAMACHSTATE["FAMachineState"]:::core
            TMACHSTATE["TMachineState"]:::core
            ITRANS["ITransition"]:::core
            CTRANS["CharacterTransition"]:::core
            TTRANS["TuringTransition"]:::core
            NODE["Node"]:::core
            NLIST["NodeList"]:::core
            EDGE["Edge"]:::core
            ELIST["EdgeList"]:::core
            UUID["getUUID"]:::core
        end
        subgraph "Controller Layer"
            direction TB
            BOARD["Board"]:::core
            STACK["BoardInvocationStack"]:::core
            ICOMM["ICommand"]:::core
            ADDNODE["AddNodeAtPointCommand"]:::core
            ADDEDGE["AddEdgeFromNodeCommand"]:::core
            ERASENODE["EraseNodeCommand"]:::core
            ERASEEDGE["EraseEdgeCommand"]:::core
            MOVENODE["MoveNodeCommand"]:::core
            BSTATE["BoardState"]:::core
            BSETTINGS["BoardSettings"]:::core
        end
        subgraph "View Layer"
            direction TB
            NODEVIS["NodeVisualization"]:::core
            EDGEVIS["EdgeVisualization"]:::core
            VISCOL["VisualizationCollection"]:::core
            EDITTXT["EditableTextNode"]:::core
            FUTEDGE["FutureEdgeVisualization"]:::core
        end
    end

    %% Runtime Web App
    subgraph "Runtime Web App"
        INDEX["index.html"]:::runtime
        ASSETS["assets/"]:::runtime
        TEMPLATES["templates/"]:::runtime
    end

    %% Distribution Outputs
    subgraph "Distribution Outputs"
        JS["dist/js/jsflap.js"]:::dist
        JSTEST["dist/js/jsflap-withtests.js"]:::dist
        CSS["dist/css/jsflap.css"]:::dist
    end

    %% User Interaction
    User(("User")):::external

    %% Relationships
    User -->|interacts via| INDEX
    INDEX -->|loads| ANG
    INDEX -->|loads| D3
    BOWER -->|provides| ANG
    BOWER -->|provides| D3

    NPM -->|configures| Gulp
    BOWER -->|used by| Gulp
    Gulp -->|compiles| JS
    Gulp -->|compiles| CSS
    KARMA -->|runs tests on| JSTEST

    ANG -->|invokes| NODEVIS
    ANG -->|invokes| EDGEVIS
    ANG -->|uses| VISCOL
    D3 -->|renders| NODEVIS
    D3 -->|renders| EDGEVIS

    BOARD -->|executes| ICOMM
    ICOMM -->|mutates| BSTATE
    BSTATE -->|updates| VISCOL
    VISCOL -->|reads| IGRAPH
    VISCOL -->|reads| FAGRAPH
    VISCOL -->|reads| TMGRAPH

    ADDNODE -->|updates| NODE
    ADDEDGE -->|updates| EDGE
    ERASENODE -->|updates| NODE
    ERASEEDGE -->|updates| EDGE
    MOVENODE -->|updates| NODE

    INDEX -->|serves| ASSETS
    INDEX -->|uses templates| TEMPLATES

    %% Click Events
    click Gulp "https://github.com/bgrawi/jsflap/blob/master/Gulpfile.js"
    click NPM "https://github.com/bgrawi/jsflap/blob/master/package.json"
    click NPM "https://github.com/bgrawi/jsflap/blob/master/tsconfig.json"
    click BOWER "https://github.com/bgrawi/jsflap/blob/master/bower.json"
    click KARMA "https://github.com/bgrawi/jsflap/blob/master/karma.conf.js"
    click ANG "https://github.com/bgrawi/jsflap/blob/master/bower_components/angular/angular.js"
    click D3 "https://github.com/bgrawi/jsflap/blob/master/bower_components/d3/d3.js"
    click IGRAPH "https://github.com/bgrawi/jsflap/blob/master/src/Graph/IGraph.ts"
    click FAGRAPH "https://github.com/bgrawi/jsflap/blob/master/src/Graph/FAGraph.ts"
    click TMGRAPH "https://github.com/bgrawi/jsflap/blob/master/src/Graph/TMGraph.ts"
    click IMACHINE "https://github.com/bgrawi/jsflap/blob/master/src/Machine/IMachine.ts"
    click FAMACHINE "https://github.com/bgrawi/jsflap/blob/master/src/Machine/FAMachine.ts"
    click TMACHINE "https://github.com/bgrawi/jsflap/blob/master/src/Machine/TMachine.ts"
    click IMACHSTATE "https://github.com/bgrawi/jsflap/blob/master/src/Machine/IMachineState.ts"
    click FAMACHSTATE "https://github.com/bgrawi/jsflap/blob/master/src/Machine/FAMachineState.ts"
    click TMACHSTATE "https://github.com/bgrawi/jsflap/blob/master/src/Machine/TMachineState.ts"
    click ITRANS "https://github.com/bgrawi/jsflap/blob/master/src/Transition/Itransition.ts"
    click CTRANS "https://github.com/bgrawi/jsflap/blob/master/src/Transition/CharacterTransition.ts"
    click TTRANS "https://github.com/bgrawi/jsflap/blob/master/src/Transition/TuringTransition.ts"
    click NODE "https://github.com/bgrawi/jsflap/blob/master/src/Node.ts"
    click NLIST "https://github.com/bgrawi/jsflap/blob/master/src/NodeList.ts"
    click EDGE "https://github.com/bgrawi/jsflap/blob/master/src/Edge.ts"
    click ELIST "https://github.com/bgrawi/jsflap/blob/master/src/EdgeList.ts"
    click UUID "https://github.com/bgrawi/jsflap/blob/master/src/Utils/getUUID.ts"
    click BOARD "https://github.com/bgrawi/jsflap/blob/master/src/Board/Board.ts"
    click STACK "https://github.com/bgrawi/jsflap/blob/master/src/Board/BoardInvocationStack.ts"
    click ICOMM "https://github.com/bgrawi/jsflap/blob/master/src/Board/Command/ICommand.ts"
    click ADDNODE "https://github.com/bgrawi/jsflap/blob/master/src/Board/Command/AddNodeAtPointCommand.ts"
    click ADDEDGE "https://github.com/bgrawi/jsflap/blob/master/src/Board/Command/AddEdgeFromNodeCommand.ts"
    click ERASENODE "https://github.com/bgrawi/jsflap/blob/master/src/Board/Command/EraseNodeCommand.ts"
    click ERASEEDGE "https://github.com/bgrawi/jsflap/blob/master/src/Board/Command/EraseEdgeCommand.ts"
    click MOVENODE "https://github.com/bgrawi/jsflap/blob/master/src/Board/Command/MoveNodeCommand.ts"
    click BSTATE "https://github.com/bgrawi/jsflap/blob/master/src/Board/BoardState.ts"
    click BSETTINGS "https://github.com/bgrawi/jsflap/blob/master/src/Board/BoardSettings.ts"
    click NODEVIS "https://github.com/bgrawi/jsflap/blob/master/src/Visualization/NodeVisualization.ts"
    click EDGEVIS "https://github.com/bgrawi/jsflap/blob/master/src/Visualization/EdgeVisualization.ts"
    click VISCOL "https://github.com/bgrawi/jsflap/blob/master/src/Visualization/VisualizationCollection.ts"
    click EDITTXT "https://github.com/bgrawi/jsflap/blob/master/src/Visualization/EditableTextNode.ts"
    click FUTEDGE "https://github.com/bgrawi/jsflap/blob/master/src/Visualization/FutureEdgeVisualization.ts"
    click INDEX "https://github.com/bgrawi/jsflap/blob/master/index.html"

    %% Styles
    classDef build fill:#D0E6FF,stroke:#004080
    classDef core fill:#E6FFEA,stroke:#006600
    classDef runtime fill:#FFE6B3,stroke:#994C00
    classDef external fill:#F2F2F2,stroke:#666666
    classDef dist fill:#FDEDEC,stroke:#C0392B
```
