AI summary by TwinMind
From 0 to Production - The Modern React Tutorial (RSCs, Next.js, Shadui, Drizzle, TS and more)
Theo - t3․gg
3h 3m 11s
Tutorial Introduction & Setup
- Full production-ready gallery app tutorial using modern T3 stack
- Tech stack: Next.js 14 (app router), TypeScript, Tailwind, Drizzle ORM, Clerk auth, Upload Thing
- Not designed for brand new developers - requires existing GitHub and project experience
- Goal: showcase real production app building choices used at Twitch and personal projects
T3 Stack Philosophy & Evolution
- T3 stack as mindset rather than concrete stack - modular approach chasing best tools
- Technology changes since original: Next.js moved to server components, Prisma overtaken by Drizzle, tRPC more optional
- CLI tool created by community member Nexxel for scaffolding projects
- Emphasis on type safety and modern full-stack development
Hosting & Sponsors Overview
- Vercel: deploying web apps at scale
- Clerk: authentication and user management
- PostHog: analytics and product insights (first sponsored creator)
- UpStash: fastest KV store and rate limiting
- Sentry: industry standard error management
- Using Vercel Postgres instead of PlanetScale for free tutorial access
Project Initialization
- Create T3 app with pnpm create t3-app@latest
- Project name: T3 Gallery
- Selected options: TypeScript, Tailwind, no tRPC, no auth (manual Clerk setup), Drizzle ORM, app router, Postgres
- Initialize Git repo and commit initial state
- Set up Vercel deployment with GitHub integration
Build Process Optimization
- Add turbo flag to dev command for faster development
- Ignore TypeScript and ESLint errors during build (run separately in CI)
- Build time improvements from ~50 seconds to ~35 seconds
- Separate type checking from build process for faster deployments
Database Setup & Configuration
- Create Vercel Postgres database in same region as deployment (West 2)
- Configure environment variables for database connection
- Important: match database and app regions to prevent latency issues
- Use database prefixes (T3_gallery_) to share databases across projects safely
Initial UI Scaffolding
- Create basic layout with top navigation and main content area
- Implement dark mode with BG black and white text
- Mock data setup using Upload Thing URLs for initial development
- Basic image grid layout with Flexbox and gap spacing
Schema Design & Database Integration
- Define image schema with ID, name, URL, user ID, created/updated timestamps
- Use Drizzle push command instead of migrations for simpler workflow
- Server-side data fetching in React server components
- Dynamic page configuration to prevent caching issues
Authentication Implementation (Clerk Beta)
- Install Clerk beta version for improved middleware and performance
- Set up middleware.ts for authentication handling
- Configure ClerkProvider in root layout
- Implement sign-in/sign-out UI components with conditional rendering
- User-specific image filtering in database queries
File Upload System (Upload Thing)
- Configure Upload Thing for file management and CDN
- Set up file router with authentication middleware
- Implement custom upload button with progress states
- Server-side file processing with onUploadComplete webhook
- Client-side refresh on upload completion
Advanced Routing & Modal System
- Implement parallel routes for image modal/page views
- Create @modal folder structure for Next.js parallel routing
- Build reusable full-page image component
- Fix dialog element styling for full-screen modals
- URL-based modal system (works with refresh/direct links)
Image Optimization & Layout
- Integrate Next.js Image component for automatic optimization
- Configure allowed image domains in next.config.js
- Implement responsive image layouts with object-fit
- Grid-based layout system for consistent spacing
- Handle different aspect ratios and image sizes
Component Architecture & Server Actions
- Move data access to dedicated server/queries.ts file
- Implement server-only imports for security
- Create reusable components for image display
- Server actions for delete functionality with automatic navigation
- Form-based interactions without client-side JavaScript
User Interface Polish (Shad/CN UI)
- Install and configure Shad/CN UI component library
- Implement toast notifications with Sonner
- Create loading states with SVG spinners
- Style upload buttons and delete actions
- Dark mode configuration and consistent theming
Error Management (Sentry)
- Install Sentry for production error tracking
- Configure source maps and error reporting
- Set up tunnel routes to bypass ad blockers
- Global error boundary with proper status codes
- Integration with deployment pipeline
Analytics Implementation (PostHog)
- Set up PostHog for product analytics and user tracking
- Configure user identification with Clerk integration
- Track upload events and user interactions
- Server-side analytics for delete actions
- Ad-blocker resistant configuration with rewrites
Security & Rate Limiting
- Implement UpStash Redis for rate limiting uploads
- Configure per-user rate limits (10 uploads per 100 seconds)
- Error handling for rate limit violations
- User permission system via Clerk metadata
- Production-ready upload restrictions
Production Deployment & Environment
- Environment variable management across dev/production
- Vercel deployment with automatic builds
- Database migrations and schema updates
- Error monitoring and user analytics in production
- Performance optimization and caching strategies
Advanced Features & Challenges
- Suggested improvements: responsive image layouts, infinite scroll
- Multi-image selection with state management
- Album/folder organization system
- Image sharing and permissions
- Performance optimizations and edge cases
