Skip to content

About

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.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Todo App - tRPC Monorepo

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.

πŸš€ Features

  • βœ… 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

πŸ› οΈ Tech Stack

Frontend

  • 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

Backend

  • 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

πŸ“ Project Structure

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

πŸš€ Getting Started

Prerequisites

  • Node.js >= 18
  • npm or yarn
  • MongoDB (local or Docker)

Installation

  1. Clone or navigate to the project:

    cd todo-app
  2. Install dependencies for all workspaces:

    npm run install:all
  3. Set up environment variables:

    Create server/.env file:

    DATABASE_URL=mongodb://localhost:27017/todos
    PORT=4000
    CORS_ORIGIN=http://localhost:5173
  4. Start MongoDB (using Docker Compose):

    cd server
    docker-compose up -d
  5. Generate Prisma Client:

    npm run prisma:generate
  6. Push schema to database:

    npm run prisma:push

Development

Start both client and server with hot-reload:

npm run dev

This runs:

  • Server on http://localhost:4000
  • Client on http://localhost:5173

Separate Commands

Start only the server:

npm run dev:server

Start only the client:

npm run dev:client

πŸ“š Available Scripts

Root Level

npm 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

Database Management

# 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 UI

πŸ”Œ API Endpoints

The tRPC server provides the following procedures:

Todo Router

  • todo.list() - Get all todos
  • todo.get(id) - Get a single todo by ID
  • todo.create(data) - Create a new todo
  • todo.update(id, data) - Update a todo
  • todo.delete(id) - Delete a todo
  • todo.toggle(id) - Toggle todo completion status

All endpoints are fully type-safe through tRPC's end-to-end type checking.

πŸ—„οΈ Database Schema

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.

πŸ” Type Safety

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

πŸ§ͺ Development Tips

Prisma Studio

View and edit your database visually:

npm run prisma:studio

Hot Module Replacement (HMR)

Both client and server support HMR for instant feedback during development.

Adding New Todo Properties

  1. Update server/prisma/schema.prisma
  2. Run npm run prisma:push
  3. Update server/src/schemas/todo.schema.ts validation
  4. Update client/src/types/todo.ts types
  5. Update components as needed

πŸ“¦ Building for Production

npm run build

This produces optimized builds in:

  • client/dist/ - Static client bundle
  • server/dist/ - Compiled server code

Then start with:

npm run start

πŸ› Troubleshooting

MongoDB connection error:

  • Ensure Docker is running: docker-compose up -d in the server directory
  • Check DATABASE_URL in .env

Port already in use:

  • Server default: 4000 β†’ set PORT in .env
  • Client default: 5173 β†’ set VITE_PORT in client/.env

Type errors in editor:

  • Run npm run prisma:generate to update Prisma types
  • Restart TypeScript server in your editor

πŸ“ Future Enhancements

  • 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

About

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.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages