AI summary by TwinMind
T3 Stack Tutorial - FROM 0 TO PROD FOR $0 (Next.js, tRPC, TypeScript, Tailwind, Prisma & More)
Theo - t3․gg
2h 59m 2s
Introduction & Project Overview
- Created official T3 stack tutorial building emoji-only Twitter clone called "Chirp"
- Year and a half since first T3 stack video, stack has evolved significantly
- Goal: demonstrate zero to production-ready app with beginner-friendly approach
- Stack components: Next.js, Prisma, PlanetScale, tRPC, Vercel, Clerk
- All services have generous free tiers supporting tens of thousands of users
Initial Project Setup
- Three-step process: initialize, GitHub setup, early deployment
- Used create-t3-app CLI tool for project scaffolding
- Selected TypeScript (JavaScript not available), Prisma, Tailwind, tRPC
- Created GitHub repository and connected to Vercel for continuous deployment
- Early deployment philosophy: deploy often to catch issues early
Database Configuration
- Switched from SQLite to PlanetScale for production scalability
- Updated Prisma schema from SQLite to MySQL configuration
- Added relationMode = "prisma" for PlanetScale compatibility
- Used npx prisma db push to sync schema changes
- Demonstrated Prisma Studio for database management
Authentication Setup with Clerk
- Integrated Clerk for authentication over Next-Auth
- Configured GitHub OAuth as primary authentication method
- Added Clerk middleware for server-side authentication
- Wrapped app with ClerkProvider in _app.tsx
- Created protected and public procedures in tRPC
Database Schema Design
- Created Post model with: id (cuid), createdAt, content (varchar 255), authorId (string)
- Added database index on authorId for efficient queries
- Used Prisma's orderBy for chronological post ordering
- Implemented proper type safety throughout data flow
UI Development & Styling
- Applied global dark theme with Tailwind CSS
- Created Twitter-like centered layout with responsive design
- Implemented loading states with custom spinner component
- Used Next.js Image component for optimized profile pictures
- Added proper responsive design patterns
tRPC API Development
- Created posts router with get-all and create procedures
- Implemented private procedures requiring authentication
- Used Zod validators for input validation (emoji-only content)
- Added proper error handling and type safety
- Created helper functions for filtering user data
Rate Limiting Implementation
- Integrated Upstash Redis for serverless rate limiting
- Set limit to 3 posts per minute per user
- Used @upstash/ratelimit package with simple configuration
- Demonstrated production-ready spam protection
Advanced Features
Post Creation
- Real-time post creation with optimistic updates
- Input validation using Zod emoji validator
- Loading states and error handling with toast notifications
- Auto-clear input on successful post
- Submit on Enter key press
Profile Pages
- Dynamic routing with [slug].tsx pattern
- SSG (Static Site Generation) with tRPC SSG helper
- Pre-fetched user data for instant loading
- Profile layout with Twitter-like design
- User posts feed with proper loading states
Individual Post Pages
- Dynamic routing with [id].tsx in /post directory
- SSG implementation for SEO and performance
- Proper metadata generation for social sharing
- Single post view with author information
Production Optimizations
Performance Improvements
- Implemented tRPC SSG helpers for static generation
- Used React Query for efficient data caching
- Added proper loading states and error boundaries
- Optimized images with Next.js Image component
CI/CD Pipeline
- GitHub Actions for type checking and linting
- Separated build validation from deployment
- Disabled build-time type checking on Vercel
- Reduced build times from 43s to 28s
Monitoring & Logging
- Integrated Axiom for enhanced logging
- Connected to Vercel for automatic log forwarding
- Better error tracking and debugging capabilities
Domain & Deployment
- Custom domain setup through Vercel
- Emoji subdomain configuration (🐦.t3.gg)
- Automatic HTTPS and CDN configuration
- Production deployment with continuous integration
Code Organization & Patterns
- Modular component architecture
- Shared utilities and helpers
- Type-safe data flow throughout application
- Reusable layout components
- Proper separation of concerns
Future Enhancements Discussion
- Infinite scroll pagination with tRPC infinite queries
- React Hook Form integration for better form handling
- Database synchronization with Clerk webhooks
- OG image generation for social media previews
- Improved link handling and routing patterns
