Skip to content

Styleguide

Valentino edited this page Mar 1, 2019 · 3 revisions

To keep a consistent, clean and maintainable codebase, there are some rules which we've defined. 😊

Kotlin

The backend is written in Kotlin and we decided to adapt the conventions which JetBrains defined. https://kotlinlang.org/docs/reference/coding-conventions.html

Backend

Services

Every Service which is going to be written should implement an Interface.
Interfaces should be placed under services/. Implementations should be located under a separate package named services/impl.

Data Flow

Every Controller should use services for executing business logic. Every Service which needs to interact with the database should do this by using repositories.

Dependency Injection

Not wiring the dependencies by hand is a huge relief. We let the spring dependency container do the work for us. There are different types of injection methods. We agreed to use Constructor Injection because it gives us a valid object after it is constructed unlike Setter Injection.

Note: Classes which should be declared as Beans should be located under the AppConfig.kt

Logging

Every Logger which is going to be declared should have this format and be placed at the bottom of the source file.

companion object {
    private val LOGGER: Logger = LoggerFactory.getLogger(Service::class.java)
}

Comments

Every method which is going to be declared in an interface should be commented with the KDoc Syntax (KDoc is Kotlins equivalent of JavaDoc). The comments should describe what the method is going to do and what the intention of the author is or was. Additional comments can be placed within the methods and provide further documentation.

Clone this wiki locally