Skip to content

ayitas/logicflow

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

10 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

LogicFlow β€” Algorithm Visualizer

A high-performance, full-stack algorithm visualizer designed for backend engineers to analyze and compare algorithm efficiency in real-time through animated step-by-step execution traces.

Built with Go (Backend) and D3.js v7 (Frontend). Zero external Go dependencies.


About

LogicFlow visualizes how algorithms work internally β€” not just the final result, but every single comparison, swap, search check, and elimination rendered as an animated bar chart.

Reading pseudocode or Big-O notation alone doesn't give a clear picture of how algorithms actually behave under different data conditions. LogicFlow solves this by providing:

  • Step-by-step execution traces generated server-side by the Go backend, giving an accurate representation of each algorithm's internal operations.
  • Real-time performance metrics including comparison count, operation count, time complexity label, and actual server processing time in microseconds.
  • Visual comparison across algorithms on the same dataset, making it straightforward to reason about algorithmic trade-offs.
  • Multi-category support β€” currently supports sorting and searching algorithms, with architecture designed for future categories (graph, pathfinding, etc.).

Supported Algorithms

Sorting (6 algorithms)

Algorithm Time Complexity Notes
Bubble Sort O(nΒ²) Stable, early termination
Selection Sort O(nΒ²) Minimizes swaps
Insertion Sort O(nΒ²) Efficient for nearly sorted data
Merge Sort O(n log n) Stable, divide & conquer
Quick Sort O(n log n) avg Lomuto partition
Heap Sort O(n log n) In-place, guaranteed performance

Searching (4 algorithms)

Algorithm Time Complexity Notes
Linear Search O(n) Works on unsorted arrays
Binary Search O(log n) Requires sorted array
Jump Search O(√n) Block-based, requires sorted array
Interpolation Search O(log log n) avg Best for uniform distributions

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    Browser (Client)                   β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚  Vanilla JS + D3.js v7                        β”‚   β”‚
β”‚  β”‚  - SVG bar chart with animated transitions    β”‚   β”‚
β”‚  β”‚  - Category-aware UI (sorting vs searching)   β”‚   β”‚
β”‚  β”‚  - Real-time metric counters                  β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β”‚                    β”‚                                  β”‚
β”‚         GET /algorithms    POST /execute              β”‚
β”‚         (auto-discovery)   (execution trace)          β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                     β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                Go HTTP Server (:8080)                  β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚  handler/sort.go                               β”‚   β”‚
β”‚  β”‚  - POST /execute  β†’ run algorithm, return traceβ”‚   β”‚
β”‚  β”‚  - GET /algorithms β†’ list registered algos     β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β”‚                    β”‚                                  β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚  engine/registry.go (Plugin Registry)          β”‚   β”‚
β”‚  β”‚  - Algorithm interface (with Category)         β”‚   β”‚
β”‚  β”‚  - Register() / Get() / List()                 β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β”‚                    β”‚                                  β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚  algorithm/ (one file per algorithm)           β”‚   β”‚
β”‚  β”‚  - Sorting: bubble, selection, insertion,      β”‚   β”‚
β”‚  β”‚             merge, quick, heap                 β”‚   β”‚
β”‚  β”‚  - Searching: linear, binary, jump,            β”‚   β”‚
β”‚  β”‚               interpolation                    β”‚   β”‚
β”‚  β”‚  - [future categories...]                      β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Project Structure

logicflow/
β”œβ”€β”€ main.go                            # Entry point β€” HTTP server, routing, static file serving
β”œβ”€β”€ go.mod                             # Go module definition
β”‚
β”œβ”€β”€ internal/                          # Internal packages (unexported outside module)
β”‚   β”œβ”€β”€ engine/
β”‚   β”‚   β”œβ”€β”€ types.go                   # Shared types: Step, AlgorithmRequest, AlgorithmResponse, ExecuteParams
β”‚   β”‚   └── registry.go               # Algorithm interface + global plugin registry
β”‚   β”‚
β”‚   β”œβ”€β”€ algorithm/                     # Algorithm implementations (one file per algorithm)
β”‚   β”‚   β”œβ”€β”€ bubble.go                  # Bubble Sort β€” O(nΒ²)
β”‚   β”‚   β”œβ”€β”€ selection.go               # Selection Sort β€” O(nΒ²)
β”‚   β”‚   β”œβ”€β”€ insertion.go               # Insertion Sort β€” O(nΒ²)
β”‚   β”‚   β”œβ”€β”€ merge.go                   # Merge Sort β€” O(n log n)
β”‚   β”‚   β”œβ”€β”€ quick.go                   # Quick Sort β€” O(n log n)
β”‚   β”‚   β”œβ”€β”€ heap.go                    # Heap Sort β€” O(n log n)
β”‚   β”‚   β”œβ”€β”€ linear_search.go           # Linear Search β€” O(n)
β”‚   β”‚   β”œβ”€β”€ binary_search.go           # Binary Search β€” O(log n)
β”‚   β”‚   β”œβ”€β”€ jump_search.go             # Jump Search β€” O(√n)
β”‚   β”‚   └── interpolation_search.go    # Interpolation Search β€” O(log log n)
β”‚   β”‚
β”‚   └── handler/
β”‚       └── sort.go                    # HTTP handlers for POST /execute and GET /algorithms
β”‚
└── static/                            # Frontend (served as static files)
    β”œβ”€β”€ index.html                     # HTML5 β€” SVG container, controls, metrics panel
    β”œβ”€β”€ style.css                      # Dark theme, glassmorphism, responsive (mobile-first)
    └── script.js                      # D3.js v7 animation engine, category-aware UI

Tech Stack

Backend

Component Detail
Language Go 1.24
HTTP Server net/http (standard library, zero external dependencies)
Architecture Plugin/Registry pattern with category support
API Format JSON REST

Frontend

Component Detail
Language Vanilla JavaScript (no frameworks)
Visualization D3.js v7.9.0 β€” SVG-based bar chart with animated transitions
Styling Vanilla CSS β€” dark theme, glassmorphism, CSS Grid/Flexbox
Typography Google Fonts (Inter, JetBrains Mono)
Responsive Mobile-first with breakpoints for smartphone, tablet, and desktop

Getting Started

Prerequisites

  • Go >= 1.24

Run

git clone <repository-url>
cd logicflow
go run main.go

Expected output:

LogicFlow β€” Algorithm Visualizer
   Registered algorithms: 10

   [searching]
   - Binary Search             O(log n)
   - Interpolation Search      O(log log n)
   - Jump Search               O(√n)
   - Linear Search             O(n)
   [sorting]
   - Bubble Sort               O(nΒ²)
   - Heap Sort                 O(n log n)
   - Insertion Sort            O(nΒ²)
   - Merge Sort                O(n log n)
   - Quick Sort                O(n log n)
   - Selection Sort            O(nΒ²)

   Server listening on http://localhost:8080

Open http://localhost:8080 in your browser.

Build Binary (Optional)

go build -o logicflow .
./logicflow

Usage

Sorting Algorithms

  1. Select a sorting algorithm from the dropdown (grouped under "Sorting").
  2. Adjust array size and animation speed using the sliders.
  3. Click "Generate" for a new random array.
  4. Click "Start" to execute β€” the array is sent to the Go backend, which returns a step-by-step trace. The frontend animates through each operation.

Searching Algorithms

  1. Select a searching algorithm from the dropdown (grouped under "Searching").
  2. A "Search Target" input field appears β€” enter the value to find.
  3. Click "Start" to execute β€” the backend runs the search and returns a trace showing every comparison and elimination.
  4. When the animation finishes, a result banner shows whether the target was found (and at which index) or not found.

Note: Binary Search, Jump Search, and Interpolation Search require sorted arrays. The backend automatically sorts the array before searching.

Bar Colors

Sorting mode:

Color Meaning
Gray/Purple Default (unprocessed)
Yellow Currently being compared
Red Being swapped
Cyan Pivot / Partition point
Green Sorted (final position)

Searching mode:

Color Meaning
Gray/Purple Default
Yellow Currently being checked
Cyan Jump / Search range
Dimmed gray Eliminated from search
Green Found (target located)

API Reference

GET /algorithms

Returns a list of all algorithms registered in the backend registry, grouped by category.

Response:

[
  {
    "name": "binary_search",
    "display_name": "Binary Search",
    "category": "searching",
    "time_complexity": "O(log n)",
    "description": "Divides the sorted array in half repeatedly..."
  },
  {
    "name": "bubble_sort",
    "display_name": "Bubble Sort",
    "category": "sorting",
    "time_complexity": "O(nΒ²)",
    "description": "Repeatedly steps through the list..."
  }
]

POST /execute

Executes the specified algorithm and returns a step-by-step execution trace.

Request (sorting):

{
  "algorithm": "bubble_sort",
  "array": [5, 3, 1, 4, 2]
}

Request (searching):

{
  "algorithm": "binary_search",
  "array": [5, 3, 1, 4, 2],
  "target": 3
}

Response:

{
  "steps": [
    {
      "current_state": [1, 2, 3, 4, 5],
      "highlights": [2],
      "action_type": "found"
    }
  ],
  "metadata": {
    "execution_time_us": 2,
    "comparisons": 3,
    "operations": 3,
    "time_complexity": "O(log n)",
    "algorithm_name": "Binary Search",
    "category": "searching",
    "found_index": 2
  }
}

Adding a New Algorithm

The backend uses a plugin/registry pattern. Adding a new algorithm requires creating a single file β€” no modifications to any existing code.

Steps

1. Create a new file in internal/algorithm/:

package algorithm

import "logicflow/internal/engine"

type HeapSort struct{}

func init() {
    engine.Register(&HeapSort{})
}

func (h *HeapSort) Name() string           { return "heap_sort" }
func (h *HeapSort) DisplayName() string    { return "Heap Sort" }
func (h *HeapSort) Category() string       { return "sorting" }       // or "searching"
func (h *HeapSort) TimeComplexity() string { return "O(n log n)" }
func (h *HeapSort) Description() string    { return "Uses a binary heap..." }

func (h *HeapSort) Execute(params engine.ExecuteParams) ([]engine.Step, int, int) {
    data := engine.CopyArray(params.Array)
    target := params.Target  // only used by searching algorithms
    steps := make([]engine.Step, 0)
    comparisons, operations := 0, 0

    // Implement the algorithm, appending Steps for each operation...

    return steps, comparisons, operations
}

2. Restart the server. The new algorithm automatically appears in the frontend dropdown under the correct category.

How It Works

  • Go's init() functions execute automatically when a package is imported.
  • main.go imports _ "logicflow/internal/algorithm", which triggers all init() registrations.
  • The frontend fetches GET /algorithms on page load to discover all registered algorithms dynamically.
  • The UI automatically adapts based on the algorithm's category β€” showing target input for searching, adjusting legend colors, etc.

License

MIT

About

Interactive algorithm visualizer with a scalable Go backend and D3.js animated frontend.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors