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.
- Dual-Stack Memory Architecture: Tracks
UndoandRedooperation 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, orredo. - 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.
- Runtime: Node.js
- Framework: Express / Fastify
- Real-Time: Socket.io /
ws - Data Structures: Custom Bounded Stack (JS/TS)
- Testing: Jest / Vitest
- Persistence (Optional): Redis
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.
└───────────────┘
| Operation | Time Complexity | Space Complexity |
|---|---|---|
push(action) |
||
undo() |
||
redo() |
||
peek() |
#### `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.
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
Prerequisites Node.js (v18+ recommended) npm
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
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
- ESLint: Enforces clean code standards, consistent syntax, and catches potential runtime errors early.
- Jest: Provides unit tests for the core
BoundedStackdata structure to verify stack constraints, LIFO order, and bounded capacity algorithms.
# Run static analysis and linting
npx eslint .
# Run unit test suite
npm test