A comprehensive RESTful API for managing student attendance with role-based access control, built with Node.js, Express.js, and PostgreSQL.
SAMS is a full-featured student attendance management system designed for educational institutions. It provides secure authentication, role-based access control, and comprehensive attendance tracking capabilities.
- Amogh Sunil
- Abhin G Das
- Aarush Lobo
- Amogh Vaidya
- 2 Sprints (8 days total)
- JWT Authentication - Secure token-based authentication
- Role-Based Access Control - Student, Faculty, and Admin roles
- Password Hashing - Bcrypt for secure password storage
- Input Validation - Express-validator for request validation
- Error Handling - Centralized error handling middleware
- CORS Support - Cross-origin resource sharing configuration
- PostgreSQL Database - Robust relational database
- RESTful API - Clean and consistent API design
SAMS/
βββ src/
β βββ config/
β β βββ database.js # PostgreSQL connection pool
β β βββ jwt.js # JWT configuration
β βββ middleware/
β β βββ auth.js # Authentication & authorization
β β βββ errorHandler.js # Global error handling
β βββ models/
β β βββ User.js # User model with database operations
β βββ routes/
β β βββ auth.js # Authentication routes
β βββ controllers/
β β βββ authController.js # Authentication logic
β βββ utils/
β β βββ responses.js # Standard API responses
β βββ app.js # Express app configuration
βββ tests/
β βββ unit/ # Unit tests
β βββ integration/ # Integration tests
βββ .env.example # Environment variables template
βββ .gitignore # Git ignore rules
βββ .eslintrc.json # ESLint configuration
βββ jest.config.js # Jest testing configuration
βββ package.json # Dependencies and scripts
βββ server.js # Server entry point
- Runtime: Node.js
- Framework: Express.js v5
- Database: PostgreSQL
- Authentication: JWT (jsonwebtoken)
- Password Hashing: bcrypt
- Validation: express-validator
- Testing: Jest + Supertest
- Linting: ESLint (Airbnb style guide)
- Node.js (v14 or higher)
- PostgreSQL (v12 or higher)
- npm or yarn
-
Clone the repository
git clone <repository-url> cd SEmini
-
Install dependencies
npm install
-
Set up environment variables
cp .env.example .env
Edit
.envwith your configuration:PORT=3000 NODE_ENV=development DB_HOST=localhost DB_PORT=5432 DB_NAME=sams_db DB_USER=your_username DB_PASSWORD=your_password JWT_SECRET=your-super-secret-jwt-key JWT_EXPIRATION=24h CORS_ORIGIN=http://localhost:3001
-
Set up the database
-- Create database CREATE DATABASE sams_db; -- Connect to database \c sams_db -- Create users table CREATE TABLE users ( id SERIAL PRIMARY KEY, email VARCHAR(255) UNIQUE NOT NULL, password VARCHAR(255) NOT NULL, first_name VARCHAR(100) NOT NULL, last_name VARCHAR(100) NOT NULL, role VARCHAR(20) NOT NULL CHECK (role IN ('student', 'faculty', 'admin')), registration_number VARCHAR(50) UNIQUE, is_active BOOLEAN DEFAULT true, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ); -- Create indexes CREATE INDEX idx_users_email ON users(email); CREATE INDEX idx_users_role ON users(role); CREATE INDEX idx_users_registration_number ON users(registration_number);
-
Start the server
# Development mode with auto-reload npm run dev # Production mode npm start
# Run all tests with coverage
npm test
# Run tests in watch mode
npm run test:watch
# Run linting
npm run lint
# Check linting without fixing
npm run lint:checkhttp://localhost:3000/api
POST /api/auth/register
Content-Type: application/json
{
"email": "student@example.com",
"password": "SecurePass123",
"firstName": "John",
"lastName": "Doe",
"role": "student",
"registrationNumber": "PES1202100123"
}
Response (201):
{
"success": true,
"message": "User registered successfully",
"data": {
"user": {
"id": 1,
"email": "student@example.com",
"firstName": "John",
"lastName": "Doe",
"role": "student",
"registrationNumber": "PES1202100123"
},
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
},
"timestamp": "2025-11-06T10:30:00.000Z"
}POST /api/auth/login
Content-Type: application/json
{
"email": "student@example.com",
"password": "SecurePass123"
}
Response (200):
{
"success": true,
"message": "Login successful",
"data": {
"user": {...},
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
},
"timestamp": "2025-11-06T10:30:00.000Z"
}GET /api/auth/profile
Authorization: Bearer <token>
Response (200):
{
"success": true,
"message": "Profile retrieved successfully",
"data": {
"user": {
"id": 1,
"email": "student@example.com",
"firstName": "John",
"lastName": "Doe",
"role": "student",
"registrationNumber": "PES1202100123",
"isActive": true,
"createdAt": "2025-11-06T10:00:00.000Z",
"updatedAt": "2025-11-06T10:00:00.000Z"
}
},
"timestamp": "2025-11-06T10:30:00.000Z"
}PUT /api/auth/profile
Authorization: Bearer <token>
Content-Type: application/json
{
"firstName": "Jane",
"lastName": "Smith",
"email": "jane.smith@example.com"
}PUT /api/auth/password
Authorization: Bearer <token>
Content-Type: application/json
{
"currentPassword": "SecurePass123",
"newPassword": "NewSecurePass456"
}GET /health
Response (200):
{
"status": "OK",
"message": "Student Attendance Management System API is running",
"timestamp": "2025-11-06T10:30:00.000Z",
"uptime": 3600.5
}- Password Hashing - Bcrypt with 10 salt rounds
- JWT Authentication - Secure token-based auth
- SQL Injection Prevention - Parameterized queries
- Input Validation - Express-validator middleware
- CORS Configuration - Controlled cross-origin access
- Role-Based Access Control - Fine-grained permissions
- ESLint Score: β₯7.5/10 (Airbnb style guide)
- Test Coverage: β₯75%
- Conventional Commits: feat:, fix:, test:, docs:
- Branch Protection: No direct commits to main
- Code Reviews: All PRs require review
- Create feature branch from
main - Implement feature with tests
- Run linting:
npm run lint - Run tests:
npm test - Commit with conventional commit message
- Push and create Pull Request
- Wait for code review and CI/CD checks
- Merge after approval
| Script | Description |
|---|---|
npm start |
Start production server |
npm run dev |
Start development server with auto-reload |
npm test |
Run tests with coverage report |
npm run test:watch |
Run tests in watch mode |
npm run lint |
Run ESLint and auto-fix issues |
npm run lint:check |
Check linting without fixing |
All errors follow a consistent format:
{
"success": false,
"message": "Error description",
"errors": {
"field": "Specific error details"
},
"timestamp": "2025-11-06T10:30:00.000Z"
}Common HTTP Status Codes:
200- Success201- Created400- Bad Request / Validation Error401- Unauthorized403- Forbidden404- Not Found409- Conflict500- Internal Server Error
- Attendance Module - Mark and view attendance
- Notifications - Email/SMS alerts for low attendance
- Reports - PDF/Excel generation
- Admin Dashboard - User management
- Audit Logs - Track all changes
- CI/CD Pipeline - GitHub Actions workflow
MIT License - See LICENSE file for details
- Amogh Sunil
- Abhin G Das
- Aarush Lobo
- Amogh Vaidya
For issues and questions, please create an issue in the repository.
Built with β€οΈ for PESU Software Engineering Mini Project