Giter Club home page Giter Club logo

ktoreasy's Introduction

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
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. 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.

ktoreasy's People

Contributors

mathias21 avatar dmcallejo avatar elraro avatar svill avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.