A comprehensive Order Management System built with Spring Boot and MongoDB for managing customers, products, orders, and suppliers. This RESTful API application provides full CRUD operations for enterprise-level order management.
- Features
- Tech Stack
- Architecture
- Prerequisites
- Installation
- Configuration
- Running the Application
- API Endpoints
- Project Structure
- Testing
- Deployment
- Security
- Contributing
- License
- Customer Management: Create, retrieve, and delete customer records
- Product Management: Manage product inventory with pricing and expiry tracking
- Order Management: Complete order lifecycle management
- Supplier Management: Track and manage supplier information
- RESTful API: Clean and intuitive REST endpoints
- MongoDB Integration: Scalable NoSQL database for data persistence
- DTO Pattern: Data Transfer Objects for clean separation of concerns
- MapStruct: Automatic entity-to-DTO mapping
- Cross-Origin Support: CORS enabled for frontend integration
- Environment Configuration: Secure configuration via environment variables
- Heroku Ready: Configured for easy cloud deployment
- Java 21 - Programming language
- Spring Boot 3.5.8 - Application framework
- Spring Web - RESTful web services
- Spring Data MongoDB - MongoDB integration
- Maven - Build automation and dependency management
- MongoDB - NoSQL database
- Lombok 1.18.42 - Reduce boilerplate code
- MapStruct 1.5.5 - Type-safe bean mapping
- Spring Dotenv 4.0.0 - Environment variable management
This application follows a layered architecture pattern:
┌─────────────────┐
│ Controllers │ ← REST endpoints
├─────────────────┤
│ Services │ ← Business logic
├─────────────────┤
│ Repositories │ ← Data access layer
├─────────────────┤
│ Entities │ ← MongoDB documents
└─────────────────┘
Design Patterns Used:
- Repository Pattern
- Data Transfer Object (DTO) Pattern
- Dependency Injection
- Service Layer Pattern
Before running this application, ensure you have:
- JDK 21 or higher
- Maven 3.8+
- MongoDB Atlas account (or local MongoDB instance)
- Git (for cloning the repository)
- Clone the repository:
git clone https://github.com/yourusername/OrderManagementSystem.git
cd OrderManagementSystem- Create a
.envfile in the project root:
touch .env- Add the following environment variables to
.env:
MONGODB_URI=mongodb+srv://username:password@cluster.mongodb.net/yourdbname?retryWrites=true&w=majority
PORT=8080Note: Replace
username,password,cluster, andyourdbnamewith your actual MongoDB credentials.
The application uses environment variables for configuration defined in application.yml:
| Variable | Description | Default | Required |
|---|---|---|---|
MONGODB_URI |
MongoDB connection string | - | ✅ Yes |
PORT |
Application server port | 8080 | ❌ No |
Linux/macOS:
export MONGODB_URI="mongodb+srv://username:password@cluster.mongodb.net/oms_db"
export PORT=8080Windows (CMD):
set MONGODB_URI=mongodb+srv://username:password@cluster.mongodb.net/oms_db
set PORT=8080Windows (PowerShell):
$env:MONGODB_URI="mongodb+srv://username:password@cluster.mongodb.net/oms_db"
$env:PORT=8080# Clean and build the project
mvn clean install
# Run the application
mvn spring-boot:run# Package the application
mvn clean package
# Run the JAR file
java -jar target/org.craftigen-1.0-SNAPSHOT.jar- Import the project as a Maven project
- Configure Project SDK to JDK 21
- Set environment variables in Run Configuration:
- Edit Configurations → Environment Variables
- Add
MONGODB_URIandPORT
- Run
Main.java
The application will start at: http://localhost:8080
Base URL: http://localhost:8080
| Method | Endpoint | Description | Request Body |
|---|---|---|---|
GET |
/customer/get-customer |
Retrieve all customers | - |
POST |
/customer/add-customer |
Add a new customer | CustomerDTO |
DELETE |
/customer/remove-customer/{id} |
Delete a customer by ID | - |
CustomerDTO Structure:
{
"id": "string",
"firstName": "string",
"lastName": "string",
"phoneNumber": "string",
"city": "string"
}| Method | Endpoint | Description | Request Body |
|---|---|---|---|
GET |
/product/get-product |
Retrieve all products | - |
POST |
/product/add-product |
Add a new product | ProductDTO |
DELETE |
/product/remove-product/{id} |
Delete a product by ID | - |
ProductDTO Structure:
{
"id": "string",
"name": "string",
"price": 0.0,
"addedDate": "string",
"expiryDate": "string"
}| Method | Endpoint | Description | Request Body |
|---|---|---|---|
GET |
/orders/get-order |
Retrieve all orders | - |
POST |
/orders/add-order |
Create a new order | OrderDTO |
DELETE |
/orders/remove-order/{id} |
Delete an order by ID | - |
OrderDTO Structure:
{
"id": "string",
"name": "string",
"date": "string",
"qty": 0,
"price": 0.0
}| Method | Endpoint | Description | Request Body |
|---|---|---|---|
GET |
/supplier/get-supplier |
Retrieve all suppliers | - |
POST |
/supplier/add-supplier |
Register a new supplier | SupplierDTO |
DELETE |
/supplier/remove-customer/{id} |
Delete a supplier by ID | - |
SupplierDTO Structure:
{
"id": "string",
"firstName": "string",
"lastName": "string",
"email": "string",
"contact": "string",
"company": "string",
"registeredDate": "string"
}OrderManagementSystem/
├── src/
│ ├── main/
│ │ ├── java/
│ │ │ └── org/
│ │ │ └── craftigen/
│ │ │ ├── Main.java # Application entry point
│ │ │ ├── controller/ # REST controllers
│ │ │ │ ├── CustomerController.java
│ │ │ │ ├── OrderController.java
│ │ │ │ ├── ProductController.java
│ │ │ │ └── SupplierController.java
│ │ │ ├── dtos/ # Data Transfer Objects
│ │ │ │ ├── CustomerDTO.java
│ │ │ │ ├── OrderDTO.java
│ │ │ │ ├── ProductDTO.java
│ │ │ │ └── SupplierDTO.java
│ │ │ ├── entity/ # MongoDB entities
│ │ │ │ ├── Customer.java
│ │ │ │ ├── Order.java
│ │ │ │ ├── Product.java
│ │ │ │ └── Supplier.java
│ │ │ ├── mapper/ # MapStruct mappers
│ │ │ │ ├── CustomerMapper.java
│ │ │ │ ├── OrderMapper.java
│ │ │ │ ├── ProductMapper.java
│ │ │ │ └── SupplierMapper.java
│ │ │ ├── repository/ # MongoDB repositories
│ │ │ │ ├── CustomerRepository.java
│ │ │ │ ├── OrderRepository.java
│ │ │ │ ├── ProductRepository.java
│ │ │ │ └── SupplierRepository.java
│ │ │ └── service/ # Business logic
│ │ │ ├── CustomerService.java
│ │ │ ├── OrderService.java
│ │ │ ├── ProductService.java
│ │ │ ├── SupplierService.java
│ │ │ └── impl/ # Service implementations
│ │ └── resources/
│ │ └── application.yml # Application configuration
│ └── test/
│ └── java/ # Test files
├── target/ # Build output
├── .env # Environment variables (gitignored)
├── .gitignore # Git ignore rules
├── Procfile # Heroku deployment config
├── system.properties # Java version for Heroku
├── pom.xml # Maven configuration
└── README.md # This file
Run all tests:
mvn testRun tests with coverage:
mvn clean test jacoco:reportRun specific test class:
mvn test -Dtest=YourTestClassNameThis application is pre-configured for Heroku deployment with Procfile and system.properties.
- Create a Heroku app:
heroku create your-app-name- Set environment variables:
heroku config:set MONGODB_URI="your-mongodb-connection-string"- Deploy:
git push heroku main- Open the application:
heroku openCreate a Dockerfile:
FROM openjdk:21-jdk-slim
WORKDIR /app
COPY target/org.craftigen-1.0-SNAPSHOT.jar app.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "app.jar"]Build and run:
# Build Docker image
docker build -t order-management-system .
# Run container
docker run -p 8080:8080 \
-e MONGODB_URI="your-connection-string" \
order-management-systemThe packaged JAR file can be deployed to any cloud platform that supports Java applications. Ensure environment variables are configured in the respective platform's configuration.
- Spring Security for authentication/authorization
- JWT tokens for stateless authentication
- Role-based access control (RBAC)
- API rate limiting
- Input validation and sanitization
- ✅ Never commit
.envfiles or secrets to version control - ✅ Use environment variables for all sensitive data
- ✅ Rotate MongoDB credentials regularly
- ✅ Enable MongoDB network access controls
- ✅ Use HTTPS in production
- ✅ Implement proper error handling without exposing sensitive information
- ✅ Keep dependencies up to date
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch:
git checkout -b feature/AmazingFeature
- Commit your changes:
git commit -m 'Add some AmazingFeature' - Push to the branch:
git push origin feature/AmazingFeature
- Open a Pull Request
- Follow Java naming conventions
- Use Lombok annotations to reduce boilerplate
- Write meaningful commit messages
- Add comments for complex logic
- Ensure all tests pass before submitting PR
This project is open source and available under the MIT License.
Pramuditha Lakshan
- GitHub: @Pramudithalakshan
- Spring Boot Team for the excellent framework
- MongoDB for the flexible NoSQL database
- MapStruct for simplified object mapping
- Lombok for reducing boilerplate code
If you encounter any issues or have questions:
- 🐛 Open an issue
- 📧 Contact the maintainer
- 📖 Check the Spring Boot Documentation
Made with ❤️ using Spring Boot and MongoDB