Skip to content

Speed(t)Code: Race to solve LeetCode-style coding problems by typing code at lightning speed! Built with Next.js, FastAPI, Redis, and deployed on Cloud Run.

License

Notifications You must be signed in to change notification settings

imrahnf/speedtcode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

46 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Speed(t)Code

The ultimate typing speed test for developers. Race against time (and others) by typing real code snippets.

Improve your syntax muscle memory, track your WPM, and climb the leaderboards.

πŸ† View the Hall of Fame | 🐞 Report a Bug | ▢️ Join a Lobby


Core Features

  • Real Code Challenges - Type actual code snippets from popular problems
  • Real-Time Multiplayer - Race against friends in live lobbies with WebSockets
  • Performance Tracking - Track your WPM, accuracy, and personal records
  • Leaderboards - Compete globally on the leaderboards
  • User Profiles - View your stats and search your performance history
  • GitHub Authentication - Sign in seamlessly with Firebase Auth

Tech Stack

Frontend

  • Next.js
  • Tailwind CSS
  • SWR
  • WebSockets

Backend

  • FastAPI
  • Redis (Upstash)
  • Firebase Admin
  • WebSockets

Deployment

  • Google Cloud Run
  • Vercel
  • Docker

Quick Start

Prerequisites

  • Python 3.11+
  • Node.js 18+
  • Firebase project with GitHub auth enabled
  • Upstash Redis database

1. Clone and Setup

git clone https://github.com/imrahnf/speedtcode.git
cd speedtcode

2. Backend Setup

cd backend

# Create virtual environment
python -m venv venv
source venv/bin/activate  # Windows: venv\Scripts\Activate

# Install dependencies
pip install -r requirements.txt

# Configure environment (see Environment Setup below)
# Then run
uvicorn main:app --reload

Backend runs at http://localhost:8000

3. Frontend Setup

cd frontend

npm install
npm run dev

Frontend runs at http://localhost:3000

4. Environment Setup

Root .env (Backend) Get your Redis connection string from the Upstash Console.

REDIS_URL=rediss://default:PASSWORD@HOST:6379

Root firebase-credentials.json (Backend) Required for the backend to verify tokens.

  1. Go to Firebase Console β†’ Project Settings β†’ Service accounts.
  2. Click Generate new private key.
  3. Rename the file to firebase-credentials.json and place it in the root.

frontend/.env.local (Frontend) Get these from Firebase Console β†’ Project Settings β†’ General β†’ Your apps (Web).

NEXT_PUBLIC_FIREBASE_API_KEY=AIza...
NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=project.firebaseapp.com
NEXT_PUBLIC_FIREBASE_PROJECT_ID=project-id
NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET=project.firebasestorage.app
NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID=123456789
NEXT_PUBLIC_FIREBASE_APP_ID=1:123456789:web:abc...
NEXT_PUBLIC_API_URL=http://localhost:8000

API Endpoints

Endpoint Method Description
GET /healthz Health check Server status
GET /api/problems Get all problems List of coding challenges
GET /api/problems/{id} Get problem details Problem metadata + code
GET /api/problems/{id}/content/{lang} Get problem content Specific language content
POST /api/lobbies Create lobby Multiplayer room creation
GET /api/lobbies/{id} Get lobby info Lobby details and players
WS /ws/lobby/{id}/{userId}/{username} WebSocket Real-time lobby connection
POST /api/results Submit result Save typing performance
GET /api/leaderboard/{id} Get leaderboard Top scores for problem
GET /api/users/{username} Get user stats User profile and stats
GET /api/users/{username}/problems/{id} Get user problem stats Performance on specific problem
GET /api/users/me/stats Get my stats Current user stats

Project Structure

speedtcode/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ main.py                    # FastAPI app & startup
β”‚   β”œβ”€β”€ routers/
β”‚   β”‚   β”œβ”€β”€ general.py             # Health check
β”‚   β”‚   β”œβ”€β”€ problems.py            # Problem endpoints
β”‚   β”‚   β”œβ”€β”€ lobbies.py             # Multiplayer lobbies
β”‚   β”‚   β”œβ”€β”€ results.py             # Performance tracking
β”‚   β”‚   └── users.py               # User profiles
β”‚   β”œβ”€β”€ services/
β”‚   β”‚   β”œβ”€β”€ redis_service.py       # Redis client wrapper
β”‚   β”‚   └── lobby_manager.py       # Lobby state management
β”‚   β”œβ”€β”€ models/
β”‚   β”‚   └── problem_manager.py     # Problem loading
β”‚   β”œβ”€β”€ problems/                  # Actual challenge files
β”‚   β”‚   β”œβ”€β”€ python/
β”‚   β”‚   β”œβ”€β”€ javascript/
β”‚   β”‚   └── cpp/
β”‚   β”œβ”€β”€ Dockerfile                 # Container config
β”‚   └── requirements.txt
β”‚
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”‚   β”œβ”€β”€ page.js            # Landing page
β”‚   β”‚   β”‚   β”œβ”€β”€ play/              # Singleplayer mode
β”‚   β”‚   β”‚   β”œβ”€β”€ lobby/             # Multiplayer mode
β”‚   β”‚   β”‚   └── profile/           # User profile
β”‚   β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”‚   β”œβ”€β”€ typing/
β”‚   β”‚   β”‚   β”‚   └── TypingEngine.tsx   # Core typing logic
β”‚   β”‚   β”‚   └── lobby/
β”‚   β”‚   β”‚       β”œβ”€β”€ LobbySidebar.tsx
β”‚   β”‚   β”‚       └── HostControls.tsx
β”‚   β”‚   β”œβ”€β”€ context/
β”‚   β”‚   β”‚   └── AuthContext.tsx    # Firebase auth state
β”‚   β”‚   └── lib/
β”‚   β”‚       └── firebase.ts        # Firebase config
β”‚   └── package.json
β”‚
β”œβ”€β”€ cloudbuild.yaml                # Cloud Build config
└── README.md

Docker Testing

Test the containerized backend locally before deploying:

# Build image
docker build -f backend/Dockerfile -t speedtcode-backend:latest .

# Run container
docker run --rm -p 8000:8000 \
  --env-file .env \
  -v "${PWD}/firebase-credentials.json:/app/firebase-credentials.json:ro" \
  speedtcode-backend:latest

Verify: curl http://localhost:8000/docs


Deployment

Google Cloud Run (Backend)

1. Setup

gcloud auth login
gcloud config set project YOUR_PROJECT_ID
gcloud services enable run.googleapis.com cloudbuild.googleapis.com

2. Create cloud-run-env.yaml Use the same values as your local setup. For FIREBASE_CREDENTIALS_JSON, paste the key file into one line.

REDIS_URL: "rediss://default:PASSWORD@HOST:6379"
FIREBASE_CREDENTIALS_JSON: '{"type":"service_account",...}'

3. Build & Deploy

# Build in cloud
gcloud builds submit --config cloudbuild.yaml .

# Deploy
gcloud run deploy speedtcode-backend \
  --image gcr.io/YOUR_PROJECT_ID/speedtcode-backend \
  --platform managed \
  --region us-central1 \
  --allow-unauthenticated \
  --env-vars-file cloud-run-env.yaml \
  --timeout 3600 \
  --min-instances 0 \
  --max-instances 1

Help Improve Speed(t)Code

Have you tested the app? I'm looking for technical feedback on the stability and typing engine latency. ➣ Submit your Feedback & Bug Reports here

By submitting the form, you can opt-in to be featured in the Hall of Fame below!

Hall of Fame

A massive thank you to everyone who helped stress test the game and try to break the typing engine!

User 1
imrahnf

Me!
User 1
imankamrann

Tester
User 1
burhanf

Tester
User 1
HARSHEE04

Tester
User 1
MaryamElhamidi

Tester

Built with ❀️ by Omrahn Faqiri

About

Speed(t)Code: Race to solve LeetCode-style coding problems by typing code at lightning speed! Built with Next.js, FastAPI, Redis, and deployed on Cloud Run.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published