Git Product home page Git Product logo

cleanarchitecture's Introduction

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 infrastructure module consumes all adapters (e.g. databases, (graphql) endpoints, authentication logic)

GraphQL endpoints are auto-generated from the Usecases

Technologies:

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

image

OpenAPI REST

Docs URL: http://localhost:8080/docs

API definitions: http://localhost:8080/openapi.json

GraphQL

Playground URL: http://localhost:8080/graphql

Login

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

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]"
}

cleanarchitecture's People

Contributors

eschouten avatar francynox avatar sugasaki avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

cleanarchitecture's Issues

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

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?

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.

[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

Provide a REST API with OpenAPI generated docs alongside GraphQL

Like GraphQL, Rest APIs with OpenAPI generated docs, can enable client-side code generation

Third-party alternative

Since we're only utilizing GraphQL as a typed API, using GraphQL is overkill and requires a lot of verbose queries on the client-side.

OpenAPI would provide a nice, less verbose alternative to the GraphQL API, while maintaining the ability to generate code on the client-side.

Ktor official OpenAPI support

Planned on the latest roadmap

I can't configure it to sqlite DB.

I just change application.conf file

ktor {
deployment {
port = 9090
}
application {
modules = [ ktor.ServerKt.module ]
}
development = true
}

database {
type = "JDBC"
drop = false
jdbc {

    driver = "org.sqlite.JDBC" 
    url = "jdbc:sqlite:file:test?mode=memory&cache=shared"
    schema = ""
    username = "root"
    username = ${?MYSQL_USER}
    password = "root"
    username = ${?MYSQL_PASSWORD}
}

}

jwt {
domain = "http://localhost:8080"
domain = ${?DOMAIN}
secret = "490626fc-d735-4b85-a953-386f0b8cd2f5"
secret = ${?JWT_SECRET}
}

and add this dependency implementation("org.xerial:sqlite-jdbc:3.45.0.0")

that throw this error message:

Exception in thread "DefaultDispatcher-worker-1" java.lang.IllegalStateException: repositories.user.UserTable.id is not in record set

CleanArchitecture.zip

Can anyone help me to solve this problem?

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.