Skip to content

Saeed-7/swapi

Repository files navigation

StarWars Universe Application

This project is a simple application that displays a list of characters from the Star Wars movie series, with search functionality and the ability to view detailed information for each character. The web service used is the SWAPI, which is implemented in the project through the Retrofit library.

For dependency injection, the Dagger library is utilized, and for building the user interface, Jetpack Compose is fully employed.

The project follows a Clean Architecture approach. Although a simpler MVP or MVVM structure could have been used, I chose to implement Clean Architecture as the overall structure and used MVVM in the presentation layer.

As we know, implementing Clean Architecture highly depends on the project's package structure. In this project, the overall structure is composed of 4 main layers. In Clean Architecture, the structure is built as nested loops where inner loops should be independent of the outer loops, but the reverse is permissible.

1. Core: The core is the innermost layer of the architecture, containing low-level code, tools, base models, and code that does not depend on other layers. This layer usually includes general logic and project-independent code that can be used throughout the project.

2. Data: This layer is responsible for accessing data sources, which may include local databases, network APIs, files, or other types of storage. The Repository Pattern is used in this layer to abstract data sources and provide interfaces for the domain layer. Implementation details, such as using Retrofit or other libraries, are handled here.

3. Domain: This layer contains the business logic of the application and is independent of other layers. It acts as an intermediary between the data and presentation layers. Models used in this layer are simple and independent of external tools. This layer only depends on interfaces in the data layer.

4. Presentation: This layer is concerned with the user interface (UI) and presentation logic. All aspects of data presentation and user interactions are handled here. The MVVM architecture is typically used in this layer, where ViewModels retrieve data from the domain layer and prepare it for display in the View. This layer can include Jetpack Compose components, Activities, Fragments, or Views. In this project, only Jetpack Compose along with a single Activity in a Single-Activity Architecture is used.

Core:

In the core package, the following sub-packages are included: constants, di, logging, src, and utils. Additionally, the main Application class of the project resides in this package.

  • constants: The UrlConstants class holds the baseUrl and endpoint values for the web service, while the RouteConstants class contains values related to navigation between pages. Enums, such as ApiStatus, used to control the status of the web service connection, are also placed here.

  • di: All dependency injection configurations, including modules, qualifiers, and the ApplicationComponent interface, are placed here.

  • logging: A file for error logging is included in this package.

  • utils: Utilities like the hasNetwork method to check internet connectivity and the AppResult class for managing web service response statuses are provided here.

  • src: This package contains the resources for the app. All fixed texts, colors, sizes, and drawables used in the project are included in classes within this package. For example, the Texts class is created for cleaner code, where each string is filled from the corresponding entry in strings.xml. To support multilingual functionality, values are converted to the corresponding methods to be assigned at runtime. These are considered dependencies and injected into required classes via Dagger.

Data and Domain:

In this package, we have sub-packages like api, model, mapper, and repository.

  • api: As the name suggests, this package contains interfaces for the web services required by Retrofit. These interfaces are defined in a module named ApiModule for dependency injection, which is located in the core/di/modules directory.

  • model: This package contains data classes that represent the responses from the web service and are used to map them to objects.

  • mapper: These are the classes responsible for converting the models between the data and domain layers.

  • repository: These classes contain the necessary code to fetch data from the web service. The structure of the methods in these classes is defined by the repository interfaces located in the domain layer.

Presentation:

This layer is dedicated to the UI of the project, which follows the MVVM architecture. In this package, Activities, Screens, and ViewModels are found.

Since the project exclusively uses Jetpack Compose, navigation between screens is handled through this library, and all page navigation is implemented in the NavGraph method.

Additionally, tools related to the UI, such as a method to convert height from cm to ft, are included in this layer.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages