How sakthivelvelmurugan/comment-box works
Purpose and entry points
CommentBox is a stateless Java 17/Spring Boot REST service that turns submitted source code into commented code through OpenRouter-hosted LLMs. The process starts at src/main/java/com/commentbox/api/CommentboxApiApplication.java; its public API is POST /api/v1/comments/generate in src/main/java/com/commentbox/api/controller/CommentController.java. It also serves a small static browser UI from src/main/resources/static/index.html.
HTTP/API boundary
CommentController accepts a typed generation payload—language, comment style, density, code, and optional BYOK key—using src/main/java/com/commentbox/api/model/CommentRequest.java. It returns the generated code plus request/provider metadata via src/main/java/com/commentbox/api/model/CommentResponse.java. CORS policy is centralized in src/main/java/com/commentbox/api/config/CorsConfig.java.
Generation orchestration
src/main/java/com/commentbox/api/service/CommentService.java is the core application stage: it coordinates request handling, key selection, prompt creation, invocation of the model provider, and response shaping. The service is stateless: there is no persistence layer or database in the repository. Any usage/remaining-generation information is therefore request/service-level rather than durable application state.
Prompt and provider boundary
src/main/java/com/commentbox/api/util/PromptBuilder.java converts language, style, density, and raw code into the LLM instruction payload. src/main/java/com/commentbox/api/config/OpenRouterConfig.java configures Spring WebFlux WebClient, separating outbound OpenRouter HTTP integration from controller logic. The configured provider is OpenRouter, with GPT-4o-mini described as the target model; credentials come from a request apiKey when supplied, otherwise backend environment configuration.
Security and sensitive inputs
src/main/java/com/commentbox/api/service/EncryptionService.java is the dedicated boundary for handling sensitive material, notably user-supplied API-key flow. The API supports BYOK and a server-side OPENROUTER_API_KEY; callers should not expect keys to be persisted, consistent with the stateless design.
Validation and failure handling
Input-size and request/provider failures flow through application-specific exceptions in src/main/java/com/commentbox/api/util/LimitExceededException.java and src/main/java/com/commentbox/api/util/ApiException.java. src/main/java/com/commentbox/api/config/GlobalExceptionHandler.java maps these failures into the API error contract represented by src/main/java/com/commentbox/api/util/ErrorResponse.java, keeping error translation outside core generation logic.
Runtime and deployment
Spring Boot runs on port 8085 and exposes health through Actuator. Base and production runtime properties are in src/main/resources/application.properties and src/main/resources/application-prod.properties. Maven builds the service (pom.xml); Dockerfile packages it as a lean Alpine-based container. Deployment metadata targets Railway (railway.toml) and Vercel (vercel.json), with production behavior selected through SPRING_PROFILES_ACTIVE=prod.
Main entry points: CommentService.java Comment service · CommentboxApiApplication.java Spring Boot application · CommentController.java Comment endpoint · GlobalExceptionHandler.java Error translation
Components 20
HTTP API
- Static browser UI
src/main/resources/static/index.html - Comment endpoint · POST /api/v1/comments/generate.
src/main/java/com/commentbox/api/controller/CommentController.java - Generation request · Carries code, language, style, density, and optional BYOK key.
src/main/java/com/commentbox/api/model/CommentRequest.java - Generation response · Returns commented code and provider metadata.
src/main/java/com/commentbox/api/model/CommentResponse.java - CORS policy
src/main/java/com/commentbox/api/config/CorsConfig.java - Provider failures
src/main/java/com/commentbox/api/util/ApiException.java - Input limit failures
src/main/java/com/commentbox/api/util/LimitExceededException.java - Error translation
src/main/java/com/commentbox/api/config/GlobalExceptionHandler.java - API error response
src/main/java/com/commentbox/api/util/ErrorResponse.java
Generation pipeline
- Comment service · Statelessly selects credentials, builds prompts, invokes the model, and shapes responses.
src/main/java/com/commentbox/api/service/CommentService.java - Sensitive key handling · Dedicated boundary for user-supplied API keys.
src/main/java/com/commentbox/api/service/EncryptionService.java - Prompt builder
src/main/java/com/commentbox/api/util/PromptBuilder.java
Provider integration
- OpenRouter WebClient
src/main/java/com/commentbox/api/config/OpenRouterConfig.java - OpenRouter / GPT-4o-mini · External model endpoint.
Runtime & deployment
- Spring Boot application
src/main/java/com/commentbox/api/CommentboxApiApplication.java - Production runtime config · Port 8085; production profile is selected with SPRING_PROFILES_ACTIVE=prod.
src/main/resources/application-prod.properties - Actuator health
- Container build · Alpine-based service package.
Dockerfile - Railway deployment
railway.toml - Vercel deployment
vercel.json
Connections 20
- Static browser UI → Comment endpoint: submits generation request
- Spring Boot application → Comment endpoint: starts
- Spring Boot application → CORS policy: loads
- Spring Boot application → Production runtime config: uses production profile
- Spring Boot application → Actuator health: exposes health
- Comment endpoint → Generation request: binds
- Comment endpoint → Comment service: delegates
- Comment endpoint → Generation response: returns
- Comment service → Sensitive key handling: handles BYOK key
- Comment service → Prompt builder: builds instruction
- Comment service → OpenRouter WebClient: invokes through
- OpenRouter WebClient → OpenRouter / GPT-4o-mini: outbound model request
- Comment service → Provider failures: raises provider failures
- Comment service → Input limit failures: raises size failures
- Provider failures → Error translation: handled by
- Input limit failures → Error translation: handled by
- Error translation → API error response: maps to
- Container build → Spring Boot application: packages
- Railway deployment → Container build: deploys
- Vercel deployment → Container build: deploys