Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
189 changes: 189 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
# Learning Management System (LMS) Backend

A comprehensive Learning Management System backend built with Spring Boot, featuring role-based authentication and comprehensive course management capabilities.

## Features

### Core Entities
- **Students**: User accounts for learners with enrollment tracking
- **Instructors**: User accounts for educators with course management
- **Admins**: Administrative users with system-wide permissions
- **Courses**: Course management with enrollment limits and status tracking
- **Enrollments**: Student-course relationships with grades and progress
- **Lessons**: Course content with multimedia support

### Key Functionalities
- JWT-based authentication and authorization
- Role-based access control (ADMIN, INSTRUCTOR, STUDENT)
- Course enrollment and management
- User profile management
- Grade tracking and course completion
- RESTful API endpoints
- H2 in-memory database for development

## Technology Stack

- **Framework**: Spring Boot 3.2.0
- **Security**: Spring Security with JWT
- **Database**: H2 (development), MySQL (production ready)
- **ORM**: Spring Data JPA with Hibernate
- **Java Version**: 17
- **Build Tool**: Maven

## API Endpoints

### Authentication
- `POST /api/auth/signin` - User login
- `POST /api/auth/signup/student` - Student registration
- `POST /api/auth/signup/instructor` - Instructor registration
- `POST /api/auth/signup/admin` - Admin registration

### Students
- `GET /api/students` - Get all students (Admin/Instructor)
- `GET /api/students/{id}` - Get student by ID
- `POST /api/students/{studentId}/enroll/{courseId}` - Enroll in course
- `GET /api/students/{studentId}/courses` - Get student's courses

### Courses
- `GET /api/courses` - Get all courses (Public)
- `GET /api/courses/{id}` - Get course by ID (Public)
- `POST /api/courses` - Create course (Admin/Instructor)
- `GET /api/courses/available` - Get available courses
- `GET /api/courses/search?searchTerm=` - Search courses

### Instructors
- `GET /api/instructors` - Get all instructors (Admin)
- `GET /api/instructors/{id}` - Get instructor by ID
- `POST /api/instructors/{instructorId}/assign-course/{courseId}` - Assign course
- `GET /api/instructors/{instructorId}/courses` - Get instructor's courses

## Getting Started

### Prerequisites
- Java 17 or higher
- Maven 3.6 or higher

### Installation

1. Clone the repository:
```bash
git clone <repository-url>
cd learning-management-system
```

2. Build the project:
```bash
mvn clean install
```

3. Run the application:
```bash
mvn spring-boot:run
```

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

### Database Access
- H2 Console: `http://localhost:8080/h2-console`
- JDBC URL: `jdbc:h2:mem:lmsdb`
- Username: `sa`
- Password: `password`

## Authentication

The system uses JWT (JSON Web Tokens) for authentication. To access protected endpoints:

1. Register or login to get a JWT token
2. Include the token in the Authorization header: `Bearer <token>`

### Sample Authentication Flow

1. **Register a student:**
```json
POST /api/auth/signup/student
{
"username": "john_doe",
"email": "john@example.com",
"password": "password123",
"firstName": "John",
"lastName": "Doe",
"studentId": "STU001"
}
```

2. **Login:**
```json
POST /api/auth/signin
{
"username": "john_doe",
"password": "password123"
}
```

3. **Response:**
```json
{
"accessToken": "eyJhbGciOiJIUzUxMiJ9...",
"tokenType": "Bearer",
"id": 1,
"username": "john_doe",
"email": "john@example.com",
"authorities": ["ROLE_STUDENT"]
}
```

## Database Schema

The system uses a single table inheritance strategy for users with the following main entities:

- **users** - Base table for all user types (students, instructors, admins)
- **courses** - Course information and metadata
- **enrollments** - Student-course relationships with grades
- **lessons** - Course content and materials
- **student_courses** - Many-to-many relationship table

## Security

- Passwords are encrypted using BCrypt
- JWT tokens expire after 24 hours
- Role-based access control with method-level security
- CORS enabled for cross-origin requests

## Configuration

Key configuration properties in `application.properties`:

```properties
# Database
spring.datasource.url=jdbc:h2:mem:lmsdb
spring.h2.console.enabled=true

# JWT
jwt.secret=<base64-encoded-secret>
jwt.expiration=86400000

# Server
server.port=8080
```

## Production Deployment

For production deployment:

1. Replace H2 with MySQL/PostgreSQL
2. Update `application.properties` with production database settings
3. Use environment variables for sensitive configuration
4. Enable HTTPS
5. Configure proper CORS origins

## Contributing

1. Fork the repository
2. Create a feature branch
3. Commit your changes
4. Push to the branch
5. Create a Pull Request

## License

This project is licensed under the MIT License.
Loading