This project provides a RESTful API for managing customer data. It uses Kotlin, Spring Boot, Postgres, and jOOQ for type-safe database interactions. The API supports basic CRUD operations, along with validations, custom exception handling, and observability. It also includes automated acceptance testing, containerization for deployment, and instructions for Kubernetes integration.
Key Features:
main.This project follows the practice of documenting architectural decisions using Architectural Decision Records (ADRs). Each significant technical decision is captured in a dedicated ADR file to provide context, rationale, and implications.
You can find the first ADR, which documents the decision to adopt this practice, here.
For a full list of ADRs, navigate to the docs/ADRs/ directory.
graph TD
A[Client Application] -->|API Requests| B[Customer Management API]
B -->|Database Queries| C[Postgres Database]
B --> D[Metrics/Logs Exporter]
D --> E[Monitoring System]
subgraph Acceptance Tests
F[Postman Collection]
G[Newman Container]
end
F --> B
sequenceDiagram
participant Client
participant API
participant Database
Client->>API: POST /customers
API->>Database: Insert new customer record
Database-->>API: Success or error response
API-->>Client: 201 Created or 400 Bad Request
Client->>API: GET /customers
API->>Database: Fetch all customers
Database-->>API: List of customers
API-->>Client: 200 OK
Client->>API: GET /customers/{id}
API->>Database: Fetch customer by ID
Database-->>API: Customer record or null
API-->>Client: 200 OK or 404 Not Found
Client->>API: PUT /customers/{id}
API->>Database: Update customer record
Database-->>API: Success or error response
API-->>Client: 200 OK or 400 Bad Request
Client->>API: DELETE /customers/{id}
API->>Database: Delete customer record
Database-->>API: Success or error response
API-->>Client: 204 No Content or 404 Not Found
Components:
mvn -v.Clone the repository:
git clone https://github.com/aaiezza/customer-management-api.git
cd customer-management-api
Build the project:
mvn clean install
Run the application:
mvn spring-boot:run
The API is now available at: http://localhost:8080
Alternatively, you can use Docker Compose to run the application along with Postgres locally:
Run the following command:
docker-compose up app
This will build and run the Spring Boot application, as well as a Postgres database.
The API will be available at: http://localhost:8080
Ensure Minikube and kubectl are installed and configured.
minikube start --memory=6144 --cpus=4
./scripts/start-kubernetes.sh
minikube service customer-management-api --url
kubectl get pods --watch
./scripts/shutdown-kubernetes.sh
The Swagger UI provides an interactive interface for exploring and testing the API endpoints defined in the OpenAPI Specification.
swaggerapi/swagger-ui Docker container to serve your OpenAPI spec.docker create --name swagger-ui-extract swaggerapi/swagger-ui
docker cp swagger-ui-extract:/usr/share/nginx/html ./swagger-static
docker rm swagger-ui-extract
swagger-static into docs/swagger:mv swagger-static docs/swagger
docs/swagger/swagger-initializer.js to reference the OpenAPI spec:url: "../openapi.yaml"
docs folder.jOOQ generates type-safe database schema classes. To run the code generation:
mvn clean install -Pjooq-codegen
This will generate the database schema classes in target/generated-sources/jooq.
Run unit tests:
mvn test
To simplify acceptance testing, you can leverage the provided docker-compose configuration to run Newman:
Run the acceptance tests with:
docker-compose up postman
This will execute the Postman collection against the running API and generate a report.
GitHub Actions Workflow:
.github/workflows/ci.yml that triggers on merges to main.
Before running the project, create a secrets.yaml file for your credentials:
secrets.yaml.template to secrets.yaml.<base64-encoded-username> and <base64-encoded-token> with your Base64-encoded Git credentials.
echo -n 'your-username' | base64
echo -n 'your-token' | base64
Important: Do not commit secrets.yaml to the repository. It is excluded by .gitignore.
minikube start --memory=6144 --cpus=4
./scripts/start-kubernetes.sh
kubectl get pods
minikube service customer-management-api
./scripts/shutdown-kubernetes.sh
main.