AdamAI is a Spring Boot based middleware service that acts as a bridge between a user and a Large Language Model (LLM) using OpenRouter AI.
The application supports:
- AI personalities (helper, coder, pirate)
- Session memory/context handling
- Retry & exponential backoff for failed AI requests
- Swagger/OpenAPI documentation
- Global exception handling
- Frontend chat interface
- REST API communication
Users can choose between different personalities:
helpercoderpirate
Each personality maps to a different system prompt before sending requests to the AI model.
The application stores conversation history in-memory using:
Map<String, List<AIMessage>>This allows the AI to remember previous messages in the same conversation.
Failed AI requests automatically retry using Spring Retry.
Implemented with:
@Retryable(
retryFor = Exception.class,
maxAttempts = 3,
backoff = @Backoff(
delay = 1000,
multiplier = 2
)
)Retry functionality is enabled globally using:
@EnableRetryThis improves resilience when the AI service is temporarily unavailable.
The application uses:
@ControllerAdviceto return clean and user-friendly error responses.
API documentation is automatically generated using SpringDoc OpenAPI.
Swagger UI:
http://localhost:8080/swagger-ui.html
- Java 25
- Spring Boot 4
- Spring Web
- Spring Validation
- Spring Retry
- OpenRouter AI
- Swagger / OpenAPI
- JUnit 5
- Mockito
- MockMvc
- JaCoCo
- HTML / CSS / JavaScript
src
├── client
├── controllers
├── DTO
├── exceptions
├── services
├── resources
│ ├── static
│ └── application.properties
└── test
{
"message": "Hello AI",
"personality": "helper",
"sessionId": "user-123"
}{
"reply": "Hello! How can I help you today?"
}The API validates incoming request bodies before processing them.
The application validates incoming requests using:
@NotBlankIf validation fails, the API returns:
400 Bad Request
The project includes:
- Controller tests using MockMvc
- Service layer unit tests
- Validation tests
- Global exception handler tests
- AIClient personality tests
- Mocked dependencies using Mockito
- Spring Boot context loading tests
Code coverage is measured using JaCoCo.
git clone https://github.com/addee1/AdamAI-chatbot.gitThe application uses environment variables to securely manage the OpenRouter API key.
Inside:
src/main/resources/application.properties
the following property is already configured:
ai.api.key=${OPENROUTER_API_KEY:test-key}- Open:
Run → Edit Configurations
-
Select the Spring Boot application
-
Add the following environment variable:
OPENROUTER_API_KEY=your_api_key_here
- Save and run the application
mvn spring-boot:runThe application includes a custom frontend chat interface where users can:
- send messages
- choose AI personalities
- maintain conversation memory
- interact with the AI in real-time
Built and designed by Adam Ottosson
Portfolio: https://adamottosson.se