Skip to content

Starfall-inc/online-exam-system

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

8 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ“ Online Exam System

A comprehensive web-based examination platform that enables educational institutions to conduct secure online exams with automatic grading, real-time monitoring, and detailed analytics.

Node.js TypeScript MongoDB License

๐ŸŒŸ Features

For Administrators

  • Student Management: Create student accounts with auto-generated secure passwords
  • Exam Creation: Build exams with multiple-choice questions and customizable duration
  • Question Bank: Visual editor with bottom navigation for easy question management
  • Result Analytics: Comprehensive statistics with filters and Excel export
  • Access Control: Activate/deactivate exams and manage student access
  • Dashboard: Real-time overview of students, exams, and submissions

For Students

  • User-Friendly Interface: Clean, intuitive dashboard showing available exams
  • Exam Experience:
    • Real-time countdown timer with auto-submit
    • Bottom question navigator with color-coded progress
    • Auto-save answers
    • Visual feedback for answered questions
  • Instant Results: Automatic grading with detailed performance analysis
  • Result History: View all past exam results with statistics
  • No Retakes: Exam integrity maintained with single-attempt restriction

Core Functionality

  • Automatic Grading: Instant score calculation upon submission
  • JWT Authentication: Secure token-based authentication system
  • Role-Based Access: Separate admin and student portals
  • Responsive Design: Works seamlessly on desktop and mobile devices
  • Excel Export: Download detailed result reports in Excel format
  • Professional UI: Modern design with TailwindCSS

๐Ÿš€ Tech Stack

Backend

  • Runtime: Node.js v18+
  • Language: TypeScript
  • Framework: Express.js
  • Database: MongoDB with Mongoose ODM
  • Authentication: JWT (JSON Web Tokens)
  • Password Security: bcrypt
  • Excel Generation: ExcelJS

Frontend

  • Template Engine: EJS (Embedded JavaScript)
  • CSS Framework: TailwindCSS (CDN)
  • Icons: Font Awesome
  • Animations: CSS transitions and keyframes

๐Ÿ“‹ Prerequisites

Before you begin, ensure you have the following installed:

  • Node.js (v18 or higher)
  • MongoDB (v6.0 or higher)
  • npm or yarn package manager

โš™๏ธ Installation

1. Clone the Repository

git clone https://github.com/yourusername/online-exam-system.git
cd online-exam-system

2. Install Dependencies

npm install

3. Environment Configuration

Create a .env file in the root directory:

# Server Configuration
PORT=3000
NODE_ENV=development

# Database
MONGODB_URI=mongodb://localhost:27017/online_exam_system

# JWT Secret (use a strong random string)
JWT_SECRET=your_super_secret_jwt_key_here_change_this_in_production

# JWT Expiration
JWT_EXPIRE=7d

4. Start MongoDB

# On Linux/Mac
sudo systemctl start mongod

# Or using MongoDB Compass GUI

5. Create First Admin

npm run create-admin

This will create an admin account with:

  • Email: admin@example.com
  • Password: admin123

โš ๏ธ Important: Change the password after first login!

6. Start the Application

# Development mode with auto-reload
npm run dev

# Production mode
npm run build
npm start

The application will be available at http://localhost:3000

๐Ÿ“ Project Structure

online-exam-system/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ config/
โ”‚   โ”‚   โ””โ”€โ”€ database.ts           # MongoDB connection
โ”‚   โ”œโ”€โ”€ controllers/
โ”‚   โ”‚   โ”œโ”€โ”€ adminAuth.controller.ts
โ”‚   โ”‚   โ”œโ”€โ”€ admin.controller.ts
โ”‚   โ”‚   โ”œโ”€โ”€ studentAuth.controller.ts
โ”‚   โ”‚   โ”œโ”€โ”€ exam.controller.ts
โ”‚   โ”‚   โ”œโ”€โ”€ question.controller.ts
โ”‚   โ”‚   โ””โ”€โ”€ result.controller.ts
โ”‚   โ”œโ”€โ”€ middleware/
โ”‚   โ”‚   โ””โ”€โ”€ auth.middleware.ts    # JWT authentication
โ”‚   โ”œโ”€โ”€ models/
โ”‚   โ”‚   โ”œโ”€โ”€ Admin.ts
โ”‚   โ”‚   โ”œโ”€โ”€ Student.ts
โ”‚   โ”‚   โ”œโ”€โ”€ Exam.ts
โ”‚   โ”‚   โ”œโ”€โ”€ Question.ts
โ”‚   โ”‚   โ””โ”€โ”€ Result.ts
โ”‚   โ”œโ”€โ”€ routes/
โ”‚   โ”‚   โ”œโ”€โ”€ adminAuth.routes.ts
โ”‚   โ”‚   โ”œโ”€โ”€ admin.routes.ts
โ”‚   โ”‚   โ”œโ”€โ”€ studentAuth.routes.ts
โ”‚   โ”‚   โ”œโ”€โ”€ exam.routes.ts
โ”‚   โ”‚   โ”œโ”€โ”€ question.routes.ts
โ”‚   โ”‚   โ”œโ”€โ”€ result.routes.ts
โ”‚   โ”‚   โ”œโ”€โ”€ view.routes.ts
โ”‚   โ”‚   โ””โ”€โ”€ index.ts
โ”‚   โ”œโ”€โ”€ types/
โ”‚   โ”‚   โ””โ”€โ”€ express.types.ts      # TypeScript type definitions
โ”‚   โ”œโ”€โ”€ utils/
โ”‚   โ”‚   โ”œโ”€โ”€ password.utils.ts
โ”‚   โ”‚   โ”œโ”€โ”€ password-generator.utils.ts
โ”‚   โ”‚   โ”œโ”€โ”€ token.utils.ts
โ”‚   โ”‚   โ”œโ”€โ”€ validation.utils.ts
โ”‚   โ”‚   โ””โ”€โ”€ excel.utils.ts
โ”‚   โ”œโ”€โ”€ views/
โ”‚   โ”‚   โ”œโ”€โ”€ partials/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ head.ejs
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ header.ejs
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ footer.ejs
โ”‚   โ”‚   โ”œโ”€โ”€ home.ejs
โ”‚   โ”‚   โ”œโ”€โ”€ login.ejs
โ”‚   โ”‚   โ”œโ”€โ”€ admin-dashboard.ejs
โ”‚   โ”‚   โ”œโ”€โ”€ admin-students.ejs
โ”‚   โ”‚   โ”œโ”€โ”€ admin-exams.ejs
โ”‚   โ”‚   โ”œโ”€โ”€ admin-questions.ejs
โ”‚   โ”‚   โ”œโ”€โ”€ admin-results.ejs
โ”‚   โ”‚   โ”œโ”€โ”€ student-dashboard.ejs
โ”‚   โ”‚   โ”œโ”€โ”€ student-results.ejs
โ”‚   โ”‚   โ”œโ”€โ”€ take-exam.ejs
โ”‚   โ”‚   โ””โ”€โ”€ exam-result.ejs
โ”‚   โ””โ”€โ”€ index.ts                  # Main server file
โ”œโ”€โ”€ public/
โ”‚   โ””โ”€โ”€ css/
โ”‚       โ””โ”€โ”€ input.css             # Custom styles
โ”œโ”€โ”€ scripts/
โ”‚   โ””โ”€โ”€ create-admin.ts           # Admin creation script
โ”œโ”€โ”€ .env                          # Environment variables
โ”œโ”€โ”€ .gitignore
โ”œโ”€โ”€ package.json
โ”œโ”€โ”€ tsconfig.json
โ””โ”€โ”€ README.md

๐ŸŽฏ Usage Guide

Admin Workflow

  1. Login: Access /login and select "Admin" tab
  2. Create Students: Go to Students page and add student accounts
  3. Create Exams: Navigate to Exams page and create a new exam
  4. Add Questions: Click "Manage Questions" on any exam to add MCQs
  5. Activate Exam: Toggle exam status to make it available to students
  6. Monitor Results: View submissions and analytics in Results page
  7. Export Data: Download Excel reports for detailed analysis

Student Workflow

  1. Login: Access /login with credentials provided by admin
  2. View Exams: See all available exams on dashboard
  3. Start Exam: Click "Start Exam" to begin (cannot retake)
  4. Take Exam: Answer questions using the visual navigator
  5. Submit: Submit before timer expires or it auto-submits
  6. View Result: See instant results with grade and performance analysis
  7. Check History: View all past results in Results page

๐Ÿ” Default Credentials

Admin

  • Email: admin@example.com
  • Password: admin123

Students

  • Passwords are auto-generated when admin creates accounts
  • Admin can reset student passwords anytime

๐Ÿ“Š API Endpoints

Authentication

POST   /api/admin/auth/login       - Admin login
GET    /api/admin/auth/profile     - Get admin profile
POST   /api/student/auth/login     - Student login
GET    /api/student/auth/profile   - Get student profile
PUT    /api/student/auth/change-password - Change password

Student Management (Admin)

POST   /api/admin/students         - Create student
GET    /api/admin/students         - Get all students
GET    /api/admin/students/:id     - Get student by ID
PUT    /api/admin/students/:id     - Update student
DELETE /api/admin/students/:id     - Delete student
POST   /api/admin/students/:id/reset-password - Reset password

Exam Management

POST   /api/exams                  - Create exam (Admin)
GET    /api/exams                  - Get all exams
GET    /api/exams/:id              - Get exam by ID
PUT    /api/exams/:id              - Update exam (Admin)
DELETE /api/exams/:id              - Delete exam (Admin)
PATCH  /api/exams/:id/toggle-status - Toggle exam status (Admin)

Question Management

POST   /api/exams/:examId/questions - Add question (Admin)
GET    /api/exams/:examId/questions - Get questions
GET    /api/questions/:id          - Get question by ID (Admin)
PUT    /api/questions/:id          - Update question (Admin)
DELETE /api/questions/:id          - Delete question (Admin)

Results

POST   /api/results/submit         - Submit exam (Student)
GET    /api/results/my-results     - Get student's results (Student)
GET    /api/results/:id            - Get result by ID
GET    /api/results/exam/:examId   - Get exam results (Admin)
GET    /api/results                - Get all results (Admin)
GET    /api/results/export         - Export to Excel (Admin)

๐Ÿ”ง Configuration

Change JWT Secret

In .env file:

JWT_SECRET=your_new_secret_key_minimum_32_characters_long

Change Port

PORT=8080

MongoDB Configuration

MONGODB_URI=mongodb://username:password@host:port/database

๐Ÿš€ Deployment

Using PM2

npm install -g pm2
npm run build
pm2 start dist/index.js --name "online-exam-system"

Using Docker

FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install --production
COPY . .
RUN npm run build
EXPOSE 3000
CMD ["node", "dist/index.js"]

๐Ÿงช Testing

# Test admin creation
npm run create-admin

# Test API endpoints (using your preferred tool)
# Postman, Thunder Client, or curl

๐Ÿค Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create a 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

๐Ÿ“ License

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

๐Ÿ› Known Issues

  • Excel export requires modern browser with Blob support
  • Timer continues in background if tab is inactive (by design)
  • Mobile view optimized for portrait mode

๐Ÿ”ฎ Future Enhancements

  • Bulk question import from CSV/Excel
  • Question categories and difficulty levels
  • Randomized question order per student
  • Detailed answer review after exam
  • Email notifications for results
  • Advanced analytics with charts
  • Multi-language support
  • Dark mode theme

๐Ÿ‘ Acknowledgments

  • TailwindCSS for the beautiful UI framework
  • MongoDB for the robust database
  • Express.js for the powerful backend framework
  • Font Awesome for the icon library

Built with โค๏ธ using Node.js, TypeScript, MongoDB & TailwindCSS

About

A modern, full-stack online examination platform with automatic grading, real-time timers, role-based dashboards, and comprehensive analytics built with Node.js, TypeScript, MongoDB, and TailwindCSS.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors