Skip to content
splagemannPublic

About

A quiz app to create and play quizzes

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

89 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Quiz App

A full-featured online quiz application with multiplayer support built with Next.js, TypeScript, and SQLite.

⚠️ Disclaimer

This application was completely generated by AI. There is no guarantee that the code will work correctly or is secure. Use at your own risk. This project is provided as-is for educational and experimental purposes.

Internationalization: Supports English (default) and German with per-quiz language settings.

License

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

Features

Internationalization (i18n)

  • Multi-Language Support: English (default) and German
  • Per-Quiz Language Settings: Each quiz can have its own language, independent of the global interface language
  • Global Language Selector: Users can switch the admin interface language in the admin section
  • Language Persistence: User's language preference is saved in cookies
  • Automatic Language Application: Quiz gameplay automatically uses the quiz's configured language

UI/UX

  • Dynamic Browser Titles: Shows quiz names in the browser tab
  • Custom Favicon: Purple-blue gradient icon matching the app design
  • Responsive Design: Optimized for desktop and mobile
  • Mobile-Optimized: Color-coded answers and full-screen views

Admin Mode

  • Quiz Management: Create, edit, and delete quizzes
  • Question Management: Add, edit, and delete questions with optional title, description, and image
  • Image Upload: Upload images directly (stored locally)
  • Answer Management: Each question has 2-4 possible answers, with flexible configuration and image support
  • Quiz Overview: Display all created quizzes with question count and metadata
  • Session Management: View and manage all active multiplayer game sessions
    • Real-time session monitoring with automatic refresh
    • Individual and bulk session deletion
    • Mark Player to Win: Special feature for celebrations - mark a player who will automatically win (crown emoji visible only in admin)

Single Player Mode

  • Quiz Selection: Browse and select available quizzes
  • Interactive Gameplay: Answer questions one by one with visual feedback
  • Scoring System: 1 point for each correct answer
  • Progress Indicator: Live progress bar during gameplay
  • Results Screen: Final score and percentage with options to retry or choose another quiz

Multiplayer Mode

  • Host Interface: Host games, generate QR codes, view real-time player list
  • Player Join: Join via QR code or 6-digit session code
  • Real-time Updates: Server-Sent Events (SSE) for live synchronization between host and players
  • Flexible Control: Host can manually reveal answers at any time, even if not all players have answered
  • Live Scoreboard: Real-time leaderboard during gameplay
  • Final Rankings: Final leaderboard with avatars and scores
  • Avatar System: Customizable avatars with "Switch Avatar" button - players can change their avatar in the waiting room and it persists throughout the game

Tech Stack

  • Framework: Next.js 14+ (App Router)
  • Language: TypeScript
  • Database: SQLite with Prisma ORM
  • Real-time: Server-Sent Events (SSE)
  • Styling: Tailwind CSS
  • Internationalization: next-intl
  • QR Codes: qrcode library
  • Avatars: Multiavatar library
  • Deployment: Docker & Docker Compose

Getting Started

Prerequisites

  • Node.js 18+
  • npm or yarn

Installation

  1. Clone the repository
  2. Install dependencies:
npm install
  1. Create .env file (copy from .env.example):
cp .env.example .env
  1. Update the .env file with your configuration:
DATABASE_URL="file:./prisma/dev.db"
NEXT_PUBLIC_APP_URL="http://localhost:3210"
DEFAULT_LANG="en"  # Default language: 'en' (English) or 'de' (German)
ADMIN_PASSPHRASE=""  # Optional passphrase for admin access
  1. Set up the database:
npx prisma migrate dev
npx prisma generate
  1. Start the development server:
npm run dev
  1. Open http://localhost:3210 in your browser

Project Structure

/app                         # Next.js App Router pages and API routes
  /admin                     # Quiz management interface
  /game                      # Single and multiplayer game modes
  /api                       # REST and SSE endpoints
  /components                # Shared React components
/lib                         # Utility functions and configurations
/locales                     # i18n translation files (en.json, de.json)
/prisma                      # Database schema and migrations
/public/uploads              # User-uploaded images

Database Schema

Quiz

  • id (primary key)
  • title
  • description (optional)
  • language (default: 'en', supports 'en' and 'de')
  • createdAt
  • updatedAt

Question

  • id (primary key)
  • quizId (foreign key)
  • title (optional)
  • questionText
  • description (optional)
  • imageUrl (optional)
  • orderIndex
  • createdAt

Answer

  • id (primary key)
  • questionId (foreign key)
  • answerText
  • isCorrect
  • orderIndex

GameSession

  • id (primary key)
  • quizId (foreign key)
  • sessionCode (6-digit unique code)
  • status (waiting, in_progress, finished)
  • currentQuestion (index)
  • createdAt, startedAt, finishedAt

Player

  • id (primary key)
  • sessionId (foreign key)
  • playerName
  • score
  • joinedAt
  • isConnected
  • markedToWin (boolean, default: false)

PlayerAnswer

  • id (primary key)
  • sessionId (foreign key)
  • playerId (foreign key)
  • questionId (foreign key)
  • answerId (foreign key)
  • answeredAt
  • isCorrect
  • timeToAnswer

Usage

Creating a Quiz

  1. Navigate to /admin in your browser
  2. Click "Create New Quiz"
  3. Enter title and optional description
  4. Select the quiz language (English or German)
  5. Click "Create Quiz"
  6. Add questions with optional title, description, and image
  7. Optionally upload an image for each question
  8. Enter 2-4 answers and mark the correct answer

Note: The quiz language setting determines what language will be used during gameplay, independent of the admin interface language.

Single Player Mode

  1. From the homepage, click "Browse Games" or navigate to /games
  2. Select a quiz from available options
  3. Choose "Play Solo"
  4. Read each question and click your answer
  5. Get immediate feedback (green = correct, red = incorrect)
  6. Progress through all questions
  7. View your final score

Note: The interface will use the language configured for the selected quiz.

Multiplayer Mode

As Host:

  1. From the homepage, click "Browse Games" or navigate to /games
  2. Select a quiz and choose "Host Multiplayer"
  3. Share the QR code or 6-digit session code with players
  4. Wait for all players to join
  5. Start the game
  6. Manually reveal answers or wait until all have answered
  7. Proceed to next question
  8. View final leaderboard at the end

As Player:

  1. On the homepage, enter the 6-digit session code or scan the QR code
  2. Enter your name (2-20 characters)
  3. Wait for the host to start the game
  4. Answer questions as quickly as possible
  5. View your position in the leaderboard at the end

Note: All players will see the interface in the language configured for the quiz being played.

Development

Database Migrations

When you make changes to the Prisma schema:

npx prisma migrate dev --name description_of_changes

Generate Prisma Client

npx prisma generate

View Database

npx prisma studio

Releases

This project uses Semantic Versioning (SemVer) for version management.

Release Information

Version Format

Versions follow the MAJOR.MINOR.PATCH format:

  • MAJOR (1.0.0 → 2.0.0): Breaking changes or major new features
  • MINOR (1.0.0 → 1.1.0): New features, backwards-compatible
  • PATCH (1.0.0 → 1.0.1): Bug fixes, backwards-compatible

Creating a Release

Note: The main branch is protected and requires pull requests.

There are two ways to create a release:

Option 1: Automated GitHub Actions Workflow (Recommended)

The easiest way to create a release is through the GitHub Actions workflow:

  1. Go to Actions tab in GitHub
  2. Select "Automated Release" workflow
  3. Click "Run workflow"
  4. Choose version type (patch/minor/major)
  5. Optionally enable dry run to test
  6. Click "Run workflow"

The workflow will automatically:

  • Bump version in package.json
  • Validate CHANGELOG entry exists
  • Create release PR with extracted notes
  • Merge PR (or wait for approval)
  • Create and push git tag
  • Trigger Docker build and GitHub release

Documentation: See .github/workflows/RELEASE.md for detailed instructions

Requirements:

  • CHANGELOG.md must be updated with release notes
  • All tests must pass

Option 2: Manual Release Script

Alternatively, use the command-line release script:

# Patch release (bug fixes): 1.0.0 → 1.0.1
./scripts/release.sh patch

# Minor release (new features): 1.0.0 → 1.1.0
./scripts/release.sh minor

# Major release (breaking changes): 1.0.0 → 2.0.0
./scripts/release.sh major

# Preview changes without committing
./scripts/release.sh patch --dry-run

The release script will:

  1. Ensure you're on the latest main branch
  2. Update package.json version
  3. Verify CHANGELOG.md has been updated
  4. Run tests
  5. Create a release branch and commit
  6. Create and merge a Pull Request to main (using admin privileges)
  7. Create and push an annotated git tag
  8. Trigger the CI/CD pipeline

Requirements:

  • GitHub CLI (gh) must be installed and authenticated
  • Repository admin access (for merging protected branch)
  • All tests must pass

Important: Before creating a release with either method, update CHANGELOG.md with your changes following the Keep a Changelog format.

CI/CD Pipeline

Every release automatically triggers a GitHub Actions workflow that:

  • Builds multi-platform Docker images (linux/amd64, linux/arm64)
  • Publishes to GitHub Container Registry (ghcr.io)
  • Creates version-specific tags (e.g., v1.0.0, 1.0.0, 1.0, 1)
  • Updates the latest tag
  • Automatically creates a GitHub Release with:
    • Release notes extracted from CHANGELOG.md
    • Docker image pull commands
    • Supported architectures information

Monitor builds: GitHub Actions

Deployment with Docker

This application is ready to deploy using Docker. You can either use pre-built images from GitHub Container Registry or build locally.

Option 1: Using Pre-built Images (Fastest)

Pre-built Docker images are automatically published to GitHub Container Registry on every commit to main.

  1. Pull the latest image:
docker pull ghcr.io/splagemann/quiz-app:latest
  1. (Optional) Configure environment variables by creating a .env file:
cp .env.example .env
# Edit .env to set DEFAULT_LANG and ADMIN_PASSPHRASE if needed
  1. Run with Docker Compose:
# The docker-compose.yml is already configured to use pre-built images
docker compose up -d
  1. The application will be available at http://localhost:3210

Available Image Tags:

  • latest - Latest stable build from main branch
  • main - Latest commit on main branch
  • v1.0.0 - Specific version tags
  • sha-abc1234 - Specific commit builds

Option 2: Using Docker Compose with Local Build

  1. Clone the repository:
git clone git@github.com:splagemann/quiz-app.git
cd quiz-app
  1. Edit docker-compose.yml to use local build:
# Comment out the 'image' line
# image: ghcr.io/splagemann/quiz-app:latest

# Uncomment the 'build' section
build:
  context: .
  dockerfile: Dockerfile
  1. Build and start the application:
docker compose up -d --build
  1. The application will be available at http://localhost:3210

Option 3: Using Docker CLI directly

  1. Build the Docker image:
docker build -t quiz-app .
  1. Create a volume for persistent data:
docker volume create quiz-data
docker volume create quiz-uploads
  1. Run the container:
docker run -d \
  --name quiz-app \
  -p 3210:3000 \
  -e DATABASE_URL=file:/app/data/quiz.db \
  -e NEXT_PUBLIC_APP_URL=http://localhost:3210 \
  -e DEFAULT_LANG=en \
  -e ADMIN_PASSPHRASE="" \
  -v quiz-data:/app/data \
  -v quiz-uploads:/app/public/uploads \
  --restart unless-stopped \
  quiz-app

Managing the Application

View logs:

docker-compose logs -f
# or
docker logs -f quiz-app

Stop the application:

docker-compose down
# or
docker stop quiz-app

Update the application:

git pull
docker-compose down
docker-compose up -d --build

Production Considerations

  • Update NEXT_PUBLIC_APP_URL to your actual domain
  • Use a reverse proxy (nginx/traefik) with SSL/TLS for HTTPS
  • Set up regular backups of the Docker volumes (database and uploads)
  • Mount the volumes to specific host directories for easier backup:
    volumes:
      - ./data:/app/data
      - ./uploads:/app/public/uploads

About

A quiz app to create and play quizzes

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages