Spring Boot backend for transformer thermal inspection workflows, including transformer management, inspection lifecycle, AI-assisted anomaly detection, and secure image handling with AWS S3 pre-signed URLs.
- Overview
- Key Features
- Tech Stack
- Architecture at a Glance
- Project Structure
- Prerequisites
- Configuration
- Database Notes
- Run the Application
- API Documentation
- API Surface Summary
- Authentication & Authorization
- Testing
- Troubleshooting
This service exposes REST APIs under /api/v1/** for:
- transformer records,
- inspections linked to transformers,
- anomaly annotations,
- AI-based analysis of inspection images,
- signed upload/download URL generation for private S3 objects.
It acts as:
- an OAuth2 resource server (JWT validation against Keycloak),
- a PostgreSQL-backed persistence layer via Spring Data JPA,
- an integration layer to a FastAPI anomaly-detection microservice,
- an S3 pre-signed URL provider for direct client upload/download flows.
- Transformer lifecycle APIs (CRUD).
- Inspection lifecycle APIs (CRUD per transformer).
- Annotation APIs for detected/manual anomalies.
- Anomaly analysis endpoint that calls FastAPI and persists detection metadata.
- Pre-signed S3 URLs for secure client-side image upload/download.
- OpenAPI/Swagger UI for interactive API exploration.
- Legacy profile endpoints for annotation logs and maintenance records export flows.
- Unified API response envelope via
ApiResponse<T>.
- Java 21
- Spring Boot 3.4.1
- Spring Web, Spring Data JPA, Validation, Security, OAuth2 Resource Server, Actuator
- Spring WebFlux
WebClient(FastAPI integration) - PostgreSQL (runtime)
- H2 (tests)
- AWS SDK v2 (S3 pre-signing)
- springdoc-openapi (Swagger UI)
- Maven Wrapper (
./mvnw)
- Client uploads image to S3 using a backend-generated pre-signed PUT URL.
- Client stores S3 object key through transformer/inspection APIs.
POST /api/v1/inspections/{id}/analyze:- backend generates pre-signed GET URLs for baseline and maintenance images,
- backend generates pre-signed PUT URL for AI-annotated image,
- backend calls FastAPI
/api/v1/detect, - backend stores image-level and anomaly-level detection results in PostgreSQL.
/home/runner/work/backend/backend
├── pom.xml
├── docs/
│ └── api-examples.md
├── src/main/java/com/chamikara/spring_backend
│ ├── config/ # Security, S3, OpenAPI, WebClient configs
│ ├── controller/ # REST controllers
│ ├── dto/ # Request/response DTOs
│ ├── entity/ # JPA entities
│ ├── exception/ # Global exception handling
│ ├── repository/ # Spring Data repositories
│ ├── security/ # JWT -> local user sync/auth principal
│ └── service/ # Business logic + integrations
├── src/main/resources
│ ├── application.properties
│ └── db/migration/ # SQL migration scripts (manual usage notes)
└── src/test
- JDK 21 (required by
pom.xmlrelease target) - Maven (optional if using
./mvnw) - PostgreSQL instance
- Keycloak realm / JWT issuer
- AWS S3 bucket and credentials
- FastAPI detection service
Primary configuration is in:
/home/runner/work/backend/backend/src/main/resources/application.properties
You can keep secrets out of source control by using environment variables (.env is gitignored).
| Property | Purpose | Default / Example |
|---|---|---|
server.port |
HTTP port | 8080 |
spring.datasource.url |
PostgreSQL JDBC URL | jdbc:postgresql://localhost:5432/transformer_db |
spring.datasource.username |
DB username | postgres |
spring.datasource.password |
DB password | 1234 (change for local/prod) |
spring.jpa.hibernate.ddl-auto |
Schema strategy | validate |
fastapi.service.url |
FastAPI base URL | http://localhost:8000 |
fastapi.service.detect-endpoint |
Detect path config | /api/v1/detect |
fastapi.service.timeout |
Detect call timeout (ms) | 300000 |
spring.security.oauth2.resourceserver.jwt.issuer-uri |
JWT issuer URI | http://localhost:9090/realms/transformer-realm |
aws.accessKeyId |
AWS access key | ${AWS_ACCESS_KEY_ID:CHANGE_ME} |
aws.secretKey |
AWS secret key | ${AWS_SECRET_ACCESS_KEY:CHANGE_ME} |
aws.region |
AWS region | ${AWS_REGION:us-east-1} |
aws.s3.bucketName |
S3 bucket | ${AWS_S3_BUCKET_NAME:CHANGE_ME} |
- JPA is configured with
ddl-auto=validate, so expected tables must already exist. - The repository includes SQL scripts in:
/home/runner/work/backend/backend/src/main/resources/db/migration/V2__add_detection_columns.sql/home/runner/work/backend/backend/src/main/resources/db/migration/V3__add_annotated_image_key.sql
- These scripts are written as manual migration steps and should be applied before startup when relevant.
From /home/runner/work/backend/backend:
chmod +x ./mvnw
./mvnw spring-boot:runRun with legacy profile enabled:
./mvnw spring-boot:run -Dspring-boot.run.profiles=legacyBuild JAR:
./mvnw clean package- Swagger UI:
http://localhost:8080/swagger-ui.html - OpenAPI JSON:
http://localhost:8080/v3/api-docs - Detailed request/response examples:
/home/runner/work/backend/backend/docs/api-examples.md
All /api/v1/** routes require JWT unless stated otherwise.
GET/POST/PUT/DELETE /api/v1/transformersGET/POST/PUT/DELETE /api/v1/inspections(path variants under transformer)GET/POST /api/v1/inspections/{inspectionId}/anomaliesPUT/DELETE /api/v1/anomalies/{id}POST /api/v1/inspections/{id}/analyzeGET /api/v1/images/generate-upload-urlGET /api/v1/images/generate-download-url
/api/v1/annotation-logs/**/api/v1/records/**
GET /actuator/healthGET /actuator/info
- App is stateless (
SessionCreationPolicy.STATELESS). - Security rules:
/api/v1/**-> authenticated/actuator/health,/actuator/info-> public
- JWT is validated using configured issuer URI.
- JWT claims are used to upsert a local
userstable record (LocalUserSyncService). - CORS currently allows
http://localhost:5173.
From /home/runner/work/backend/backend:
./mvnw testTest profile uses:
- H2 in-memory database (
src/test/resources/application-test.properties) - separate test app name and security test configuration
release version 21 not supported: your runtime JDK is lower than 21; install/use Java 21.- 401 on
/api/v1/**: verifyAuthorization: Bearer <token>and JWT issuer configuration. - S3 URL generation issues: verify AWS credentials, region, and bucket env vars.
- Analyze endpoint failures: verify FastAPI service URL, timeout, and reachability.