A Spring Boot REST API project that provides mathematical operations through RESTful endpoints. This project demonstrates the use of modern Spring Boot features, Swagger documentation, and Docker containerization.
- Java 17
- Spring Boot 3.2.3
- SpringDoc OpenAPI (Swagger) 2.3.0
- Maven
- Docker
- Lombok
- RESTful API endpoints for mathematical operations
- Comprehensive API documentation using Swagger/OpenAPI
- Docker containerization
- Error handling and validation
- Logging using SLF4J with Lombok
- Clean code architecture
src/main/java/com/arjunai/project/
├── ArjunAiProjectApplication.java
├── config/
│ └── SwaggerConfig.java
└── controllers/
└── MathOperationsController.java
- JDK 17 or higher
- Maven 3.6+
- Docker (optional)
# Clone the repository
git clone <repository-url>
cd arjun-ai-project
# Build with Maven
mvn clean packagejava -jar target/arjun-ai-project-1.0.0.jar# Build Docker image
docker build -t arjun-ai-project .
# Run container
docker run -p 8080:8080 arjun-ai-project| Method | URL | Description | Parameters |
|---|---|---|---|
| GET | /api/math/add |
Add two numbers | a, b (double) |
| GET | /api/math/subtract |
Subtract two numbers | a, b (double) |
| GET | /api/math/multiply |
Multiply two numbers | a, b (double) |
| GET | /api/math/divide |
Divide two numbers | a, b (double) |
# Addition
curl "http://localhost:8080/api/math/add?a=5&b=3"
# Response: 8.0
# Subtraction
curl "http://localhost:8080/api/math/subtract?a=10&b=4"
# Response: 6.0
# Multiplication
curl "http://localhost:8080/api/math/multiply?a=6&b=7"
# Response: 42.0
# Division
curl "http://localhost:8080/api/math/divide?a=15&b=3"
# Response: 5.0| Method | URL | Description | Parameters |
|---|---|---|---|
| GET | /api/split/equal |
Split amount equally | amount, people |
| GET | /api/split/with-tip |
Split with tip | amount, people, tipPercentage |
| POST | /api/split/custom |
Split by custom ratios | amount, ratios |
| GET | /api/split/by-items |
Split by items | items, participants |
# Equal split
curl "http://localhost:8080/api/split/equal?amount=100&people=4"
# Response: 25.0
# Split with tip
curl "http://localhost:8080/api/split/with-tip?amount=100&people=4&tipPercentage=15"
# Response: 28.75The API documentation is available through Swagger UI when the application is running:
- Swagger UI: http://localhost:8080/swagger-ui.html
- OpenAPI Specification: http://localhost:8080/v3/api-docs
The API includes comprehensive error handling for:
- Invalid input parameters
- Division by zero
- Invalid number of participants
- Server errors
# Server Configuration
server.port=8080
# Logging Configuration
logging.level.com.arjunai.project=DEBUG
# Swagger Configuration
springdoc.swagger-ui.path=/swagger-ui.html
springdoc.api-docs.path=/v3/api-docs- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Arjun Raju
- GitHub: @arjunraju
For support, please open an issue in the GitHub repository or contact the development team.
This project uses GitHub Actions for CI/CD and deploys to an AWS EC2 Ubuntu instance.
- AWS EC2 Ubuntu instance
- Docker Hub account
- Domain name (optional, for SSL)
Set up the following secrets in your GitHub repository:
DOCKER_HUB_USERNAME
DOCKER_HUB_ACCESS_TOKEN
AWS_HOST
AWS_USERNAME
AWS_SSH_KEY
-
SSH into your EC2 instance:
ssh -i your-key.pem ubuntu@your-ec2-ip
-
Clone the repository:
git clone https://github.com/your-username/arjun-ai-project.git cd arjun-ai-project -
Run the setup script:
chmod +x scripts/setup-ubuntu.sh ./scripts/setup-ubuntu.sh
-
Update Nginx configuration:
sudo nano /etc/nginx/sites-available/arjun-ai-project # Update server_name with your domain -
Set up SSL (if using a domain):
sudo certbot --nginx
The CI/CD pipeline performs the following steps:
- Builds the application with Maven
- Runs tests
- Builds Docker image
- Pushes image to Docker Hub
- Deploys to AWS EC2
The pipeline runs automatically on:
- Push to main branch
- Pull requests to main branch
The application is monitored using:
- Cron job checking container status every 5 minutes
- Automatic container restart on failure
- Nginx as reverse proxy
SSL certificates are managed by Let's Encrypt and auto-renewed by certbot.