Clean Architecture Example

repository·master·Indexed 19 days ago

https://github.com/carlphilipp/clean-architecture-example

A Java demonstration of Clean Architecture principles featuring implementations for Spring Boot and Vert.x. The project includes a User API and a manual application mode using ManualConfig to wire use cases for creating, finding, and logging in users.

Tokens
935
Snippets
5
Records
6
Agent score
19%

What's inside clean-architecture-example

  1. Run the manual application mode

    master

    The Main class provides a manual entry point to demonstrate the core business logic of the application without a full web server (like Spring or Vert.x). It uses ManualConfig to wire together use cases for user management.

    To use this mode, you must initialize a ManualConfig instance to obtain the necessary use case handlers: createUser(), findUser(), and loginUser().

    // Setup
    var config = new ManualConfig();
    var createUser = config.createUser();
    var findUser = config.findUser();
    var loginUser = config.loginUser();
    
    // Create a user
    var user = User.builder()
        .email("john.doe@gmail.com")
        .password("mypassword")
        .lastName("doe")
        .firstName("john")
        .build();
    var actualCreateUser = createUser.create(user);
    
    // Find a user by id
    var actualFindUser = findUser.findById(actualCreateUser.getId());
    
    // List all users
    var users = findUser.findAllUsers();
    
    // Login
    loginUser.login("john.doe@gmail.com", "mypassword");
  2. Interact with the User API

    master

    The application provides several endpoints to manage users. Note that the base URL is http://localhost:8080.

    #### Create User
    ```http
    POST http://localhost:8080/users
    {
      "email": "test@test.com",
      "password": "mypassword",
      "lastName": "Doe",  
      "firstName": "John"
    }

    Get all users

    GET http://localhost:8080/users

    Get one user

    GET http://localhost:8080/users/0675171368e011e882d5acde48001122

    Login

    GET http://localhost:8080/login?email=test@test.com&password=mypassword
  3. Use ManualConfig to access use cases

    master

    The ManualConfig class acts as a manual dependency injection container for the application's use cases. It provides methods to retrieve specific service handlers:

    • createUser(): Returns a handler to create new users.
    • findUser(): Returns a handler to query users (supports findById and findAllUsers).
    • loginUser(): Returns a handler to perform user authentication via login(email, password).