LLD5
LLD5
---
---
---
```plaintext
+-------------------+ +-------------------+ +-------------------+
| UserController | | UserService | | UserRepository |
+-------------------+ +-------------------+ +-------------------+
| + createUser() |<------>| + createUser() |<------>| + saveUser() |
| + getUserById() | | + getUserById() | | + findById() |
| + updateUser() | | + updateUser() | | + update() |
| + deleteUser() | | + deleteUser() | | + deleteById() |
+-------------------+ +-------------------+ +-------------------+
```
**Explanation:**
- `UserController`: Handles HTTP requests and responses.
- `UserService`: Contains business logic for user-related operations.
- `UserRepository`: Interfaces with the database for CRUD operations.
---
```sql
CREATE TABLE users (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(50) NOT NULL UNIQUE,
email VARCHAR(100) NOT NULL UNIQUE,
password_hash VARCHAR(255) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE
CURRENT_TIMESTAMP
);
```
**Indexes:**
- Unique index on `username` and `email` for faster lookups.
---
---
**Example Code:**
```java
import org.springframework.security.crypto.bcrypt.BCrypt;
---
---
**Example:**
```java
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
---
class UserServiceTest {
@Test
void testCreateUser() {
UserService userService = new UserService();
User user = new User("john_doe", "john@example.com", "secure123");
User savedUser = userService.createUser(user);
assertNotNull(savedUser.getId());
assertEquals("john_doe", savedUser.getUsername());
}
}
```
---
---
---
This single-page LLD provides a comprehensive overview of the design and implementation
details for the specified feature/module. It ensures clarity for developers and stakeholders
while maintaining technical precision.