A full-stack, open-source chatbot application that combines the power of Spring AI (backend) with React (frontend) to deliver intelligent chat completions and AI-powered image generation in a seamless, user-friendly experience.
This project demonstrates a modern full-stack architecture for building AI-powered applications. It serves as:
- A learning resource for developers interested in integrating OpenAI APIs with Spring Boot and React
- A production-ready foundation for building custom chatbot applications
- A best-practices example for handling user API credentials securely on the client side (localstorage)
- A template for extending with additional AI features and integrations
- Real-time conversational UI with smooth message streaming
- Multi-session history that persists across browser sessions using localStorage
- Responsive sidebar with conversation switching and management
- Built with React and optimized for all screen sizes
- DALLΒ·E 3 integration for high-quality AI image generation
- Dedicated image tab with preview and download capabilities
- History tracking of generated images within your session
- Client-side API key storage in localStorage (never sent to backend unless needed)
- Modal-based configuration for easy setup and key management
- User control over credentials without server-side storage
- Spring AI integration for OpenAI chat completions and image generation
- REST API endpoints with proper error handling and validation
- CORS configuration for secure frontend-backend communication
- Docker support for containerized deployment
Before getting started, ensure you have the following installed:
- Node.js β₯ 20.x
- Maven β₯ 3.9
- JDK 21 or later
- OpenAI API key with access to:
- GPT-4o model (for chat completions)
- DALLΒ·E-3 model (for image generation)
git clone https://github.com/shihabhasan0161/react-spring-chatbot.git
cd react-spring-chatbotBackend Configuration - Edit backend/src/main/resources/application.properties:
# OpenAI Model Configuration
spring.ai.openai.chat.options.model=gpt-4o
spring.ai.openai.api-key=
# Note: Leave the API key empty here - it will be passed at runtime from the frontendFrontend Configuration - Create frontend/.env:
VITE_BACKEND_URL=http://localhost:8080/
cd backend
mvn spring-boot:runThe Spring Boot server will start on http://localhost:8080.
In a new terminal window:
cd frontend
npm install
npm run devThe React development server will start on http://localhost:5173.
- Open your browser to
http://localhost:5173 - Click the "Set API Key" button in the top-right corner
- Enter your OpenAI API key
- Start chatting or generating images!
| Layer | Technology | Responsibility |
|---|---|---|
| Frontend | React + Vite | User interface, conversation management, local persistence, API key handling |
| Gateway | Axios HTTP Client | Routing requests from frontend to backend API endpoints |
| Backend | Spring Boot + Spring AI | OpenAI integration, chat completion orchestration, image generation |
User Input (Frontend)
β
React Chat Component
β
Axios HTTP Request β Backend REST API
β
Spring AI Service Layer
β
OpenAI API (with user's API key)
β
Response β React Component
β
Browser LocalStorage (for persistence)
POST /api/chat
Request payload:
{
"prompt": "What is machine learning?",
"apiKey": "sk-..."
}Response:
{
"response": "Machine learning is...",
"timestamp": "2025-11-17T10:30:00Z"
}POST /api/generate-image
Request payload:
{
"prompt": "A futuristic city at sunset",
"apiKey": "sk-..."
}Response:
{
"imageUrl": "https://...",
"timestamp": "2025-11-17T10:30:00Z"
}react-spring-chatbot/
βββ backend/ # Spring Boot application
β βββ src/main/java/com/chatbot/
β β βββ controller/ # REST API controllers
β β βββ service/ # Business logic layer
β β βββ model/ # Data models
β β βββ config/ # Configuration classes
β βββ pom.xml # Maven dependencies
β βββ Dockerfile # Container configuration
β
βββ frontend/ # React application
β βββ src/
β β βββ components/ # React components
β β βββ utils/ # Helper functions
β β βββ App.jsx # Main app component
β β βββ main.jsx # Entry point
β βββ package.json # NPM dependencies
β βββ vite.config.js # Vite configuration
β
βββ README.md # This file
βββ LEARN.md # Deep dive into architecture
βββ CONTRIBUTING.md # Contribution guidelines
βββ LICENSE.md # MIT License
- LEARN.md β Detailed architectural documentation, design patterns, and extension ideas
- CONTRIBUTING.md β Guidelines for contributing, development workflow, and code standards
This project is licensed under the MIT License - see the LICENSE.md file for details.
Feel free to use this project for learning, development, and as a foundation for your own applications.
- Check LEARN.md for architectural deep-dives
- Review CONTRIBUTING.md for development setup
- Open an issue on GitHub for bugs or feature requests
- Refer to the official Spring AI documentation
Happy coding! π
