Giter VIP home page Giter VIP logo

kotlin-micronaut-example's Introduction

Example Micronaut API with Postgres. Written in Kotlin.

Tech and tools used

  • Kotlin - for development
  • PostgreSQL - persistence store
  • Liquibase - aMigrations and DB change version control
  • NORM - Types for your SQL in kotlin created in house
  • Micronaut - Framework just like SpringBoot for good support for cloud native applications.
  • Gradle - Build tool
  • Ktlint - for linting

Project Structure

The project structure follows CCD Architecture

  • core - Business logic
  • connector - Database/Kinesis/API ingest
  • delivery - API
  • migration : Database migrations.

It is a multi-module gradle project. Top Level project does not contain any sources.

Main module: api : Exposes API for example app

Pre-requisites

You need Java 11.08, which can be configured using SDKMAN. Also, you would need to setup Gradle JVM to 11.08

Setting up Java

  • Install JDK: $brew cask install adoptopenjdk/openjdk/adoptopenjdk11

  • Setup JAVA_HOME: Follow these steps.

  • Select Gradle JVM Version 11.08

Ktlint Commands:

  • Configure IntelliJ IDEA - ./gradlew ktlintApplyToIdea
  • Configure Pre-commit Hook for Format - ./gradlew addKtlintFormatGitPreCommitHook
  • Format Kotlin Code - ./gradlew ktlintFormat
  • Check Kotlin Lint - ./gradlew ktlintCheck

Local setup:

Required tools:

  1. Java 11.08
  2. Postgres server (by default, this project looks for a local Postgres instance called kt_mn_example) a. The example credentials expect a user named 'johndoe' with password 'secret' to exist in your database. You can either create this user or create your own and change the credentials locally.
  3. sam cli

Running API locally:

Can be run in two modes:

Continuous running server

As lambda (using sam cli):

  • Generate zip using ./gradlew shadowJar
  • Run sam-cli command sam local start-api -t sam.yaml
  • Hit using following endpoint http://localhost:3000/api

Executing tests (Using Gradle command):

Run Gradle command:

./gradlew test

This Gradle command will execute all tests present in project.

Executing tests (Using Kotest plugin)

  • Install Kotest plugin in IntelliJ.
  • In Test class, at the left side of class name (after line number) you'll see GREEN Play button ๐ŸŸขโ–ถ๏ธ. Just click on that and test will be executed.

Guidelines for adding SQLs

We are using NORM for generating types for our SQLs. Once we write the SQLs we need to run the below command to generate those types

./gradlew compileNorm

Guidelines for writing migrations

  1. Add new sql query in migration/sql/<file_name>.sql
  2. Please follow below convention while naming file
    • Add the time stamp at which you are creating the file.
    • YYYY_MM_DD_HR_MM_.sql (Use 24hour format)
  3. This file will get included in migrations

Update: migrations/migration.gradle file with your local Postgres instance

Before pushing code

  • Format code with KtLint
  • Make sure ./gradlew build is executing without failure.

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.