Project Hub is a Spring Boot REST service that manages Projects, Owners, Addresses, and Files. It exposes CRUD endpoints for each domain, using a layered architecture that separates HTTP, business logic, and persistence.
The service follows a classic Spring layered design:
- Controllers (
controllers) handle HTTP requests/responses and map routes to services. - Services (
services) implement business logic and orchestrate repository calls. - Repositories (
repositories) provide data access via Spring Data JPA. - Domain (
domain) contains JPA entities mapped to database tables. - DTOs (
dto) represent request/response shapes when needed. - Config (
config) holds application and API documentation configuration.
This keeps HTTP concerns (validation, status codes) separate from domain rules, and domain rules separate from persistence details.
src/main/java/pexper/projects/project_hub
bootstrap/- seed data for local development.config/- CORS, web settings, and OpenAPI configuration.controllers/- REST controllers for each aggregate.domain/- JPA entities and relationships.dto/- DTOs used by controllers/services.repositories/- Spring Data interfaces for persistence.services/- service interfaces and implementations.ProjectHubApplication.java- application entry point.
Controllers map incoming HTTP requests to service methods. Each controller is focused on one
aggregate (Project, Owner, Address, File) and exposes standard CRUD operations. They
return DTOs or entities (depending on the endpoint) and handle status codes and validation
errors at the edge.
Services encapsulate business logic and transactional behavior. Each service implementation coordinates repository calls, enforces invariants, and transforms data when needed.
Repositories are Spring Data JPA interfaces. They provide CRUD operations without custom SQL, which keeps the persistence layer concise and testable.
Entities are JPA-annotated classes that define how data is stored and related. They model the core concepts of the system: projects, owners, addresses, and files.
application.yml- app settings (database, server port, etc).OpenApiConfig- Swagger / OpenAPI setup.WebConfig- web and CORS configuration.
The default profile is h2, which uses an in-memory database for local runs.
Use the persist profile to connect to MySQL.
h2usesapplication-h2.yml.persistusesapplication-persist.ymland reads MySQL settings fromSPRING_DATASOURCE_URL,SPRING_DATASOURCE_USERNAME, andSPRING_DATASOURCE_PASSWORD(with local defaults).
When the persist profile is active, the service loads seed data from
src/main/resources/db/mysql/data.sql. This runs on every startup with the
persist profile and is intended for local/dev usage.
SQLite dependencies are included (sqlite-jdbc and Hibernate community dialects).
To use SQLite, define a profile with a jdbc:sqlite: URL and set
spring.jpa.database-platform=org.hibernate.community.dialect.SQLiteDialect.
./mvnw spring-boot:runOn Windows (PowerShell):
.\mvnw.cmd spring-boot:runTo run with MySQL:
./mvnw spring-boot:run -Dspring-boot.run.profiles=persistTo re-seed MySQL data, drop the database (or truncate the tables) and restart with
persist, or edit db/mysql/data.sql and restart. If you want to disable seeding,
set spring.sql.init.mode=never in application-persist.yml.
Dependencies are already included. Create application-sqlite.yml with:
spring:
datasource:
url: jdbc:sqlite:./project-hub.db
driver-class-name: org.sqlite.JDBC
jpa:
database-platform: org.hibernate.community.dialect.SQLiteDialect
hibernate:
ddl-auto: updateThen run:
./mvnw spring-boot:run -Dspring-boot.run.profiles=sqlitedocker build -t project-hub-service .
docker run -p 8080:8080 project-hub-servicedocker-compose up --buildThe compose stack starts MySQL and runs the API with the persist profile.
When using Docker Compose, phpMyAdmin is available at:
http://localhost:8082/
Login with:
- Server:
db - Username:
project_hub - Password:
project_hub
These scripts build both the API (this repo) and the Angular UI, then start the stack via
Docker Compose. They expect the Angular app to exist at ../angular/project-hub relative to
this service.
chmod +x build-and-run.sh rebuild.sh
./build-and-run.shUse rebuild.sh when you want to force a fresh rebuild of images before starting:
./rebuild.shOpenAPI/Swagger is enabled. When the service is running, visit:
http://localhost:8080/swagger-ui.htmlorhttp://localhost:8080/swagger-ui/index.html
All /api/** endpoints are protected. Clients must authenticate and send a Bearer token on
every request.
POST /api/auth/login
Request body:
{
"username": "admin",
"password": "admin123"
}Response body:
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"tokenType": "Bearer",
"expiresAt": "2026-01-18T23:10:00Z"
}Use the token on all API calls:
Authorization: Bearer <token>
Update these in application.yml for local/dev:
app:
jwt:
secret: change-me-to-a-long-random-secret
expiration-minutes: 60
auth:
default-user: admin
default-password: admin123
default-role: ADMINbootstrap/UserBootstrapData creates the default user on startup if it does not exist.
The Angular app logs in, stores the token, and attaches it on every API call.
High level flow:
LoginComponentposts credentials to/api/auth/login.AuthServicestores thetoken(the app uses theBearerscheme).AuthInterceptoraddsAuthorization: Bearer <token>to all/api/**requests.
If the backend runs on a different port (example 8081), update the Angular API base URL or
proxy to match the running backend URL.
Spring Boot Actuator is included to expose operational endpoints for health checks and diagnostics.
By default, only health and info are exposed over HTTP:
http://localhost:8080/actuator/healthhttp://localhost:8080/actuator/info
To expose additional endpoints, add or update the following properties in
application.yml (or a profile-specific file like application-h2.yml):
management:
endpoints:
web:
base-path: /actuator
exposure:
include: health,info,metrics,env,loggers,threaddump
endpoint:
health:
show-details: when_authorizedNotes:
- Use
management.endpoints.web.exposure.include=*only in local/dev. - Keep sensitive endpoints (
env,loggers) restricted in production. management.endpoint.health.show-detailscan benever,when_authorized, oralways.
Examples using curl:
curl http://localhost:8080/actuator
curl http://localhost:8080/actuator/health
curl http://localhost:8080/actuator/metricsbootstrap/BootstrapData can seed initial data for local development, making it easier to
work with the frontend right away.
- Prefer placing validation and business rules in services instead of controllers.
- Keep repository interfaces simple; introduce custom queries only when needed.
- When adding new domains, follow the same package conventions:
domainentityrepositoryinterfaceserviceinterface +serviceimplementationcontrollerendpoints
Run the unit test suite with:
./mvnw testOn Windows (PowerShell):
.\mvnw.cmd testCoverage reports are generated automatically when tests run. The HTML report is located at:
target/site/jacoco/index.html
If you want to force a fresh report:
./mvnw clean testOn Windows (PowerShell):
.\mvnw.cmd clean test- Lambdas
- Records
- Threads/syncronized
- Actuator
- java versions
- microservices/patterns
- azure (cloud)
- interfaces funcionais (???)
- jdk, jvm, jrm
- Seção 11: MySql with Spring Boot -> ADMIN
- Seção 16: Paging and Sorting with Spring MVC
- Seção 23: Spring Authorization Server
- Seção 24: Spring MVC OAuth2 Resource Server
- Seção 30: Spring Data MongDB
- Seção 37: Spring Cloud Gateway
- Seção 44: Spring Boot Actuator - Seção 51: Kubernetes with Spring Boot
- Seção 53: Spring Boot Microservices with Apache Kafka
- complement vi tests
- lambdas
- Records