Skip to content

Repository files navigation

↺ RevertEngine

A high-performance, real-time Undo/Redo state management service built with Node.js and Stack Data Structures.

RevertEngine provides a session-based history tracking architecture for interactive visual applications, canvas tools, collaborative whiteboards, and multi-step form builders. It leverages dual-stack memory management to handle state mutations, undo/redo operations, and real-time client sync.


🚀 Key Features

  • Dual-Stack Memory Architecture: Tracks Undo and Redo operation history independently per session.
  • Bounded Stack Memory Guard: Custom stack implementation with strict capacity limits to prevent memory leaks.
  • Real-time WebSockets: Instant state broadcast to connected clients upon push, undo, or redo.
  • Session Isolation: Supports multiple concurrent user sessions simultaneously using efficient key-value mapped stacks.
  • Automated Clearing: Automatically flushes the Redo stack when new state mutations occur post-undo.

🛠️ Tech Stack

  • Runtime: Node.js
  • Framework: Express / Fastify
  • Real-Time: Socket.io / ws
  • Data Structures: Custom Bounded Stack (JS/TS)
  • Testing: Jest / Vitest
  • Persistence (Optional): Redis

🧠 Data Structure Architecture

RevertEngine uses two bounded LIFO (Last-In-First-Out) Stacks for every active session:

[ New Client Action ]
│
▼
┌───────────────┐                             ┌───────────────┐
│  UNDO STACK   │ ──── (Trigger: Undo) ─────► │  REDO STACK   │
├───────────────┤                             ├───────────────┤
│ Action 3 (Top)│ ◄─── (Trigger: Redo) ────── │ Action 3 (Top)│
│ Action 2      │                             └───────────────┘
│ Action 1      │  *Note: Pushing a NEW action flushes Redo Stack completely.
└───────────────┘

Stack Complexity

Operation Time Complexity Space Complexity
push(action) $\mathcal{O}(1)$ $\mathcal{O}(N)$
undo() $\mathcal{O}(1)$ $\mathcal{O}(1)$
redo() $\mathcal{O}(1)$ $\mathcal{O}(1)$
peek() $\mathcal{O}(1)$ $\mathcal{O}(1)$

🌐 API Overview

REST Endpoints

#### `POST /api/v1/sessions`
Creates a new active history session.
```json
// Response
{
  "sessionId": "sess_89f1a23b",
  "maxDepth": 50,
  "createdAt": "2026-08-09T21:26:00.000Z"
}

POST /api/v1/sessions/:sessionId/undo Pops the latest state from the Undo stack and moves it to the Redo stack. POST /api/v1/sessions/:sessionId/redo Pops from the Redo stack and pushes back to the Undo stack.

📂 Project Structure:

RevertEngine/
├── src/
│   ├── ds/
│   │   ├── BoundedStack.js     # Custom Stack DS implementation
│   │   └── BoundedStack.test.js # Jest testing file 
│   ├── services/
│   │   └── SessionManager.js   # Manages active session stacks
│   ├── controllers/
│   │   └── historyController.js
│   ├── websockets/
│   │   └── socketHandler.js
│   └── app.js
├── package.json
└── README.md
└── load-test.js # K6 engine file to test the backend system with 10 virtual users
└── eslint.config.js # ESLint configuration for possible syntax error

🏃 Getting Started:

Prerequisites Node.js (v18+ recommended) npm

installation:

git clone [https://github.com/your-username/revert-engine.git](https://github.com/your-username/revert-engine.git)
cd revert-engine

npm install
npm test

npm run dev

⚡ Load Testing (k6)

Performance benchmarking conducted using k6 to validate system throughput and latency under concurrent load:

  • Concurrent Users (VUs): 10
  • Test Duration: 30s
  • Total Requests: 300
  • Success Rate: 100% (0 failures, status 200 OK)
  • Average Latency (http_req_duration): 3.96 ms
  • Median Latency: 2.01 ms
  • p95 Latency: 7.87 ms

🧪 Testing & Code Quality

  • ESLint: Enforces clean code standards, consistent syntax, and catches potential runtime errors early.
  • Jest: Provides unit tests for the core BoundedStack data structure to verify stack constraints, LIFO order, and bounded capacity algorithms.

Run Checks

# Run static analysis and linting
npx eslint .

# Run unit test suite
npm test

About

A high-performance, real-time Undo/Redo state management service built with Node.js and Stack Data Structures.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages