Project based on Java AI Framework
- User Authentication: Secure user registration and login with JWT authentication.
- Session Management: Create, retrieve, update, and delete chat sessions.
- AI Chat: Real-time chat with AI models, with support for different providers.
- Extensible AI Tools: A variety of tools to enhance the AI's capabilities, such as web search, code execution, and more.
- Admin Panel: Manage users and their roles.
- Email Verification: Verify user accounts via email.
- Java 24
- Spring Boot 3.4.8
- Spring AI 1.0.0
- MongoDB: NoSQL database for storing user data and chat sessions.
- Spring Security: For authentication and authorization.
- JJWT: For creating and validating JSON Web Tokens.
- Maven: Dependency management.
- Selenium & Playwright: For web scraping and browser automation tools.
- Java 24 or higher
- Maven
- MongoDB instance running
- Clone the repository:
git clone https://github.com/your-username/BackendAI.git
- Navigate to the project directory:
cd BackendAI - Install the dependencies:
mvn install
- Create an
application.propertiesfile insrc/main/resourcesand add the following properties:# MongoDB Configuration spring.data.mongodb.uri=mongodb://localhost:27017/your-db-name # JWT Configuration jwt.secret=your-jwt-secret # Email Configuration spring.mail.host=smtp.gmail.com spring.mail.port=587 spring.mail.username[email protected] spring.mail.password=your-email-password spring.mail.properties.mail.smtp.auth=true spring.mail.properties.mail.smtp.starttls.enable=true # Spring AI Configuration (choose one) # For OpenRouter spring.ai.openrouter.api-key=your-openrouter-api-key # For LMStudio spring.ai.lmstudio.url=http://localhost:1234/v1
- Run the application:
mvn spring-boot:run
- POST
/api/v1/users/register
Request Body:
{
"userName": "testuser",
"password": "password123",
"gmail": "[email protected]"
}Response Body:
{
"success": true,
"message": "User registered successfully",
"data": {
"userId": "60d5f3f7e8a8d82e8c3e8e3e",
"userName": "testuser",
"gmail": "[email protected]",
"roles": [
"USER"
],
"sessionCount": 0,
"isVerified": false
}
}- POST
/api/v1/users/login
Request Body:
{
"userName": "testuser",
"password": "password123"
}Response Body:
{
"success": true,
"message": "Login successful",
"data": {
"token": "your-jwt-token",
"tokenType": "Bearer",
"user": {
"userId": "60d5f3f7e8a8d82e8c3e8e3e",
"userName": "testuser",
"gmail": "[email protected]",
"roles": [
"USER"
],
"sessionCount": 0,
"isVerified": false
}
}
}- GET
/api/v1/users/profile
Response Body:
{
"success": true,
"message": "User profile retrieved successfully",
"data": {
"userId": "60d5f3f7e8a8d82e8c3e8e3e",
"userName": "testuser",
"gmail": "[email protected]",
"roles": [
"USER"
],
"sessionCount": 0,
"isVerified": false
}
}- POST
/api/v1/sessions/create
Request Body:
{
"nameSession": "My First Session",
"model": "gpt-3.5-turbo"
}Response Body:
{
"success": true,
"message": "Session created successfully",
"data": {
"sessionId": "60d5f3f7e8a8d82e8c3e8e3f",
"nameSession": "My First Session",
"model": "gpt-3.5-turbo",
"dateTime": "2025-08-23T10:00:00",
"messages": [],
"messageCount": 0
}
}- GET
/api/v1/sessions
Response Body:
{
"success": true,
"message": "Found 1 sessions",
"data": [
{
"sessionId": "60d5f3f7e8a8d82e8c3e8e3f",
"nameSession": "My First Session",
"model": "gpt-3.5-turbo",
"dateTime": "2025-08-23T10:00:00",
"messageCount": 0
}
]
}- POST
/api/v1/chat/{sessionId}
Request Body:
{
"prompt": "Hello, how are you?"
}Response Body: (Server-Sent Events)
data: Hello! I am doing great.
data: How can I help you today?
- GET
/api/v1/verify/send
Response Body:
{
"success": true,
"message": "Verification code sent to [email protected]",
"data": null
}- POST
/api/v1/verify/check/{code}
Response Body:
{
"success": true,
"message": "Verification successful",
"data": null
}- POST
/api/v1/admins/make/{username}
Response Body:
{
"userId": "60d5f3f7e8a8d82e8c3e8e3e",
"userName": "testuser",
"gmail": "[email protected]",
"roles": [
"USER",
"ADMIN"
],
"sessionCount": 0,
"isVerified": false
}- GET
/api/v1/admins/users
Response Body:
[
{
"userId": "60d5f3f7e8a8d82e8c3e8e3e",
"userName": "testuser",
"gmail": "[email protected]",
"roles": [
"USER",
"ADMIN"
],
"sessionCount": 0,
"isVerified": false
}
]The application uses application.properties for configuration. You can create different profiles for different environments (e.g., application-dev.properties, application-prod.properties).
The application supports two AI providers:
- OpenRouter: To use OpenRouter, activate the
openrouterprofile and set thespring.ai.openrouter.api-keyproperty. - LMStudio: To use LMStudio, activate the
lmstudioprofile and set thespring.ai.lmstudio.urlproperty.
The application includes a variety of tools that can be used by the AI model:
- ArxivApiTools: Search for papers on Arxiv.
- CodeforcesProblemSetTools: Get problems from Codeforces.
- EmailTools: Send emails.
- PlaywrightBrowserSearchTools: Search the web using a headless browser (Playwright).
- PlaywrightWebScraperTools: Scrape websites using a headless browser (Playwright).
- ReportTools: Generate reports.
- SeleniumBrowserSearchTools: Search the web using a headless browser (Selenium).
- SeleniumWebScraperTools: Scrape websites using a headless browser (Selenium).
- ServerInfoTools: Get server information.
- WeatherTools: Get weather information.
- WebScraperTools: Scrape websites.
- WebSearchTools: Search the web.
- WikipediaTools: Search for articles on Wikipedia.
- BraveSearchApiTools: Search the web using the Brave Search API.
- ExchangeRateApiTools: Get exchange rates.
- GNewsApiTools: Get news from the GNews API.
- NewsDataApiTools: Get news from the NewsData API.
- ScoutApiTools: Search the web using the Scout API.
- SerpApiTools: Search the web using the SerpApi.
- TempMailApiTools: Get temporary email addresses.
- YouTubeSummarizerTools: Summarize YouTube videos.