The SkillForge Course Service is a Spring Boot microservice responsible for course management, content delivery, and learning path generation in the SkillForge learning platform. It provides comprehensive course functionality including creation, management, search, enrollment tracking, and AI-powered course generation.
The course service is built with:
- Spring Boot 3.x: Core application framework
- Spring Security: Authentication and authorization
- Spring Data MongoDB: Data persistence
- JWT (JSON Web Tokens): Stateless authentication
- OpenAPI 3.0: API documentation with Swagger UI
- GenAI Integration: AI-powered course generation and content creation
- Web Crawling: Content extraction from external sources
- Course creation, updating, and deletion
- Course publishing and visibility controls
- Module and lesson management
- Course metadata and categorization
- Advanced search with multiple filters
- Public course browsing
- Category and skill-based filtering
- Instructor and level-based search
- Course enrollment and unenrollment
- Course bookmarking and unbookmarking
- Course completion tracking
- Progress monitoring and skill acquisition
- GenAI course generation from learning paths
- AI-assisted content creation
- Web crawling for content extraction
- Intelligent course recommendations
- User service integration for enrollment management
- Secure service-to-service communication
- User progress synchronization
- Request Reception: HTTP request received by controller
- Security Filter: JWT token validation (if required)
- Business Logic: Service layer processes request
- Data Persistence: MongoDB operations via repository layer
- Inter-Service Calls: User service communication (if needed)
- Response: Structured JSON response with appropriate HTTP status
- Course Creation: Manual creation or AI generation
- Content Development: Module and lesson addition
- Publishing: Course made available to users
- Enrollment: Users enroll in courses
- Progress Tracking: User progress and completion monitoring
- Analytics: Course performance and user engagement metrics
The service integrates with GenAI for:
- Course Generation: Creating courses from learning path requests
- Content Enhancement: AI-assisted content creation
- Web Crawling: Extracting content from external URLs
- Intelligent Recommendations: Suggesting courses based on user preferences
The service validates JWT tokens for protected endpoints:
// Token Validation
public boolean isTokenValid(String token, String userId) {
try {
final String subject = extractUserId(token);
final Date expiration = extractClaim(token, Claims::getExpiration);
return (subject.equals(userId) && !expiration.before(new Date()));
} catch (JwtException | IllegalArgumentException e) {
return false;
}
}GET /api/v1/courses/public/**- Public course browsingGET /api/v1/courses/search- Course search functionalityGET /api/v1/courses/categories/**- Category informationGET /api/v1/courses/health- Health checkGET /docs/**- API documentationGET /actuator/*- Monitoring endpoints
- All other
/api/v1/courses/**endpoints - Course creation and management
- User enrollment operations
- Course generation and AI features
The course service communicates with the user service using:
- Service Key Authentication:
X-Service-Keyheader for internal operations - Secure Headers: User ID injection via
X-User-Idheader - Stateless Design: No shared state between services
Environment-specific CORS policies for cross-origin requests:
// Development
config.addAllowedOriginPattern("*");
config.
setAllowedMethods(Arrays.asList("GET", "POST","PUT","DELETE","OPTIONS"));
config.
setAllowedHeaders(List.of("*"));POST /api/v1/courses- Create a new courseGET /api/v1/courses/{courseId}- Get course detailsGET /api/v1/courses- Get all coursesPUT /api/v1/courses/{courseId}- Update coursePATCH /api/v1/courses/{courseId}- Partial course updateDELETE /api/v1/courses/{courseId}- Delete course
GET /api/v1/courses/public- Get public coursesGET /api/v1/courses/published- Get published courses
GET /api/v1/courses/search- Advanced search with filtersGET /api/v1/courses/search/instructor/{instructor}- Search by instructorGET /api/v1/courses/search/level/{level}- Search by levelGET /api/v1/courses/search/language/{language}- Search by languageGET /api/v1/courses/search/skill/{skillName}- Search by skillGET /api/v1/courses/search/category/{categoryName}- Search by categoryGET /api/v1/courses/search/title/{title}- Fuzzy title search
POST /api/v1/courses/{courseId}/enroll/{userId}- Enroll user in courseDELETE /api/v1/courses/{courseId}/enroll/{userId}- Unenroll user from coursePOST /api/v1/courses/{courseId}/complete/{userId}- Mark course as completedPOST /api/v1/courses/{courseId}/bookmark/{userId}- Bookmark courseDELETE /api/v1/courses/{courseId}/bookmark/{userId}- Unbookmark courseGET /api/v1/courses/user/{userId}/enrolled- Get user's enrolled courses
POST /api/v1/courses/generate/learning_path/{userId}- Generate course from learning pathPOST /api/v1/courses/generate/learning_path/{userId}/confirm- Confirm generated coursePOST /api/v1/courses/generate/prompt- Generate response from promptPOST /api/v1/courses/crawl/url- Crawl web URL for content
GET /api/v1/courses/health- Service health checkGET /actuator/health- Spring Boot health endpointGET /actuator/prometheus- Prometheus metrics
GET /docs- Swagger UI documentationGET /course-openapi.yaml- OpenAPI specification
public class Course {
private String id;
private String title;
private String description;
private String instructor; // "AI" or user ID
private List<String> skills;
private List<Module> modules;
private List<EnrolledUserInfo> enrolledUsers;
private Integer numberOfEnrolledUsers;
private List<String> categories;
private Level level; // BEGINNER, INTERMEDIATE, ADVANCED
private String thumbnailUrl;
private Boolean published;
private Boolean isPublic;
private Language language; // EN, ES, FR, etc.
private double rating;
}public class Module {
private String id;
private String title;
private String description;
private List<Lesson> lessons;
private Integer order;
}public class Lesson {
private String id;
private String title;
private String description;
private List<LessonContent> content;
private Integer order;
private Integer estimatedDuration; // in minutes
}public class EnrolledUserInfo {
private String userId;
private LocalDateTime enrolledAt;
private LocalDateTime completedAt;
private List<String> acquiredSkills;
private Map<String, Integer> moduleProgress; // moduleId -> progress percentage
}- CourseRequest: Course creation data
- CourseUpdateRequest: Course update data
- CourseResponse: Course response data
- CourseSummaryResponse: Course summary for listings
- LearningPathRequest: AI course generation request
- EnrolledUserInfoResponse: User enrollment information
# Service Configuration
SERVER_PORT_COURSES=8083
# MongoDB Configuration
MONGODB_DATABASE=skillforge
MONGO_URL=mongodb://localhost:27017/skillforge
# JWT Configuration
JWT_SECRET=your-secret-key-here
# User Service Integration
SERVER_HOST_USER=localhost
SERVER_PORT_USER=8082
# GenAI Service Integration (Ensure it is running)
SERVER_HOST_GENAI=localhost
SERVER_PORT_GENAI=8888server:
port: ${SERVER_PORT_COURSES:8083}
address: "0.0.0.0"
spring:
data:
mongodb:
database: ${MONGODB_DATABASE:skillforge}
uri: ${MONGO_URL:mongodb://localhost:27017/skillforge}
jwt:
secret: ${JWT_SECRET:default-secret-key}
user:
service:
uri: http://${SERVER_HOST_USER:localhost}:${SERVER_PORT_USER:8082}- dev: Development configuration with debug logging
- docker: Docker environment configuration
- prod: Production configuration with optimized settings
- test: Test configuration with in-memory database
# 1. Start MongoDB
# On macOS with Homebrew:
brew services start mongodb-community
# On Ubuntu/Debian:
sudo systemctl start mongod
# On Windows:
# Download MongoDB from https://www.mongodb.com/try/download/community and run:
mongod
# Or using Docker:
docker run -d -p 27017:27017 --name mongodb mongo:latest
# 2. Start User Service (required for course enrollment operations)
# In the user service directory:
./gradlew bootRun
# 3. Set environment variables (optional - defaults are provided)
export SERVER_PORT_COURSES=8083
export MONGODB_DATABASE=skillforge
export MONGO_URL=mongodb://localhost:27017/skillforge
export JWT_SECRET=your-secret-key-here
export SERVER_HOST_USER=localhost
export SERVER_PORT_USER=8082
# 4. Start the course service
./gradlew bootRun
# Or with specific profile
./gradlew bootRun --args='--spring.profiles.active=dev'# Run all tests
./gradlew test
# Run specific test
./gradlew test --tests CourseServiceTest
# Run with coverage
./gradlew test jacocoTestReportOnce the service is running, access the API documentation:
- Swagger UI: http://localhost:8083/docs
- OpenAPI Spec: http://localhost:8083/course-openapi.yaml (This will download the OpenAPI spec file)
- Swagger UI: http://localhost:8081/api/v1/courses/docs
- OpenAPI Spec: http://localhost:8081/api/v1/courses/user-openapi.yaml (This will download the OpenAPI spec file)
# Connect to MongoDB
mongosh mongodb://localhost:27017/skillforge
# View collections
show collections
# Query courses
db.courses.find()
# Query specific course
db.courses.findOne({title: "Introduction to Java"})
# Query by category
db.courses.find({categories: "Programming"})logging:
level:
com.gitittogether.skillforge.server.course: DEBUG
org.springframework.security: DEBUG
org.springframework.data.mongodb: DEBUG- Service Health:
GET /api/v1/courses/health - Spring Boot Health:
GET /actuator/health - Database Connectivity: Included in health checks
- User Service Connectivity: Monitored for inter-service communication
- Prometheus Metrics:
GET /actuator/prometheus - Application Metrics: Request counts, response times, error rates
- Database Metrics: Connection pool, query performance
- AI Generation Metrics: Course generation success rates and performance
-
JWT Security
- Token validation on protected endpoints
- User ID extraction and validation
- Secure error responses without information leakage
-
Input Validation
- Request DTO validation with Bean Validation
- SQL injection prevention (MongoDB)
- XSS protection through proper encoding
-
CORS Configuration
- Environment-specific CORS policies
- Proper preflight request handling
- Secure header configuration
-
Inter-Service Security
- Service key authentication for internal operations
- Secure user service communication
- Proper error handling for service failures
-
AI Integration Security
- Secure GenAI service communication
- Input sanitization for AI prompts
- Rate limiting for AI generation endpoints
The service includes security headers:
X-Content-Type-Options: nosniffX-Frame-Options: DENYX-XSS-Protection: 1; mode=block
-
MongoDB Connection Errors
- Ensure MongoDB is running and accessible
- Check MongoDB host/port configuration
- Verify database name and authentication
-
JWT Validation Failures
- Check JWT secret configuration
- Verify token format and expiration
- Ensure proper Authorization header format
-
User Service Communication Errors
- Ensure user service is running
- Check user service host/port configuration
- Verify service key authentication
-
AI Generation Failures
- Check GenAI service connectivity
- Verify AI service configuration
- Monitor AI service logs for errors
-
CORS Errors
- Verify CORS configuration for environment
- Check allowed origins and methods
- Ensure proper preflight request handling
Enable debug logging for troubleshooting:
logging:
level:
com.gitittogether.skillforge.server.course: DEBUG
org.springframework.security: DEBUG
org.springframework.data.mongodb: DEBUG# Check MongoDB status
sudo systemctl status mongod
# Check MongoDB logs
sudo journalctl -u mongod
# Test MongoDB connection
mongosh mongodb://localhost:27017/skillforge --eval "db.runCommand('ping')"# Test user service connectivity
curl -H "X-Service-Key: course-service-key" \
http://localhost:8082/api/v1/users/health
# Check service communication logs
tail -f logs/course-service.log | grep "user-service"- Receives requests through API Gateway
- JWT tokens validated by gateway
- User ID injected via
X-User-Idheader
- Inter-service communication via service keys
- Course enrollment, bookmarking, and completion tracking
- User progress synchronization
- AI-powered course generation
- Content extraction and enhancement
- Intelligent learning path creation
- Prometheus metrics for monitoring
- Health checks for load balancers
- Structured logging for log aggregation
- Learning Path Analysis: Analyzes user skills and goals
- Content Creation: Generates course structure and content
- Skill Mapping: Maps course content to specific skills
- Personalization: Tailors content to user preferences
- Content Extraction: Extracts relevant content from URLs
- Data Processing: Processes and structures extracted content
- Quality Assurance: Validates and filters extracted content
- Skill-Based: Recommends courses based on user skills
- Progress-Based: Suggests next steps based on completion
- Popularity-Based: Recommends trending and popular courses