A full-stack todo application built with tRPC, React, Express, and MongoDB. This monorepo demonstrates end-to-end type safety with a modern tech stack.
- β Create, read, update, and delete todos
- π¨ Beautiful UI with TailwindCSS
- π Real-time syncing with React Query
- π Form validation with Zod
- π― Type-safe API with tRPC
- ποΈ MongoDB with Prisma ORM
- π¦ Monorepo structure with shared types
- π CORS-enabled Express server
- β‘ Hot-reload development
- React 19.2 - UI framework
- TypeScript - Type safety
- Vite - Build tool with HMR
- TailwindCSS 4 - Styling
- TanStack React Query - Server state management
- TanStack React Router - Client-side routing
- tRPC Client - Type-safe API client
- Zod - Schema validation
- Lucide React - Icons
- Node.js - Runtime
- Express - Web framework
- tRPC Server - RPC framework for type-safe APIs
- Prisma - ORM for MongoDB
- MongoDB - Database
- Zod - Schema validation
- CORS - Cross-Origin Resource Sharing
todo-app/
βββ client/ # React frontend
β βββ src/
β β βββ components/ # Reusable components
β β β βββ todo/ # Todo-specific components
β β β βββ ui/ # UI primitives
β β βββ hooks/ # Custom React hooks
β β βββ lib/ # Utilities and tRPC setup
β β βββ types/ # TypeScript types
β β βββ utils/ # Helper functions
β β βββ App.tsx # Main app component
β β βββ main.tsx # Entry point
β β βββ index.css # Global styles
β βββ package.json
β βββ vite.config.ts
β βββ tsconfig.json
β
βββ server/ # Express + tRPC backend
β βββ src/
β β βββ routers/ # tRPC routers
β β βββ services/ # Business logic
β β βββ schemas/ # Zod validation schemas
β β βββ middleware/ # Express middleware
β β βββ lib/ # Utilities (Prisma client)
β β βββ trpc/ # tRPC setup
β β βββ index.ts # Server entry point
β βββ prisma/
β β βββ schema.prisma # Database schema
β βββ package.json
β βββ tsconfig.json
β βββ docker-compose.yml # MongoDB setup
β
βββ package.json # Root package (monorepo config)
βββ README.md # This file
- Node.js >= 18
- npm or yarn
- MongoDB (local or Docker)
-
Clone or navigate to the project:
cd todo-app -
Install dependencies for all workspaces:
npm run install:all
-
Set up environment variables:
Create
server/.envfile:DATABASE_URL=mongodb://localhost:27017/todos PORT=4000 CORS_ORIGIN=http://localhost:5173
-
Start MongoDB (using Docker Compose):
cd server docker-compose up -d -
Generate Prisma Client:
npm run prisma:generate
-
Push schema to database:
npm run prisma:push
Start both client and server with hot-reload:
npm run devThis runs:
- Server on
http://localhost:4000 - Client on
http://localhost:5173
Start only the server:
npm run dev:serverStart only the client:
npm run dev:clientnpm run dev # Start dev server + client
npm run dev:server # Start dev server only
npm run dev:client # Start dev client only
npm run build # Build both client and server
npm run build:server # Build server only
npm run build:client # Build client only
npm run start # Start production builds
npm run start:server # Start production server
npm run start:client # Start production client
npm run install:all # Install deps in all workspaces
npm run prisma:generate # Generate Prisma Client
npm run prisma:push # Push schema to database# In server directory
npm run db:generate # Generate Prisma Client
npm run db:push # Push schema changes to MongoDB
npm run db:studio # Open Prisma Studio UIThe tRPC server provides the following procedures:
todo.list()- Get all todostodo.get(id)- Get a single todo by IDtodo.create(data)- Create a new todotodo.update(id, data)- Update a todotodo.delete(id)- Delete a todotodo.toggle(id)- Toggle todo completion status
All endpoints are fully type-safe through tRPC's end-to-end type checking.
Todo Model
model Todo {
id String @id @default(auto()) @map("_id") @db.ObjectId
title String
description String @default("")
completed Boolean @default(false)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}Future plans include User authentication and per-user todos.
This project leverages tRPC to provide:
- Automatic type inference - Client types match server types
- Runtime validation - Zod schemas validate input/output
- IDE autocompletion - Full TypeScript autocomplete on API calls
- Compile-time safety - Catch errors before runtime
View and edit your database visually:
npm run prisma:studioBoth client and server support HMR for instant feedback during development.
- Update
server/prisma/schema.prisma - Run
npm run prisma:push - Update
server/src/schemas/todo.schema.tsvalidation - Update
client/src/types/todo.tstypes - Update components as needed
npm run buildThis produces optimized builds in:
client/dist/- Static client bundleserver/dist/- Compiled server code
Then start with:
npm run startMongoDB connection error:
- Ensure Docker is running:
docker-compose up -din the server directory - Check
DATABASE_URLin.env
Port already in use:
- Server default: 4000 β set
PORTin.env - Client default: 5173 β set
VITE_PORTinclient/.env
Type errors in editor:
- Run
npm run prisma:generateto update Prisma types - Restart TypeScript server in your editor
- User authentication & authorization
- Per-user todos with relationships
- Todo categories/tags
- Due dates and reminders
- Dark mode
- Offline support with service workers
- Real-time updates with WebSockets