How jhonatademuner/studai works
Project type and purpose
• This is a standalone backend microservice (Spring Boot) that exposes REST APIs for the StudAI quiz platform. It handles user management, question/quiz persistence, authentication (JWT + Spring Security), and delegates quiz‐generation to an external “studai-assistant” microservice.
File structure
• Top-level layers correspond to:
• client (HTTP client for studai-assistant)
• config (CORS, Security, RestTemplate)
• controller (REST API endpoints)
• service (business logic + JWT management)
• repository (Spring Data JPA for PostgreSQL)
• domain (entities, enums, DTOs)
• utils (assemblers, exception handling)
• Database migrations live under src/main/resources/db/migration (SQL scripts).
• Build and CI/CD: Maven (pom.xml, Maven wrapper) and GitHub Actions workflow (.github/workflows/java-backend-ci-cd.yml).
README for additional insights
• Uses PostgreSQL (Docker) for data persistence.
• Integrates with studai-assistant microservice via REST (configured by AssistantProperties + AssistantClient).
• Exposes Swagger UI at /swagger-ui/index.html for API exploration.
• Enforces JWT-based authentication via a JWTFilter and SecurityConfig.
Main components & interactions (to include
a. External Client (Web or Mobile)
• Issues HTTPS requests →
b. API Gateway / Spring Boot Application
• CORSConfig
• JWTFilter / SecurityConfig
• Controllers (UserController, QuestionController, QuizController)
• Services (UserService, QuestionService, QuizService, JWTService)
• AssistantClient (RestTemplate adapter to studai-assistant)
• Exception Handling (GlobalExceptionHandler)
c. Database (PostgreSQL)
• Entities managed by JPA Repositories (UserRepository, QuestionRepository, QuizRepository, QuizAttemptRepository)
• Schema evolution via migration scripts
d. External Service: studai-assistant
• Hosts AI quiz‐generation logic
• Invoked by QuizService through AssistantClient
Architectural patterns & design principles
• Layered (Onion / Hexagonal): Controllers → Services → Repositories → Database
• Separation of Concerns: DTOs + Assemblers decouple domain models from API contracts
• External API Client (Adapter Pattern): AssistantClient isolates remote‐service calls
• Security Filter Chain: JWT filter sits before controller invocation
• Database Migrations: Immutable SQL scripts for versioned schema changes
Essential elements
• Clear component names (e.g., QuizController, QuizService, QuizRepository)
• Annotations for critical configurations (CORS, JWT) and migration path