Overview
DriveX is built on a modern Spring Boot architecture with a RESTful API design. The system follows a layered architecture pattern with clear separation of concerns across controllers, services, and data models.Technology Stack
Framework
Spring Boot - Core application framework with dependency injection and auto-configuration
Database
MySQL with JPA/Hibernate for object-relational mapping
Security
BCrypt password encoding for secure authentication
API Design
REST principles with JSON request/response format
Architectural Layers
Controller Layer
The controller layer handles HTTP requests and responses using Spring’s@RestController annotation. Controllers are responsible for:
- Request validation and mapping
- Delegating business logic to services
- Returning appropriate HTTP status codes
- CORS configuration for cross-origin requests
All controllers use
@CrossOrigin(origins = "*") to enable CORS support for frontend applications.Service Layer
The service layer contains the business logic and orchestrates data operations. Services interact with JPA repositories to perform CRUD operations and implement domain-specific workflows. Key responsibilities:- User authentication and registration
- Vehicle management and search
- Rental booking and status management
- Data validation and business rules
Data Access Layer
The data access layer uses Spring Data JPA to interact with the MySQL database. Entity classes are annotated with JPA annotations to define:- Table mappings (
@Entity,@Table) - Primary keys (
@Id,@GeneratedValue) - Relationships (
@OneToMany,@ManyToOne) - Column constraints and configurations
Security Configuration
DriveX implements password encryption using BCrypt through Spring Security:BCrypt is a one-way hashing algorithm designed specifically for password storage. It includes a salt to protect against rainbow table attacks.
Design Patterns
Dependency Injection
All components use constructor-based dependency injection for better testability and immutability:Repository Pattern
Spring Data JPA repositories provide an abstraction layer over database operations, eliminating boilerplate code.Entity Lifecycle Callbacks
Automatic timestamp management using JPA callbacks:Data Flow
- Client sends HTTP request to REST endpoint
- Controller receives and validates the request
- Service executes business logic
- Repository performs database operations via JPA
- Database stores and retrieves data
- Response flows back through the layers
API Response Patterns
The API uses standard HTTP status codes:- 200 OK - Successful request with data
- 401 Unauthorized - Authentication failed
- 409 Conflict - Resource already exists (e.g., duplicate email)
- 404 Not Found - Resource not found
Database Strategy
- ID Generation:
IDENTITYstrategy for auto-incrementing primary keys - Naming Convention: Snake_case for database columns, camelCase in Java code
- Cascading: Parent entities cascade operations to child entities (e.g., Vehicle → VehicleImage)
- Orphan Removal: Enabled on one-to-many relationships to maintain referential integrity