Kotlin backend based on the Clean Architecture principles. Ktor, JWT, Exposed, Flyway, KGraphQL/GraphQL generated endpoints, Gradle.

Overview

Kotlin Clean Architecture Backend

Kotlin backend based on the Clean Architecture principles.

The application is separated into three modules: Domain, Usecases and Adapters

  • Domain module contains all entities, it's validation and repository interfaces
  • Usecases module performs actions on the domain entities and repositories and does authorization

The domain and usecases modules do not have any external dependencies.

  • Adapter layer: each adapter is implemented as a standalone module, lowering dependence on specific frameworks and libraries and making them interchangable. The server module consumes all adapters (e.g. databases, (graphql) endpoints, authentication logic)

GraphQL endpoints are auto-generated from the Usecases

Technologies:

Ktor, JWT, Exposed, Flyway, KGraphQL/GraphQL generated endpoints, Gradle.

image

GraphQL Plaground

Default url: http://localhost:8080/graphql

Login

query Login {
  LoginUser(a0: { email: "[email protected]", password: "[email protected]!" })
}

Retrieve current user

query CurrentUser {
  AuthenticatedUser {
    id
    email
    authorities
  }
}
HTTP Headers
{
  "Authorization": "Bearer [TOKEN FROM LOGIN]"
}

Create new user

mutation CreateUser {
  CreateUser(
    a0: {
      email: "[email protected]"
      password: "Penait1!"
      authorities: [USER]
    }
  ) {
    id
    email
    authorities
  }
}
HTTP Headers
{
  "Authorization": "Bearer [TOKEN FROM LOGIN]"
}
Comments
  • [QUESTION] Do you have an online course / tutorial for this repo

    [QUESTION] Do you have an online course / tutorial for this repo

    Hi,

    I was browsing the kgraphql.io documentation and i was redirected to your repository. I am in the process of building a saas app using ktor and graphql. Browsing the web for tips and help i came across this old tutorial https://michaelstromer.nyc/books/kotlin-multiplatform-mobile/ktor-and-kgraphql which i followed and made it somehow work with ktor 2 since kgraphql doesnt for now.

    I was looking for a better way to handle authentication (with access and refresh tokens) and stumbled upon your repo. If you have a course or tutorial about it please forward it to me so i can improve my current architecture which is mostly organized as shown in the link above. If no videos are available then ill try my best to understand and update where it makes sense.

    Thank you for the great repo

    opened by zjjt 12
  • Graphql kotlin

    Graphql kotlin

    @ESchouten I added argument renaming to graphql-kotlin although the way I did it is a little unusual

    I worked with the Hook methods didGenerateQueryField and didGenerateMutationField to modify the schema and rename the arguments

    Doing this broke the DataFetcher (the original implementation compares the name of the query argument with the name of the function parameter, if there is a match calls the convertArgumentValue for the conversion)... This method convertArgumentValue is internal and not public, so I had to retrieve it with reflections

    I honestly don't understand the purpose of the two methods didGenerateQueryField and didGenerateMutationField, because every change in the schema results in a break in the datafetcher

    opened by Francynox 7
  • Authetication - decode cookie

    Authetication - decode cookie

    the /login endpoint sends a cookie; this cookie uses the CookieEncoding.URI_ENCODING encoding by default.

    before executing the parseAuthorizationHeader method you must decode the cookie, otherwise it will never be recognized as correct

    opened by Francynox 5
  • No licence

    No licence

    I assume the repo is meant as an example, especially as it is linked here https://kgraphql.io/Examples/. However as long as there is no appropriate licence attached to it, nobody is actually allowed to use this as a starting point for their own project. See https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/licensing-a-repository#choosing-the-right-license for details.

    If this isn't intentional, would you mind adding a licence file?

    opened by zypus 4
  • Ktor 2.0.3 - KGraphql not parse errors

    Ktor 2.0.3 - KGraphql not parse errors

    I noticed that with Ktor 2.0.3 when a query or a mutation trows an error the Graphql server shows the error like this

    (example with login query) { "error": "Server response was missing for query 'Login'." }

    in Ktor 2.0.1 errors are shown instead like this { "errors": [ { "message": "Invalid authentication", "locations": [ { "line": 2, "column": 3 } ], "path": [] } ] }

    is this new behaviour correct or stills a parsing error with this new Ktor version?

    ps: also tried with the new version of KGrapgql 0.17.15

    opened by Francynox 2
  • Provide a REST API with OpenAPI generated docs alongside GraphQL

    Provide a REST API with OpenAPI generated docs alongside GraphQL

    opened by ESchouten 1
  • How do you create a new module?

    How do you create a new module?

    Greeting, I want to create a new module just like you did in this repo with the adapters, domain and use-cases modules but I don't know how to add the correct type of module with intellij.

    info 
    opened by Orpheus007 1
  • Explore different Graphql servers

    Explore different Graphql servers

    opened by ESchouten 9
Owner
null
Backend-aio - A ktor based ready to use backend

BackendAIO A ktor based ready to use backend BackendAIO is a project made to hel

Fabrizio Scarponi 2 Jan 24, 2022
The sample App implements type safe SQL by JOOQ & DB version control by Flyway

The sample App implements type safe SQL by JOOQ & DB version control by Flyway Setup DB(PostgreSQL) $ docker compose up -d Migration $ ./gradlew flywa

t-kurihara 3 Jan 1, 2022
A Modern Kotlin-Ktor RESTful API example. Connects to a PostgreSQL database and uses Exposed framework for database operations.

kotlin-ktor-rest-api A Modern Kotlin-Ktor RESTful API example. Connects to a PostgreSQL database and uses Exposed framework for database operations. F

Selim Atasoy 28 Sep 14, 2022
A simple (and naive) RESTful API made with Ktor, jasync-sql and JWT.

A simple (and naive) RESTful API made with Ktor, jasync-sql and JWT. Route Method Description /account POST Create a new account /account DELETE Delet

null 2 Nov 4, 2021
Kotlin-GraphQL-Apollo - Sencillo cliente para consumir una API GraphQL con Apollo usando Kotlin

Kotlin GraphQL Apollo Sencillo cliente para consumir una API GraphQL con Apollo

José Luis González Sánchez 2 Jan 25, 2022
A program written entirely in Kotlin using the principles of Clean Architecture according to the MVVM pattern

A program written entirely in Kotlin using the principles of Clean Architecture according to the MVVM pattern. An application that shows a list of ani

Yusuf Ruziev 2 Apr 26, 2022
GraphQL Jetpack - A collection of packages for easily writing Java GraphQL server implementations

GraphQL Jetpack A collection of packages for easily writing Java GraphQL server

Ryan Yang 17 Jun 5, 2022
Victor Hugo 1 Feb 2, 2022
A sample skeleton backend app built using Spring Boot kotlin, Expedia Kotlin Graphql, Reactive Web that can be deployed to Google App Engine Flexible environmennt

spring-kotlin-gql-gae This is a sample skeleton of a backend app that was built using: Spring Boot(Kotlin) Reactive Web Sprinng Data R2DBC with MYSQL

Dario Mungoi 7 Sep 17, 2022
Mock up social media android application created to interact with a backend Java server using GraphQL.

The Community Board Project Authorship: author: dnglokpor date: may 2022 Project Summary: The Community Board Project consists of a Java Spring Boot b

Delwys Glokpor 1 May 17, 2022
A complete Kotlin application built to demonstrate the use of Modern development tools with best practices implementation using multi-module architecture developed using SOLID principles

This repository serves as template and demo for building android applications for scale. It is suited for large teams where individuals can work independently on feature wise and layer wise reducing the dependency on each other.

Devrath 10 Sep 12, 2022
Integration Testing Kotlin Multiplatform Kata for Kotlin Developers. The main goal is to practice integration testing using Ktor and Ktor Client Mock

This kata is a Kotlin multiplatform version of the kata KataTODOApiClientKotlin of Karumi. We are here to practice integration testing using HTTP stub

Jorge Sánchez Fernández 28 Jun 16, 2022
Backend coding challenge using Kotlin and Ktor

Backend Coding Challenge We appreciate you taking the time to participate and su

Thermondo 0 Jan 4, 2022
A small backend for the Thinkrchive app written in Kotlin with Ktor

A small backend for the Thinkrchive app written in Kotlin with Ktor. It uses Postgresql with a few requests and JWT authentication for admins.

Thinkrchive 6 Sep 14, 2022
Backend aio - A project made to help all newbie programmers that are approaching backend development

BackendAIO A ktor based ready to use backend BackendAIO is a project made to hel

Fabrizio Scarponi 4 Feb 1, 2022
It is a repository containing backend structure for Ktor.

Backend Architecture with Ktor + KMongo This project contains, Authentication using Jwt Database Layer (KMongo - Orm for MongoDB) Routing Advanced Rou

Himanshu Singh 52 Aug 22, 2022
Android Note app that uses the "ktor-note-app" backend

KtorNoteApp Android Notes app that uses Ktor back end server Technologies employed: Kotlin MVVM Coroutines Custom REST API build with Ktor Responds to

Chris Athanas 2 Jul 25, 2022
Generated with spring boot kotlin starter kit

Kotlin backend Generated with spring boot kotlin starter kit The idea is to: Get a microservice written in kotlin for managing users and roles. To be

Oriol Subirana 1 Oct 19, 2021
ExposedDropdownMenu - Android Exposed Dropdown Menus

Exposed Dropdown Menu Exposed dropdown menus display the currently selected menu

Chayan Mistry 1 Jan 21, 2022