https://github.com/jayakrishna1509/online-quiz-application
Online Quiz Application Full Stack App.
https://github.com/jayakrishna1509/online-quiz-application
css env flask html javascript json node python react sqlite
Last synced: 2 months ago
JSON representation
Online Quiz Application Full Stack App.
- Host: GitHub
- URL: https://github.com/jayakrishna1509/online-quiz-application
- Owner: jayakrishna1509
- License: mit
- Created: 2025-10-05T05:43:17.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2025-10-05T06:15:27.000Z (9 months ago)
- Last Synced: 2025-10-05T08:29:13.340Z (9 months ago)
- Topics: css, env, flask, html, javascript, json, node, python, react, sqlite
- Language: CSS
- Homepage: https://online-quiz-application-test.vercel.app/
- Size: 64.5 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ๐ง Online Quiz Application
A full-stack quiz application with a Python Flask backend and React frontend, featuring real-time timer, detailed results, and responsive design.
## ๐ Project Overview
This application allows users to:
- Select from multiple quiz categories
- Take timed quizzes with navigation between questions
- View detailed results with question-by-question breakdown
- See performance metrics and time taken
## ๐๏ธ Architecture
```
online-quiz-application/
โโโ backend/ # Flask REST API
โ โโโ app.py
โ โโโ models.py
โ โโโ database.py
โ โโโ init_db.py
โ โโโ test_scoring.py
โ โโโ quiz_data.json
โ โโโ config.json
โ โโโ requirements.txt
โ โโโ README.md
โ
โโโ frontend/ # React + Vite
โโโ src/
โ โโโ components/
โ โโโ App.jsx
โ โโโ App.css
โ โโโ main.jsx
โ โโโ index.css
โโโ package.json
โโโ vite.config.js
โโโ README.md
```
## ๐ Quick Start
### Prerequisites
- Python 3.7 or higher
- Node.js 16 or higher
- npm or yarn
### Backend Setup
1. **Navigate to backend directory**:
```bash
cd backend
```
2. **Create virtual environment** (recommended):
```bash
python -m venv venv
```
3. **Activate virtual environment**:
- Windows:
```bash
venv\Scripts\activate
```
- macOS/Linux:
```bash
source venv/bin/activate
```
4. **Install dependencies**:
```bash
pip install -r requirements.txt
```
5. **Initialize database**:
```bash
python init_db.py
```
6. **Start backend server**:
```bash
python app.py
```
Backend will run on `http://localhost:5000`
### Frontend Setup
1. **Navigate to frontend directory** (in a new terminal):
```bash
cd frontend
```
2. **Install dependencies**:
```bash
npm install
```
3. **Start development server**:
```bash
npm run dev
```
Frontend will run on `http://localhost:3000`
4. **Open your browser**:
Navigate to `http://localhost:3000`
## โจ Features
### Core Features
#### Backend
- **RESTful API**: Clean endpoints for quiz management
- **SQLite Database**: Stores quizzes, questions, and options
- **JSON Configuration**: Easy configuration via `quiz_data.json` and `config.json`
- **Scoring Logic**: Automatic score calculation with detailed results
- **Test Suite**: Comprehensive pytest tests for scoring functionality
- **Data Validation**: Backend validation for question limits and correct options
#### Frontend
- **Modern UI**: Beautiful gradient designs with smooth animations
- **Fully Responsive**: Works on desktop, tablet, and mobile (media queries for all breakpoints)
- **Timer System**: 5-minute countdown with visual warnings (yellow at 60s, red at 30s)
- **Progress Tracking**: Real-time progress bar and question counter
- **Navigation**: Previous/Next buttons to move between questions
- **Smart Validation**: Warns about unanswered questions before submission
- **Detailed Results**:
- Circular progress indicator
- Performance message based on score
- Question-by-question breakdown
- Shows user's answer vs correct answer
- Color-coded correct/incorrect indicators
- Time taken display
### Bonus Features โ
- โ
**Timer**: 5-minute countdown with visual indicators
- โ
**Detailed Results**: Shows which questions were right/wrong with correct answers
- โ
**Backend Tests**: Comprehensive pytest suite for scoring logic
## ๐งช Sample Data
The application comes with 3 sample quizzes:
1. **Programming Fundamentals** (5 questions)
- HTML, JavaScript, CSS, Python, API basics
2. **JavaScript Basics** (4 questions)
- Variables, arrays, operators, NaN
3. **Database Concepts** (3 questions)
- SQL, SELECT, primary keys
## ๐ง API Endpoints
### Quiz Management
- **GET** `/api/quizzes` - Get all available quizzes
- **POST** `/api/quizzes` - Create a new quiz
- **GET** `/api/quizzes/{id}` - Get a specific quiz
- **GET** `/api/quizzes/{id}/questions` - Get questions for a quiz (without correct answers)
- **POST** `/api/quizzes/{id}/questions` - Add a question to a quiz
- **POST** `/api/quizzes/{id}/submit` - Submit quiz answers and get results
- **GET** `/api/health` - Health check endpoint
### Request/Response Examples
#### Get Questions
```json
GET /api/quizzes/1/questions
Response:
[
{
"id": 1,
"text": "What does HTML stand for?",
"options": [
{"id": 1, "text": "Hyper Text Markup Language"},
{"id": 2, "text": "High Tech Modern Language"}
]
}
]
```
#### Submit Quiz
```json
POST /api/quizzes/1/submit
Request:
{
"answers": [
{"questionId": 1, "selectedOptionId": 1},
{"questionId": 2, "selectedOptionId": 5}
]
}
Response:
{
"score": 8,
"total": 10,
"percentage": 80.0,
"results": [
{
"questionId": 1,
"questionText": "What does HTML stand for?",
"userAnswer": "Hyper Text Markup Language",
"correctAnswer": "Hyper Text Markup Language",
"isCorrect": true
}
]
}
```
## ๐งช Testing
### Backend Tests
Run the unit tests for scoring logic:
```bash
cd backend
pytest test_scoring.py -v
```
Test coverage includes:
- All correct answers
- All wrong answers
- Partial correct answers
- Missing answers
- Results details validation
- Invalid quiz ID handling
- Missing answers field validation
## ๐จ Customization
### Adding New Quizzes
1. Edit `backend/quiz_data.json`:
```json
{
"quizzes": [
{
"title": "Your Quiz Title",
"questions": [
{
"text": "Your question?",
"options": [
{ "text": "Option 1", "is_correct": true },
{ "text": "Option 2", "is_correct": false }
]
}
]
}
]
}
```
2. Reinitialize database:
```bash
cd backend
python init_db.py
```
### Changing Timer Duration
Edit `frontend/src/components/QuizView.jsx`:
```javascript
const [timeRemaining, setTimeRemaining] = useState(300); // seconds
```
### Customizing Colors
Edit `frontend/src/index.css`:
```css
:root {
--primary-color: #6366f1;
--secondary-color: #ec4899;
--success-color: #10b981;
--error-color: #ef4444;
}
```
### Backend Configuration
Edit `backend/config.json`:
```json
{
"app": {
"port": 5000,
"debug": true
},
"quiz_settings": {
"default_timer_minutes": 5,
"max_question_length": 300
}
}
```
## ๐ฑ Responsive Design
The application is fully responsive with breakpoints for:
- **Desktop**: > 768px
- **Tablet**: 481px - 768px
- **Mobile**: โค 480px
All components adapt seamlessly to different screen sizes with optimized layouts and touch-friendly interfaces.
## ๐ Troubleshooting
### Backend Issues
**Database errors:**
```bash
cd backend
rm -rf instance/quiz.db # Delete database
python init_db.py # Recreate
```
**Port already in use:**
- Change port in `backend/app.py` or `backend/config.json`
**Import errors:**
- Ensure virtual environment is activated
- Reinstall dependencies: `pip install -r requirements.txt`
### Frontend Issues
**API connection errors:**
- Ensure backend is running on port 5000
- Check proxy configuration in `frontend/vite.config.js`
**Build errors:**
```bash
cd frontend
rm -rf node_modules
npm install
```
**Styling issues:**
- Clear browser cache
- Check browser compatibility
## ๐ฑ Browser Compatibility
- โ
Chrome 80+
- โ
Firefox 75+
- โ
Safari 13+
- โ
Edge 80+
## ๐ Production Deployment
### Backend
```bash
cd backend
pip install gunicorn
gunicorn -w 4 -b 0.0.0.0:5000 app:app
```
### Frontend
```bash
cd frontend
npm run build
# Serve the dist/ folder with your web server
```
## ๐ Project Evaluation
### Dev Skills & Code Quality โ
- Full end-to-end functionality
- State management with React hooks
- Well-designed RESTful API
- Clean code structure with separation of concerns
- Comprehensive error handling
### Completion โ
- Users can complete entire quiz flow from start to finish
- All core features implemented
- Bonus features included
### Bonus Features โ
- Timer with visual indicators
- Detailed results with right/wrong breakdown
- Backend tests for scoring logic
## ๐ค Contributing
1. Fork the repository
2. Create a feature branch
3. Make your changes
4. Add tests if applicable
5. Submit a pull request
## ๐ License
This project is open source and available under the MIT License.
---
**Built with โค๏ธ using React, Python Flask, and Modern Web Technologies**