__..._ |
..-' o. .'|'.
.-' : /.'|\ \
_..' .'__..--< | /|'.|
...--"" '-. \ |\/
..-" __.' \|/
.' ___...--' `
: ____....---'
: .'
: : _____
: : _..--""" """--..__
: : ." ""i--.
: '.: : '.
: '--...___i---""""--..___.' :
: ""---...---"" :
'. :
'-. :
'--... .'
: ""---....._____.....---""
'. '.
'-.. '.
'. :
: .'
/ :
.' :
.' .--'
'--'
- Description
- Features
- Prerequisites
- Quick Start
- API Documentation
- Configuration
- Usage
- Development
- Project Structure
- Testing
- Troubleshooting
- Contributing
- License
- Author
Spring Snake is a comprehensive key-value store system that combines a Spring Boot REST API backend with MongoDB storage and an interactive Python CLI client. This project demonstrates modern software architecture principles including containerization, comprehensive error handling, input validation, and user-friendly interfaces.
- REST API: Complete CRUD operations for key-value pairs
- MongoDB Integration: Persistent data storage with timestamps
- Docker Multi-stage Build: Optimized container images with SHA256 hashes
- Health Checks: Built-in actuator endpoints for monitoring
- Comprehensive Error Handling: Proper HTTP status codes and error messages
- Input Validation: Bean validation with detailed error responses
- Logging: Structured logging for debugging and monitoring
- Interactive Menu System: User-friendly command-line interface
- Enhanced Error Handling: Graceful error recovery and user feedback
- Input Validation: Comprehensive validation with helpful error messages
- Debug Mode: Optional detailed logging with
--debugflag - Export Capabilities: Save data to JSON, CSV, and TXT formats
- Keyboard Interrupt Handling: Graceful exit with Ctrl+C
- Docker & Docker Compose
- Python 3.13+ (for CLI client)
- curl or similar HTTP client (for manual API testing)
# Clone the repository
git clone https://github.com/M04ph3u2/Spring-Snake.git
cd Spring-Snake
# Run setup script (creates Python env, builds containers, starts services)
./setup.sh
# Verify everything is working
./verify.sh# Build and start all services with Docker Compose
docker compose up -d
# Check service health
curl http://localhost:8080/actuator/health# Navigate to Python directory
cd Python
# Create virtual environment
python3 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt# Normal operation (clean interface)
python main.py
# Debug mode (detailed logging)
python main.py --debugThe CLI provides:
- Save Operation: Store single or multiple key-value pairs
- Get Operation: Retrieve values by key or get all data
- Delete Operation: Remove specific keys or all data
- Export Functions: Save data to JSON, CSV, or text files
The Spring Boot backend exposes the following REST API endpoints:
GET /api/get?key={key}- Get value by key (value only)GET /api/getfull?key={key}- Get complete object with metadataGET /api/getall- Get all key-value pairs
PUT /api/put- Create new key-value pair (fails if key exists)PUT /api/putall- Create multiple key-value pairs (batch operation)POST /api/update- Update existing key-value pair
DELETE /api/delete?key={key}- Delete specific key-value pairDELETE /api/deleteall- Delete all data (use with caution)
GET /actuator/health- Application health checkGET /actuator/info- Application information
# Save a value
curl -X PUT "http://localhost:8080/api/put" \
-H "Content-Type: application/json" \
-d '{"key":"username","value":"john_doe"}'
# Get a value
curl -X GET "http://localhost:8080/api/get?key=username"
# Get full object with metadata
curl -X GET "http://localhost:8080/api/getfull?key=username"
# Update a value
curl -X POST "http://localhost:8080/api/update" \
-H "Content-Type: application/json" \
-d '{"key":"username","value":"jane_doe"}'
# Delete a value
curl -X DELETE "http://localhost:8080/api/delete?key=username"The application uses environment variables for configuration:
MONGO_USERNAME: MongoDB username (default: springsnake)MONGO_PASSWORD: MongoDB password (default: defaultpassword)MONGO_DATABASE: Database name (default: springsnake_db)SPRING_PORT: Application port (default: 8080)SPRING_PROFILE: Spring profile (default: docker)
The application includes health checks for both services:
- MongoDB: Available at
mongodb:27017 - Spring Boot: Available at
http://localhost:8080/actuator/health
# Save multiple values at once
curl -X PUT "http://localhost:8080/api/putall" \
-H "Content-Type: application/json" \
-d '[
{"key":"user1","value":"john"},
{"key":"user2","value":"jane"}
]'
# Get all values
curl -X GET "http://localhost:8080/api/getall"
# Delete all values (caution!)
curl -X DELETE "http://localhost:8080/api/deleteall"The Python CLI client provides an interactive menu for seamless interaction with the Spring Boot backend:
- Save Operation: Store single or multiple key-value pairs with validation
- Get Operation: Retrieve specific values by key or export all data to files
- Delete Operation: Remove specific keys or clear the entire database
- Export Functions: Save retrieved data to JSON, CSV, or text formats
# Start the interactive CLI (normal mode)
python main.py
# Start with debug logging enabled
python main.py --debug
# The CLI will guide you through available operationsThe project includes utility scripts for development:
setup.sh: Quick project setup - creates Python environment, builds Docker containers, and starts all servicesverify.sh: System health check - verifies all services are running and APIs are responsivecompose.yaml: Docker Compose configuration for all services
# Initial setup
./setup.sh
# Verify system health
./verify.sh
# Development cycle
docker compose logs -f api # Monitor backend logs
# Cleanup (if needed)
docker compose down -v # Stop and remove all containers and volumesSpring-Snake/
├── Python/ # Python CLI client
│ ├── venv/ # Virtual environment (auto-generated)
│ ├── requirements.txt # Python dependencies
│ ├── main.py # Main CLI application with debug support
│ ├── helper.py # Utility functions and data structures
│ ├── requester.py # HTTP client for API communication
├── SpringBoot/ # Spring Boot backend
│ ├── src/main/java/ # Java source code
│ │ └── com/springsnake/backend/
│ │ ├── BackendApplication.java # Main Spring Boot application
│ │ ├── ValueController.java # REST API controller
│ │ ├── ValueService.java # Business logic service
│ │ ├── values.java # Entity model
│ │ └── utils/ # Data transfer objects
│ ├── Dockerfile # Multi-stage Docker build
│ └── pom.xml # Maven dependencies
├── setup.sh # Automated project setup script
├── verify.sh # System verification script
├── compose.yaml # Docker Compose configuration
├── README.md # This file
└── SpringSnake_APIs_Tests.postman_collection.json # Postman API tests
Use the provided Postman collection (SpringSnake_APIs_Tests.postman_collection.json) for comprehensive API testing, or test endpoints manually:
The updated Postman collection includes:
- 18 comprehensive test scenarios: Complete coverage of all API endpoints
- Complete endpoint coverage: All 9 API endpoints with proper HTTP methods
- Comprehensive test scenarios: Success cases, error handling, and edge cases
- Automated verification: Response validation and follow-up tests
- Clean variables: Simplified BASE_URL and test data management
- Error testing: Non-existent keys, duplicate keys, validation errors, malformed JSON, and missing headers
- Bean validation testing: Empty key validation, null value validation with proper Spring Boot error parsing
To use the collection:
- Import
SpringSnake_APIs_Tests.postman_collection.jsoninto Postman - Ensure your Spring Snake system is running (
./setup.sh) - Run the entire collection or individual requests
- All tests should pass if the system is working correctly
# Test all endpoints
curl http://localhost:8080/actuator/health
curl -X GET "http://localhost:8080/api/getall"
curl -X PUT "http://localhost:8080/api/put" -H "Content-Type: application/json" -d '{"key":"test","value":"hello"}'
curl -X GET "http://localhost:8080/api/get?key=test"
curl -X DELETE "http://localhost:8080/api/delete?key=test"# Test normal operation
cd Python && python main.py
# Test with debug logging
cd Python && python main.py --debug- Port already in use: Ensure ports 8080 and 27017 are available
- Docker build fails: Run
docker compose build --no-cache - Python dependencies: Ensure you're using Python 3.13+ and have activated the virtual environment
- Connection refused: Wait for services to fully start (check with
docker compose ps)
# View backend logs
docker logs spring-snake-spring-1
# View MongoDB logs
docker logs spring-snake-mongodb-1
# View all service logs
docker compose logs -fThis project demonstrates modern software development practices including:
- Containerized microservices architecture
- Comprehensive error handling and input validation
- User-friendly interfaces with proper feedback
- Structured logging and monitoring
- Reproducible builds and deployment
- Environment variables are used instead of hardcoded credentials
- The
.envfile is excluded from version control - CORS is configured for development (configure properly for production)
- Input validation is implemented on API endpoints
This project is licensed under the MIT License - see the LICENSE file for details.
M04ph3u2 - GitHub Profile
Project Repository: Spring-Snake