A backend Learning Management System built using Java and Spring Boot.
LearnGrid provides secure JWT authentication, role-based authorization, course management, student enrollment, API documentation, automated enrollment notifications, integration testing, and containerized deployment.
- User registration and login
- JWT-based authentication
- Role-based access control:
- ADMIN
- TEACHER
- STUDENT
- Password encryption using BCrypt
- Method-level authorization using Spring Security
@PreAuthorize - JWT authentication support in Swagger
- View authenticated user profile
- View all users (Admin)
- Update user roles (Admin)
- Secure user responses using DTOs
- Create courses
- Update courses
- Delete courses
- View course details
- View all courses
- Pagination and sorting support
- Automatic teacher assignment using the authenticated user
- Teachers can only modify their own courses
- Teachers can view students enrolled in their own courses
- Students can enroll in courses
- Prevent duplicate enrollments
- Students can view their own enrollments
- Students can cancel enrollments
- Teachers can view students enrolled in their courses
- Admins can view all enrollments
- Asynchronous enrollment confirmation emails
- Enrollment email processing using Spring's
@Async - Gmail SMTP integration
- Request/Response DTO pattern
- Input validation
- Global exception handling using
@RestControllerAdvice - Custom exceptions
- Appropriate HTTP status codes
- Swagger/OpenAPI documentation
- Pagination and sorting
- Dockerized Spring Boot application
- PostgreSQL running in a Docker container
- Docker Compose for multi-container setup
- Persistent PostgreSQL volume
- Environment-based configuration for database credentials and JWT secret
- 67 automated tests
- Service-layer unit tests with Mockito
- Repository integration tests with PostgreSQL
- Controller integration tests using MockMvc
- Authentication and JWT testing
- Role-based access control testing
- Course ownership/authorization testing
- JWT expiration testing
- JWT signature/tampering testing
- Java 21
- Spring Boot 4.1
- Spring Security
- Spring Data JPA
- Hibernate
- Maven
- PostgreSQL 18
- JWT
- BCrypt Password Encoder
- JUnit 5
- Mockito
- Spring Boot Test
- MockMvc
- Swagger / OpenAPI
- Docker
- Docker Compose
HTTP Request
|
v
+---------------------+
| JWT Security |
| Filter |
+---------------------+
|
v
+---------------------+
| Controller |
+---------------------+
|
v
+---------------------+
| Service |
+---------------------+
|
v
+---------------------+
| Repository |
+---------------------+
|
v
PostgreSQL
The application follows a layered architecture:
- Security layer validates JWT tokens and establishes the authenticated user
- Controller layer handles HTTP requests and API responses
- Service layer contains business logic
- Repository layer handles database operations
- DTOs handle API request and response objects
- Exception layer provides centralized error handling
Stores application users.
Fields:
- id
- name
- password
- role
Roles:
- ADMIN
- TEACHER
- STUDENT
Stores available courses.
Fields:
- id
- title
- description
- createdAt
- instructor
Connects students and courses.
Fields:
- id
- student
- course
- enrolledAt
Swagger UI is available at:
http://localhost:8081/swagger-ui/index.html
After logging in, JWT tokens can be supplied using the Swagger Authorize button.
| Method | Endpoint | Access |
|---|---|---|
| POST | /api/auth/register |
Public |
| POST | /api/auth/login |
Public |
| Method | Endpoint | Access |
|---|---|---|
| GET | /api/users/me |
Authenticated |
| GET | /api/users |
ADMIN |
| GET | /api/users/admin |
ADMIN |
| PUT | /api/users/{id}/role |
ADMIN |
| Method | Endpoint | Access |
|---|---|---|
| POST | /api/courses |
ADMIN, TEACHER |
| GET | /api/courses |
Authenticated |
| GET | /api/courses/{id} |
Authenticated |
| GET | /api/courses/my |
TEACHER |
| PUT | /api/courses/{id} |
ADMIN, TEACHER |
| DELETE | /api/courses/{id} |
ADMIN, TEACHER |
| GET | /api/courses/{courseId}/students |
ADMIN, TEACHER |
| Method | Endpoint | Access |
|---|---|---|
| GET | /api/enrollments |
ADMIN |
| POST | /api/enrollments/{courseId} |
STUDENT |
| GET | /api/enrollments/my |
STUDENT |
| DELETE | /api/enrollments/{enrollmentId} |
STUDENT |
Register a user:
POST /api/auth/register
Login:
POST /api/auth/login
The login endpoint returns a JWT.
Authenticated requests use:
Authorization: Bearer <JWT>
The JWT contains the user's email and role.
Spring Security validates the token before allowing access to protected endpoints.
git clone https://github.com/vipul080/LearnGrid-API.git
cd LearnGrid-APICreate a PostgreSQL database:
lms
Configure the required environment variables:
DB_URL=jdbc:postgresql://localhost:5432/lms
DB_PASSWORD=your_database_password
JWT_SECRET=your_jwt_secret
Do not commit your .env file or expose your JWT secret.
Windows:
.\mvnw.cmd clean packageLinux/macOS:
./mvnw clean package.\mvnw.cmd spring-boot:runThe application runs on:
http://localhost:8081
Swagger UI:
http://localhost:8081/swagger-ui/index.html
Make sure Docker Desktop is installed and running.
Create a .env file in the project root:
DB_PASSWORD=your_database_password
JWT_SECRET=your_jwt_secretThe .env file should not be committed to GitHub.
docker compose up --buildThis starts:
Spring Boot application
|
v
PostgreSQL container
The application will be available at:
http://localhost:8081
Swagger UI:
http://localhost:8081/swagger-ui/index.html
docker compose downPostgreSQL data is stored in a persistent Docker volume, so normal container shutdowns do not remove the database data.
Run the complete test suite using Maven.
.\mvnw.cmd test./mvnw testCurrent test result:
67 tests
0 failures
0 errors
0 skipped
The test suite includes:
- 14 service-layer unit tests
- Repository integration tests
- Controller integration tests
- Authentication integration tests
- JWT security tests
- Role-based authorization tests
- Ownership/authorization tests
- Register as a teacher
- Login and receive a JWT token
- Create a course
- Manage their own courses
- View students enrolled in their courses
- Register as a student
- Login and receive a JWT token
- Browse available courses
- Enroll in a course
- Receive an enrollment confirmation email
- View enrolled courses
- Cancel an enrollment
- Login and receive a JWT token
- View registered users
- Manage user roles
- Manage courses
- View all enrollments
- Frontend application
- Course categories
- File uploads for course materials
- Cloud deployment
- Additional API features
Vipul Shukla