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 currently includes Parts 1 through 5:
- 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)
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)
- Planned single exception: ws (introduced in final WebSocket step)
Everything else is built natively.
server.js: HTTP server, route handling, JSON parsing, middleware executionbenchmarks.js: Big O demonstration (Array.find vs Map.get)src/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/middleware/: Chain of Responsibility implementation for Auth, Permissions, and Validationssrc/config/env.js: Zero dependency.envparserlearner/README.md: Learning path and deep-dive documentation index
- 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.
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
- Intentional memory leak demonstration and remediation
- Worker Thread report generation for CPU-heavy processing
- Streaming CSV export via Node streams
- WebSocket live updates using ws
This repository currently has Steps 1 through 5 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!