A collection of mini-projects built from scratch to master Low-Level Design (LLD), Object-Oriented Programming (OOP), SOLID principles, and Data Structures & Algorithms (DSA). All projects are written in strictly-typed TypeScript and executed in a Node.js environment.
- Runtime: Node.js
- Language: TypeScript
- Execution:
tsx(for seamless TypeScript execution without build steps)
To run any of the individual project files, use the tsx command followed by the filename. For example:
npx tsx src/01-singleton-lru-cache.ts
- Filename:
01-singleton-cache.ts - Concepts: Singleton Pattern
- Description: An in-memory cache system that guarantees a single global instance using the Singleton pattern.
- Filename:
02-factory-notification.ts - Concepts: Factory Pattern (Creational), SOLID Principles (SRP, OCP, DIP).
- Description: A dynamic notification service (Email, SMS, Push) built to strictly adhere to SOLID principles. By using the Factory pattern and interfaces, the system avoids fragile
if/elseblocks and remains fully open for extension but closed for modification.
- Filename:
03-strategy-payment-gateway.ts - Concepts: Strategy Pattern (Behavioral), Encapsulation.
- Description: A modular checkout processor that delegates payment execution to interchangeable strategy classes (Credit Card, PayPal, Crypto). This allows the application to swap complex payment and verification algorithms dynamically at runtime without altering the core checkout logic.
-
Filename:
04-lru-cache.ts -
Concepts: Hash Maps, Doubly Linked Lists,
$O(1)$ Time Complexity. -
Description: A highly performant cache eviction algorithm. It combines a Hash Map for instant data lookups with a Doubly Linked List to track the chronological order of usage, ensuring both read and write operations execute in constant
$O(1)$ time.
- Filename:
05-observer-pub-sub.ts - Concepts: Observer Pattern (Behavioral), Event-Driven Architecture, Node.js Event Emitters.
- Description: Implements a Publish/Subscribe architecture from scratch. It demonstrates how to decouple application components so that a central "Publisher" can notify multiple "Subscribers" of state changes asynchronously, strictly adhering to the Open/Closed Principle.
- Filename:
06-queue-rate-limiter.ts - Concepts: Queue Data Structure, Sliding Window Algorithm, System Protection.
- Description: A security mechanism to protect APIs from DDoS attacks and spam. It uses a Sliding Window Log algorithm, combining a Hash Map with internal Queues to track user request timestamps and strictly limit the number of operations a single user can perform within a specific timeframe.
- Filename:
07-producer-consumer-queue.ts - Concepts: Producer-Consumer Pattern (Concurrency), Message Queues, Asynchronous Processing, Node.js Event Loop.
- Description: Demonstrates how to handle heavy computational tasks without blocking the Node.js main thread. Implements an in-memory message queue where "Producers" push background jobs and asynchronous "Consumers" (Workers) process them concurrently at their own pace.
- Filename:
08-facade-api-gateway.ts - Concepts: Facade Pattern (Structural), Microservices Orchestration, Principle of Least Knowledge.
- Description: Demonstrates how to hide a complex system of microservices (Auth, Inventory, Payment, Shipping) behind a single, unified interface. This prevents the frontend client from having to manage multiple network requests and handles complex orchestration on the backend.
- Filename:
09-adapter-pattern.ts - Concepts: Adapter Pattern (Structural), Interface Integration, Legacy Migration.
- Description: Demonstrates how to make two incompatible interfaces work together. By using a wrapper class, it translates the requests from your core application into a format that a legacy system or new third-party library can understand, without modifying either's source code.
- Filename:
10-state-pattern.ts - Concepts: State Pattern (Behavioral), Finite State Machines, Open/Closed Principle.
- Description: Eliminates massive
switchstatements when managing an object's lifecycle (like an Order). Each state (Pending, Paid, Shipped) is extracted into its own distinct class. The main Order object simply delegates behavior to its current state class, allowing it to transition seamlessly without bloated conditional logic.
- Filename:
11-builder-pattern.ts - Concepts: Builder Pattern (Creational), Method Chaining, Fluent Interfaces.
- Description: Demonstrates how to construct a complex object step-by-step. By returning the current instance (
this) from each method, it creates a "fluent interface" that allows developers to chain methods together cleanly, completely avoiding massive and confusing constructor functions.
--
-
Filename:
12-sliding-window.ts -
Concepts: Sliding Window, Dynamic Window Sizing,
$O(N)$ Time Optimization, Hash Sets. -
Description: Transforms
$O(N^2)$ nested loops into highly efficient$O(N)$ linear passes. Demonstrates how to maintain a dynamic "window" of elements to solve continuous subarray or substring problems, specifically finding the longest substring without repeating characters.
-
Filename:
13-two-pointers.ts -
Concepts: Two Pointers, Time Complexity Optimization
$O(N)$ , Space Complexity$O(1)$ . - Description: Eliminates nested loops when searching for pairs in a collection. By placing one pointer at the beginning and one at the end of a sorted array, we can systematically narrow down our search window to find a target sum or validate palindromes in a single linear pass without using extra memory.
-
Filename:
14-prefix-sum.ts -
Concepts: Precomputation,
$O(1)$ Range Queries, Array Caching. -
Description: Demonstrates how to instantly calculate the sum of elements within a specific range of an array. By preprocessing the array into a "running total" map, we eliminate the need for repetitive
$O(N)$ loops, allowing massive amounts of queries to be answered in constant time.
-
Filename:
15-binary-search.ts -
Concepts: Binary Search, Boundary Finding,
$O(\log N)$ Time Complexity. -
Description: Demonstrates how to adapt standard binary search to find the exact boundaries (first and last occurrence) of a target in a sorted array containing duplicates. This drops the search time from a linear
$O(N)$ scan to a logarithmic$O(\log N)$ search.
-
Filename:
16-sorting-strategies.ts -
Concepts: Strategy Pattern, Divide and Conquer, Time Complexity (
$O(N^2)$ vs $O(N \log N)$). - Description: Implements the three most important interview sorting algorithms (Bubble, Merge, and Quick Sort) using the Strategy Pattern. Demonstrates how to write decoupled, extensible algorithmic logic while contrasting slow nested loops with high-performance recursive sorting.
- Filename:
17-generic-tree.ts - Concepts: N-ary Nodes, Dynamic Children Arrays, Breadth-First Search (BFS) for locating nodes.
- Description: Implements a foundational, unrestricted tree structure where each node can have infinite children. Includes methods to search the tree and insert new nodes under specific parents, demonstrating how pointers physically connect data in memory.
-
Filename:
18-binary-search-tree.ts -
Concepts: Binary Nodes, Left/Right Pointers,
$O(\log N)$ Insertion and Search. - Description: Transforms a standard tree into a highly searchable data structure by enforcing a strict mathematical rule: all left children must be smaller than the parent, and all right children must be larger. Demonstrates how to dynamically route and insert nodes to maintain this balance.
- Filename:
19-tree-traversals.ts - Concepts: Pre-order, In-order, Post-order, Level-order, Recursion vs. Queues.
- Description: Implements the four essential tree traversal algorithms. Demonstrates how changing the placement of a single line of code in DFS drastically alters the output, and how BFS utilizes a Queue to sweep across a tree level-by-level.
-
Filename:
20-linked-lists.ts - Concepts: Singly Linked Lists, Pointers, In-Place Reversal, Floyd's Cycle Detection (Tortoise and Hare).
-
Description: Introduces the Linked List, a linear data structure where elements are not stored in contiguous memory. Demonstrates how to build, traverse, and completely reverse a list in
$O(N)$ time with$O(1)$ space, along with detecting infinite loops.
-
Filename:
21-graphs.ts - Concepts: Vertices (Nodes), Edges (Connections), Adjacency Lists, Undirected Networks.
-
Description: Introduces the Graph data structure, used to model complex networks like social media friendships or GPS maps. Demonstrates how to build an Adjacency List using a Hash Map to efficiently store and remove bi-directional connections in
$O(1)$ time.