Skip to content

A modern, production-ready touch typing practice website built with Next.js , TypeScript, MongoDB and Tailwind CSS. Learn to type faster and more accurately through progressive lessons, speed tests, and real-time feedback.

Notifications You must be signed in to change notification settings

holywen/typingtoy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Typing Toy

A modern, production-ready touch typing practice website built with Next.js 15, TypeScript, and Tailwind CSS. Learn to type faster and more accurately through progressive lessons, speed tests, and real-time feedback.

Features

  • βœ… 15 Progressive Lessons - From beginner (home row) to advanced (special characters)
  • βœ… Real-time WPM Calculation - Industry-standard Gross WPM and Net WPM metrics
  • βœ… Accuracy Tracking - Character-by-character accuracy with visual feedback
  • βœ… Speed Test Mode - Practice with randomized texts (500-1000 words)
  • βœ… Responsive Design - Works on desktop and mobile devices
  • βœ… Dark Mode Support - System-aware theme switching
  • βœ… Multiple Keyboard Layouts - QWERTY, Dvorak, Colemak, AZERTY, QWERTZ
  • βœ… Multilingual Support (i18n) - 6 languages with database persistence for authenticated users
    • English, Chinese, Japanese, Spanish, French, Thai
    • Language preference synced across devices
    • Full admin dashboard internationalization
  • βœ… SEO Optimized - Full metadata, sitemap, robots.txt, and social sharing
  • βœ… Docker Deployment - Complete Docker and Docker Compose setup
  • βœ… Testing & CI/CD - 98.64% test coverage with GitHub Actions automation
  • βœ… User Authentication - NextAuth.js 5.0 with email verification and OAuth (Google)
  • βœ… Admin Dashboard - Complete admin system with user/room management and analytics
  • βœ… Role-Based Access - First user becomes admin, automatic role assignment
  • βœ… Email Verification - SMTP-based email verification for new user registrations
  • βœ… Progress Tracking - MongoDB storage with sync API for authenticated users
  • βœ… Multiplayer Mode - Real-time typing games with Socket.IO
  • βœ… Leaderboards - Global and friend leaderboards with player statistics
  • 🚧 Achievements & Gamification - Badges and rewards system (coming soon)

Tech Stack

Frontend

  • Next.js 16.0.1 - React framework with App Router and Turbopack
  • React 19.2.0 - Latest React features
  • TypeScript 5 - Type-safe development
  • Tailwind CSS 3.4 - Utility-first CSS framework
  • Framer Motion 12.0 - Smooth animations
  • Chart.js 4.4 - Data visualization
  • React Chart.js 2 - React wrapper for Chart.js
  • Clsx & Tailwind Merge - Dynamic className utilities
  • Zustand 5.0 - State management

Backend & Authentication

  • NextAuth 5.0 (Beta 30) - Authentication solution with role-based access
  • MongoDB 6.12 - NoSQL database
  • Mongoose 8.9 - MongoDB ODM
  • @auth/mongodb-adapter - NextAuth MongoDB integration
  • Socket.IO 4.8 - Real-time bidirectional communication for multiplayer
  • Nodemailer 6.9 - SMTP email sending for verification
  • Redis 4.7 - Caching, session management, and real-time data
  • bcryptjs 2.4 - Password hashing
  • Zod 3.24 - Schema validation

Internationalization

  • Custom i18n - React Context-based i18n system with NextAuth integration
  • 6 Languages - English, Chinese, Japanese, Spanish, French, Thai (68+ keys per language)
  • Database Persistence - Language preference saved to MongoDB for authenticated users
  • Cross-Device Sync - Settings synchronized across devices and browsers

Development & Build

  • ESLint 9 - Code linting
  • Jest 29 - Testing framework with 98.64% code coverage
  • @testing-library/react - React component testing
  • @testing-library/jest-dom - DOM matchers for Jest
  • PostCSS 8 - CSS processing
  • Autoprefixer - CSS vendor prefixes
  • Turbopack - Fast bundling (Next.js 16)

Getting Started

Prerequisites

  • Node.js 18+
  • npm or pnpm
  • MongoDB (optional, for user features)
  • Redis (optional, for caching)

Installation

  1. Clone the repository:
git clone https://github.com/yourusername/typingtoy.git
cd typingtoy
  1. Install dependencies:
npm install
  1. Create environment file:
cp .env.local.example .env.local
  1. Edit .env.local with your configuration:
# Database
MONGODB_URI=mongodb://localhost:27017/typingstudy
REDIS_URL=redis://localhost:6379

# Authentication
NEXTAUTH_SECRET=your-secret-key-here
NEXTAUTH_URL=http://localhost:3000

# Email (SMTP) - Required for email verification
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_SECURE=false
SMTP_USER=your-email@gmail.com
SMTP_PASSWORD=your-app-password
SMTP_FROM=typingtoy@444666.best

# Support Email (publicly visible for contact links)
NEXT_PUBLIC_SUPPORT_EMAIL=typingtoy@444666.best

# OAuth (Optional)
GOOGLE_CLIENT_ID=your-google-client-id
GOOGLE_CLIENT_SECRET=your-google-client-secret
  1. Run the development server:
npm run dev
  1. Open http://localhost:3000 in your browser.

Testing

The project includes a comprehensive unit test suite with 98.64% code coverage.

Running Tests

# Run all tests
npm test

# Run tests in watch mode (for development)
npm run test:watch

# Generate coverage report
npm run test:coverage

Test Coverage

Tests cover:

  • Typing Metrics - WPM and accuracy calculations
  • Progress Storage - LocalStorage operations
  • User Settings - Settings management
  • Device ID - Device identification
  • Skill Rating - Player rating calculations
  • Sound Effects - Audio system
  • Text Generator - Random text generation
  • Name Generator - Display name generation
  • Profanity Filter - Content filtering
  • Lessons Data - Lesson structure validation

CI/CD

GitHub Actions workflow automatically runs tests on:

  • Pull requests
  • Pushes to main and dev branches
  • Node.js 18 and 20 environments

Project Structure

typingtoy/
β”œβ”€β”€ app/                          # Next.js App Router pages
β”‚   β”œβ”€β”€ api/                      # API routes
β”‚   β”‚   β”œβ”€β”€ auth/                 # NextAuth endpoints
β”‚   β”‚   β”‚   β”œβ”€β”€ register/         # User registration API
β”‚   β”‚   β”‚   └── verify-email/     # Email verification API
β”‚   β”‚   β”œβ”€β”€ admin/                # Admin API routes
β”‚   β”‚   β”‚   β”œβ”€β”€ stats/            # Platform statistics
β”‚   β”‚   β”‚   β”œβ”€β”€ statistics/       # Detailed analytics
β”‚   β”‚   β”‚   β”œβ”€β”€ users/            # User management CRUD
β”‚   β”‚   β”‚   └── rooms/            # Room management CRUD
β”‚   β”‚   β”œβ”€β”€ generate-text/        # Text generation API
β”‚   β”‚   └── user/                 # User data sync
β”‚   β”œβ”€β”€ admin/                    # Admin dashboard (protected)
β”‚   β”‚   β”œβ”€β”€ layout.tsx            # Admin layout with role check
β”‚   β”‚   β”œβ”€β”€ page.tsx              # Admin dashboard
β”‚   β”‚   β”œβ”€β”€ users/                # User management page
β”‚   β”‚   β”œβ”€β”€ rooms/                # Room management page
β”‚   β”‚   └── statistics/           # Analytics dashboard
β”‚   β”œβ”€β”€ auth/                     # Authentication pages
β”‚   β”‚   β”œβ”€β”€ signin/               # Sign in page
β”‚   β”‚   β”œβ”€β”€ signup/               # Sign up page
β”‚   β”‚   └── verify-email/         # Email verification page
β”‚   β”œβ”€β”€ lessons/                  # Lesson pages
β”‚   β”‚   β”œβ”€β”€ page.tsx              # Lessons list
β”‚   β”‚   β”œβ”€β”€ layout.tsx            # Lessons metadata
β”‚   β”‚   └── [id]/                 # Individual lesson
β”‚   β”‚       β”œβ”€β”€ page.tsx          # Lesson content
β”‚   β”‚       └── layout.tsx        # Dynamic metadata
β”‚   β”œβ”€β”€ test/                     # Speed test page
β”‚   β”‚   β”œβ”€β”€ page.tsx              # Test interface
β”‚   β”‚   └── layout.tsx            # Test metadata
β”‚   β”œβ”€β”€ practice/                 # Custom practice
β”‚   β”‚   β”œβ”€β”€ page.tsx              # Practice interface
β”‚   β”‚   └── layout.tsx            # Practice metadata
β”‚   β”œβ”€β”€ progress/                 # Progress tracking
β”‚   β”‚   β”œβ”€β”€ page.tsx              # Progress dashboard
β”‚   β”‚   └── layout.tsx            # Progress metadata
β”‚   β”œβ”€β”€ layout.tsx                # Root layout with SEO
β”‚   β”œβ”€β”€ page.tsx                  # Home page
β”‚   β”œβ”€β”€ globals.css               # Global styles
β”‚   β”œβ”€β”€ sitemap.ts                # Dynamic sitemap
β”‚   └── robots.ts                 # Dynamic robots.txt
β”œβ”€β”€ components/                   # React components
β”‚   β”œβ”€β”€ TypingTest.tsx            # Main typing test component
β”‚   β”œβ”€β”€ VirtualKeyboard.tsx       # Keyboard visualization
β”‚   β”œβ”€β”€ HandDiagram.tsx           # Hand position guide
β”‚   β”œβ”€β”€ LanguageSelector.tsx      # Language switcher
β”‚   β”œβ”€β”€ UserMenu.tsx              # User dropdown menu
β”‚   β”œβ”€β”€ TipsBanner.tsx            # Tips for unregistered users
β”‚   └── SessionProvider.tsx       # NextAuth provider wrapper
β”œβ”€β”€ lib/                          # Utilities and services
β”‚   β”œβ”€β”€ db/                       # Database setup
β”‚   β”‚   β”œβ”€β”€ mongodb.ts            # MongoDB connection
β”‚   β”‚   └── models/               # Mongoose models
β”‚   β”‚       β”œβ”€β”€ User.ts           # User model with role field
β”‚   β”‚       └── VerificationToken.ts  # Email verification tokens
β”‚   β”œβ”€β”€ admin.ts                  # Admin helper functions
β”‚   β”œβ”€β”€ i18n/                     # Internationalization
β”‚   β”‚   β”œβ”€β”€ index.ts              # i18n configuration
β”‚   β”‚   β”œβ”€β”€ LanguageContext.tsx   # React context for i18n
β”‚   β”‚   └── locales/              # Translation files
β”‚   β”‚       β”œβ”€β”€ en.ts             # English
β”‚   β”‚       β”œβ”€β”€ zh.ts             # Chinese
β”‚   β”‚       β”œβ”€β”€ ja.ts             # Japanese
β”‚   β”‚       β”œβ”€β”€ es.ts             # Spanish
β”‚   β”‚       β”œβ”€β”€ fr.ts             # French
β”‚   β”‚       └── th.ts             # Thai
β”‚   β”œβ”€β”€ services/                 # Business logic
β”‚   β”‚   β”œβ”€β”€ typingMetrics.ts      # WPM/accuracy calculations
β”‚   β”‚   β”œβ”€β”€ progressStorage.ts    # Progress tracking
β”‚   β”‚   β”œβ”€β”€ userSettings.ts       # User settings management
β”‚   β”‚   └── emailService.ts       # SMTP email sending
β”‚   β”œβ”€β”€ utils/                    # Helper functions
β”‚   β”‚   └── textGenerator.ts      # Random text generation
β”‚   └── data/                     # Static data
β”‚       β”œβ”€β”€ lessons.ts            # Lesson content
β”‚       └── keyboardLayout.ts     # Keyboard layouts
β”œβ”€β”€ types/                        # TypeScript type definitions
β”‚   └── index.ts                  # Shared types
β”œβ”€β”€ public/                       # Static assets
β”‚   β”œβ”€β”€ icon.svg                  # App icon (512x512)
β”‚   β”œβ”€β”€ favicon.svg               # Favicon (32x32)
β”‚   β”œβ”€β”€ apple-touch-icon.svg      # iOS icon (180x180)
β”‚   β”œβ”€β”€ manifest.json             # PWA manifest
β”‚   └── robots.txt                # Static robots.txt
β”œβ”€β”€ docker-compose.yml            # Docker Compose config
β”œβ”€β”€ Dockerfile                    # Docker build config
β”œβ”€β”€ Makefile                      # Docker commands
└── package.json                  # Dependencies

Key Features Explained

WPM Calculation

The application uses industry-standard formulas:

Gross WPM (Raw Speed)

Gross WPM = (Total Characters Γ· 5) Γ· Time in Minutes

Net WPM (Adjusted for Errors)

Net WPM = Gross WPM - (Uncorrected Errors Γ· Time in Minutes)

Accuracy

Accuracy = (Correct Characters Γ· Total Characters) Γ— 100

Typing Test Component

The TypingTest component (components/TypingTest.tsx) handles:

  • Real-time keystroke tracking
  • Visual feedback (green for correct, red for errors)
  • Live WPM and accuracy updates every second
  • Completion detection and final metrics

Lessons System

15 progressive lessons covering:

  1. Lessons 1-4: Home row keys (ASDF JKL;)
  2. Lessons 5-8: Top row keys (QWERTY UIOP)
  3. Lessons 9-12: Bottom row keys (ZXCV BNM,.)
  4. Lesson 13: Number keys (0-9)
  5. Lesson 14: Special characters (!@#$%^&*)
  6. Lesson 15: Master challenge (all keys)

Authentication & User System

Email Verification

  • New user registrations require email verification via SMTP
  • Verification tokens expire after 24 hours
  • Automatic token cleanup using MongoDB TTL indexes
  • First registered user automatically becomes admin (no verification required)

Role-Based Access Control

  • Two roles: user (default) and admin
  • First user in database automatically assigned admin role
  • OAuth users (Google) follow same first-user-becomes-admin logic
  • Admin role persisted in JWT token and session

Admin Dashboard (/admin)

  • Protected route requiring admin role
  • User management: View, search, update roles, delete users
  • Room management: Monitor and manage multiplayer rooms
  • Statistics: Platform analytics with Chart.js visualizations
  • Noindex meta tags prevent search engine indexing

Email Configuration

The application uses Nodemailer for SMTP email sending. To enable email verification:

  1. Gmail Setup (Recommended for development):

    • Enable 2-factor authentication on your Google account
    • Generate an App Password at https://myaccount.google.com/apppasswords
    • Use these settings:
      SMTP_HOST=smtp.gmail.com
      SMTP_PORT=587
      SMTP_SECURE=false
      SMTP_USER=your-email@gmail.com
      SMTP_PASSWORD=your-app-password
  2. Other SMTP Providers:

    • Port 587: Use SMTP_SECURE=false (STARTTLS)
    • Port 465: Use SMTP_SECURE=true (SSL/TLS)
  3. Test Email Configuration:

    npx tsx scripts/test-email.ts

Deployment

Docker (Recommended)

For complete Docker deployment instructions, see docs/DOCKER.md.

Quick start:

# Copy environment file
cp .env.example .env

# Start with Docker Compose
docker compose up -d

# Or use the helper script
./docker-start.sh dev

Vercel (Alternative)

  1. Push your code to GitHub
  2. Import the project in Vercel
  3. Add environment variables in Vercel dashboard
  4. Deploy!
npm run build

Documentation

Development Roadmap

Phase 1: MVP βœ… Complete

  • Basic typing test interface
  • Real-time WPM/accuracy calculation
  • 15 progressive lessons
  • Speed test mode with generated text (500-1000 words)
  • Responsive design with dark mode
  • Virtual keyboard visualization
  • Hand position diagrams

Phase 2: Internationalization βœ… Complete

  • Multi-language support (6 languages)
  • English, Chinese, Japanese, Spanish, French, Thai
  • Custom i18n system with React Context
  • Language selector component
  • Multiple keyboard layouts (QWERTY, Dvorak, Colemak, etc.)

Phase 3: User System & Progress βœ… Complete

  • NextAuth 5.0 authentication with JWT
  • Email verification system (SMTP with Nodemailer)
  • OAuth integration (Google Sign-In)
  • Role-based access control (user/admin roles)
  • First-user-becomes-admin logic
  • Admin dashboard with user/room management
  • Platform statistics and analytics with Chart.js
  • MongoDB user data storage
  • Progress tracking and history (MongoDB with sync API)
  • User profiles and settings
  • Cloud sync for authenticated users
  • Leaderboards (global and friends)
  • Achievement system (planned)

Phase 4: SEO & Deployment βœ… Complete

  • Full SEO optimization (metadata, OG tags, Twitter cards)
  • Dynamic sitemap.xml generation
  • robots.txt configuration
  • PWA manifest
  • Docker & Docker Compose setup
  • Production deployment ready

Phase 4.5: Testing & Quality Assurance βœ… Complete

  • Jest testing framework setup
  • Unit tests for core functionality
  • 98.64% code coverage achieved
  • GitHub Actions CI/CD pipeline
  • Automated testing on PRs
  • Multi-version Node.js testing (18, 20)

Phase 5: Multiplayer & Social βœ… Complete

  • Real-time multiplayer typing games (Socket.IO)
  • Room creation and management
  • Online player list with presence tracking
  • Global leaderboards
  • Friend leaderboards
  • Player statistics and rankings
  • Quick match system
  • Game lobby with chat

Phase 6: Advanced Features πŸ“‹ Planned

  • Custom text practice presets
  • Export typing data
  • Additional typing games
  • Daily challenges
  • Streak tracking
  • Achievement badges and rewards system
  • Code snippet practice mode
  • Advanced analytics dashboard

Phase 7: Enhanced Gamification πŸ’‘ Future

  • Team competitions
  • Live tournaments
  • Season rankings
  • Advanced matchmaking with ELO ratings
  • Spectator mode for tournaments
  • Replay system

Performance

  • Lighthouse Score: 95+ (Performance)
  • First Contentful Paint: < 1s
  • Time to Interactive: < 2s
  • Bundle Size: ~150KB (gzipped)

Browser Support

  • Chrome/Edge 90+
  • Firefox 88+
  • Safari 14+
  • Mobile browsers (iOS Safari, Chrome Mobile)

Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

This project is licensed under the MIT License.

Acknowledgments

Contact

For questions or feedback, please open an issue on GitHub.


Happy Typing! πŸš€

About

A modern, production-ready touch typing practice website built with Next.js , TypeScript, MongoDB and Tailwind CSS. Learn to type faster and more accurately through progressive lessons, speed tests, and real-time feedback.

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages