A Spring Boot-based food delivery application that allows customers to order food from restaurants, restaurants to manage their menus and orders, and delivery agents to handle deliveries.
- Implementation:
UserFactoryManager
class - Purpose: Creates different types of users based on their role
- Usage:
// Creates a Customer user User customer = userFactoryManager.createUser(UserRole.CUSTOMER, username, password, email); // Creates a Restaurant user User restaurant = userFactoryManager.createUser(UserRole.RESTAURANT, username, password, email);
- Implementation:
OrderBuilder
class - Purpose: Constructs Order objects with multiple optional parameters
- Usage:
Order order = new OrderBuilder() .setCustomer(customer) .setRestaurant(restaurant) .setOrderItems(orderItems) .setPaymentMethod(paymentMethod) .build();
- Implementation:
OrderProcessingFacade
class - Purpose: Provides a simplified interface to the complex order processing subsystem
- Usage:
// Handles the entire order process in one call orderProcessingFacade.processOrder(customer, restaurant, items, paymentMethod);
- Implementation:
PaymentGatewayAdapter
class - Purpose: Adapts different payment gateway interfaces to a common interface
- Usage:
// Adapts different payment gateways to a common interface PaymentGatewayAdapter adapter = new PaymentGatewayAdapter(paymentGateway); PaymentResult result = adapter.processPayment(order);
UserFactoryManager
: Solely responsible for user creationOrderService
: Focused on order-related operationsPaymentService
: Dedicated to payment processingNotificationService
: Handles only notification management
UserFactory
: Extensible for new user types without modificationRecommendationStrategy
: Interface allowing new recommendation algorithmsPaymentGatewayAdapter
: Extensible for new payment gateways
- User types (Customer, Restaurant, DeliveryAgent) are substitutable
- Recommendation strategies are interchangeable
- Payment methods can be substituted through adapter pattern
RecommendationStrategy
: Focused interface for recommendationsPaymentGateway
: Specific interface for payment processingUserFactory
: Minimal interface for user creation
- Services depend on abstractions (interfaces)
- Controllers depend on service interfaces
- Factory pattern implementation follows DIP
OrderService
: Expert in order processingUserService
: Expert in user managementPaymentService
: Expert in payment processing
UserFactoryManager
: Creates User objectsOrderService
: Creates Order objectsPaymentService
: Creates Payment objects
- Controllers handle HTTP requests and delegate to services
OrderController
: Manages order-related requestsCustomerController
: Handles customer operations
- Services are loosely coupled through interfaces
- Factory pattern reduces coupling in user creation
- Adapter pattern decouples payment gateways
UserFactoryManager
: High cohesion in user creationOrderService
: High cohesion in order operationsPaymentService
: High cohesion in payment processing
- User types polymorphism
- Recommendation strategies polymorphism
- Payment gateway adapter polymorphism
UserFactoryManager
as pure fabrication- Service classes as pure fabrications
- Adapter classes as pure fabrications
- Service layer provides indirection
- Factory pattern provides creation indirection
- Adapter pattern provides external system indirection
- Factory pattern protects user creation variations
- Strategy pattern protects recommendation variations
- Adapter pattern protects payment gateway variations
+----------------+ +----------------+ +----------------+
| User | | Restaurant | | Order |
+----------------+ +----------------+ +----------------+
| -id: Long | | -id: Long | | -id: Long |
| -username: String| | -name: String | | -status: String|
| -password: String| | -address: String| | -totalAmount: Double|
| -email: String | | -phone: String | | -orderDate: Date|
| -role: UserRole| | -isActive: Boolean| | -customer: User|
+----------------+ +----------------+ | -restaurant: Restaurant|
| | | -orderItems: List<OrderItem>|
| | +----------------+
| | |
| | |
v v v
+----------------+ +----------------+ +----------------+
| UserFactory | | MenuItem | | OrderItem |
+----------------+ +----------------+ +----------------+
| +createUser() | | -id: Long | | -id: Long |
+----------------+ | -name: String | | -quantity: Integer|
| -price: Double | | -menuItem: MenuItem|
| -description: String| | -order: Order |
+----------------+ +----------------+
|
|
v
+----------------+
| Payment |
+----------------+
| -id: Long |
| -amount: Double|
| -status: String|
| -order: Order |
+----------------+
Relationships:
- User 1 --- * Order (One user can have many orders)
- Restaurant 1 --- * MenuItem (One restaurant can have many menu items)
- Order 1 --- * OrderItem (One order can have many order items)
- MenuItem 1 --- * OrderItem (One menu item can be in many order items)
- Order 1 --- 1 Payment (One order has one payment)
- Users (customers, restaurant owners, delivery agents, admins)
- Restaurants
- Menu Items
- Orders
- Order Items
- Payments
- Notifications
-
User Management
- Multi-role authentication (Customer, Restaurant, Delivery Agent, Admin)
- Profile management
-
Restaurant Management
- Menu management
- Order processing
- Operating hours
-
Order Processing
- Cart functionality
- Payment processing
- Order tracking
-
Delivery Management
- Order assignment
- Delivery tracking
- Status updates
-
Recommendation System
- Basic filtering (popular items, discounts)
- User-based recommendations
- Spring Boot
- Spring Data JPA
- Thymeleaf
- MySQL
- Maven
- Bootstrap (for UI)
- Clone the repository
- Configure database connection in
application.properties
- Run
mvn spring-boot:run
- Access the application at
http://localhost:8080
src/main/java/com/fooddelivery/
├── config/ # Configuration classes
├── controller/ # MVC controllers
├── model/ # Entity classes
├── repository/ # JPA repositories
├── service/ # Business logic
└── notifications/ # Event handling
- Real-time order tracking
- Advanced analytics
- Mobile application
- Integration with payment gateways
- Enhanced recommendation system