Skip to content

Latest commit

Β 

History

11 Commits

Folders and files

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

Repository files navigation

DonkeyType - Multiplayer Typing Game

A real-time multiplayer typing game built with Next.js and Socket.IO.

Features

  • Solo Mode: Practice typing alone with timer and stats
  • Multiplayer Mode: Race against friends in real-time
  • Real-time WPM and accuracy tracking
  • Live player progress visualization
  • Custom room system for private matches
  • Responsive design with Tailwind CSS

Project Structure

donkeytype/
β”œβ”€β”€ client/                    # Next.js frontend application
β”‚   β”œβ”€β”€ public/               # Static assets
β”‚   β”‚   └── logo.png         # App logo
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ app/             # Next.js App Router pages
β”‚   β”‚   β”‚   β”œβ”€β”€ (solo)/      # Solo mode (root route)
β”‚   β”‚   β”‚   β”‚   └── page.js  # Solo typing game
β”‚   β”‚   β”‚   β”œβ”€β”€ multiplayer/ # Multiplayer mode
β”‚   β”‚   β”‚   β”‚   └── page.js  # Multiplayer typing game
β”‚   β”‚   β”‚   β”œβ”€β”€ chart/       # Stats visualization
β”‚   β”‚   β”‚   β”‚   └── page.js  # Chart display page
β”‚   β”‚   β”‚   β”œβ”€β”€ globals.css  # Global styles
β”‚   β”‚   β”‚   β”œβ”€β”€ layout.js    # Root layout
β”‚   β”‚   β”‚   β”œβ”€β”€ page.js      # Home page wrapper
β”‚   β”‚   β”‚   └── providers.js # App providers
β”‚   β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”‚   β”œβ”€β”€ chart.jsx    # Chart component
β”‚   β”‚   β”‚   β”œβ”€β”€ navbar.js    # Navigation bar
β”‚   β”‚   β”‚   β”œβ”€β”€ multi/       # Multiplayer components
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ Chat.js
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ GameSettings.js
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ PlayerCard.js
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ ResultSummary.js
β”‚   β”‚   β”‚   β”‚   └── TypingArea.js
β”‚   β”‚   β”‚   β”œβ”€β”€ solo/        # Solo mode components
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ InputBar.js
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ restartButton.js
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ result.js
β”‚   β”‚   β”‚   β”‚   └── typing.js
β”‚   β”‚   β”‚   └── ui/          # UI components (shadcn/ui)
β”‚   β”‚   β”‚       β”œβ”€β”€ card.jsx
β”‚   β”‚   β”‚       β”œβ”€β”€ chart.jsx
β”‚   β”‚   β”‚       β”œβ”€β”€ resizable-navbar.jsx
β”‚   β”‚   β”‚       └── select.jsx
β”‚   β”‚   β”œβ”€β”€ contexts/
β”‚   β”‚   β”‚   └── SocketContext.js  # Socket.IO context provider
β”‚   β”‚   β”œβ”€β”€ hooks/
β”‚   β”‚   β”‚   β”œβ”€β”€ countdownTimer.js # Timer hook
β”‚   β”‚   β”‚   └── usetyping.js      # Typing logic hook
β”‚   β”‚   β”œβ”€β”€ lib/
β”‚   β”‚   β”‚   └── utils.js          # Utility functions
β”‚   β”‚   └── services/
β”‚   β”‚       └── helper.js         # WPM/accuracy calculations
β”‚   β”œβ”€β”€ .env.local          # Environment variables (Socket URL)
β”‚   β”œβ”€β”€ .env.example        # Environment variables template
β”‚   β”œβ”€β”€ components.json     # shadcn/ui config
β”‚   β”œβ”€β”€ eslint.config.mjs   # ESLint configuration
β”‚   β”œβ”€β”€ next.config.mjs     # Next.js configuration
β”‚   β”œβ”€β”€ postcss.config.mjs  # PostCSS configuration
β”‚   β”œβ”€β”€ tailwind.config.mjs # Tailwind CSS configuration
β”‚   └── package.json        # Frontend dependencies
β”‚
β”œβ”€β”€ server/                 # Socket.IO backend server
β”‚   β”œβ”€β”€ server.js          # Socket.IO server implementation
β”‚   β”‚                      # - Room management
β”‚   β”‚                      # - Real-time game state sync
β”‚   β”‚                      # - Player progress tracking
β”‚   β”‚                      # - Chat functionality
β”‚   β”œβ”€β”€ .env               # Server environment variables
β”‚   β”œβ”€β”€ .env.example       # Environment variables template
β”‚   β”œβ”€β”€ .gitignore         # Git ignore rules
β”‚   └── package.json       # Backend dependencies
β”‚
β”œβ”€β”€ DEPLOYMENT.md          # Deployment guide
└── README.md             # This file

Technology Stack

Frontend

  • Next.js 15.1.6 - React framework with App Router
  • React 19 - UI library
  • Socket.IO Client - Real-time communication
  • Tailwind CSS - Styling
  • Motion - Animations
  • Recharts - Data visualization
  • shadcn/ui - UI components
  • Faker.js - Random word generation

Backend

  • Node.js - Runtime environment
  • Express - Web server
  • Socket.IO - Real-time bidirectional communication
  • dotenv - Environment variable management

Getting Started

Prerequisites

  • Node.js 18+ installed
  • npm or yarn package manager

Installation

  1. Clone the repository
git clone https://github.com/tejash111/donkeytype.git
cd donkeytype
  1. Install server dependencies
cd server
npm install
  1. Install client dependencies
cd ../client
npm install

Running the Application

You need to run both the server and client simultaneously.

Environment Setup

Client (.env.local):

NEXT_PUBLIC_SOCKET_URL=http://localhost:4000

Server (.env):

PORT=4000
CORS_ORIGIN=*
NODE_ENV=development

Development Mode

Terminal 1 - Start Socket.IO Server:

cd server
npm run dev

βœ… Server runs on http://localhost:4000

Terminal 2 - Start Next.js Client:

cd client
npm run dev

βœ… Client runs on http://localhost:3000

Production Mode

Server:

cd server
npm install
node server.js

Client:

cd client
npm install
npm run build
npm start

How to Play

Solo Mode

  1. Navigate to http://localhost:3000/ (root page)
  2. Choose between time or words mode
  3. Select duration (15s, 30s, 1m, 2m) or word count (10, 25, 50, 100)
  4. Start typing when ready
  5. View your WPM, accuracy, and detailed stats after completion

Multiplayer Mode

  1. Navigate to http://localhost:3000/multiplayer
  2. Enter your username
  3. Create Room: Click "create room" to generate a 6-character room code
  4. Join Room: Enter the room code shared by a friend
  5. Wait for other players (only room creator can start)
  6. Room creator can adjust settings (time limit, word count, game mode)
  7. Click "Start" to begin the race
  8. Type the words - see live progress of all players!
  9. Check the leaderboard and WPM charts when finished

Socket.IO Events

Client β†’ Server

  • join-room - Join/create a multiplayer room
  • start-game - Start the typing game (creator only)
  • update-progress - Update player's WPM, accuracy, progress
  • update-settings - Change game settings (creator only)
  • player-ready - Mark player as ready
  • chat-message - Send chat message
  • time-up - Notify when time expires
  • leave-room - Leave the current room

Server β†’ Client

  • room-state - Initial room state with players and settings
  • player-joined - New player joined with updated player list
  • player-left - Player disconnected
  • game-started - Game begins with words and start time
  • progress-update - Real-time player progress updates
  • game-finished - Game ended with final results
  • settings-updated - Game settings changed by creator
  • player-ready-update - Player ready status changed
  • new-chat-message - New chat message received
  • error - Error messages

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

Configuration

Server Port

Change in server/server.js:

const PORT = 4000; // Change this

Socket.IO URL

Change in client/src/contexts/SocketContext.js:

const socketInstance = io("http://localhost:4000", {
  // Change URL
  transports: ["websocket"],
});

Troubleshooting

"Cannot connect to server"

  • Make sure the Socket.IO server is running on port 4000
  • Check if another application is using port 4000
  • Verify the URL in SocketContext.js matches your server

"Module not found" errors

  • Run npm install in both client/ and server/ directories
  • Delete node_modules and reinstall if issues persist

Port already in use

  • Kill the process using the port:
# Windows
netstat -ano | findstr :4000
taskkill /PID <PID> /F

# Mac/Linux
lsof -ti:4000 | xargs kill -9

Development

Adding new features

  1. Frontend changes go in client/src/
  2. Backend/Socket.IO logic goes in server/server.js
  3. Shared types/interfaces can be documented in comments

Code structure

  • Components: client/src/components/
  • Pages: client/src/app/*/page.js
  • Hooks: client/src/hooks/
  • Utils: client/src/services/

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Commit your changes
  4. Push to the branch
  5. Open a Pull Request

License

This project is open source and available under the MIT License.

Author

Tejash

Show your support

Give a ⭐️ if you like this project!

Releases

Packages

Contributors

Languages