DEV Community

Cover image for Kotlin & JVM first thoughts (Day 2) - Creating a SaaS Startup in 30 Days
Sotiris Kourouklis
Sotiris Kourouklis

Posted on • Updated on • Originally published at sotergreco.com

Kotlin & JVM first thoughts (Day 2) - Creating a SaaS Startup in 30 Days

After spending hours reading about the JVM and Kotlin, I was initially surprised by its complexity. However, its ecosystem structure is essentially the same whether for Java, Kotlin, or Groovy. It offers a wide range of libraries, and the framework I am using, Spring Boot, is quite simple.

Progress

So far, I have created a test controller, set up Gradle, and used Flyway to create the database migrations. I spent most of my time reading about JVM, Kotlin, and Spring Boot. I have not yet made any significant progress on the logic staff.

Syntax

Kotlin has simplified the syntax from Java a lot, to be honest coming from a PHP, Node.js background I kind of like it and I think it is a lot more modern and easy to write.

The fact that is statically type by default is a huge bonus, here is one of my controllers.

package com.whoyou.whoyou.controllers

import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RestController

@RestController
class IndexController {
    @GetMapping("/")
        fun index(): String {
                return "Index"
        }
}
Enter fullscreen mode Exit fullscreen mode

Gradle and Maven

From what I understand, Gradle, which I will be using for this project, serves both as a build tool and a package manager. When compared to npm and package.json in Node.js, I believe Gradle offers a better approach to handling dependencies.

The fact that Gradle uses a Kotlin file, allowing you to write logic within your configuration, is impressive. Additionally, Gradle is extensible, meaning you can add plugins and expand the command line interface.

For instance, with the Flyway plugin, I can execute database migrations directly from the command line using ./gradlew flywayMigrate.

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
    id("org.springframework.boot") version "3.2.5"
    id("io.spring.dependency-management") version "1.1.4"
    id("org.flywaydb.flyway") version "6.4.3"
    kotlin("jvm") version "1.9.23"
    kotlin("plugin.spring") version "1.9.23"
}

group = "com.whoyou"
version = "0.0.1-SNAPSHOT"

java {
    sourceCompatibility = JavaVersion.VERSION_21
}

repositories {
    mavenCentral()
}

dependencies {
    implementation("org.flywaydb:flyway-core:9.22.0")
    implementation("org.springframework.boot:spring-boot-starter-web")
    implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
    implementation("org.jetbrains.kotlin:kotlin-reflect")
    implementation("org.springframework.boot:spring-boot-starter-data-jpa")
    implementation("org.springframework.boot:spring-boot-starter-security")
    implementation("io.jsonwebtoken:jjwt:0.9.1")
    runtimeOnly("org.postgresql:postgresql")
    testImplementation("org.springframework.boot:spring-boot-starter-test")
    developmentOnly("org.springframework.boot:spring-boot-devtools")

}
Enter fullscreen mode Exit fullscreen mode

Spring

Spring by default is not some bloaded framework which by default have a million features like Laravel. It is pretty empty, basic and it gives you a strong foundation to work on.

The thing I didn't like, though, is the documentation, which compared to Laravel or Django, is not as good. Essentially, Spring and Boot are treated as two separate entities in the documentation. Spring includes many so-called "projects" like CLI, AI, Boot, etc.

For some, this might not be a bad thing because it allows you to use only the features you want. However, in general, I find the documentation a bit confusing.

Folder Structure

Unlike Laravel, Spring Boot does not come with a predetermined folder structure; it lets you choose. You have the src/main directory, and from there, it's up to you.

Also, keep in mind that Boot is the application part; Spring just provides the tools. For example, Boot adds features that make it easier to create REST APIs, such as Authentication, WebSockets, CLI, etc.

Conclusion

In conclusion, the second day of developing a SaaS startup with Kotlin and JVM has been a learning curve filled with both surprises and appreciations.

Kotlin's modern and simplified syntax is a refreshing change from PHP and Node.js, making the transition smoother than expected. Utilizing Gradle for build and dependency management has introduced a flexible and powerful tool into the workflow.

However, navigating Spring's documentation has been challenging, and its modular approach, while beneficial for some, can be confusing for newcomers.

The freedom in project structure that Spring Boot offers is empowering yet requires careful consideration to maintain organization. Moving forward, the focus will be on implementing the core logic of the application, leveraging the strengths of the tools and languages chosen to build a robust and scalable product.

Thanks for reading, and I hope you found this article helpful. If you have any questions, feel free to email me at kourouklis@pm.me, and I will respond.

You can also keep up with my latest updates by checking out my X here: x.com/sotergreco

Top comments (0)