This is a README for the Microbus Quiz App, which is a web application built with Node.js, Express.js, and MongoDB. The application allows users to register, login, create or join teams, participate in quizzes, and view leaderboards. Below is a detailed explanation of the project structure, files, and functionalities.
The project follows a standard Node.js project structure with the following main directories:
- routes: Contains route definitions for different API endpoints.
- controllers: Contains controller functions that handle the business logic for each route.
- models: Contains Mongoose models for MongoDB schema definitions.
- index.js: Entry point of the application.
- .env: Environment variables configuration file.
- This file serves as the entry point for the application.
- It sets up the Express server, connects to the MongoDB database, configures routes, and starts the server.
- UserRoutes.js: Defines routes for user-related operations such as registration, login, and profile update.
- QuesRoutes.js: Defines routes for managing quiz questions, including adding and updating questions.
- QuizRoutes.js: Defines routes for handling quiz-related operations such as fetching questions and checking answers.
- TeamRoutes.js: Defines routes for team management, including creating and joining teams.
- LeaderRoutes.js: Defines routes for leaderboard functionalities.
- UserController.js: Contains controller functions for user-related operations like registration, login, and profile update.
- QuesController.js: Contains controller functions for managing quiz questions.
- QuizController.js: Contains controller functions for handling quiz operations such as fetching questions and checking answers.
- TeamController.js: Contains controller functions for team-related operations like creating and joining teams.
- LeaderController.js: Contains controller functions for leaderboard functionalities.
- UserModel.js: Defines the Mongoose schema for user data.
- QuestionModel.js: Defines the Mongoose schema for quiz questions.
- QuizModel.js: Defines the Mongoose schema for storing quiz answers.
- TeamModel.js: Defines the Mongoose schema for team data.
- User Management: Users can register, login, and update their profiles.
- Team Management: Users can create teams with unique team codes and join existing teams.
- Quiz Participation: Users can participate in quizzes by answering questions.
- Leaderboard: The application maintains a leaderboard to display the scores of teams.
To run the application locally, follow these steps:
- Clone the repository to your local machine.
- Navigate to the project directory and install dependencies using
npm install. - Create a
.envfile and configure environment variables likePORT,MONGO_URL, andJWT_KEY. - Start the server using
npm start. - Access the application through
http://localhost:<PORT>.
The project utilizes the following main dependencies:
- Express.js: A minimalist web framework for Node.js.
- Mongoose: An Object Data Modeling (ODM) library for MongoDB and Node.js.
- bcrypt: A library for hashing passwords.
- jsonwebtoken: A library for generating JSON Web Tokens (JWT) for user authentication.
This section provides detailed documentation for the API endpoints available in the Microbus Quiz App.
- URL:
/api/auth/register - Method:
POST - Description: Register a new user.
- Request Body:
email: User's email address.password: User's password.confirmPassword: Confirm password to ensure accuracy.
- Response: Returns a success message and user data upon successful registration.
- URL:
/api/auth/login - Method:
POST - Description: Login an existing user.
- Request Body:
email: User's email address.password: User's password.
- Response: Returns a JWT token upon successful login.
- URL:
/api/auth/profile - Method:
PUT - Description: Update user profile details.
- Request Body: Can include any of the following:
username: User's username.rollNo: User's roll number.mobileNo: User's mobile number.email: User's email address.password: User's password.
- Response: Returns a success message and updated user profile data.
- URL:
/api/que/queData - Method:
POST - Description: Add a new question to the quiz.
- Request Body:
set: Quiz set number.queNo: Question number.queUrl: URL of the question.queAns: Answer to the question.
- Response: Returns a success message and the added question data.
- URL:
/api/que/queData - Method:
PUT - Description: Update an existing question in the quiz.
- Request Body:
set: Quiz set number.queNo: Question number.queUrl: Updated URL of the question.queAns: Updated answer to the question.
- Response: Returns a success message and the updated question data.
- URL:
/api/dashboard/contest/:set - Method:
GET - Description: Fetch the next question for the quiz.
- Parameters:
set: Quiz set number.
- Response: Returns the next question details.
- URL:
/api/dashboard/contest/:set - Method:
PUT - Description: Check the user's answer, update score, and fetch the next question.
- Parameters:
set: Quiz set number.
- Request Body:
answer: User's answer to the question.
- Response: Returns feedback on the answer and the next question details.
- URL:
/api/teamdetails/createTeam - Method:
POST - Description: Create a new team.
- Request Body:
teamName: Name of the team.
- Response: Returns a success message and details of the newly created team.
- URL:
/api/teamdetails/joinTeam - Method:
PUT - Description: Join an existing team.
- Request Body:
teamCode: Team code to join.
- Response: Returns a success message and details of the joined team.
- URL:
/api/leaderboard/winners - Method:
GET - Description: Retrieve the list of teams sorted by score.
- Response: Returns a list of teams ordered by score.
- Ensure to include appropriate JWT tokens in the headers for authorized requests.
- Certain routes may require authentication to access. Use the provided JWT token upon successful login.
- Error responses will include relevant error messages for troubleshooting purposes.
This API documentation provides a comprehensive guide to the endpoints available in the Microbus Quiz App, facilitating usage and integration with other applications.
Contributions to the project are welcome. Feel free to submit bug reports, feature requests, or pull requests.
This project is licensed under the MIT License. See the LICENSE file for more details.
Keshav Garg Raghav Garg