This guide will walk you through setting up and running the complete Quiz App system.
The Quiz App consists of:
- Backend API: Node.js + Express + Socket.io + Appwrite
- Admin Dashboard: React web app for managing quizzes
- React Native App: Mobile client (created separately)
- Shared Package: Common types and utilities
- Node.js 18+ and npm 8+
- Git
- Code editor (VS Code recommended)
git clone <your-repo-url>
cd quiz-app-back
./setup.sh # or bash setup.sh on WindowsFollow the detailed Appwrite Setup Guide:
- Create account at https://cloud.appwrite.io
- Create new project
- Get Project ID and API Key
- Update
packages/backend/.env
npm run dev # Starts both backend and dashboardVisit:
- Backend API: http://localhost:3001/health
- Admin Dashboard: http://localhost:3000
Edit packages/backend/.env:
# Required - Get from Appwrite
APPWRITE_PROJECT_ID=your_project_id_here
APPWRITE_API_KEY=your_api_key_here
# Required - Generate secure random strings
JWT_SECRET=your_super_secure_jwt_secret_here
ADMIN_SECRET_KEY=your_admin_secret_key_here
# Optional - Defaults provided
PORT=3001
APPWRITE_ENDPOINT=https://cloud.appwrite.io/v1
ALLOWED_ORIGINS=http://localhost:3000,http://localhost:19006- Start the backend:
npm run dev:backend- Register a user:
curl -X POST http://localhost:3001/api/auth/register \
-H "Content-Type: application/json" \
-d '{
"username": "admin",
"email": "admin@example.com",
"password": "password123"
}'-
In Appwrite Dashboard:
- Go to Database → quiz_app_db → users collection
- Find your user and edit
- Change
rolefrom"student"to"admin"
-
Test admin login:
curl -X POST http://localhost:3001/api/auth/admin-login \
-H "Content-Type: application/json" \
-d '{
"email": "admin@example.com",
"password": "password123",
"adminKey": "your_admin_secret_key_here"
}'-
Login to Dashboard at http://localhost:3000
-
Create Questions:
- Click "Add Question"
- Enter question text and options
- Select correct answer
- Set time limit (default 60s)
-
Start Quiz Session:
- Click "Start Quiz"
- Questions will automatically cycle every 60s
- Monitor live leaderboard
-
Manage Active Quiz:
- Skip to next question manually
- View participant count
- Stop quiz session
- Register/Login:
# Register
curl -X POST http://localhost:3001/api/auth/register \
-H "Content-Type: application/json" \
-d '{"username":"student1","email":"student1@example.com","password":"password123"}'
# Login
curl -X POST http://localhost:3001/api/auth/login \
-H "Content-Type: application/json" \
-d '{"email":"student1@example.com","password":"password123"}'- Connect to Live Quiz (Socket.io):
import io from 'socket.io-client';
const socket = io('http://localhost:3001');
// Join quiz
socket.emit('join-quiz', 'user_id_from_login');
// Listen for new questions
socket.on('new-question', (question) => {
console.log('New question:', question);
// Display question to user
});
// Submit answer
socket.emit('submit-answer', {
questionId: 'question_id',
selectedAnswer: 2,
responseTime: 15000 // milliseconds
});
// Watch leaderboard updates
socket.on('leaderboard-update', (leaderboard) => {
console.log('Updated scores:', leaderboard);
});# Root level
npm run dev # Start both backend and dashboard
npm run build # Build all packages
npm run install:all # Install all dependencies
# Backend only
npm run dev:backend # Start backend with auto-reload
npm run build:backend # Build backend
# Dashboard only
npm run dev:dashboard # Start dashboard dev server
npm run build:dashboard # Build dashboard for production
# Shared package
npm run build:shared # Build shared typesquiz-app-back/
├── packages/
│ ├── backend/ # Node.js API server
│ │ ├── src/
│ │ │ ├── controllers/ # Route handlers
│ │ │ ├── middleware/ # Auth, validation
│ │ │ ├── routes/ # API endpoints
│ │ │ ├── services/ # Business logic
│ │ │ ├── socket/ # Real-time events
│ │ │ └── utils/ # Helpers
│ │ └── README.md
│ │
│ ├── dashboard/ # React admin panel
│ │ ├── src/
│ │ │ ├── components/ # UI components
│ │ │ ├── pages/ # Route pages
│ │ │ ├── contexts/ # React contexts
│ │ │ ├── hooks/ # Custom hooks
│ │ │ └── services/ # API calls
│ │ └── README.md
│ │
│ └── shared/ # Common types/utils
│ ├── src/
│ │ ├── types.ts # TypeScript types
│ │ └── utils.ts # Utility functions
│ └── README.md
│
├── docs/ # Documentation
│ ├── APPWRITE_SETUP.md # Appwrite configuration
│ └── API.md # API documentation
│
├── setup.sh # Automated setup script
└── README.md # Main documentation
Use the provided Postman collection or curl commands:
# Health check
curl http://localhost:3001/health
# Get current quiz status
curl http://localhost:3001/api/quiz/current
# Admin: Get questions (requires auth token)
curl -H "Authorization: Bearer YOUR_TOKEN" \
http://localhost:3001/api/admin/questionsThe system uses Socket.io for real-time updates:
quiz-started- New quiz session beginsnew-question- Next question available (every 60s)question-ended- Current question time expiredleaderboard-update- Live score updatesquiz-ended- Session finished
join-quiz- Student joins sessionsubmit-answer- Answer submissionadmin-join- Admin connects for controlforce-next-question- Admin skips question
Auto-created collections:
- users: Student/admin accounts
- questions: Quiz questions with options
- quiz_sessions: Active quiz tracking
- user_responses: Answer submissions
- leaderboard: Calculated scores
npm run build:backend
cd packages/backend
npm startnpm run build:dashboard
# Deploy packages/dashboard/dist to your hosting provider"Appwrite connection failed"
- Check APPWRITE_ENDPOINT and APPWRITE_PROJECT_ID
- Verify API key has correct permissions
- Ensure Appwrite project exists
"Collections not created"
- Check API key has
collections.writepermission - Verify database permissions in Appwrite console
- Restart backend server
"Socket connection failed"
- Check CORS configuration in ALLOWED_ORIGINS
- Verify backend is running on correct port
- Check firewall/network settings
"Admin login failed"
- Ensure user role is set to "admin" in Appwrite
- Verify ADMIN_SECRET_KEY matches in .env
- Check user exists and password is correct
Backend logs:
# View logs
tail -f packages/backend/logs/combined.log
# Debug mode
DEBUG=* npm run dev:backendDatabase inspection:
- Visit Appwrite Console
- Navigate to Database → quiz_app_db
- Inspect collections and documents
-
Connect React Native App:
- Use same Socket.io events
- Implement mobile UI for questions
- Handle real-time score updates
-
Enhance Features:
- Question categories
- Timed quiz sessions
- Image/video questions
- Team-based scoring
-
Production Deployment:
- Set up CI/CD pipeline
- Configure production environment
- Add monitoring and logging
- Implement backup strategy
For issues and questions, check the documentation or create an issue in the repository.