This project describes a comprehensive chat application that integrates a Spring Boot backend, a React frontend, a PostgreSQL database, and the Ollama AI service, all orchestrated with Docker Compose.
Before setting up the Chat App, ensure you have the following installed:
- Docker and Docker Compose: For containerization and service management.
- Maven: For building the Spring Boot backend.
- JDK 21: For compiling and running the Java Spring Boot backend.
- Node.js: For frontend development tasks (e.g.,
npm install,npm startoutside Docker).
Follow these steps to get your Chat App running:
-
Build and Package Backend: Whenever you modify the Spring Boot backend code, execute the following command to build and package it:
mvn clean package
-
Start Services: Navigate to the project root directory (where
docker-compose.ymlis located) and run:docker-compose up --build
This command will build and start all services:
- Backend: Accessible on port
8080(Spring Boot, JDK 21). - Frontend: Accessible on port
3000(Node.js, React). - Ollama AI Service: Accessible on port
11434. - PostgreSQL Database: Accessible on port
5432.
- Backend: Accessible on port
-
Apply Backend Changes: After rebuilding your Spring Boot backend with Maven, rebuild and restart only the backend container to apply the updates:
docker-compose build backend docker-compose up -d backend
-
Apply Frontend Changes: If you make changes to the Node.js/React frontend code, you'll need to rebuild and restart its container to see the updates:
docker-compose build frontend docker-compose up -d frontend
Configure the following environment variables for proper service operation:
- Backend (Spring Boot):
SPRING_DATASOURCE_URL: JDBC URL for PostgreSQL database connection.SPRING_DATASOURCE_USERNAME: Username for database authentication.SPRING_DATASOURCE_PASSWORD: Password for database authentication.
- Frontend (Node.js/React):
REACT_APP_BACKEND_URL: The URL of the backend service.
Data persistence is managed through Docker volumes:
ollama-data: Ensures persistence of Ollama AI service data.postgres-data: Persists PostgreSQL database data.- Database initialization is handled by the
./user-manager-database/init.sqlscript.
All services communicate over a dedicated Docker bridge network named app-network.
The following ports are exposed by the services:
| Service | Port |
|---|---|
| Backend | 8080 |
| Frontend | 3000 |
| Ollama | 11434 |
| Database | 5432 |
- Ensure that ports
8080,3000,11434, and5432are not in use by other applications before starting the services. - To stop and remove all containers, networks, and volumes defined in
docker-compose.yml, usedocker-compose down. - For any code changes in the frontend (Node.js/React) or backend (Spring Boot/JDK 21), remember to rebuild their respective Docker images and restart their containers to apply the updates.