# robpruzan/algoviz architecture

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

- Interactive diagram: https://gitdiagram.com/robpruzan/algoviz
- Repository: https://github.com/robpruzan/algoviz

## Overview

##### Main Architectural Layers and Components
- Frontend:
- Pages & UI: This is primarily found under the “app” directory which contains pages for editing, creating, visualizing graphs, and sign-in/out (e.g., app/page.tsx, app/editor, app/visualizer).
- State Management & Context: Redux (in redux/) and various context providers (e.g., AuthProvider, CanvasProvider) in the “app” folder, plus custom hooks for canvas interactions and code storage.
- Backend/API:
- API Endpoints: The “app/api” folder houses dynamic routes for creating, editing, deleting, and fetching algorithms, playgrounds, and code execution (including a separate exec endpoint).
- Authentication: Managed via NextAuth integrated in the “app/api/auth/[…nextauth]” folder.
- Code Execution Server: An endpoint that takes code from the editor, processes it (likely via the “code-runner” module), and streams back the output to the browser for direct visualization on the canvas.
- Database and Persistence:
- Prisma is used for database interactions, as indicated by the “prisma” folder (with plenty of migration files) and the “lib/prisma.ts” file.
- Desktop Integration:
- There’s a “src-tauri” directory, which shows the project is also set up to be built as a desktop application using Tauri and Rust.
- Utility and Library Modules:
- “lib” contains utilities for canvas drawing, work with language snippets, and socket functionality.
- “hooks” and “context” provide custom logic for animations, network interactions, and algorithm visualization.

##### Interactions and Data Flow
- Frontend Communication: The frontend is made up of multiple pages (coding editor, graph visualizer, admin pages) that use React context providers, Redux for state management, and custom hooks to manage UI state and handle events.
- Code Execution: A dedicated endpoint under “app/api/exec/route.ts” handles code execution requests. Once the user submits code, the server processes it (using code-runner utilities) and returns visualized data (graph state changes, call stacks, etc.).
- Desktop Integration: Optionally, show a branch for Tauri which encapsulates a similar frontend view packaged into a desktop app through the “src-tauri” module.

##### Architectural Patterns and Technologies
- Full-Stack Separation: Clearly differentiate between the frontend (React/Next.js, Redux, Context) and the backend (Next.js API routes, custom code execution logic, database access via Prisma).
- Code Execution Pipeline: Emphasize that there is an interactive code execution server that takes user-submitted code, processes it, and then relays execution state back to the UI.
- Reusable Components and Hooks: Note the emphasis on modularity in the front end through context providers, UI components, and hooks.

##### Technologies and Libraries
- That Next.js underpins both the frontend and server-side routes.
- Use of Redux, NextAuth, Prisma, and Tauri, along with various custom hooks (for handling canvas interactions, code execution monitoring, etc.) and utility libraries (for canvas drawing, socket communication, etc.).

## Diagram (Mermaid)

```mermaid
flowchart TD
    user("User"):::user

    subgraph "Frontend Layer"
        subgraph "Pages & UI"
            F1("app/page.tsx"):::frontend
            F2("app/editor"):::frontend
            F3("app/visualizer"):::frontend
            F4("app/signin"):::frontend
            F5("app/create"):::frontend
            F6("app/admin"):::frontend
        end
        subgraph "Reusable UI Components"
            F7("components"):::frontend
            F8("components/ui"):::frontend
            F9("components/icons"):::frontend
        end
        subgraph "State Management & Context"
            F10("redux"):::frontend
            F11("app/AuthProvider.tsx"):::frontend
            F12("app/CanvasProvider.tsx"):::frontend
            F13("context"):::frontend
        end
    end

    subgraph "Backend/API Layer"
        subgraph "API Endpoints"
            A1("app/api/algo"):::backend
            A2("app/api/playground"):::backend
            A3("app/api/exec/route.ts"):::backend
            A4("app/api/auth/[...nextauth]"):::backend
        end
    end

    subgraph "Database Layer"
        D1("prisma"):::database
        D2("lib/prisma.ts"):::database
    end

    subgraph "Utility & Code Execution"
        U1("lib"):::utility
        U2("hooks"):::utility
        CR("code-runner"):::backend
    end

    subgraph "Desktop Integration"
        DT("src-tauri"):::desktop
    end

    %% User interactions
    user -->|"interacts"| F1
    user -->|"interacts"| DT

    %% Frontend to API interactions
    F1 -->|"callsAlgo"| A1
    F2 -->|"executesCode"| A3
    F3 -->|"fetchesPlayground"| A2
    F4 -->|"authenticates"| A4
    F5 -->|"createsPlayground"| A2
    F6 -->|"fetchesAlgo"| A1

    %% API to Database interactions
    A1 -->|"queries"| D1
    A2 -->|"queries"| D1
    A3 -->|"queries"| D1
    A4 -->|"queries"| D1

    A1 -->|"queries"| D2
    A2 -->|"queries"| D2
    A3 -->|"queries"| D2
    A4 -->|"queries"| D2

    %% Code execution connection
    A3 -->|"uses"| CR

    %% Frontend internal utility usage
    F7 -->|"renders"| U1
    F8 -->|"renders"| U1
    F9 -->|"renders"| U1

    F10 -->|"managesState"| U2
    F11 -->|"providesAuth"| U2
    F12 -->|"providesCanvas"| U2
    F13 -->|"providesContext"| U2

    %% Click Events
    click F1 "https://github.com/robpruzan/algoviz/blob/main/app/page.tsx"
    click F2 "https://github.com/robpruzan/algoviz/tree/main/app/editor"
    click F3 "https://github.com/robpruzan/algoviz/tree/main/app/visualizer"
    click F4 "https://github.com/robpruzan/algoviz/tree/main/app/signin"
    click F5 "https://github.com/robpruzan/algoviz/tree/main/app/create"
    click F6 "https://github.com/robpruzan/algoviz/tree/main/app/admin"
    click F7 "https://github.com/robpruzan/algoviz/tree/main/components"
    click F8 "https://github.com/robpruzan/algoviz/tree/main/components/ui"
    click F9 "https://github.com/robpruzan/algoviz/tree/main/components/icons"
    click F10 "https://github.com/robpruzan/algoviz/tree/main/redux"
    click F11 "https://github.com/robpruzan/algoviz/blob/main/app/AuthProvider.tsx"
    click F12 "https://github.com/robpruzan/algoviz/blob/main/app/CanvasProvider.tsx"
    click F13 "https://github.com/robpruzan/algoviz/tree/main/context"
    click A1 "https://github.com/robpruzan/algoviz/tree/main/app/api/algo"
    click A2 "https://github.com/robpruzan/algoviz/tree/main/app/api/playground"
    click A3 "https://github.com/robpruzan/algoviz/blob/main/app/api/exec/route.ts"
    click A4 "https://github.com/robpruzan/algoviz/blob/main/app/api/auth/[...nextauth]"
    click D1 "https://github.com/robpruzan/algoviz/tree/main/prisma"
    click D2 "https://github.com/robpruzan/algoviz/blob/main/lib/prisma.ts"
    click CR "https://github.com/robpruzan/algoviz/tree/main/code-runner"
    click DT "https://github.com/robpruzan/algoviz/tree/main/src-tauri"
    click U1 "https://github.com/robpruzan/algoviz/tree/main/lib"
    click U2 "https://github.com/robpruzan/algoviz/tree/main/hooks"

    %% Styles
    classDef frontend fill:#a2d2ff,stroke:#000,stroke-width:1px;
    classDef backend fill:#ffafcc,stroke:#000,stroke-width:1px;
    classDef database fill:#cdb4db,stroke:#000,stroke-width:1px;
    classDef desktop fill:#bde0fe,stroke:#000,stroke-width:1px;
    classDef utility fill:#ffc8dd,stroke:#000,stroke-width:1px;
    classDef user fill:#d0f4de,stroke:#000,stroke-width:1px;
```
