Skip to content

kewalll/AcademicTracker

Repository files navigation

Academic Tracker - Spring Boot Application

A comprehensive academic management system built with Spring Boot 3.5.6, featuring JWT authentication, role-based access control, and RESTful APIs for managing users, courses, attendance, and marks.

πŸš€ Features

  • JWT Authentication with secure cookie-based sessions
  • Role-Based Access Control (ADMIN, TEACHER, STUDENT, PARENT)
  • User Management with password encryption
  • Course Management with teacher assignments
  • Attendance Tracking with date-based queries
  • Marks/Grades Management with validation
  • Comprehensive Error Handling and validation
  • MySQL Database with JPA/Hibernate

πŸ“‹ Prerequisites

  • Java 21
  • MySQL 8.0+
  • Maven 3.6+

πŸ› οΈ Setup Instructions

1. Database Configuration

Create a MySQL database:

CREATE DATABASE academictracker;

Update src/main/resources/application.properties with your MySQL credentials:

spring.datasource.url=jdbc:mysql://localhost:3306/academictracker?useSSL=false&allowPublicKeyRetrieval=true
spring.datasource.username=your_username
spring.datasource.password=your_password

2. Build and Run

# Clean and build
./mvnw clean install

# Run the application
./mvnw spring-boot:run

The application will start on http://localhost:8080

πŸ“š API Documentation

Authentication Endpoints

Register User

POST /api/auth/register
Content-Type: application/json

{
  "name": "John Doe",
  "email": "john@example.com",
  "password": "password123",
  "role": "STUDENT"
}

Login

POST /api/auth/login
Content-Type: application/json

{
  "email": "john@example.com",
  "password": "password123"
}

Response includes JWT token in cookie and user details in body.

Logout

POST /api/auth/logout

User Management Endpoints

Get All Users (ADMIN only)

GET /api/users/all

Get User by ID

GET /api/users/{id}

Get User by Email

GET /api/users/email/{email}

Delete User (ADMIN only)

DELETE /api/users/{id}

Course Management Endpoints

Get All Courses

GET /api/courses/all

Get Course by ID

GET /api/courses/{id}

Add Course (ADMIN or TEACHER)

POST /api/courses/add
Content-Type: application/json

{
  "name": "Mathematics",
  "section": "A",
  "teacher": {
    "id": 1
  }
}

Delete Course (ADMIN only)

DELETE /api/courses/{id}

Attendance Management Endpoints

Mark Attendance (TEACHER only)

POST /api/attendance/mark
Content-Type: application/json

{
  "studentId": 1,
  "courseId": 1,
  "date": "2025-10-08",
  "present": true,
  "remarks": "On time"
}

Get Attendance by Student

GET /api/attendance/student/{studentId}

Accessible by: STUDENT, TEACHER, PARENT

Get Attendance by Course (TEACHER only)

GET /api/attendance/course/{courseId}

Get Attendance by Date (TEACHER only)

GET /api/attendance/date/{date}

Example: /api/attendance/date/2025-10-08

Marks Management Endpoints

Add Marks (TEACHER only)

POST /api/marks/add
Content-Type: application/json

{
  "student": {
    "id": 1
  },
  "course": {
    "id": 1
  },
  "score": 85.5
}

Get Marks by Student

GET /api/marks/student/{studentId}

Accessible by: STUDENT, TEACHER, PARENT

Get Marks by Course (TEACHER only)

GET /api/marks/course/{courseId}

πŸ” Security

Roles and Permissions

  • ADMIN: Full system access, user management, course deletion
  • TEACHER: Course creation, attendance marking, marks entry, view all course data
  • STUDENT: View own attendance and marks
  • PARENT: View child's attendance and marks

JWT Configuration

JWT tokens are:

  • Stored in HTTP-only cookies
  • Valid for 24 hours (configurable in application.properties)
  • Signed with HS512 algorithm
  • Automatically validated on each request

πŸ—οΈ Project Structure

src/main/java/com/example/academictracker/
β”œβ”€β”€ controller/          # REST API endpoints
β”‚   β”œβ”€β”€ AuthController.java
β”‚   β”œβ”€β”€ UserController.java
β”‚   β”œβ”€β”€ CourseController.java
β”‚   β”œβ”€β”€ AttendanceController.java
β”‚   └── MarksController.java
β”œβ”€β”€ service/            # Business logic
β”‚   β”œβ”€β”€ UserService.java
β”‚   β”œβ”€β”€ CourseService.java
β”‚   β”œβ”€β”€ AttendanceService.java
β”‚   └── MarksService.java
β”œβ”€β”€ repository/         # Data access layer
β”‚   β”œβ”€β”€ UserRepository.java
β”‚   β”œβ”€β”€ CourseRepository.java
β”‚   β”œβ”€β”€ AttendanceRepository.java
β”‚   └── MarksRepository.java
β”œβ”€β”€ model/             # Entity classes
β”‚   β”œβ”€β”€ User.java
β”‚   β”œβ”€β”€ Course.java
β”‚   β”œβ”€β”€ Attendance.java
β”‚   β”œβ”€β”€ Marks.java
β”‚   └── Role.java
β”œβ”€β”€ dto/               # Data transfer objects
β”‚   β”œβ”€β”€ LoginRequest.java
β”‚   └── AttendanceDTO.java
β”œβ”€β”€ security/          # Security configuration
β”‚   β”œβ”€β”€ SecurityConfig.java
β”‚   β”œβ”€β”€ JwtUtil.java
β”‚   β”œβ”€β”€ JwtAuthenticationFilter.java
β”‚   └── CustomUserDetailsService.java
└── AcademictrackerApplication.java

πŸ”§ Configuration

Key configuration properties in application.properties:

# Database
spring.datasource.url=jdbc:mysql://localhost:3306/academictracker
spring.jpa.hibernate.ddl-auto=update

# JWT
jwt.secret=yourSecretKey123456789yourSecretKey123456789
jwt.expiration=86400000

# CORS (update for production)
# Configured in SecurityConfig.java

βœ… Key Improvements Made

  1. Centralized Password Encoding: Moved to UserService for consistency
  2. Proper Validation: Added @Valid annotations and comprehensive validation
  3. Error Handling: Try-catch blocks with meaningful error messages
  4. Entity Relationships: Fixed lazy loading and JSON serialization issues
  5. Security: Proper JWT configuration from properties file
  6. Service Layer: Added ID-based query methods for better performance
  7. API Consistency: Standardized response formats and error handling
  8. Code Organization: Removed duplicate classes and unused code

πŸ§ͺ Testing

Sample Test Flow

  1. Register a user:
curl -X POST http://localhost:8080/api/auth/register \
  -H "Content-Type: application/json" \
  -d '{"name":"Test User","email":"test@example.com","password":"password123","role":"STUDENT"}'
  1. Login:
curl -X POST http://localhost:8080/api/auth/login \
  -H "Content-Type: application/json" \
  -d '{"email":"test@example.com","password":"password123"}' \
  -c cookies.txt
  1. Access protected endpoint:
curl -X GET http://localhost:8080/api/courses/all \
  -b cookies.txt

πŸ“ Notes

  • Default role for new users is STUDENT
  • Passwords are encrypted using BCrypt
  • All timestamps use system timezone
  • Database schema is auto-created/updated on startup
  • CORS is configured for http://localhost:3000 (update for production)

πŸ› Troubleshooting

Common Issues

  1. Database Connection Failed

    • Verify MySQL is running
    • Check credentials in application.properties
    • Ensure database exists
  2. JWT Token Invalid

    • Check if token has expired (24h default)
    • Verify secret key is consistent
    • Clear cookies and login again
  3. Access Denied

    • Verify user has correct role
    • Check @PreAuthorize annotations
    • Ensure JWT token is being sent

πŸ“„ License

This project is for educational purposes.

πŸ‘₯ Contributors

Academic Tracker Development Team

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages