A production-ready Java-based static analysis service that communicates with FastAPI backend to perform deep code analysis using SootUp framework.
FastAPI Backend → Analyzer Service (Spring Boot) → SootUp Engine → Analysis Results → FastAPI Backend
-
Controller Layer (
AnalysisController)- REST API endpoint
/api/analyze - Health check endpoint
/api/health
- REST API endpoint
-
Service Layer
AnalysisService: Orchestrates the analysis workflowSootUpEngine: Performs static analysis using SootUpDownloadUtil: Downloads and extracts source ZIP filesPomGenerator: Generates Maven pom.xml from dependency listMavenExecutor: Compiles projects using Maven
-
Client Layer
FastApiClient: Async HTTP client with retry logic for backend communication
-
Model Layer
- Request/Response models with Jackson serialization
- Call graph and CFG data structures
POST http://analyzer-service:8080/api/analyze
{
"projectId": "abc123",
"sourceZipUrl": "https://backend.com/uploads/projects/abc123.zip",
"dependencies": [
{
"groupId": "org.springframework.boot",
"artifactId": "spring-boot-starter-webflux",
"version": "3.2.0"
}
]
}POST http://backend-fastapi:8000/api/analysis/result
{
"projectId": "abc123",
"analysis": {
"callGraph": {
"nodes": [
{"id": "n1", "label": "App.main()", "type": "entry"},
{"id": "n2", "label": "ServiceA.init()", "type": "intermediate"},
{"id": "n3", "label": "UnsafeLib.execute()", "type": "vulnerable"}
],
"edges": [
{"source": "n1", "target": "n2"},
{"source": "n2", "target": "n3"}
]
},
"cfg": [
{
"class": "ServiceA",
"method": "init()",
"nodes": [
{"id": "c1", "stmt": "new Object()"},
{"id": "c2", "stmt": "return"}
],
"edges": [
{"source": "c1", "target": "c2"}
]
}
]
}
}- Entry Points: Identifies main() methods and controller endpoints
- CHA Algorithm: Class Hierarchy Analysis for call graph construction
- Node Classification:
entry: Main methods or endpoint handlersintermediate: Application codevulnerable: Methods from listed dependencies
- Extracts Jimple IR (intermediate representation)
- Builds CFG nodes and edges for each method
- Captures statement-level control flow
analyzer-service/
├── src/main/java/com/example/analyzer/
│ ├── AnalyzerServiceApplication.java
│ ├── controller/
│ │ └── AnalysisController.java
│ ├── service/
│ │ ├── AnalysisService.java
│ │ ├── SootUpEngine.java
│ │ ├── DownloadUtil.java
│ │ ├── PomGenerator.java
│ │ └── MavenExecutor.java
│ ├── client/
│ │ └── FastApiClient.java
│ └── model/
│ ├── AnalysisRequest.java
│ ├── AnalysisResult.java
│ ├── CallGraph.java
│ ├── CallGraphNode.java
│ ├── CallGraphEdge.java
│ ├── CFGMethod.java
│ ├── CFGNode.java
│ ├── CFGEdge.java
│ └── Dependency.java
├── src/main/resources/
│ └── application.properties
├── Dockerfile
├── docker-compose.yml
└── pom.xml
Edit src/main/resources/application.properties:
# Server
server.port=8080
# Analyzer paths
analyzer.repository.base=/app/repository
# FastAPI Backend
fastapi.backend.url=http://backend-fastapi.com
fastapi.backend.result-endpoint=/api/analysis/result
fastapi.backend.error-endpoint=/api/analysis/error
fastapi.backend.retry-attempts=3# Build
mvn clean package
# Run
java -jar target/analyzer-service-1.0.0.jar# Build image
docker build -t analyzer-service:latest .
# Run container
docker run -p 8080:8080 \
-e FASTAPI_BACKEND_URL=http://backend:8000 \
-v $(pwd)/repository:/app/repository \
analyzer-service:latest# Start service
docker-compose up -d
# View logs
docker-compose logs -f
# Stop service
docker-compose down- Receive Request: FastAPI sends analysis request with project ZIP URL
- Download: Service downloads and extracts source code to
/app/repository/{projectId}/src/ - Generate POM: Creates
pom.xmlwith specified dependencies - Compile: Runs Maven to compile code to
/app/repository/{projectId}/build/classes/ - Analyze: SootUp loads bytecode, builds call graph and CFG
- Send Result: Asynchronously posts results back to FastAPI with retry logic
- Spring Boot 3.2.0: Web framework
- SootUp 2.0.0: Static analysis engine
- OkHttp 4.12.0: Async HTTP client
- Apache Commons: File operations
- Jackson: JSON serialization
- Lombok: Code generation
- Automatic retries (configurable, default: 3 attempts)
- Exponential backoff between retries
- Error notifications sent to FastAPI on failure
- Comprehensive logging at all stages
- Console and file logging
- Log file:
/app/logs/analyzer-service.log - Debug level for analyzer components
- Warn level for SootUp (reduces noise)
GET http://localhost:8080/api/health
{
"status": "healthy",
"service": "analyzer-service"
}JAVA_OPTS: JVM options (default:-Xmx2g -Xms512m)SPRING_PROFILES_ACTIVE: Spring profileFASTAPI_BACKEND_URL: Backend URLANALYZER_REPOSITORY_BASE: Base path for project repositories
- Configure backend URL in environment
- Mount persistent volumes for
/app/repositoryand/app/logs - Set appropriate memory limits via
JAVA_OPTS - Use health check endpoint for load balancer
- Monitor logs for errors and performance
MIT License