Segundos API is a Spring Boot REST API designed to manage study sessions, subjects, materials, and exam questions. The application provides a comprehensive platform for tracking learning progress, study time, and question performance across different subjects and materials.
This is a backend service that supports a frontend application (React/Frontend) running on localhost:3000 for study management and progress tracking.
- ✅ User authentication and management with JWT tokens
- ✅ Material (Subject Area) management
- ✅ Topic/Subject management under materials
- ✅ Question tracking with success/failure metrics
- ✅ Study time tracking
- ✅ Access control and authorization
- ✅ RESTful API with Swagger documentation
- ✅ CORS support for frontend integration
- ✅ Data persistence with H2 Database
- Spring Boot 3.5.4 - Java-based web framework for building REST APIs
- Java 21 - Programming language
- Maven - Dependency management and build tool
- H2 Database - In-memory relational database for development/testing
- Spring Data JPA - Object-Relational Mapping (ORM) framework
- Hibernate - JPA implementation for database interactions
- SpringDoc OpenAPI (v2.8.8) - Generates OpenAPI/Swagger documentation
- Swagger UI - Interactive API documentation interface
- Spring Security - Framework for authentication and authorization
- JJWT (v0.12.6) - JWT (JSON Web Token) library for token-based authentication
- JWT Secret - Token encryption and validation
- Spring Validation - Data validation framework
- Lombok - Java library to reduce boilerplate code
- MySQL Connector - Support for MySQL database (can be used instead of H2)
- JUnit 5 (Jupiter) - Unit testing framework
- Spring REST Docs - REST API documentation with tests
- Spring DevTools - Hot reload and development features
- Spring Configuration Processor - Metadata processing for configuration properties
The application follows a three-layer architecture pattern:
┌─────────────────────────────────────────┐
│ REST Controllers │
│ (HTTP Request/Response Layer) │
└──────────────────┬──────────────────────┘
│
┌──────────────────▼──────────────────────┐
│ Service Layer │
│ (Business Logic & Validations) │
└──────────────────┬──────────────────────┘
│
┌──────────────────▼──────────────────────┐
│ Repository Layer (Data Access) │
│ (Spring Data JPA Repositories) │
└──────────────────┬──────────────────────┘
│
┌──────────────────▼──────────────────────┐
│ Database (H2 In-Memory) │
│ (Data Persistence) │
└─────────────────────────────────────────┘
- Controllers - Handle HTTP requests and responses
- Services - Contain business logic and domain operations
- Repositories - Interface with the database
- DTOs (Data Transfer Objects) - Transfer data between layers
- Mappers - Convert between entities and DTOs
- Models/Entities - Database entity representations
- Configuration - CORS, Swagger, Web configuration
src/main/
├── java/com/example/segundos_api/
│ ├── SegundosApiApplication.java # Main Spring Boot application entry point
│ │
│ ├── config/ # Configuration classes
│ │ ├── CorsConfig.java # CORS configuration
│ │ ├── SwaggerConfig.java # Swagger/OpenAPI documentation
│ │ └── WebConfig.java # Web configuration
│ │
│ ├── controller/ # REST API Controllers
│ │ ├── UserController.java # User management endpoints
│ │ ├── MateriaController.java # Material management endpoints
│ │ ├── AssuntoController.java # Subject/Topic endpoints
│ │ ├── QuestaoController.java # Question tracking endpoints
│ │ ├── TempoController.java # Study time endpoints
│ │ └── AcessoController.java # Authentication/Access control
│ │
│ ├── service/ # Business Logic Layer
│ │ ├── UserService.java # User operations
│ │ ├── MateriaService.java # Material operations
│ │ ├── AssuntoService.java # Subject operations
│ │ ├── QuestaoService.java # Question operations
│ │ ├── TempoService.java # Study time operations
│ │ ├── AcessoService.java # Authentication logic
│ │ ├── JwtTokenService.java # JWT token generation/validation
│ │ └── impl/ # Service implementations
│ │
│ ├── repository/ # Data Access Layer (Spring Data JPA)
│ │ ├── UserRepository.java
│ │ ├── MateriaRepository.java
│ │ ├── AssuntoRepository.java
│ │ ├── QuestaoRepository.java
│ │ └── TempoRepository.java
│ │
│ ├── model/ # Entity Classes (JPA Entities)
│ │ ├── User.java
│ │ ├── Materia.java
│ │ ├── Assunto.java
│ │ ├── Questao.java
│ │ ├── Tempo.java
│ │ └── ...
│ │
│ ├── dto/ # Data Transfer Objects
│ │ ├── UserMapper.java # User DTOs mapper
│ │ ├── MateriaMapper.java # Material DTOs mapper
│ │ ├── AssuntoMapper.java # Subject DTOs mapper
│ │ ├── QuestaoMapper.java # Question DTOs mapper
│ │ ├── TempoMapper.java # Study time DTOs mapper
│ │ ├── request/ # Request DTOs (input)
│ │ │ ├── UserRequest.java
│ │ │ ├── MateriaRequest.java
│ │ │ ├── AssuntoRequest.java
│ │ │ ├── QuestaoRequest.java
│ │ │ └── TempoRequest.java
│ │ └── response/ # Response DTOs (output)
│ │ ├── UserResponse.java
│ │ ├── MateriaResponse.java
│ │ ├── AssuntoResponse.java
│ │ ├── QuestaoResponse.java
│ │ └── TempoResponse.java
│ │
│ ├── exception/ # Custom Exceptions
│ │ └── ...
│ │
│ └── enums/ # Enumerations
│ └── ...
│
└── resources/
├── application.properties # Main configuration
├── data.sql # Initial SQL data
└── META-INF/
└── additional-spring-configuration-metadata.json
The application manages 5 main entities with the following relationships:
┌─────────────┐
│ User │
│ (tsec_users)│
└──────┬──────┘
│ 1:N
│
├──────────────────┬──────────────┬──────────────┐
│ │ │ │
▼ ▼ ▼ ▼
┌────────────┐ ┌────────────┐ ┌──────────┐ ┌────────────────┐
│ Materia │ │ Questao │ │ Assunto │ │ Tempo Estudo │
│(tsec_ │ │(tsec_ │ │(tsec_ │ │ (tsec_tempos) │
│materias) │ │questoes) │ │assuntos) │ └────────────────┘
└─────┬──────┘ └────────────┘ └────┬─────┘
│ │ │
│ 1:N │ 1:N │ 1:N
│ │ │
└───────────────┴──────────────┘
Assunto (Subject)
(1:N relation)
CORS is configured to allow requests from the frontend application:
- Allowed Origins:
http://localhost:3000 - Allowed Methods: GET, POST, PUT, DELETE
- Allowed Headers: All (*)
- Allow Credentials: Yes
- Max Age: 3600 seconds
- Java 21 or higher
- Maven 3.6+ (or use
mvnwprovided) - Git
- Clone the repository
git clone <repository-url>
cd segundos-back/segundos-api- Build the project
./mvnw clean installOn Windows:
mvnw.cmd clean install- Run the application
./mvnw spring-boot:runOn Windows:
mvnw.cmd spring-boot:runThe application will start on http://localhost:8080/Segundos_api
http://localhost:8080/Segundos_api/swagger-ui.html
Interactive API documentation where you can test all endpoints.
http://localhost:8080/Segundos_api/api-docs
http://localhost:8080/Segundos_api/h2-console
Default credentials:
- Username: sa
- Password: (leave empty)
- JDBC URL: jdbc:h2:mem:segundos
The application includes Spring DevTools for hot reload:
- Code changes are automatically reloaded during development
- No need to restart the application manually
H2 Database Console is enabled for development:
- Visual inspection of database data
- Execute SQL queries directly
- Monitor database state in real-time
Hibernate SQL logging is enabled to see executed queries:
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
Run unit tests:
./mvnw testThe project includes:
- JUnit 5 for unit testing
- Spring Test for integration testing
- Spring REST Docs for API documentation tests
If port 8080 is already in use, change it in application.properties:
server.port=8081 # or any other available portFor H2 database issues:
- Clear Maven cache:
./mvnw clean - Check H2 console at
http://localhost:8080/Segundos_api/h2-console - Verify JDBC URL:
jdbc:h2:mem:segundos
- Ensure token is included in request headers
- Check token hasn't expired (1 hour default)
- Verify JWT secret in configuration matches
- Project Name: Segundos API
- Version: 0.0.1-SNAPSHOT
- Java Version: 21
- Spring Boot Version: 3.5.4
- Status: Active Development