Spring Boot backend for analyzing code snippets and uploaded source files with OpenAI-backed bug finding and fallback local analysis.
- Java 17
- Spring Boot
- Maven Wrapper
- OpenAI Java SDK
- Accepts source code as JSON and returns bug analysis, fixes, explanations, edge cases, and complexity notes
- Accepts source files or zip uploads for analysis
- Uses OpenAI when
OPENAI_API_KEYis configured - Falls back to a local rule-based response when the API key is missing or the OpenAI call fails
src/main/java/com/aibugfinder/backend/controller- REST API controllerssrc/main/java/com/aibugfinder/backend/service- analysis logic and OpenAI client integrationsrc/main/java/com/aibugfinder/backend/dto- request and response DTOssrc/main/resources/application.properties- app configuration
- Java 17+
- Internet access for dependency download and OpenAI API calls
PowerShell, current terminal only:
$env:OPENAI_API_KEY="your_real_key_here"Permanent Windows user variable:
[System.Environment]::SetEnvironmentVariable("OPENAI_API_KEY", "your_real_key_here", "User")Important:
- Do not commit the real API key into the repository
- If you set the key permanently, reopen your terminal or IDE before starting the app again
Windows:
.\mvnw.cmd spring-boot:runmacOS or Linux:
./mvnw spring-boot:runThe backend runs on:
http://localhost:8081
Base path:
/api
Analyze raw code sent in JSON.
Request body:
{
"code": "public class Demo { public static void main(String[] args) {} }",
"language": "java"
}Sample response shape:
{
"bugs": ["Possible misuse of '==' instead of equals()"],
"fixedCode": "...",
"explanation": "...",
"edgeCasesToTest": ["..."],
"timeComplexity": "...",
"spaceComplexity": "...",
"optimality": "...",
"learningResources": ["..."]
}Analyze an uploaded source file or zip archive.
Form fields:
file- required multipart filelanguage- optional language override
Example with PowerShell:
curl.exe -X POST "http://localhost:8081/api/analyze/upload?language=java" ^
-F "file=@D:\path\to\BinarySearch.java"- The frontend should call this backend only
- The OpenAI API key must stay on the backend or deployment environment
- Do not place the OpenAI API key in frontend code,
.envfrontend files, or client-side requests - If the backend is deployed centrally, frontend developers do not need the OpenAI key at all
Current app settings live in src/main/resources/application.properties:
spring.application.name=demo
openai.model=gpt-5-mini
openai.api-key=${OPENAI_API_KEY}
server.port=8081Run tests with the Maven wrapper:
Windows:
.\mvnw.cmd testmacOS or Linux:
./mvnw test- If
OPENAI_API_KEYis invalid, the service returns fallback analysis instead of crashing - Error messages are sanitized so API keys are not echoed back in responses
- CORS is enabled on the controller for frontend integration