This is a full-stack quiz application where users can select quizzes, answer questions, and see their scores. The app is containerized using Docker and includes the following:
- Frontend: React (served via Nginx in production).
- Backend: Node.js with Express.
- Database: MySQL.
- Orchestration: Docker Compose.
- Dynamic quiz selection and question answering.
- Backend API to fetch quizzes and questions.
- Toast notifications for errors and validation.
- Optimized production setup using Nginx.
Ensure you have the following installed on your system:
- Docker: Install Docker
- Docker Compose: Install Docker Compose
- jq: Install jq (Optional)
Follow these steps to run the application:
git clone <repository-url>
cd <repository-folder>
docker-compose up -d --build
- Frontend: Open your browser and navigate to
http://localhost:8080
. - Backend API: Accessible at
http://localhost:3001/api
.
- Built with React.
- Served using Nginx in production.
- Proxying API requests to the backend (
/api
).
- Node.js with Express.
- Provides RESTful API endpoints:
GET /quizzes
: Fetch all quizzes.GET /quizzes/:id/questions
: Fetch questions for a specific quiz.POST /submit
: Submit answers and calculate scores.
- MySQL database to store quiz and question data.
- The schema is initialized using
quiz-data.sql
. You may use the utility scriptrefresh-data.sh -f /path/to/quiz-data.json
to update the database whenever changes are made to thequiz-data.json
file. Please ensure thatquiz-data.json
is formatted correctly and that there are no errors when running the utility script.
The application uses the following environment variables:
- DB_HOST: Database hostname (default:
db
for Docker networking). - DB_USER: Database user (default:
username
). - DB_PASSWORD: Database password (default:
pass
). - DB_NAME: Database name (default:
quiz_app
).
- REACT_APP_API_URL: Backend API URL (default:
http://localhost:3001
).
To stop the application and remove containers:
docker-compose down
To stop and remove all volumes (including the database):
docker-compose down -v
- Ensure that port
8080
(frontend),3001
(backend), and3306
(MySQL) are not occupied by other services. - When starting the app for the first time, you may see "No quizzes available" on the frontend. Give it a minute for the database to setup and inject some test data, then refresh the page.
- If you need to make changes to the app, rebuild the containers using:
docker-compose up -d --build
-
Frontend Not Loading?
- Check if the Nginx container is running:
docker ps
. - Ensure React's production build was created successfully during the build process.
- Check if the Nginx container is running:
-
Backend API Errors?
- Check the logs of the backend container:
docker logs <backend-container-id>
.
- Check the logs of the backend container:
-
Database Connection Issues?
- Ensure the MySQL service is running:
docker ps
. - Verify environment variables for the database in
docker-compose.yml
.
- Ensure the MySQL service is running:
- Add authentication and player management.
- Add more robust error handling.
- Improve quiz management (e.g., create quizzes dynamically).