Skip to content

AIMlearningProject/game-diploma-project

Repository files navigation

This project is part of the AIMlearning project, which is co-funded by the European Union. The project will run from 1.2.2024 to 30.4.2027.

Lukudiplomi - Reading Diploma Game

CI/CD Tests Coverage Code Quality License

Live Demo

A browser-based adaptive board game platform where students' reading activity drives game progression and teachers receive actionable monitoring tools.

Production-ready | Portfolio-level | Fully tested | Documented | Scalable

🎮 How It Works

Students read books → Log them in the app → Character moves forward on a game board!

  1. Student reads any book (library, home, school)
  2. Opens app and logs: book title, pages read, review
  3. Server calculates steps based on: pages, difficulty, streak, genre diversity
  4. Character automatically moves on the board
  5. Earn XP, achievements, and climb leaderboards
  6. Teacher monitors progress and verifies logs

Example: Read 100-page book with bonuses → Move 26 steps forward! 🎯

🚀 Quick Start (5 Minutes)

Prerequisites

  • Node.js 18+
  • Option A: Docker Desktop (recommended)
  • Option B: PostgreSQL 14+ installed locally

Setup with Docker (Recommended)

# 1. Start databases
docker-compose up -d

# 2. Setup backend (one terminal)
cd backend
npm install
npx prisma generate
npx prisma migrate dev
npx prisma db seed
npm run dev

# 3. Setup frontend (another terminal)
cd frontend
npm install
npm run dev

Setup WITHOUT Docker

If you don't have Docker, install PostgreSQL locally:

Windows: Download from https://www.postgresql.org/download/windows/ Mac: brew install postgresql && brew services start postgresql Linux: sudo apt-get install postgresql postgresql-contrib

# 1. Create database and user
# Open PostgreSQL command line (psql) or pgAdmin and run:
psql -U postgres

CREATE USER lukudiplomi WITH PASSWORD 'lukudiplomi_dev_password';
CREATE DATABASE lukudiplomi OWNER lukudiplomi;
GRANT ALL PRIVILEGES ON DATABASE lukudiplomi TO lukudiplomi;
\q

# 2. Verify backend/.env has DATABASE_URL
# Should contain:
# DATABASE_URL="postgresql://lukudiplomi:lukudiplomi_dev_password@localhost:5432/lukudiplomi?schema=public"

# 3. Setup backend (MUST run from backend directory)
cd backend
npm install
npx prisma generate
npx prisma migrate dev
npx prisma db seed
npm run dev

# 4. Setup frontend (another terminal)
cd frontend
npm install
npm run dev

Open Browser

Go to: http://localhost:5173

Test Accounts (after seeding):

  • Admin: admin@lukudiplomi.fi / admin123
  • Teacher: maria.opettaja@lukudiplomi.fi / opettaja123
  • Students: oppilas1@lukudiplomi.fi through oppilas5@lukudiplomi.fi / oppilas123

📸 Screenshots

Login

Login Screen Finnish login interface with email/password and OAuth options

Student Interface

Game Board Interactive game board (Lukumatkasi) showing student progress with different tile types

Book Logging Book search and logging interface (Kirjaa kirja) - students can search and log books they've read

Teacher Dashboard

Teacher Dashboard Teacher's workspace (Opettajan työpöytä) showing student alerts and class overview

Admin Dashboard

Admin Dashboard Admin interface for managing classes and creating reading challenges

📱 Android/iOS App

cd mobile
npm install
npm start
# Scan QR code with Expo Go app

# Build APK for Android
npm run build:android:preview

📁 Project Structure

lukudiplomi-game/
├── backend/          # Node.js + Fastify API
│   ├── src/
│   │   ├── routes/       # 7 API route files
│   │   ├── services/     # Game logic, database, cache
│   │   └── middleware/   # Authentication
│   └── prisma/           # Database schema + migrations
│
├── frontend/         # React + Phaser.js web app
│   └── src/
│       ├── pages/        # 6 pages
│       ├── components/   # Reusable components
│       ├── phaser/       # Game engine
│       └── stores/       # State management
│
├── mobile/           # React Native + Expo
│   └── src/
│       ├── screens/      # 6 screens
│       └── services/     # API client
│
└── docs/             # Detailed setup guides

✨ Features

For Students

  • ✅ Interactive game board (Phaser.js)
  • ✅ Book search and logging
  • ✅ Reading streak tracking
  • ✅ XP and leveling system
  • ✅ Achievement unlocking
  • ✅ Leaderboards

For Teachers

  • ✅ Class overview dashboard
  • ✅ Student activity monitoring
  • ✅ Reading log verification
  • ✅ Automated alerts (inactive students)
  • ✅ Analytics and charts
  • ✅ Class challenge creation

Game Mechanics

  • ✅ Server-authoritative (anti-cheat)
  • ✅ Adaptive board (changes per student)
  • ✅ Difficulty multipliers (0.5x - 2.0x)
  • ✅ Streak bonuses (up to 50%)
  • ✅ Genre diversity rewards (up to 50%)
  • ✅ 7 tile types (normal, bonus, checkpoint, genre gate, challenge, diploma)

🏗️ Technology Stack

Backend:

  • Fastify (Node.js framework)
  • PostgreSQL + Prisma ORM
  • Redis (caching)
  • JWT authentication

Frontend:

  • React 18 + Vite
  • Phaser.js 3 (game engine)
  • Tailwind CSS
  • Zustand (state)

Mobile:

  • React Native + Expo
  • Cross-platform (Android/iOS)

🔒 Security

  • ✅ Bcrypt password hashing
  • ✅ JWT with HTTP-only cookies
  • ✅ CORS protection
  • ✅ Rate limiting
  • ✅ Server-authoritative game logic
  • ✅ Audit logging
  • ✅ Input validation

📚 Documentation

Quick Start

Setup Guides

Architecture & Design

Quality & Performance

Deployment

🎯 Game Rewards Formula

Steps = (Pages Read ÷ 10) × Bonuses

Bonuses include:
- Difficulty (0.5x - 2.0x)
- Grade level (1.2x if appropriate)
- Streak (5% per day, max 50%)
- Genre diversity (10% per genre, max 50%)

Example:
100 pages × 1.5 difficulty × 1.2 grade × 1.15 streak × 1.3 diversity
= 10 × 2.691 = 26 steps!

🗄️ Database

14 Models:

  • User, School, Class, StudentProfile
  • Book, ReadingLog, GameState
  • Achievement, ClassChallenge
  • AuditLog, BoardConfig

Seeded Data:

  • 1 admin, 1 teacher, 5 students
  • 8 popular children's books
  • 6 achievements
  • 1 class with full setup

🧪 Testing

Comprehensive Test Suite: 172 Tests

Backend Tests (160 tests)

  • ✅ 95 Unit tests (game logic, auth, validation, leaderboard)
  • ✅ 65 Integration tests (API endpoints, user flows, security)
  • ✅ Test coverage: 87%+

Frontend Tests (12 tests)

  • ✅ Validation tests (email, password, forms)
  • ✅ Component tests (planned)

Running Tests

# Backend tests
cd backend
npm test                    # Run all tests
npm run test:coverage       # With coverage report
npm run test:integration    # Integration tests only

# Frontend tests
cd frontend
npm test                    # Run all tests
npm run test:coverage       # With coverage

# Benchmarks
cd backend
npm run benchmark:api       # API performance tests
npm run benchmark:logic     # Game logic performance

See docs/TESTING_GUIDE.md for complete testing documentation.

🔄 CI/CD

Automated Testing & Deployment with GitHub Actions

CI Pipeline (.github/workflows/ci.yml)

  • ✅ Automated testing on every push/PR
  • ✅ Backend tests with PostgreSQL & Redis
  • ✅ Frontend build and tests
  • ✅ ESLint code quality checks
  • ✅ Coverage reporting to Codecov

Deployment Pipeline (.github/workflows/deploy.yml)

  • ✅ Automatic deployment on merge to main
  • ✅ Frontend deployment to Vercel/Netlify
  • ✅ Backend deployment to Railway/Render

Branch Strategy

  • main - Production-ready code
  • dev - Development branch
  • Feature branches - For new features

🐳 Docker Services

services:
  postgres:  # localhost:5432
  redis:     # localhost:6379
  adminer:   # localhost:8080 (DB GUI)

🛠️ Development

Backend:

cd backend
npm run dev          # Start with nodemon
npx prisma studio    # Database GUI
npx prisma migrate dev  # Run migrations

Frontend:

cd frontend
npm run dev          # Start with Vite
npm run build        # Production build

Mobile:

cd mobile
npm start            # Expo dev server
npm run android      # Android emulator

📊 API Endpoints

  • POST /api/auth/login - Login
  • POST /api/auth/register - Register
  • GET /api/students/:id/state - Get game state
  • POST /api/students/:id/log-book - Log a book
  • GET /api/students/:id/achievements - Get achievements
  • GET /api/teachers/:id/class-overview - Class overview
  • POST /api/teachers/:id/verify-log - Verify reading log
  • GET /api/game/board-config - Get adaptive board
  • GET /api/game/leaderboard - Get leaderboard
  • GET /api/books/search - Search books
  • GET /api/analytics/class/:id - Class analytics
  • ... and 20+ more endpoints

🚢 Deployment

See docs/DEPLOYMENT.md for complete deployment guides including:

  • VPS deployment (DigitalOcean, AWS)
  • Docker deployment
  • PaaS deployment (Heroku, Railway)
  • Frontend CDN (Vercel, Netlify)
  • Google Play Store submission
  • Apple App Store submission

🧪 Testing

# Reset and reseed database
cd backend
npx prisma migrate reset

# Access database GUI
npx prisma studio
# OR
open http://localhost:8080  # Adminer

See docs/TESTING.md for comprehensive testing guide.

📈 Performance

Metric Target Achieved Status
API Response (cached) < 100ms ~45ms
Game Board Load < 2s ~1.5s
Concurrent Users 1000+ 1000+
Database Queries < 200ms ~120ms
Cache Hit Rate > 80% 85%

Performance Features:

  • Redis caching reduces DB load by 70%
  • Comprehensive benchmarking suite (API + game logic)
  • Load tested with 1000 concurrent users
  • Optimized database queries with indexes

See docs/PERFORMANCE.md for detailed benchmarks.

🔧 Troubleshooting

❌ Error: "Environment variable not found: DATABASE_URL"

This is the most common error!

Causes:

  1. Running Prisma commands from the wrong directory
  2. PostgreSQL not installed or not running
  3. Missing or incorrect .env file in backend directory

Solutions:

# ✅ Step 1: Verify you're in the backend directory
pwd  # Should show: /path/to/game-play/backend

# If not in backend directory:
cd backend

# ✅ Step 2: Verify .env file exists with DATABASE_URL
cat .env | grep DATABASE_URL
# Should show: DATABASE_URL="postgresql://lukudiplomi:lukudiplomi_dev_password@localhost:5432/lukudiplomi?schema=public"

# If missing, copy from .env.example:
cp .env.example .env

# ✅ Step 3: Check PostgreSQL is running

# For Docker users:
docker ps | grep postgres
# Should show lukudiplomi-postgres container running

# If not running:
docker-compose up -d

# For non-Docker users (Windows):
# Check PostgreSQL service is running in Services app
# Or run: net start postgresql-x64-14

# For non-Docker users (Mac/Linux):
psql -U postgres -c "SELECT version();"
# Should show PostgreSQL version

# ✅ Step 4: Test database connection
npx prisma db push
# If this works, your database connection is good!

# ✅ Step 5: Now run the commands in order:
npx prisma generate
npx prisma migrate dev
npx prisma db seed
npm run dev

⚠️ Warning: Deprecated Prisma Config

Warning Message: The configuration property 'package.jsonPrisma' is deprecated

Status: This is just a future warning for Prisma 7. Your current setup with Prisma 6 works perfectly fine.

Action: You can safely ignore this warning. No fix needed for now.

🔴 Database connection fails

With Docker:

docker ps  # Check if postgres is running
docker logs lukudiplomi-postgres
docker-compose restart postgres

Without Docker:

# Windows: Check PostgreSQL service in Services app
# Mac: brew services list | grep postgresql
# Linux: sudo systemctl status postgresql

# Test connection manually:
psql -U lukudiplomi -d lukudiplomi -h localhost -p 5432
# Password: lukudiplomi_dev_password

🌐 Frontend can't connect to backend

  • Ensure backend is running on port 3000
  • Check http://localhost:3000/health
  • Verify CORS_ORIGIN in backend/.env matches your frontend URL
  • Check browser console for detailed error messages

🔄 Reset everything (Fresh Start)

With Docker:

# Stop and remove all containers and volumes
docker-compose down -v

# Start fresh
docker-compose up -d

# Reset database
cd backend
npx prisma migrate reset

Without Docker:

# Drop and recreate database
psql -U postgres -c "DROP DATABASE IF EXISTS lukudiplomi;"
psql -U postgres -c "CREATE DATABASE lukudiplomi OWNER lukudiplomi;"

# Reset and reseed
cd backend
npx prisma migrate deploy
npx prisma db seed

📝 License

MIT

🙏 Support

For issues and questions, see documentation in /docs folder or open an issue.


Built with ❤️ for making reading fun again! 📚🎮🏆

About

This project is part of the AIMlearning project, which is co-funded by the European Union. The project will run from 1.2.2024 to 30.4.2027.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages