Taskflow is a real-time, collaborative task queue system built to teach backend engineering from first principles.
This repository intentionally avoids backend frameworks so learners can understand exactly what happens under the hood in production systems. Routing, request parsing, state management, and API behavior are implemented manually using core Node.js APIs.
Most tutorials start with frameworks and hide core mechanics. Taskflow does the opposite:
- Build with core Node.js first.
- Understand architecture and tradeoffs before abstractions.
- Learn data structures and algorithmic complexity in context.
- Introduce advanced capabilities (streaming, worker threads, WebSockets) progressively.
The result is a learning-first codebase that teaches both implementation and reasoning.
The code now includes Parts 1 through 10:
- Step 1: Raw Node.js HTTP server with manual routing
- Step 2: In-memory task store using JavaScript Map (O(1) Hash Map) and Singleton export
- Step 3: Priority Queue (Max-Heap) for O(log N) prioritized scheduling
- Step 4: Linked-List Task Dependency Chains with O(N) automated garbage collection (sweep)
- Step 5: OOP Middleware Chain of Responsibility (Authentication, Roles, Data Validation)
- Step 6: Global error handling with structured logging and request correlation
- Step 7: Memory leak detection, bounded caches, and memory observability
- Step 8: Worker Thread CPU offloading with a reusable worker pool
- Step 9: Streaming CSV / NDJSON exports with backpressure-safe pipelines
- Step 10: WebSocket live updates with heartbeats and task broadcast
Planned parts are documented in the roadmap below and expanded in the learner guides.
- Runtime: Node.js (No Babel, No TypeScript)
- Current external npm packages: none (zero-dependency design)
- WebSocket support is implemented natively with the Node.js
upgradepath and manual frame handling
Everything else is built natively.
server.js: HTTP server, route handling, JSON parsing, middleware execution, streaming, memory demos, and WebSocket upgrade handlingbenchmarks.js: Big O demonstration (Array.find vs Map.get)worker-thread-benchmark.js: Worker Thread benchmark for blocking vs parallel CPU workwebsocket-demo-client.js: Terminal WebSocket client for live update demossrc/store/TaskStore.js: Singleton in-memory state enginesrc/store/PriorityQueue.js: Max-Heap Queue data structure for ordering Tasks by prioritysrc/store/DependencyList.js: Singly Linked List data structure for Task prerequisite linkingsrc/services/MemoryManager.js: Bounded memory tracking, leak demo batches, and cleanupsrc/services/WorkerPool.js: Managed Worker Thread pool for CPU-heavy jobssrc/services/WebSocketHub.js: Native WebSocket broadcast and heartbeat managersrc/middleware/: Chain of Responsibility implementation for Auth, Permissions, and Validationssrc/config/env.js: Zero dependency.envparserlearner/README.md: Learning path and deep-dive documentation indexFULL_DEMO_RUNBOOK.md: End-to-end terminal demo instructions
- Node.js 18+ recommended (crypto.randomUUID support)
Create your .env file based on the example to supply the API tokens for the Middleware Chain:
cp .env.example .envnode server.jsExpected startup output:
Environment variables loaded natively.TaskFlow server is running on http://localhost:3000Listening for requests... (Press Ctrl+C to stop)
node benchmarks.jsYou should observe significantly faster Map lookup timing compared to Array.find for large collections.
Base URL: http://localhost:3000
Returns all tasks. Users and Admins can access this.
Returns the Max-Heap queue array structure highlighting task priority ordering.
Returns the absolute highest priority task without dequeuing it. O(1) read time.
Creates a new task. Requires Admin Token.
Request body (title and priority are validated):
{
"title": "Prepare sprint board",
"priority": 5,
"dependencies": []
}Updates an existing task by merging provided fields. Validates the payload and organically updates the Priority Queue and Dependency Linked List. Requires Admin Token.
Deletes a task and performs an O(N) sweep across all other tasks to cleanly remove its ID from their linked list dependencies to prevent ghost links! Requires Admin Token.
Streams all tasks as CSV using backpressure-safe streaming.
Streams all tasks as NDJSON for incremental consumption.
Lightweight endpoint for latency checks before and after heavy CPU work.
Runs CPU work on the main thread so you can demonstrate event loop blocking.
Runs the same CPU work in a Worker Thread and waits for completion.
Queues a Worker Thread job and returns a job ID for polling.
Returns heap, rss, external, and array buffer memory usage.
Creates an intentional leak batch for demonstration.
Creates a bounded cache batch that gets trimmed automatically.
Returns WebSocket hub statistics.
curl -i -X POST http://localhost:3000/tasks \
-H "Authorization: Bearer secret-admin-123" \
-H "Content-Type: application/json" \
-d '{"title":"Implement auth middleware","priority":10}'Replace TASK_A_ID with the ID generated in the last command! This automatically injects it into a native Linked List.
curl -i -X POST http://localhost:3000/tasks \
-H "Authorization: Bearer secret-admin-123" \
-H "Content-Type: application/json" \
-d '{"title":"Secondary Task","priority":5,"dependencies":["TASK_A_ID"]}'curl -i -H "Authorization: Bearer secret-user-123" http://localhost:3000/taskscurl -i -X PUT http://localhost:3000/tasks/TASK_A_ID \
-H "Authorization: Bearer secret-admin-123" \
-H "Content-Type: application/json" \
-d '{"priority":100}'curl -i http://localhost:3000/tasks/peekcurl -i -X DELETE http://localhost:3000/tasks/TASK_A_ID \
-H "Authorization: Bearer secret-admin-123"Each task currently contains:
id: UUID string generated by crypto.randomUUIDtitle: stringdescription: stringstatus: string (pending, in-progress, completed)priority: integer (higher number = higher execution urgency)dependencies: Array serialization of the activeDependencyListSingly Linked ListcreatedAt: ISO timestamp stringupdatedAt: ISO timestamp string
- Node HTTP server accepts request.
src/config/envparses.envmanually into global variables.- Stream body is read into JSON format globally for mutating requests.
- Middleware Chain of Responsibility executes: Auth -> Permission -> Validation.
- If the chain yields, URL/method handles endpoints.
TaskStoreprocesses updates:- Sets the O(1) Memory map.
- Safely sweeps and parses arrays to
DependencyList. - Modifies positions linearly in the
PriorityQueueMax Heap.
- JSON response sent explicitly.
Taskflow’s intended progression covers:
- Raw HTTP API in Node.js without frameworks (Done!)
- In-memory task store with Hash Map and complexity benchmark (Done!)
- Priority queue for prioritized scheduling (Done!)
- Linked-list dependency chains and recursive dependency resolution (Done!)
- Middleware chain (authentication, authorization, validation) (Done!)
- Global error handling and structured logging (Done!)
- Intentional memory leak demonstration and remediation (Done!)
- Worker Thread report generation for CPU-heavy processing (Done!)
- Streaming CSV export via Node streams (Done!)
- WebSocket live updates using native Node.js upgrade handling (Done!)
This repository currently has Steps 1 through 10 completely implemented natively!
- Data Structures: Priority Queues, Binary Heaps, Singly Linked Lists, Hash Maps (O(1) Time vs O(N) vs O(log N)).
- Design Patterns: Singleton State Stores, Object-Oriented Chain of Responsibility, Interceptors.
- Event Loop internals (Timers, Poll, Check phases)
- Call Stack and libuv responsibilities
Detailed guides are available in learner/README.md.
Run server on a free port by changing PORT in server.js.
Since Step 5 was introduced, modifying commands explicitly require an ADMIN_TOKEN placed inside the Authorization: Bearer <token> header as seen in the .env file.
Expected behavior. This is currently an in-memory repository designed to teach data structures without database overhead!