Skip to content

Code

Every project in the handbook with source code. Open one to read it in the editor, or press ⌘P to jump to any file.

Projects
122
Files
1304
Lines
85,065
Languages
6Java, TypeScript, TSX, JavaScript, JSX, Python
122 projects
  • OOP Notes

    Classes, objects, the four pillars, abstract vs interface

    Java · 8 files · 109 linesClient.java
  • UML Class Diagrams: Reading and Drawing the Boxes

    class box, visibility markers, attribute and method syntax, interface, abstract class, enum, and the three perspectives

    Java · 8 files · 109 linesClient.java
  • Class Relationships: Association, Aggregation and Composition

    is-a, has-a, uses-a; association, aggregation, composition; UML symbols

    Java · 8 files · 109 linesClient.java
  • Composition vs Inheritance

    The single most useful design decision to get right

    Java · 8 files · 109 linesClient.java
  • Coupling and Cohesion

    How much classes depend on each other, how well a class's parts belong together, and why low coupling with high cohesion makes code easy to change and test

    Java · 8 files · 109 linesClient.java
  • Interfaces

    An interface is a contract. It lists method names and parameters, and implementing classes write the code. Newer Java also allows a few methods with a body.

    Java · 1 file · 82 linesConceptsDemo.java
  • Implementing interfaces (implements)

    When a class implements an interface, it promises to provide a concrete implementation (method body) for every method declared in that interface.

    Java · 1 file · 82 linesConceptsDemo.java
  • Abstract classes and inheritance

    Inheritance means one class is a subtype of another: the child extends the parent and gets its fields and methods. The child can add new ones or override existing methods.

    Java · 1 file · 82 linesConceptsDemo.java
  • Encapsulation

    Encapsulation means keeping an object’s data (state) hidden from the outside and only allowing access through controlled methods.

    Java · 1 file · 82 linesConceptsDemo.java
  • Constructors

    A constructor is a block of code that runs when you create an object with new ClassName(...). It has the same name as the class and no return type.

    Java · 1 file · 82 linesConceptsDemo.java
  • static and final

    static means “belongs to the class, not to each object.”

    Java · 1 file · 82 linesConceptsDemo.java
  • Method overriding and polymorphism

    Overriding means a subclass (or a class that implements an interface) provides its own implementation of a method that already exists in the parent or interface.

    Java · 1 file · 82 linesConceptsDemo.java
  • Generics

    Generics let you write classes and methods that work with a type you specify later, so the compiler can check types and you avoid casting.

    Java · 1 file · 82 linesConceptsDemo.java
  • Exception handling

    Exceptions are Java’s way of signaling that something went wrong (invalid input, missing resource, unsupported operation, etc.). If not handled, they can stop the program.

    Java · 1 file · 82 linesConceptsDemo.java
  • Cloneable and clone()

    Cloneable is a marker interface in Java (no methods). If a class implements Cloneable, it is allowed to use the default cloning behavior from Object.clone().

    Java · 1 file · 82 linesConceptsDemo.java
  • Inner and static nested classes

    A class defined inside another class is a nested class.

    Java · 1 file · 82 linesConceptsDemo.java
  • Dependency injection

    Dependency injection means a class does not create its dependencies itself. Instead, they are passed in from outside (e.g. via constructor or setter).

    Java · 1 file · 82 linesConceptsDemo.java
  • Fluent API and annotations

    A fluent API lets you call multiple methods in a row on the same object, usually by having each method return this (the same object).

    Java · 1 file · 82 linesConceptsDemo.java
  • Enums

    An enum is a class with a fixed list of instances. You use it when a value can only be one of a few known options, like a direction, a status, or a size.

    Java · 1 file · 82 linesConceptsDemo.java
  • equals() and hashCode()

    equals() decides when two objects are the same value. hashCode() helps HashMap and HashSet find them. Override both.

    Java · 1 file · 82 linesConceptsDemo.java
  • Lambdas, functional interfaces and streams

    A lambda is a short way to write a function without giving it a name or wrapping it in a class.

    Java · 1 file · 82 linesConceptsDemo.java
  • Collections: which one to pick

    Every collection in Java sits under one of these interfaces.

    Java · 1 file · 82 linesConceptsDemo.java
  • Concurrency basics

    After an LLD design, the next question is almost always what happens if two users do this at the same time. This note covers the minimum Java tools to answer it.

    Java · 1 file · 82 linesConceptsDemo.java
  • Strings and immutability

    Why String can never change, how the string pool works, when to use StringBuilder, and how to write your own immutable class with defensive copies.

    Java · 1 file · 82 linesConceptsDemo.java
  • Memory, pass by value and garbage collection

    Stack vs heap, why Java is always pass by value, boxing traps like the Integer cache, how garbage collection decides what to free, and how Java apps still leak memory.

    Java · 1 file · 82 linesConceptsDemo.java
  • Optional and null handling

    Why null causes so many bugs, how to use Optional well (and where not to), failing fast with requireNonNull, empty collections, and the Null Object pattern.

    Java · 1 file · 82 linesConceptsDemo.java
  • Records, sealed classes and pattern matching

    Modern Java for LLD rounds. Records for value objects, sealed types for a closed set of cases, pattern matching, switch expressions, and when var helps or hurts.

    Java · 1 file · 82 linesConceptsDemo.java
  • SRP - The Single Responsibility Principle

    A class should have one reason to change, which really means one group of people who would ask you to change it.

    Java · 6 files · 96 linesMain.java
  • OCP - The Open/Closed Principle

    Add new behaviour by adding new code, not by editing code that already works. Usually one interface and one class per variant.

    Java · 9 files · 107 linesMain.java
  • LSP - The Liskov Substitution Principle

    If code works with a base type, it must keep working with any subtype. No surprise exceptions, no stricter inputs, no weaker promises.

    Java · 9 files · 95 linesMain.java
  • Interface Segregation Principle (ISP)

    No caller should be forced to depend on methods it never uses. Split fat interfaces by the role each caller plays.

    Java · 11 files · 131 linesMain.java
  • Dependency Inversion Principle (DIP)

    Business logic should not depend on details like SMS vendors or databases. Both depend on an interface that the business side owns.

    Java · 9 files · 118 linesMain.java
  • Low-Level Design (LLD): Parking Lot System

    The classic first LLD problem, built in layers with controllers, services and repositories, and a Java simulation you can run.

    Java · 25 files · 2,356 linesParkingLotSimulation.java
  • Zomato Food Delivery App (Low Level Design)

    Low level design notes for a simplified Zomato style food ordering app.

    Java · 19 files · 747 linesMain.java
  • Design Splitwise (Low Level Design)

    Design an app that tracks shared expenses in a group, splits them equally, by exact amount or by percent, and works out who should pay whom.

    Java · 12 files · 418 linesMain.java
  • Design an LRU Cache (Low Level Design)

    Build a least recently used cache in Java with O(1) get and put, a hand made linked list and hash map, a swappable eviction policy and a simple thread safe wrapper.

    Java · 9 files · 326 linesMain.java
  • Design a Rate Limiter (Low Level Design)

    Design the classes of an in-app rate limiter with token bucket, fixed window and sliding window log behind one interface, plus per user and per API rules.

    Java · 12 files · 378 linesMain.java
  • Design a Logging Framework (Low Level Design)

    Design a small logging framework with levels, loggers, console, file and in-memory appenders, formatters, a singleton manager and an async appender.

    Java · 12 files · 469 linesMain.java
  • Design a Pub/Sub Message Broker (Low Level Design)

    Build a small in-memory message broker where publishers post to topics, every subscriber gets its own queue and thread, and a slow subscriber never holds up the rest.

    Java · 7 files · 298 linesMain.java
  • Design a Meeting Room Booking System (Low Level Design)

    Design a small booking system for meeting rooms, with a one line overlap check, a sorted calendar per room, a lock per room against double booking, and a pluggable way to pick the room.

    Java · 10 files · 371 linesMain.java
  • Toast Notifications

    Show stacked toast messages that close on their own after 5 seconds or on the close button, with one timer per toast kept in a ref.

    JSX · 4 files · 208 lines
  • Pagination

    Fetch a list from an API page by page and render numbered page controls with previous and next buttons.

    JSX · 6 files · 156 lines
  • Modal

    Build a modal that opens from a button and closes on its Close button or a mousedown outside the box, using a reusable useClickOutside hook.

    JSX · 5 files · 146 lines
  • Image Carousel

    Cycle through images with previous and next buttons, wrap around at both ends, and auto-advance on a timer that pauses on hover.

    JSX · 6 files · 406 lines
  • Search Bar with Typeahead

    Search products as the user types, wait 1 second before each request, cancel stale requests, and cache the last 10 queries in a ref.

    JSX · 5 files · 336 lines
  • Accordion

    Render a list of questions where clicking one shows its answer, with each item holding its own open or closed state.

    JSX · 7 files · 162 lines
  • Tabs

    Render tab buttons from data and show the content of the active tab, keeping the active index in state.

    JSX · 7 files · 138 lines
  • Persisting State in localStorage

    Keep React state in localStorage with a typed usePersistedState hook, including JSON parsing and safe fallbacks.

    TSX, TypeScript · 7 files · 111 lines
  • useTimeout Hook

    Write a useTimeout hook that restarts when the delay changes but not when the callback changes, using a ref for the latest callback.

    JSX · 4 files · 44 lines
  • Lite Excel Sheet

    Build a small spreadsheet grid with editable cells, add rows and columns, and keep the grid as a 2D array in state.

    JSX · 5 files · 257 lines
  • Drag and Drop Board

    Move tasks between columns with the native HTML drag and drop events, tracking the dragged item in a ref.

    JSX · 5 files · 143 lines
  • Traffic Light

    Cycle green, yellow and red lights every 2 seconds with one setInterval and a modulo on the active index.

    JSX · 6 files · 70 lines
  • Day View Calendar

    Render a 24 hour day view with hourly slots and place each event block by its start and end time, at 5rem per hour.

    JSX · 8 files · 154 lines
  • Virtualized List

    Render only the rows that are visible in a long list by computing the window from scroll position and row height.

    JSX · 4 files · 74 lines
  • Stepper

    Show numbered steps joined by lines, highlight every step up to the current one, and move between steps with Back and Continue buttons.

    JSX · 5 files · 243 lines
  • Todo List

    Add, complete and delete todos, and keep the list in localStorage so it survives a refresh.

    JSX · 6 files · 272 lines
  • Controlled Tabs

    A tabs component that tells its parent which tab is active through an onTabChange callback.

    JSX · 5 files · 120 lines
  • File Upload with Progress

    Pick or drop a file, upload it with axios, and show progress, success and error states in TypeScript.

    TSX, TypeScript · 5 files · 166 lines
  • Memory Game

    Flip numbered cards on a 6 by 6 grid to find matching pairs, lock the board while two cards are open, and flip mismatches back after 3 seconds.

    JSX, JavaScript · 7 files · 156 lines
  • Progress Bar

    Animate a progress bar to a given percentage with a CSS transform, and expose the value to screen readers.

    JSX · 5 files · 69 lines
  • File Explorer

    Render a recursive folder tree where folders expand and collapse, and files and folders can be added or deleted.

    JSX · 7 files · 381 lines
  • Trello Board

    A Trello style board where you add lists and cards, archive a list, and drag a card onto another list, with board data kept in a Redux store.

    JSX, JavaScript · 19 files · 1,301 lines
  • Real-Time Chat

    Chat in rooms with a Socket.IO server that relays messages and a React client that keeps login, room and messages in Redux Toolkit.

    TypeScript, TSX, JavaScript · 21 files · 719 linesserver.js
  • Movie Seat Selection

    Pick cinema seats on a generated layout with seat categories, booked seats and a running total, built in TypeScript.

    TSX, TypeScript · 11 files · 679 lines
  • Transfer List

    Move checked items between two lists with buttons for selected items and for all items.

    JSX · 5 files · 214 lines
  • Job Board

    Load job posts from the Hacker News API six at a time with a Load more button, fetching details for each id.

    JSX · 4 files · 202 lines
  • Nested Checkboxes

    A checkbox tree where checking a parent checks all children and a parent becomes checked once all its children are.

    JSX, JavaScript · 4 files · 178 lines
  • Typing Effect

    Type a sentence one character at a time with a blinking cursor, using a timer that cleans up after itself.

    JSX · 4 files · 62 lines
  • Chips Input

    Turn typed text into chips on Enter, ignoring empty input, and remove a single chip with its X button.

    JSX · 5 files · 138 lines
  • Instagram Stories

    Upload images as stories that expire after 15 seconds, view them in a modal, and release object URLs to avoid leaks.

    JSX · 5 files · 413 lines
  • Star Rating

    A reusable star rating with hover preview, half stars, keyboard support and read-only mode.

    JSX · 5 files · 297 lines
  • Nested Comments

    A Reddit style comment tree with replies at any depth, delete, and relative timestamps, using recursive components.

    JSX, JavaScript · 9 files · 482 lines
  • Talking to an LLM from Your Application

    An LLM is a capability, a GenAI app is software built around it. Call a model from Postman, read the response and token usage, then build a ticket summariser in Spring Boot with Spring AI, Node.js and Python.

    Java, JavaScript, Python · 27 files · 1,518 linesREADME.md
  • Building a Chatbot: Context, Memory, Streaming and Hallucinations

    A model call is not a conversation. Roles, system prompts, app memory, the context window, streaming and hallucination, with a support chatbot built in Spring AI, Node.js and Python.

    Java, JavaScript, Python · 28 files · 2,417 linesREADME.md
  • Introduction to AI Agents: Tools, Tool Calling and the Agent Loop

    An LLM writes text but cannot act. Tools give it hands. Tool definitions, the tool calling loop, information vs action tools, and a sandboxed website builder agent in Spring AI, Node.js and Python.

    Java, JavaScript, Python · 39 files · 4,393 linesREADME.md
  • Streaming AI Responses: From Tokens to a Live Chat

    Why a reply that streams feels faster even when it is not. Generation vs delivery, time to first token, chunked HTTP, SSE vs WebSockets, Flux in Spring AI, saving history after the stream, and reading it in the browser.

    JavaScript, Python, Java · 30 files · 3,131 linesREADME.md
  • Vector Embeddings from First Principles

    How a computer can hold meaning as numbers. Vectors, dimensions, distance, dot product and cosine similarity, why hand made features fail, and how training turns context into embeddings.

    Python, Java, JavaScript · 29 files · 3,262 linesMain.java
  • Semantic Movie Search with Embeddings

    Build a small Netflix style search. Embedding model vs chat model, why sending the whole catalogue to an LLM fails, precomputed vectors, top K by cosine, and similar movies, in Spring AI, Node.js and Python.

    Java, JavaScript, Python · 33 files · 3,449 linesREADME.md
  • Vector Search: Brute Force KNN and the Indexing Problem

    What breaks when the movie search grows from 30 to millions of vectors. Exact vs similarity lookup, brute force top K, the real cost in compute and memory, and why B-trees and k-d trees stop helping in high dimensions.

    Python, Java, JavaScript · 32 files · 3,820 linesMain.java
  • Vector Databases and ANN: IVF, HNSW and Product Quantization

    How vector databases search millions of vectors fast by not looking at most of them. Approximate search and recall@K, IVF clusters, HNSW graphs, quantization and PQ, metadata filters, and pgvector.

    Java, Python, JavaScript · 58 files · 5,356 linesMain.java
  • Retrieval Augmented Generation (RAG): Chunking, Retrieval and Citations

    A support bot that answers from company policy documents. Chunking, embedding, a pgvector store, retrieval, prompt stuffing with citations, and the ways RAG fails in production.

    Java, JavaScript, Python · 41 files · 3,102 linesREADME.md
  • Advanced RAG: Chunking, Hybrid Search and Reranking

    Why basic RAG misses rules and exact product codes, and how to fix retrieval with structural chunking, top K, thresholds, metadata filters, BM25 hybrid search, RRF, reranking and context engineering.

    Java, JavaScript, Python · 54 files · 4,217 linesREADME.md
  • Structured Output: Typed JSON From an LLM

    Turn one sentence into a typed MeetingDetails object your code can trust. Schemas, strict mode, the checks a schema cannot do, retries with feedback, in Spring AI, Node.js and Python.

    Java, JavaScript, Python · 31 files · 2,463 linesREADME.md
  • Model Context Protocol (MCP): Hosts, Clients and Servers

    Why every AI app rewriting the same tools does not scale, and how MCP fixes it. Hosts, clients and servers, tools/list and tools/call, and a task server with an LLM client in Spring AI, Node.js and Python.

    JavaScript, Python, Java · 35 files · 2,574 linesREADME.md
  • MCP Beyond Tools: Resources and Prompts

    An MCP server offers more than tools. Resources give the app context, prompts give the user ready workflows. Who controls each, how list and read work, and a task server and client in three stacks.

    Java, JavaScript, Python · 44 files · 3,246 linesREADME.md
  • Multimodal Vision Chat: Sending Images to an LLM

    How a model reads an image (patches, a vision encoder, an adapter), what image tokens cost, size limits, upload safety, and a vision chat with a browser page in Spring AI, Node.js and Python.

    Java, JavaScript, Python · 30 files · 2,332 linesREADME.md
  • Testing an AI Agent: Deterministic Evals and LLM-as-a-Judge

    An eval runner for a support agent with RAG and tools: a trace, a golden dataset, four checks in code, a judge with strict scores and a pass threshold, in Spring AI, Node.js and Python.

    Python, Java, JavaScript · 74 files · 6,045 linesREADME.md
  • GenAI Security and Guardrails: Prompt Injection, Jailbreaks and Safe Tool Use

    Prompt injection, jailbreaks and why a system prompt is not a lock. Five rules for safe tools, layered guardrails, and a guarded support agent in Spring AI, Node.js and Python.

    Java, Python, JavaScript · 73 files · 6,405 linesREADME.md