A full-stack web application for creating and taking quizzes, built with Django REST Framework and React TypeScript.
Demo-Quiz.mp4
- Overview
- Features
- Backend Architecture
- Frontend Architecture
- Installation
- Usage
- API Documentation
- Contributing
This application provides an interactive platform for users to take quizzes, track their progress, and view their performance history. The system is built with a Django backend serving a REST API and a React TypeScript frontend providing a modern, responsive user interface.
- User authentication and authorization
- Interactive quiz sessions
- Multiple choice questions with varying difficulty levels
- Real-time scoring and progress tracking
- Performance history and analytics
- Responsive design for all devices
- Error boundary protection
- Lazy loading for optimal performance
- Django
- Django REST Framework
- SQLite Database
- Token Authentication
- CORS support
- Question
class Question(models.Model):
id = models.UUIDField(primary_key=True)
text = models.TextField()
difficulty = models.CharField(choices=['easy', 'medium', 'hard'])
- Represents quiz questions
- Uses UUID for secure identification
- Supports different difficulty levels
- QuestionOption
class QuestionOption(models.Model):
question = models.ForeignKey(Question)
text = models.CharField(max_length=255)
is_correct = models.BooleanField()
- Represents multiple choice options
- Links to parent question
- Tracks correct answers
- QuizSession
class QuizSession(models.Model):
user = models.ForeignKey(User)
started_at = models.DateTimeField()
total_questions = models.IntegerField()
correct_answers = models.IntegerField()
- Tracks individual quiz attempts
- Calculates score percentage
- Links to user profile
- Token-based authentication
- CSRF protection
- Secure password validation
- Cross-Origin Resource Sharing (CORS) configuration
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.TokenAuthentication',
),
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.IsAuthenticated',
)
}
- React 18
- TypeScript
- React Router v6
- Tailwind CSS
- Context API for state management
const AuthProvider: React.FC = ({ children }) => {
// handles user authentication state
// provides login/logout functionality
// manages authentication tokens
}
<Routes>
<Route path="/auth" element={<AuthPage />} />
<Route path="/dashboard" element={<DashboardPage />} />
<Route path="/quiz" element={<QuizPage />} />
<Route path="/attempts" element={<AttemptPage />} />
</Routes>
- Code Splitting
const AuthPage = React.lazy(() => import('./pages/AuthPage'));
const DashboardPage = React.lazy(() => import('./pages/DashboardPage'));
- Error Boundary
<ErrorBoundary>
<ToastProvider>
<AuthProvider>
<Router>
<AppRoutes />
</Router>
</AuthProvider>
</ToastProvider>
</ErrorBoundary>
- Context API for global state
- Custom hooks for quiz state management
- Toast notifications system
- Create a virtual environment:
python -m venv venv
source venv/bin/activate # on windows: venv\Scripts\activate
- Install dependencies:
cd backend
pip install -r requirements.txt
- Run migrations:
python manage.py migrate
- Create superuser:
python manage.py createsuperuser
- Start the server:
python manage.py runserver
- Install dependencies:
cd frontend
npm install
- Start the development server:
npm start
- Access the application at
http://localhost:3000
- Register a new account or login
- Navigate to the dashboard to start a quiz
- Answer questions and submit responses
- View your results and performance history
- POST
/api/auth/login/
: User login - POST
/api/auth/register/
: User registration - POST
/api/auth/logout/
: User logout
- POST
/api/sessions/new_session/
: Start new quiz session - POST
/api/sessions/<session_id>/submit_answer/
: Answer questions and gets a new one - POST
/api/sessions/<session_id>/skip_and_finish/
: Skips the quiz and shows retuns the result of the session - GET
/api/stats/
: Get user's statistics
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
For more information or support, please open an issue in the repository.