Skip to content

Create all files of all layers of your application connecting all of them. It also creates a new module for each feature generated.

License

Notifications You must be signed in to change notification settings

MayconCardoso/ArchitectureBoilerplateGenerator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Overview

Download

Recently I started off working for Unicred Mobile Banking as a Senior Android Engineer.

The app had a huge monolithic and legacy codebase written in Java. So, my first task at Unicred was to define a strategy of modularization and refactoring on the app.

We had to separate the app, initially, into three layers which are: the domain, data, and presentation.

Since the code was very tightly coupled, I decided, at first, to place all application entities within the domain layer.

However, we know how many boilerplate we need to write to create a new feature-module, don't we? ViewModel, Activity or Fragment, UseCases, Many interfaces, Datasources and Repositories and so on. So in order to turn this process easier, I built this "architecture-code-generator" to create all of the templates we need on the project for each new feature.

Download Generator

implementation 'com.mctech.architecture:generator:2.0.0'

Related Library

Mvvm Architecture Toolkit - It is a personal MVVM architecture library that contains the base codebase generated here.

Sample

Here is a Real Android App implementing this library to define its architecture.

Creating an empty feature

To start your generator you will need a ProjectSettings instance and a FeatureSettings instance. Here is an example:

fun main() {
    val projectSettings = ProjectSettings(
        basePackageName = Package("com.mctech.architecture")
    )

    val featureSettings = FeatureSettings(
        createDependencyInjectionModules = false,
        createBothRemoteAndLocalDataSources = true,
        presentationViewModel   = PresentationMode.ActivityAndFragment,
        projectSettings         = projectSettings,
        fileDuplicatedStrategy  = FileDuplicatedStrategy.Replace
    )

    // Here is an empty feature generated
    FeatureGenerator(
        settings    = featureSettings,
        featureName = "FeatureEmpty"
    ).newFeature {}
}

All you are going to do is run this main function and the files are going to be generated.

Generated files

Domain Layer

Data Layer

Presentation Layer (New Module)

Creating a complete feature with business and presentation logic

To start your generator you will need a ProjectSettings instance and a FeatureSettings instance. Here is an example:

fun main() {

    ...
    
    FeatureGenerator.newFeature(
        settings    = featureSettings,
        featureName = "ComplexFeature"
    ) {

        // Add fields on entity
        addEntityField(Parameter(
            name = "id", type = Type.Long
        ))

        addEntityField(Parameter(
            name = "name", type = Type.String
        ))

        addEntityField(Parameter(
            name = "anotherFeature", type = Type.CustomType(
                packageValue = "com.mctech.architecture.domain.feature_empty.entity",
                typeReturn = "FeatureEmpty"
            )
        ))


        // Create an use case that will call the repository and delegate it to the data sources and so on.
        addUseCase {
            UseCaseBuilder(
                name        = "LoadAllItemsCase",
                returnType  = Type.ListOfGeneratedEntity,
                isDaggerInjectable = false
            )
        }

        addUseCase {
            UseCaseBuilder(
                name        = "LoadItemDetailCase",
                returnType  = Type.ResultOf(Type.GeneratedEntity),
                parameters  = listOf(
                    Parameter(
                        name = "item",
                        type = Type.GeneratedEntity
                    ),
                    Parameter(
                        name = "simpleList",
                        type = Type.CustomType(
                            packageValue = "com.mctech.architecture.domain.feature_empty.entity",
                            typeReturn = "FeatureEmpty"
                        )
                    )
                ),
                isDaggerInjectable = false
            )
        }

        addLiveData {
            LiveDataBuilder(
                name = "items",
                type = Type.ListOfGeneratedEntity
            )
        }

        addLiveData {
            LiveDataBuilder(
                name = "userName",
                type = Type.String
            )
        }

        addComponentState {
            ComponentStateBuilder(
                name = "listEntities",
                type = Type.ListOfGeneratedEntity
            )
        }

        addUserInteraction {
            UserInteractionBuilder(
                name = "LoadList",
                connectedState = findStateByName("listEntities"),
                connectedUseCase = findUseCaseByName("LoadAllItemsCase")
            )
        }

        addUserInteraction {
            UserInteractionBuilder(
                name = "OpenDetails",
                parameters = listOf(
                    Parameter(
                        name = "item",
                        type = Type.GeneratedEntity
                    )
                ),
                connectedUseCase = findUseCaseByName("LoadItemDetailCase")
            )
        }
    }
}

Generated files

Domain Layer

Data Layer

Presentation Layer (New Module)

Roadmap

  • Improve code (Yeah, I know the code is not good, but again, this library was a personal generator before it became open source) :P
  • Make the generator easier to be used
  • Improve the templates logic.
  • Create an extension library and organize all existing functions.
  • Create all unit tests.

About

Create all files of all layers of your application connecting all of them. It also creates a new module for each feature generated.

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published

Languages