Sql_Adv_Proj

๐ŸŽ“ Examination Management System - Backend API

![Node.js](https://img.shields.io/badge/Node.js-18+-339933?style=for-the-badge&logo=node.js&logoColor=white) ![Express](https://img.shields.io/badge/Express-5.2.1-000000?style=for-the-badge&logo=express&logoColor=white) ![Sequelize](https://img.shields.io/badge/Sequelize-6.37.7-52B0E7?style=for-the-badge&logo=sequelize&logoColor=white) ![MS SQL Server](https://img.shields.io/badge/SQL%20Server-CC2927?style=for-the-badge&logo=microsoft-sql-server&logoColor=white) ![License](https://img.shields.io/badge/License-ISC-blue?style=for-the-badge) **A robust and scalable RESTful API for managing educational examinations, students, instructors, and courses.** [Getting Started](#-getting-started) โ€ข [API Documentation](#-api-endpoints) โ€ข [Database Schema](#-database-schema) โ€ข [Contributing](#-contributing)

๐Ÿ“‹ Table of Contents


๐ŸŽฏ Overview

The Examination Management System is a comprehensive backend solution designed to handle all aspects of educational institution operations. Built with modern Node.js and Express.js, this API provides secure, efficient, and scalable endpoints for managing:


โœจ Features

Feature Description
๐Ÿ” Authentication Secure login/register for students and instructors
๐Ÿ“š Course Management Full CRUD operations with instructor assignment
๐Ÿ‘จโ€๐ŸŽ“ Student Management Track assignment, enrollment, and progress tracking
๐Ÿ‘จโ€๐Ÿซ Instructor Management Department association and course management
๐Ÿ“ Dynamic Exams Auto-generated exams with MCQ and True/False questions
โฑ๏ธ Time Tracking Real-time exam timer with auto-submission on timeout
โœ… Auto-Grading Instant result calculation upon submission
๐Ÿ“Š Exam Review Detailed review with correct/incorrect answers
๐Ÿ›ก๏ธ Validation Request validation using express-validator
๐Ÿ“„ Pagination Efficient data retrieval with pagination support

๐Ÿ› ๏ธ Tech Stack

Technology Version Purpose
Node.js 18+ JavaScript Runtime
Express.js 5.2.1 Web Application Framework
Sequelize 6.37.7 ORM for SQL Server
Tedious 19.2.0 MS SQL Server Driver
express-validator 7.3.1 Input Validation Middleware
Morgan 1.10.1 HTTP Request Logger
CORS 2.8.5 Cross-Origin Resource Sharing
dotenv 17.2.3 Environment Configuration
Nodemon 3.1.11 Development Hot Reload

๐Ÿ“ Project Structure

Back_sql_project/
โ”‚
โ”œโ”€โ”€ ๐Ÿ“„ index.js                 # Application entry point
โ”œโ”€โ”€ ๐Ÿ“„ package.json             # Dependencies & scripts
โ”œโ”€โ”€ ๐Ÿ“„ .env                     # Environment variables
โ”œโ”€โ”€ ๐Ÿ“„ .gitignore               # Git ignore rules
โ”‚
โ”œโ”€โ”€ ๐Ÿ” Auth/
โ”‚   โ””โ”€โ”€ auth.js                 # Authentication routes & logic
โ”‚
โ”œโ”€โ”€ โš™๏ธ Configuration/
โ”‚   โ””โ”€โ”€ Sequelize.js            # Database connection config
โ”‚
โ”œโ”€โ”€ ๐ŸŽฎ controllers/
โ”‚   โ”œโ”€โ”€ Courses.js              # Course business logic
โ”‚   โ”œโ”€โ”€ Exams.js                # Exam generation & grading
โ”‚   โ”œโ”€โ”€ instructors.js          # Instructor operations
โ”‚   โ”œโ”€โ”€ Students.js             # Student auth logic
โ”‚   โ””โ”€โ”€ StudentsController.js   # Student CRUD operations
โ”‚
โ”œโ”€โ”€ ๐Ÿ“Š models/
โ”‚   โ”œโ”€โ”€ init-models.js          # Model initialization & relations
โ”‚   โ”œโ”€โ”€ choice.js               # Answer choices model
โ”‚   โ”œโ”€โ”€ course.js               # Course model
โ”‚   โ”œโ”€โ”€ department.js           # Department model
โ”‚   โ”œโ”€โ”€ exam.js                 # Exam model
โ”‚   โ”œโ”€โ”€ examquestion.js         # Exam-Question junction
โ”‚   โ”œโ”€โ”€ instructor.js           # Instructor model
โ”‚   โ”œโ”€โ”€ question.js             # Question model
โ”‚   โ”œโ”€โ”€ student.js              # Student model
โ”‚   โ”œโ”€โ”€ studentquestionanswer.js # Student answers model
โ”‚   โ”œโ”€โ”€ topic.js                # Topic/Subject model
โ”‚   โ””โ”€โ”€ track.js                # Learning track model
โ”‚
โ”œโ”€โ”€ ๐Ÿ›ค๏ธ Routes/
โ”‚   โ”œโ”€โ”€ Courses.js              # /api/v1/course routes
โ”‚   โ”œโ”€โ”€ ExamsRoute.js           # /api/v1/exams routes
โ”‚   โ”œโ”€โ”€ instructor.js           # /api/v1/instructor routes
โ”‚   โ””โ”€โ”€ StudentRoute.js         # /api/v1/student routes
โ”‚
โ””โ”€โ”€ โœ… validators/
    โ”œโ”€โ”€ coursesValidators.js            # Course input validation
    โ”œโ”€โ”€ validationSchemaForExams.js     # Exam input validation
    โ”œโ”€โ”€ validationSchemaForInstructors.js # Instructor validation
    โ””โ”€โ”€ ValidationSchemaForStudent.js   # Student validation

๐Ÿš€ Getting Started

Prerequisites

Before you begin, ensure you have the following installed:

Installation

  1. Clone the repository
    git clone https://github.com/your-username/examination-system.git
    cd Back_sql_project
    
  2. Install dependencies
    npm install
    
  3. Configure environment variables

    Create a .env file in the root directory:

    PORT=3000
    API_VERSION=api/v1
       
    # Database Configuration
    DB_NAME=ExaminationDB
    DB_USER=sa
    DB_PASSWORD=your_secure_password
    DB_HOST=localhost
    
  4. Restore the database

    Use SQL Server Management Studio (SSMS) to restore one of the backup files:

    • dbafterstored.bak - Database with stored procedures
    • dbveido.bak - Alternative backup
  5. Start the server
    # Development mode (with hot reload)
    npm run dev
       
    # Production mode
    npm start
    
  6. Verify the installation

    Open your browser and navigate to:

    http://localhost:3000
    

๐Ÿ”ง Environment Variables

Variable Description Default Required
PORT Server port number 3000 No
API_VERSION API version prefix api/v1 No
DB_NAME SQL Server database name - โœ… Yes
DB_USER Database username - โœ… Yes
DB_PASSWORD Database password - โœ… Yes
DB_HOST Database host address localhost No

๐Ÿ“ก API Endpoints

Base URL

http://localhost:3000/api/v1

Authentication

Method Endpoint Description
POST /auth/student/login Student login
POST /auth/student/register Student registration
POST /auth/instructor/login Instructor login

Students

Method Endpoint Description
GET /student Get all students (paginated)
GET /student/:id Get student by ID
POST /student Create new student
PATCH /student/:id Update student
DELETE /student/:id Delete student
PATCH /student/:id/track Assign student to track

Instructors

Method Endpoint Description
GET /instructor Get all instructors
GET /instructor/:id Get instructor by ID
POST /instructor Create new instructor
PATCH /instructor/:id Update instructor
DELETE /instructor/:id Delete instructor

Courses

Method Endpoint Description
GET /course Get all courses
GET /course/:id Get course by ID
POST /course Create new course
PATCH /course/:id Update course
DELETE /course/:id Delete course

Exams

Method Endpoint Description
POST /exams/generate Generate new exam
POST /exams/submit Submit exam answers
GET /exams/review/:examId/:studentId Get exam review
GET /exams/student/:studentId Get studentโ€™s exam history
GET /exams/status/:examId/:studentId Check exam status

๐Ÿ—„๏ธ Database Schema

Entity Relationship

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Department โ”‚โ”€โ”€โ”€โ”€<โ”‚  Instructor โ”‚>โ”€โ”€โ”€โ”€โ”‚   Course    โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                              โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”           โ”‚
โ”‚    Track    โ”‚โ”€โ”€โ”€โ”€<โ”‚   Student   โ”‚>โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜           โ”‚
                          โ”‚                   โ”‚
                          โ”‚              โ”Œโ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”
                          โ”‚              โ”‚  Topic  โ”‚
                          โ”‚              โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”˜
                          โ”‚                   โ”‚
                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”       โ”Œโ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”
                    โ”‚   Exam    โ”‚>โ”€โ”€โ”€โ”€โ”€โ”€โ”‚ Question  โ”‚
                    โ””โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”˜       โ””โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”˜
                          โ”‚                   โ”‚
                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                    โ”‚ StudentQuestion   โ”‚    โ”‚ Choice  โ”‚
                    โ”‚     Answer        โ”‚    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Key Tables

Table Description
Student Student information and credentials
Instructor Instructor details and department
Course Course catalog with instructor assignment
Track Learning paths/specializations
Department Academic departments
Question Question bank (MCQ, True/False)
Choice Answer choices for questions
Exam Generated exam instances
ExamQuestion Exam-Question mapping
StudentQuestionAnswer Student responses
Topic Subject/Topic categorization

๐Ÿ”ง Stored Procedures

The system leverages SQL Server stored procedures for complex operations:

Procedure Description
GenerateExam Creates exam with random questions
SubmitExamAnswers Processes and grades submissions
GetExamReview Retrieves detailed exam results
GetStudentExams Fetches exam history
CheckExamStatus Validates exam state and timing

โš ๏ธ Error Handling

Standard Error Response

{
  "success": false,
  "message": "Error description",
  "error": "Detailed error message (development only)"
}

HTTP Status Codes

Code Description
200 Success
201 Created
400 Bad Request (validation error)
401 Unauthorized
404 Not Found
500 Internal Server Error

Validation Error Response

{
  "success": false,
  "data": [
    {
      "msg": "Field is required",
      "param": "fieldName",
      "location": "body"
    }
  ]
}

๐Ÿ“š Additional Documentation

For detailed API documentation with request/response examples:


๐Ÿค Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Code Style


๐Ÿ“ Scripts

# Start production server
npm start

# Start development server with hot reload
npm run dev

# Run tests
npm test

๐Ÿ”’ Security Considerations


๐Ÿ“„ License

This project is licensed under the ISC License - see the LICENSE file for details.


๐Ÿ‘จโ€๐Ÿ’ป Author

CrossITI Team


**โญ Star this repository if you found it helpful!** Made with โค๏ธ using Node.js and Express