This is a comprehensive Bus Reservation System built using Spring Boot Microservices Architecture. The system provides a complete solution for bus booking, user management, authentication, and reservation handling with a distributed architecture that ensures scalability, maintainability, and high availability.
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β API Gateway ββββββ Eureka Server ββββββ Load Balancer β
β (Port: 8080) β β (Port: 8761) β β (Ribbon) β
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β β
β β
βΌ βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Microservices Layer β
βββββββββββββββββββ¬ββββββββββββββββββ¬ββββββββββββββββββ¬ββββββββββ€
β Auth Service β User Service β Bus Service βReservationβ
β (Port: 8081) β (Port: 8082) β (Port: 8083) β Service β
β β β β(Port:8084)β
βββββββββββββββββββ΄ββββββββββββββββββ΄ββββββββββββββββββ΄ββββββββββ
β β β β
βΌ βΌ βΌ βΌ
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββ βββββββββββββββ
β MySQL DB β β MySQL DB β β MySQL DB β β MySQL DB β
β (Auth Data) β β (User Data) β β (Bus Data) β β(Reservation)β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββ βββββββββββββββ
| Component | Technology | Version |
|---|---|---|
| Framework | Spring Boot | 3.2.12 - 3.5.5 |
| Language | Java | 17 |
| Build Tool | Maven | Latest |
| Database | MySQL | 8.0+ |
| Service | Component | Purpose |
|---|---|---|
| API Gateway | Spring Cloud Gateway | Route management, Load balancing |
| Service Discovery | Netflix Eureka | Service registration & discovery |
| Load Balancer | Spring Cloud LoadBalancer | Client-side load balancing |
| Service Communication | OpenFeign | Declarative REST client for inter-service calls |
| Component | Technology | Purpose |
|---|---|---|
| JWT | JJWT Library | Token-based authentication |
| Security | Spring Security | Authentication & authorization |
| Password Encoding | BCrypt | Secure password hashing |
| Component | Technology | Purpose |
|---|---|---|
| ORM | Spring Data JPA | Database operations |
| Validation | Bean Validation | Input validation |
| Repository | Spring Data Repository | Data access patterns |
- Port: 8761
- Purpose: Central service discovery and registration
- Features:
- Service health monitoring
- Load balancing support
- High availability configuration
- Port: 8080
- Purpose: Single entry point for all client requests
- Features:
- Route management
- Load balancing
- Cross-cutting concerns
- Service aggregation
- Port: 8081
- Purpose: User authentication and JWT token management
- Features:
- User registration
- User login
- JWT token generation
- Password encryption
- Port: 8082
- Purpose: User profile and data management
- Features:
- User CRUD operations
- User profile management
- User data validation
- Port: 8083
- Purpose: Bus operations and seat management
- Features:
- Bus CRUD operations
- Route management
- Seat availability
- Search functionality
- Port: 8084
- Purpose: Reservation and booking operations
- Features:
- Seat booking
- Reservation management
- Booking cancellation
- User reservation history
- OpenFeign Integration: Ready for inter-service communication
| Method | Endpoint | Description | Request Body | Response |
|---|---|---|---|---|
POST |
/auth/register |
User registration | User object |
Success message |
POST |
/auth/login |
User authentication | AuthRequest |
AuthResponse (JWT token) |
| Method | Endpoint | Description | Request Body | Response |
|---|---|---|---|---|
POST |
/users |
Create new user | User object |
Created User |
GET |
/users |
Get all users | - | List of User objects |
| Method | Endpoint | Description | Request Body | Response |
|---|---|---|---|---|
POST |
/buses |
Create new bus | Bus object |
Created Bus |
GET |
/buses |
Get all buses | - | List of Bus objects |
GET |
/buses/{id} |
Get bus by ID | - | Bus object |
GET |
/buses/search |
Search buses | Query params | List of Bus objects |
PATCH |
/buses/{id}/seats |
Adjust seat count | Query param delta |
Updated Bus |
| Method | Endpoint | Description | Request Body | Response |
|---|---|---|---|---|
POST |
/reservations |
Book a seat | Reservation object |
Created Reservation |
GET |
/reservations/user/{userId} |
Get user reservations | - | List of Reservation objects |
DELETE |
/reservations/{id} |
Cancel reservation | - | Success message |
GET |
/reservations/test |
Test authentication | - | Authentication status |
- Java 17 or higher
- Maven 3.6+
- MySQL 8.0+
- IDE (IntelliJ IDEA, Eclipse, or VS Code)
-
Clone the Repository
git clone https://github.com/Gantedavamsikrishna/Bus_Reservation.git cd Bus_Reservation -
Database Setup
- Create MySQL databases for each service
- Update
application.propertieswith your database credentials
-
Start Services in Order
# 1. Start Eureka Server cd eureka-server mvn spring-boot:run # 2. Start Auth Service cd ../auth-service mvn spring-boot:run # 3. Start User Service cd ../user-service mvn spring-boot:run # 4. Start Bus Service cd ../bus-service mvn spring-boot:run # 5. Start Reservation Service cd ../reservation-service mvn spring-boot:run # 6. Start API Gateway cd ../api-gateway mvn spring-boot:run
-
Access Services
- Eureka Dashboard: http://localhost:8761
- API Gateway: http://localhost:8080
- Auth Service: http://localhost:8081
- User Service: http://localhost:8082
- Bus Service: http://localhost:8083
- Reservation Service: http://localhost:8084
- User registers/logs in through Auth Service
- Auth Service validates credentials and generates JWT token
- Client includes JWT token in subsequent requests
- Services validate JWT token using shared secret
- Access granted based on token validity
Your system includes OpenFeign for seamless service-to-service communication:
- Declarative HTTP client that simplifies inter-service calls
- Automatic load balancing through Eureka service discovery
- Circuit breaker integration for fault tolerance
- Clean, interface-based approach to REST clients
- Reservation Service has OpenFeign dependency ready
- Not yet configured but can be easily enabled
// 1. Add @EnableFeignClients to main class
@SpringBootApplication
@EnableFeignClients
public class ReservationServiceApplication {
public static void main(String[] args) {
SpringApplication.run(ReservationServiceApplication.class, args);
}
}
// 2. Create Feign Client Interface
@FeignClient(name = "BUS-SERVICE")
public interface BusServiceClient {
@GetMapping("/buses/{id}")
Bus getBusById(@PathVariable("id") Long id);
@PatchMapping("/buses/{id}/seats")
Bus adjustSeats(@PathVariable("id") Long id, @RequestParam("delta") int delta);
}
// 3. Use in Service Layer
@Service
public class ReservationService {
@Autowired
private BusServiceClient busServiceClient;
public Reservation bookSeat(ReservationRequest request) {
// Call Bus Service to check availability
Bus bus = busServiceClient.getBusById(request.getBusId());
// Call Bus Service to adjust seats
busServiceClient.adjustSeats(request.getBusId(), -1);
// Create reservation...
}
}- Automatic Load Balancing: Routes to healthy instances
- Service Discovery: Uses Eureka for service lookup
- Declarative: Clean, readable interface definitions
- Fault Tolerance: Easy integration with circuit breakers
- Type Safety: Compile-time checking of API contracts
- Password encryption using BCrypt
- JWT-based stateless authentication
- Role-based access control (configurable)
- Secure password storage
- Token expiration management
- id: Long
- username: String
- password: String (encrypted)
- email: String
- role: String- id: Long
- busNumber: String
- from: String
- to: String
- travelDate: LocalDate
- totalSeats: Integer
- availableSeats: Integer
- price: BigDecimal- id: Long
- userId: Long
- busId: Long
- seatNumber: Integer
- status: String (BOOKED/CANCELLED)
- bookingDate: LocalDateTimetest-reservation-service.bat- Test reservation endpointstest-user-service.bat- Test user service endpoints
Use Postman or any REST client to test the endpoints:
- Start with registration:
POST /auth/register - Login to get JWT:
POST /auth/login - Use JWT token in Authorization header for protected endpoints
application.properties- Service-specific configurationsapplication.yml- YAML-based configurationspom.xml- Maven dependencies and build configuration
- Database URLs and credentials
- JWT secret keys
- Service ports
- Eureka server URLs
- Stateless services for easy replication
- Load balancer support
- Service discovery for dynamic scaling
- Connection pooling
- Caching strategies
- Asynchronous processing capabilities
- Custom exception classes
- Standardized error responses
- Proper HTTP status codes
- Detailed error logging
- Service resilience
- Fallback mechanisms
- Timeout handling
- Spring Boot Actuator endpoints
- Service health monitoring
- Database connectivity checks
- Structured logging
- Request/response logging
- Error tracking and debugging
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
For support and questions:
- Create an issue in the repository
- Contact the development team
- Check the documentation
Built with β€οΈ using Spring Boot Microservices Architecture