A modern, full-stack chatbot application built with Spring Boot 3 (Java 21) backend and React (TypeScript) frontend. This application provides an intelligent conversational AI interface with support for multiple LLM providers, conversation management, and web search capabilities.
- Conversational AI: Interactive chat interface with streaming responses
- Multi-LLM Support: Integration with OpenAI GPT models via LangChain4j
- Conversation Management: Create, store, and organize chat conversations
- Real-time Streaming: Server-sent events for real-time message delivery
- Web Search Integration: Enhanced responses with Tavily web search
-
Modern UI: Responsive React interface with Ant Design components
-
Conversation History: Persistent chat history with date-based organization
-
Share Functionality: Share conversations with other users
-
Accessibility: ARIA-compliant interface for screen readers
- RESTful API: Well-documented REST endpoints with OpenAPI/Swagger
- Database: PostgreSQL with JPA/Hibernate ORM
- Containerized: Docker support for easy deployment
- CI/CD: GitHub Actions workflows for automated testing and deployment
-
Java 21 (OpenJDK or Oracle JDK)
-
Yarn 4.9.2+ for frontend package management
-
PostgreSQL 12+
-
Docker (optional, for containerized deployment)
- Spring Boot 3.5.0 - Application framework
- Java 21 - Programming language
- LangChain4j - LLM integration and AI workflows
- PostgreSQL - Primary database
- HikariCP - Database connection pooling
- SpringDoc OpenAPI - API documentation
- Maven - Dependency management and build tool
- React 19 - UI framework
- TypeScript - Type-safe JavaScript
- Vite - Build tool and development server
- Ant Design - UI component library
- Tailwind CSS - Utility-first CSS framework
- React Router - Client-side routing
- Zustand - State management
- React Markdown - Markdown rendering with syntax highlighting
chatbot4j/
βββ src/main/java/dev/chatbot/ # Java backend source
β βββ aiservice/ # AI service integrations
β βββ config/ # Spring configuration
β βββ controller/ # REST API controllers
β βββ domain/ # JPA entities
β βββ dto/ # Data transfer objects
β βββ repository/ # Data access layer
β βββ service/ # Business logic
β βββ ChatBotApplication.java # Main application class
βββ src/main/resources/
β βββ application.yaml # Application configuration
β βββ static/ # Built frontend assets
βββ web/ # React frontend source
β βββ src/
β β βββ components/ # Reusable UI components
β β βββ routes/ # Page components
β β βββ store/ # State management
β β βββ utils/ # Utility functions
β β βββ assets/ # Static assets
β βββ package.json # Node.js dependencies
β βββ vite.config.ts # Vite configuration
βββ Dockerfile # Multi-stage Docker build
βββ Makefile # Build automation
βββ pom.xml # Maven configuration
git clone https://github.com/weekenthralling/chatbot4j.git
cd chatbot4jCreate a PostgreSQL database:
CREATE DATABASE chatbot4j;
CREATE USER chatbot WITH PASSWORD 'chatbot';
GRANT ALL PRIVILEGES ON DATABASE chatbot4j TO chatbot;Create environment variables or modify src/main/resources/application.yaml:
# Required Environment Variables
DB_URL=jdbc:postgresql://localhost:5432/chatbot4j
DB_USERNAME=chatbot
DB_PASSWORD=chatbot
LLM_API_KEY=your-openai-api-key
LLM_BASE_URL=https://api.openai.com/v1/
LLM_MODEL=gpt-4o-mini
TAVILY_API_KEY=your-tavily-api-key # Optional, for web searchUsing Make (recommended):
# Build the entire application
make build
# Run linting
make lint
# Format code
make format
# Run tests
make testOr manually:
# Build and run backend
mvn clean package
java -jar target/chatbot4j-*.jar
# In another terminal, build and serve frontend
cd web
yarn install
yarn build
yarn dev- Frontend: http://localhost:7000
- Backend API: http://localhost:8080
- API Documentation: http://localhost:8080/swagger-ui.html
# Build the Docker image
docker build -t chatbot4j .
# Run with docker-compose (recommended)
docker-compose up -dThe Dockerfile uses a multi-stage build process:
- Frontend Build: Node.js Alpine image builds the React application
- Backend Build: OpenJDK 21 image builds the Spring Boot JAR
- Runtime: Lightweight OpenJDK 21 slim image runs the application
docker run -d \
-p 8080:8080 \
-e DB_URL=jdbc:postgresql://your-db-host:5432/chatbot4j \
-e DB_USERNAME=chatbot \
-e DB_PASSWORD=your-password \
-e LLM_API_KEY=your-openai-key \
-e LLM_MODEL=gpt-4o-mini \
chatbot4j# Start the Spring Boot application in development mode
mvn spring-boot:run
# Run tests
mvn test
# Format code using Spotless
mvn spotless:apply
# Check code formatting
mvn spotless:checkcd web
# Install dependencies
yarn install
# Start development server with hot reload
yarn dev
# Build for production
yarn build
# Run linting
yarn lint
# Run tests
yarn testThe project includes several code quality tools:
- Backend: Spotless (Java formatting), Maven compiler warnings
- Frontend: ESLint (linting), Prettier (formatting), TypeScript checking
- CI/CD: GitHub Actions for automated testing and quality checks
The application provides a RESTful API with the following main endpoints:
GET /api/conversations- List user conversations with paginationPOST /api/conversations- Create new conversationGET /api/conversations/{id}- Get conversation details including messagesPUT /api/conversations/{id}- Update conversation (title, pinned status)DELETE /api/conversations/{id}- Delete conversation
POST /api/{conversationId}/assistant- Send message to AI assistant and get streaming response (Server-Sent Events)
GET /api/shares- List user's shared conversations with paginationPOST /api/shares- Share a conversation publiclyGET /api/shares/{id}- Get shared conversation details including messagesDELETE /api/shares/{id}- Unshare/delete a shared conversation
GET /api/users/current- Get current user information
Access the Swagger UI at http://localhost:8080/swagger-ui.html for interactive API testing and detailed endpoint documentation.
Key configuration sections in application.yaml:
chatbot:
llm:
base-url: ${LLM_BASE_URL}
model-name: ${LLM_MODEL}
api-key: ${LLM_API_KEY}
temperature: 0.8
max-tokens: 512
embedding:
base-url: ${EMBEDDING_BASE_URL}
tavily:
api-key: ${TAVILY_API_KEY}spring:
datasource:
url: ${DB_URL}
username: ${DB_USERNAME}
password: ${DB_PASSWORD}
jpa:
hibernate:
ddl-auto: update
show-sql: true- Java 21 runtime environment
- PostgreSQL database
- Reverse proxy (nginx/Apache)
- SSL certificates
- Set production profiles:
spring.profiles.active=prod - Configure external database: Use managed PostgreSQL service
- Configure logging: Use structured logging with log aggregation
- Set up monitoring: Application metrics and health checks
- Security hardening: Environment-specific security configurations
The application provides health check endpoints:
GET /actuator/health- Basic health statusGET /actuator/info- Application informationGET /actuator/metrics- Application metrics
# Backend tests
mvn test
# Frontend tests
cd web && yarn test
# All tests via Make
make test- Backend: JUnit 5 with Spring Boot Test
- Frontend: Jest with React Testing Library
- Integration: End-to-end testing planned
Error: release version 21 not supported
Solution: Ensure Java 21 is installed and JAVA_HOME is set correctly
# Check Java version
java -version
javac -version
# Set JAVA_HOME (Linux/macOS)
export JAVA_HOME=/path/to/java21Error: Connection refused or authentication failed Solution:
- Verify PostgreSQL is running
- Check connection parameters in
application.yaml - Ensure database and user exist
Error: Module not found or dependency issues Solution:
cd web
rm -rf node_modules yarn.lock
yarn installError: Port already in use Solution: Change ports in configuration:
- Backend: Modify
server.portinapplication.yaml - Frontend: Change port in
web/vite.config.ts
- Database: Ensure proper indexing on frequently queried columns
- JVM: Tune JVM parameters for production workloads
- Frontend: Enable gzip compression and CDN for static assets
- Fork the repository
- Create a feature branch:
git checkout -b feature/your-feature - Make changes and add tests
- Run linting and tests:
make lint && make test - Commit changes:
git commit -am 'Add some feature' - Push to branch:
git push origin feature/your-feature - Submit a Pull Request
- Backend: Use Spotless formatting (
make format) - Frontend: Follow ESLint and Prettier configurations
- Commits: Use conventional commit messages
- Documentation: Update README for significant changes
This project is licensed under the MIT License - see the LICENSE file for details.
- LangChain4j - Java framework for LLM integration
- Spring Boot - Application framework
- React - Frontend library
- Ant Design - UI component library
- OpenAI - Language model provider
- Tavily - Web search API
For support and questions:
- Create an Issue
- Check existing Discussions
- Review the API Documentation
Built with β€οΈ using Java 21, Spring Boot 3, and React