A full-stack quiz application for teachers and students with modern security features, user authentication, and role-based access control.
- User Authentication & Authorization
- Role-based access control (Teacher, Student, Admin)
- JWT token authentication with refresh token mechanism
- Secure password hashing using bcrypt
- Quiz Management
- Create, read, update, and delete quizzes
- Add questions with multiple choice options
- Publish/unpublish quizzes for students
- Quiz Taking (todo)
- User-friendly quiz interface
- Automatic scoring and feedback
- Progress tracking and history
- Responsive Design
- Modern UI built with React and TailwindCSS
- Mobile-first approach for all devices
- JWT Authentication
- Short-lived access tokens (7 days default)
- Long-lived refresh tokens (30 days default)
- Automatic token refresh on expiration
- HTTP-Only Cookies
- Secure, HTTP-only cookies for token storage
- Path-limited cookies for refresh tokens
- Token Validation
- Server-side refresh token storage and validation
- Token expiration detection and handling
- Protection Against Common Attacks
- CORS protection
- Helmet security headers
- Input validation with Express Validator
- Node.js & Express: Fast, unopinionated web framework
- TypeScript: Type-safe JavaScript
- MongoDB & Mongoose: NoSQL database and ODM
- JWT: JSON Web Tokens for authentication
- Winston: Logging library
- Express Validator: Input validation middleware
- React 19: Modern UI library with hooks
- TypeScript: Type safety for components
- Vite: Next-generation frontend build tool
- React Router: Client-side routing
- React Query: Data fetching and caching
- Zustand: Simple state management
- TailwindCSS: Utility-first CSS framework
- Axios: HTTP client with interceptors for token refresh
- Node.js (v16 or higher)
- MongoDB (local or Atlas)
- Git
- Clone the repository
git clone https://github.com/chhavikant-01/DLED-quiz.git
cd DLED-quiz- Install backend dependencies
cd backend
npm install- Configure backend environment
cp .env.example .env
# Edit .env with your MongoDB connection string and JWT secrets- Install frontend dependencies
cd ../frontend
npm install- Configure frontend environment
cp .env.example .env.local
# Edit .env.local with your API URL if needed- Start the backend server:
cd backend
npm run dev- In a separate terminal, start the frontend development server:
cd frontend
npm run dev- Access the application:
- Frontend: http://localhost:5173
- Backend API: http://localhost:5050/api
- Build the backend:
cd backend
npm run build
npm start- Build the frontend:
cd frontend
npm run build
# Deploy the contents of dist directoryTo populate the database with sample data:
cd backend
npm run seed- bcrypt: Secure password hashing
- cookie-parser: Parse HTTP cookies
- cors: Enable CORS for API access
- dotenv: Environment variable management
- express: Web framework
- express-validator: Input validation
- helmet: Security headers
- jsonwebtoken: JWT implementation
- mongoose: MongoDB object modeling
- morgan: HTTP request logger
- winston: Application logging
- @tanstack/react-query: Data fetching and caching
- axios: HTTP client with interceptors
- react: UI library
- react-hook-form: Form validation and handling
- react-router-dom: Client-side routing
- zod: Schema validation
- zustand: State management
- tailwindcss: Utility-first CSS framework
- User logs in with credentials
- Server validates credentials and issues access token and refresh token
- Access token used for API authorization (expires in 7 days)
- HTTP-only cookies store tokens securely
- When an access token expires, the client attempts to use the refresh token
- Server validates the refresh token against the database
- If valid, a new access token is issued
- If invalid, the user is forced to log in again
- Refresh tokens stored in database for validation
- Path-limited cookies to prevent token theft
- Automatic renewal of access tokens
- Proper error handling for expired tokens
POST /api/auth/register- Register a new userPOST /api/auth/login- Login userGET /api/auth/logout- Logout userPOST /api/auth/refresh- Refresh access token
POST /api/quizzes- Create a new quiz (Teacher only)GET /api/quizzes- Get all quizzesGET /api/quizzes/:id- Get a single quizPUT /api/quizzes/:id- Update a quiz (Teacher only)DELETE /api/quizzes/:id- Delete a quiz (Teacher only)PUT /api/quizzes/:id/publish- Publish a quiz (Teacher only)
POST /api/quizzes/:quizId/questions- Add a question to a quiz (Teacher only)GET /api/quizzes/:quizId/questions- Get all questions for a quizGET /api/questions/:id- Get a single questionPUT /api/questions/:id- Update a question (Teacher only)DELETE /api/questions/:id- Delete a question (Teacher only)
This project is licensed under the MIT License.