report of frontend
report of frontend
ON
MindSprint (quiz app)
Submitted by
Kanupriya (24MCA20508)
Submitted to
Ms. Winky
Date: 10/04/2025
In partial fulfilment for the award of the degree of
Masters Of Computer Application
IN
UNIVERSITY INSTITUTE OF COMPUTING (UIC)
Chandigarh University
April-2025
Acknowledgment
In performing our project, I would like to show our gratitude to all the faculty members of
University Institute of Computing, Chandigarh University for giving me a good guideline for the
project throughout numerous consultations. I would also like to expand our deepest gratitude
to all those who have directly and indirectly guided me in completion of this project.
In addition, a thank you to Ms. Winky, my mentor who introduced me to the Art of Computer
Programming, and her passion for the “underlying structures” had lasting effect. I also thank the
University of Chandigarh for consent to include copyright pictures as a part of our paper.
I thank all the people for their help directly and indirectly to complete my assignment.
Table of Contents
1. Introduction
2. Technology used
3. Folder Structure
4. Workflow
6. Benefits
7. Code
8. Output
9. Findings
10. Conclusion
1. Introduction
The Quiz App is a web-based application that allows users to take multiple-choice quizzes,
record their scores, and view their performance on a leaderboard. It is designed using the
MERN stack (MongoDB, Express.js, React, Node.js) and emphasizes:
1. Technologies Used
❖ Frontend (React + Vite)
• React is a component-based JavaScript library used to build the UI.
• Vite is a build tool that serves as a faster alternative to Create React App.
• Data fetching is done using the Fetch API or Axios for backend communication.
1
• Leaderboard: Displays top scores of all users
• Components: UI parts built as functions (e.g., <Quiz />, <Login />, <Leaderboard />).
• Hooks: Like useState() and useEffect() to manage data and side effects.
Used for client-side navigation, enabling SPA (Single Page Application) behavior without page
reloads.
Defined Routes:
• / → Home
Example:
jsx
<Routes>
</Routes>
2
Features Used:
• Dynamic routing
Tasks Handled:
Folder Structure:
vite-frontend/
├── src/
│ ├── pages/
│ │ ├── Home.jsx
│ │ ├── Register.jsx
│ │ ├── Login.jsx
│ │ ├── Quiz.jsx
│ │ ├── Result.jsx
│ │ └── Leaderboard.jsx
3
Handles:
• Fetching questions
• Rendering question and options
• Tracking user score
• Submitting the result
• Middleware: Custom middleware verifies JWT tokens before protected routes are
accessed.
• Backend:
4
• Frontend:
3. Workflow
1. User Registers or Logs In
o User fills out form → frontend sends data to backend via POST /api/register or
/api/login
2. Starting a Quiz
3. Quiz Interaction
4. Submitting Score
5. Leaderboard
5
• Protected Routes: Middleware checks the JWT before granting access to routes like
/api/attempts.
Example:
If a user tries to submit a quiz without logging in, the backend will reject the request.
5. Benefits
Easy Registration & Login
Leaderboard Motivation
Responsive Design
Reusable Platform
• Future versions could include an admin panel to manage questions and users.
Performance Insights
• With slight enhancement, can generate analytics on question difficulty and user trends.
6. Code
✓ Quiz
import { useEffect, useState } from "react";
import { useNavigate } from "react-router-dom";
const BASE_URL = import.meta.env.VITE_API_BASE_URL;
function Quiz() {
useEffect(() => {
fetch(`${BASE_URL}/questions/random/10`)
6
}, []);
useEffect(() => {
if (timer === 0) {
handleAnswer(null); // auto-skip if no answer
}
const interval = setInterval(() => setTimer((prev) => prev - 1), 1000);
return () => clearInterval(interval);
}, [timer]);
useEffect(() => {
setTimer(10); // reset timer when moving to next question
}, [current]);
const handleAnswer = (option) => {
const correct = questions[current]?.correctAnswer;
if (option === correct) setScore((prev) => prev + 1);
7
},
body: JSON.stringify({ username, score, total }),
});
navigate("/leaderboard");
} catch (err) {
console.error(err);
alert("Error saving score");
}
};
return (
<div style={{ padding: "1rem" }}>
<h2>Quiz Completed!</h2>
<p>
Your Score: {score} / {total}
</p>
<input
type="text"
placeholder="Enter your name"
value={username}
onChange={(e) => setUsername(e.target.value)}
style={{
body: "100vw",
margin: "1rem 0",
padding: "0.5rem",
width: "200px",
}}
/>
<br />
<button onClick={handleSubmit}>Submit Score</button>
</div>
);
}
export default Result;
✓ login
import { useState } from "react";
import { useNavigate } from "react-router-dom"
const BASE_URL = import.meta.env.VITE_API_BASE_URL;
function Login() {
8
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
const [error, setError] = useState("");
const navigate = useNavigate();
const handleLogin = async (e) => {
e.preventDefault();
localStorage.setItem("token", data.token);
navigate("/quiz");
}
export default Login;
7. Output
9
10
8. Conclusion
The Quiz App project successfully demonstrates the integration of modern web
development technologies to create an interactive, secure, and scalable platform for
conducting online quizzes. The frontend, built with React and Vite, provides a fast and
responsive user interface, while the backend, powered by Node.js and Express, handles
authentication, data processing, and API routing efficiently.
Data persistence is achieved through MongoDB, with Mongoose ensuring a structured
and consistent schema across collections. The use of JWT for authentication and bcrypt
for password hashing ensures secure access and user data protection.
Overall, this system can be expanded further into a more feature-rich learning platform
by introducing features like admin dashboards, category-based quizzes, user analytics,
and timer-based assessments. It stands as a solid foundation for both educational
purposes and real-world deployment.
11