How fuhr-br/cadastro works
Project type and purpose
• This is a monolithic, layered REST‐API built with Java Spring Boot.
• It manages “Pessoa” (person) and “Endereco” (address) entities: create/read/update operations, designate a primary address, and list records.
File structure
• Top-level: pom.xml, Maven wrapper, .github/workflows (CI with GitHub Actions), README.
• src/main/java/com/attornatus/cadastro:
• CadastroApplication.java – Spring Boot entrypoint
• controller/ – REST controllers (PessoaController)
• service/ – business logic (PessoaService, EnderecoService)
• infra/ – repositories (PessoaRepository, EnderecoRepository)
• domain/ – JPA entities (Pessoa, Endereco)
• dto/ – request/response DTO classes
• mapper/ – MapStruct or manual mappers (PessoaMapper, EnderecoMapper)
• exception/ & handler/ – exception types and global error handler
• src/main/resources: application.properties (H2 config, Swagger)
• src/test: unit & integration tests (MockMvc, in-memory H2, SQL scripts)
README for additional insights
• Uses H2 in-memory DB
• Exposes Swagger UI (/swagger-ui) and H2 console
• CI & CD via GitHub Actions and Heroku deployment
• Emphasis on clean code, test coverage, layered architecture
a. Main components:
• Client / API consumer (e.g., Swagger UI, Postman)
• REST Controller layer (handles HTTP requests)
• Service layer (business rules)
• Mapper layer (converts between domain and DTO)
• Repository layer (Spring Data JPA interacting with H2 DB)
• H2 Database (in-memory)
• Exception Handler (intercepts and formats errors)
• External services: Swagger‐UI, H2 console, CI/CD pipeline (GitHub Actions → Heroku)
b. Relationships & data flow:
Client → Controller → Service → Repository → H2 DB
Repository returns entities → Mapper → Service → Controller → JSON response
Exception thrown in any layer → RestExceptionHandler → JSON error payload
c. Architectural patterns & principles:
• Layered (Controller/Service/Repository)
• MVC-inspired REST
• DTO pattern with dedicated Mapper layer
• Repository pattern (via Spring Data JPA)
• Global exception handling (ControllerAdvice)
• In-memory DB for fast tests and demo
d. Key technologies:
• Java & Spring Boot
• Spring Web (REST controllers)
• Spring Data JPA (repositories)
• H2 Database
• Maven build & dependency management
• MapStruct or custom mappers
• Swagger UI for API documentation
• JUnit + MockMvc for testing
• GitHub Actions & Heroku for CI/CD