Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mathias21/KtorEasy
Suggested Ktor architecture
https://github.com/mathias21/KtorEasy
docker docker-compose grafana hacktoberfest koin kotlin ktor prometheus
Last synced: 29 days ago
JSON representation
Suggested Ktor architecture
- Host: GitHub
- URL: https://github.com/mathias21/KtorEasy
- Owner: mathias21
- License: gpl-3.0
- Created: 2020-07-23T09:35:01.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-02-15T12:05:13.000Z (almost 2 years ago)
- Last Synced: 2024-02-15T19:20:33.955Z (10 months ago)
- Topics: docker, docker-compose, grafana, hacktoberfest, koin, kotlin, ktor, prometheus
- Language: Kotlin
- Homepage:
- Size: 200 KB
- Stars: 216
- Watchers: 6
- Forks: 27
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-ktor - KtorEasy
- awesome-ktor - KtorEasy
README
# KtorEasy
This is a project to demonstrate a suggested Ktor architecture. It includes Backend implementation with Ktor, MariaDB database connection with Hikari, Docker command to build Backend container and Docker compose to run both database and backend instance.## Architecture explained
![arch_image](https://github.com/mathias21/KtorEasy/blob/master/ktorArch.png?raw=true)
This is a suggested architecture that pretends to follow CLEAN principles. The main idea behind it is to define each layer with one purpose and to allow unit testing each layer independently.To achieve this, I'm using Koin as a dependency injection framework.
https://insert-koin.io/Also, to make each layer testable, Controllers and APIs should always implement an interface that will be injected where they are used, instead of the implemented type.
### Application.kt
File to define Java app main method, Koin setup and configuration initialisation.### Module.kt
Application extension function where we configure Ktor application with features, interceptors and routing.### Modules
Each module will define routes related with its functionality. It will be a Route function extension to configure it and it will receive an injected controller object. This layer is responsible of reacting to API call, receive parameters and invoke controllers function with them.### Controllers
There will be one controller per module and it will receive by injection those API objects it will use to handle module requests. Here all the business logic should be defined. Controller will fetch/write data through API objects and unhappy paths will be handled throwing exceptions and answered by status pages.### APIs
This layer will use DAOs to recover/write information from/in database. It will be responsible of transforming data if needed.### DAOs
DAOs objects will define tables and those operations to do with them. It will also map table rows into API expected objects.## Kotlin London Meetup presentation
I've presented this implementation in the Kotlin London Meetup group in Youtube. You can find the presentation here: https://www.youtube.com/watch?v=RXSwQHur6zM## How to run it
This project is prepared to be run in Docker via [docker-compose](https://docs.docker.com/compose/). With a simple command, you will deploy it to Docker with a MariaDB container linked to the backend instance. Just run: `docker-compose up`.MariaDB is accesible through port `3308` with root password `mypassword` by default. The backend is accesible through port `3510`. You can change this settings in the `docker-compose.yml` file.
UPDATE: After bumping dependency versions, I've integrated monitoring with Grafana + Prometheus to the Docker compose file.