A modern, real-time multiplayer typing speed test application built with Next.js, featuring user authentication, real-time multiplayer rooms, and comprehensive performance analytics.
This is a monorepo project using Turborepo for efficient build orchestration and workspace management. The project consists of three main packages:
- Frontend - Next.js React application
- Database Package - Prisma ORM with PostgreSQL
- WebSocket Service - Real-time communication server
- Why: Provides server-side rendering, API routes, and excellent developer experience
- Purpose: Powers the main web application with modern React features
- Benefits: SEO optimization, fast page loads, built-in API routes
- Why: Industry standard for building interactive user interfaces
- Purpose: Creates responsive and dynamic typing test interface
- Benefits: Component reusability, virtual DOM, large ecosystem
- Why: Prevents runtime errors and improves code maintainability
- Purpose: Type-safe development across the entire frontend
- Benefits: Better IDE support, catch errors at compile time
- Why: Utility-first CSS framework for rapid UI development
- Purpose: Consistent, responsive design system
- Benefits: Fast development, consistent spacing, responsive design
- Why: Secure, flexible authentication solution for Next.js
- Purpose: Handles user login, registration, and session management
- Features:
- Google OAuth integration
- Credentials-based authentication
- Session management
- CSRF protection
- Why: Secure password storage and verification
- Purpose: Encrypts user passwords before database storage
- Benefits: Industry-standard hashing, salt rounds for security
- Why: Runtime type validation and parsing
- Purpose: Validates user input, API requests, and form data
- Benefits: Type-safe validation, automatic error handling
- Why: Type-safe database access with excellent developer experience
- Purpose: Database schema management, migrations, and queries
- Features:
- Type-safe database client
- Database migrations
- Prisma Studio for database management
- PostgreSQL integration
- Why: Robust, scalable relational database
- Purpose: Stores user data, test results, and room information
- Benefits: ACID compliance, JSON support, excellent performance
- Why: Low-latency bidirectional communication
- Purpose: Powers real-time multiplayer typing sessions
- Benefits: Instant updates, low overhead, persistent connections
- Why: High-performance in-memory data store
- Purpose: Caches session data and manages real-time room state
- Benefits: Fast data access, pub/sub messaging, session storage
- Why: Lightweight, simple state management solution
- Purpose: Manages WebSocket connections and real-time state
- Benefits: Minimal boilerplate, TypeScript support, small bundle size
- Why: Accessible, unstyled UI primitives
- Components Used:
@radix-ui/react-avatar- User avatars@radix-ui/react-dropdown-menu- Dropdown menus@radix-ui/react-label- Form labels@radix-ui/react-scroll-area- Custom scrollbars@radix-ui/react-select- Select components@radix-ui/react-slot- Component composition@radix-ui/react-tabs- Tab navigation
- Why: Beautiful, consistent icon library
- Purpose: Provides icons throughout the application
- Benefits: Tree-shakable, customizable, consistent design
- Why: Powerful animation library for React
- Purpose: Smooth transitions and micro-interactions
- Benefits: Declarative animations, gesture support, layout animations
- Why: Performant forms with minimal re-renders
- Purpose: Handles user registration, login, and settings forms
- Benefits: Uncontrolled components, built-in validation, small bundle
- Why: Integrates validation libraries with React Hook Form
- Purpose: Connects Zod validation with form handling
- Benefits: Type-safe validation, error handling
- Why: Composable charting library built on D3
- Purpose: Displays typing performance analytics and progress charts
- Benefits: Responsive charts, customizable, React-friendly
- Why: Promise-based HTTP client with interceptors
- Purpose: Handles API calls to backend services
- Benefits: Request/response interceptors, automatic JSON parsing
- Why: Developer-friendly email API
- Purpose: Sends verification emails and notifications
- Benefits: Simple API, good deliverability, React components
- Why: Fast, efficient build system for monorepos
- Purpose: Orchestrates builds across multiple packages
- Benefits: Parallel execution, intelligent caching, dependency management
- Why: Catches code quality issues and enforces standards
- Purpose: Maintains code quality and consistency
- Benefits: Catches bugs, enforces coding standards
- Why: Transforms CSS with JavaScript plugins
- Purpose: Processes Tailwind CSS and other CSS transformations
- Benefits: Plugin ecosystem, CSS optimization
keytype/
βββ frontend/ # Next.js React application
β βββ app/ # App Router pages and API routes
β βββ components/ # Reusable React components
β βββ lib/ # Utility functions and configurations
β βββ hooks/ # Custom React hooks
β βββ store/ # Zustand state management
β βββ UI/ # UI component library
βββ packages/
β βββ db/ # Database package with Prisma
β βββ prisma/ # Database schema and migrations
βββ wsredis/ # WebSocket server for real-time features
βββ turbo.json # Turborepo configuration
- Solo Mode: Individual typing practice
- Multiplayer Mode: Real-time competitive typing
- Custom Rooms: Create and join private typing rooms
- Authentication: Google OAuth + Email/Password
- User Profiles: Performance tracking and statistics
- Leaderboards: Global and room-specific rankings
- Live Typing: Real-time progress updates
- Chat System: In-room communication
- Room Management: Create, join, and manage typing rooms
- Performance Metrics: WPM, accuracy, consistency
- Progress Tracking: Historical performance data
- Visual Reports: Charts and graphs for analysis
- Node.js 18+
- PostgreSQL database
- Redis server
# Install dependencies
npm install
# Set up database
cd packages/db
npm run db:setup
# Start development servers
npm run devCreate .env files in each package with required environment variables:
Frontend (.env.local):
DATABASE_URL- PostgreSQL connection stringNEXTAUTH_SECRET- NextAuth secret keyGOOGLE_CLIENT_ID- Google OAuth client IDGOOGLE_CLIENT_SECRET- Google OAuth client secretREDIS_URL- Redis connection stringRESEND_API_KEY- Resend email service API key
WebSocket Service (.env):
REDIS_URL- Redis connection stringPORT- WebSocket server port
The application is designed for deployment on modern platforms:
- Frontend: Vercel, Netlify, or any Node.js hosting
- Database: PostgreSQL (Supabase, Railway, or self-hosted)
- Redis: Redis Cloud, Railway, or self-hosted
- WebSocket: Railway, Render, or any Node.js hosting
- Code Splitting: Next.js automatic code splitting
- Image Optimization: Next.js built-in image optimization
- Caching: Redis for session and real-time data
- Database Optimization: Prisma query optimization
- Bundle Size: Tree-shaking and minimal dependencies
- Authentication: Secure session management with NextAuth
- Password Security: bcrypt hashing with salt rounds
- Input Validation: Zod schema validation
- CSRF Protection: Built-in NextAuth CSRF protection
- Environment Variables: Secure configuration management
- Responsive Design: Mobile-first approach with Tailwind CSS
- Accessibility: Radix UI components with built-in accessibility
- Consistent Styling: Design tokens and utility classes
- Dark/Light Mode: Ready for theme switching implementation
This project demonstrates modern full-stack development practices with a focus on real-time features, user experience, and scalable architecture.