All projects
Todo App
easyBuild a classic todo list with filtering, inline editing, and localStorage persistence. Along the way you will practice modeling domain data with interfaces, using discriminated unions for filter state, and typing React event handlers and component props correctly.
Next.jsTypeScriptTailwind CSSZustand
Architecture
- UI layer: small presentational components (TodoItem, TodoList, FilterBar) that receive typed props and emit typed callbacks
- State layer: a single Zustand store holding the todo array and the active filter, exposed through typed selector hooks
- Domain layer: pure functions for adding, toggling, and filtering todos so business logic stays testable and framework-free
- Persistence layer: a thin storage service that serializes the store to localStorage behind a typed interface
- Type layer: a shared types module that every other layer imports from, keeping the Todo shape in one place
Folder structure
src/
app/
page.tsx
layout.tsx
components/
TodoItem.tsx
TodoList.tsx
FilterBar.tsx
AddTodoForm.tsx
store/
useTodoStore.ts
lib/
todos.ts
storage.ts
types/
todo.tsDomain type definitions
Start every project by defining its types — they become the contract for every component, service, and API call that follows.
export type TodoFilter = "all" | "active" | "completed";
export interface Todo {
id: string;
text: string;
completed: boolean;
createdAt: number;
}
export interface TodoState {
todos: Todo[];
filter: TodoFilter;
}
export interface TodoActions {
addTodo: (text: string) => void;
toggleTodo: (id: string) => void;
editTodo: (id: string, text: string) => void;
removeTodo: (id: string) => void;
setFilter: (filter: TodoFilter) => void;
clearCompleted: () => void;
}
export type TodoStore = TodoState & TodoActions;Build steps
- 1Define the domain types — write the Todo interface, the TodoFilter union, and the store shape in src/types/todo.ts.
- 2Write pure helpers in src/lib/todos.ts for creating, toggling, and filtering todos, and unit-test them mentally against the types.
- 3Create the Zustand store in src/store/useTodoStore.ts, typing it as TodoStore so every action signature is checked.
- 4Build AddTodoForm with a typed onSubmit handler that trims input and calls addTodo.
- 5Build TodoItem and TodoList, passing todos down as typed props and wiring toggle, edit, and remove callbacks.
- 6Build FilterBar that renders one button per TodoFilter value and highlights the active filter.
- 7Add the storage service and hydrate the store from localStorage on mount, guarding against malformed JSON.
- 8Polish with Tailwind — empty states, completed styling, and a remaining-items counter derived from the store.