How espirito-santo-arthais/cidadesibge works
Project type and purpose
• This is a standalone, monolithic RESTful API built with Spring Boot (Maven project).
• Purpose: ingest a CSV of Brazilian cities into a database, expose CRUD and analytics endpoints for cities (e.g., list capitals, count per state, distance calculations).
File structure
• Top-level: pom.xml, application wrapper (.mvn, mvnw), README, a CSV under planilha/.
• src/main/java/br/com/senior/DesafioSenior: follows a classic layered MVC pattern:
• controller/ – CidadeController, ImportarPlanilha, utility classes
• service/ – CidadeService (business logic)
• repository/ – CidadeRepository (Spring Data JPA)
• model/ – Cidade, Estado entities/enums
• src/main/resources/application.properties configures the database.
• test/ mirrors the main package for unit/integration tests.
Extract key architectural points from README
• One endpoint to load CSV into the database.
• Several read‐only endpoints for filtering, aggregation, and geospatial calculations.
• Endpoints for create and delete city.
Main components and their interactions
a. External Clients (Postman, browser, another service)
b. Spring MVC Layer (Controllers)
• CidadeController: exposes HTTP endpoints
• ImportarPlanilha: endpoint to trigger CSV load
• Utility classes for parsing & geolocation
c. Service Layer
• CidadeService: orchestrates business rules, delegates to repository
d. Persistence Layer
• CidadeRepository: Spring Data JPA interface
• Database: e.g., H2 for dev or Postgres/MySQL in production
e. External/File System
• CSV file (planilha/CSV_Cidades_Senior.csv) read during import
Architectural patterns & design principles
• Layered (Controller → Service → Repository → Database)
• Separation of concerns:
• Controllers handle HTTP & request validation
• Service holds business logic (calculations, filtering)
• Repository abstracts data access
• Use of Spring Boot auto-configuration and dependency injection
• Entities map one-to-one to database tables via JPA annotations