KhangTranMinh / KSurvey

1 stars 0 forks source link

KSurvey

Architecture

This project follow CLean Architecture.

The project contains 3 modules:

  1. Domain

    • This module contains business logic models of the application
    • This module define the Repository interfaces, then the higher modules can implement these interfaces
    • It also define Use Cases that handle business logic of the application using Repository interfaces
  2. Data

    • This module contains Repository implementations
    • This module contains Android components (such as Network, Data Soures..) that can be used in Repository implementation
  3. Presentation

    • This module handles UI parts of the application
    • This module follows MVVM pattern

The project use Hilt for Dependency Injection

Libraries used

The application uses following external libraries:

  1. Coil: to load image from remote
  2. Retrofit: to handle HTTP requests
  3. Room: to handle CRUD actions
  4. Lottie: to display animation

Implementation

1. UI

The application has 4 screens:

  1. Splash screen

    • To display a welcome screen to user
    • To verify user's status, then navigate user to Home screen or Login screen
  2. Login screen

    • To display input fields and Login button
    • This screen calls APIs to login and fetch user's info (includes tokens), then save to local storage
  3. Home screen

    • To display user's info
    • To display surveys page by page
    • User can logout using the left menu
    • User can navigate to Thank you screen by clicking on button Take This Survey
  4. Thank you screen

    • To display an animation
    • This page will finish in 5 seconds and back to the Home screen

2. Details implementation

2.1. Storage of access tokens securely

The implementation can be found at .data.security.CryptoUtil

2.2. Automatic usage of refresh tokens

  1. When the application launches, it checks if there are any valid Access Token (the token must be non-empty and not expires - by checking createdAt and expiresIn).
  2. If NO, navigate users to Login screen.
  3. If YES, the application check if the Access Token will expire soon.
  4. If NO, navigate users to Home screen.
  5. If YES, the application calls API to refresh the new Access Token (using refreshToken). Then the application save the new Access Token and Refresh Token into local storage (need to encrypt before saving). Then navigate users to Home Screen

The implementation can be found at .domain.usecase.UserUseCase#validateUserToken

2.3. Caching of surveys

To display the surveys when there is no network connection

The implementation can be found at .data.repository.SurveyRepositoryImpl.getSurveys

2.4. Pull-to-refresh

The implementation can be found at .data.repository.SurveyRepositoryImpl.getSurveys

3. Unit Test

The project includes Unit Test for module Data (locate at data/src/test)

The Unit Test is done with JUnit, Mockito, Mockk

  1. LoginApiTest
  2. LogoutApiTest
  3. RefershTokenApiTest
  4. FetchProfileApiTest
  5. FetchSurveysApiTest
  6. FetchUserDetailsApiTest
  7. RoomUserStoreTest
  8. RoomSurveyStoreTest
  9. UserRepositoryImplTest
  10. SurveyRepositoryImplTest

Screen record