kyledinh / zio-blogapp

A Zio, Scala 3, Postgres, ScalaJS, Laminar App
Apache License 2.0
20 stars 2 forks source link

ZIO Blog App

A sample full-stack application written with ZIO 2, Scala 3 and ScalaJS/Laminar. This project is used to explore the development experience of using Scala 3 for the full stack and deploying to Kubernetes.




Table of Contents




Software Versions

Software Version Install
JVM openjdk 17.0.4 https://sdkman.io/install
Scala 3.2.2 https://www.scala-lang.org/download
sbt 1.8.2 https://www.scala-sbt.org/download.html
Zio 2.0.2 https://zio.dev/getting_started
ScalaJS 1.13.1 https://www.scala-js.org/
Laminar 15.0.1 https://laminar.dev/
Postgres 14 https://hub.docker.com/_/postgres
Docker Desktop 4.3.x https://www.docker.com/products/docker-desktop




Quick Guide to localdev with Docker

Requires Docker to be running

Setup

Run the local database, start backend server in Terminal 1

Start the database

To run the backend API server (With sbt server)

Run the frontend in a separate Terminal 2

Check processes that are running


Port number for services

Service Default Port Environment Var Usage
frontend :3000 http://localhost:3000/
backend :4000 BLOGAPPBACKEND_PORT http://localhost:4000/scrawls
postgres :5432 DATABASE_URL postgres://$username:$password@$host:$port/$dbname




Deploy to Kubernetes Cluster

This project example will use the my Docker Hub public account at https://hub.docker.com/u/kyledinh

Build the Docker images

Setup for Kubernetes Local Stack

Command to View/Edit the Kubernetes Stack




Check the Postgres DB in the Docker container

Postgres DB




Screenshots

using the Simplex Bootstrap Theme:

Board Page Screenshot People Page Screenshot Person Page Screenshot

Or you can view screenshots with the custom Medio CSS theme, this version is preserved in the "medio" branch:

Medio Page Screenshot




Project Outline

A good starting point to understand this repo is with the Makefile. It will have the most common commands to check, setup, compile and build the project.

.
├── LICENSE
├── Makefile                   Commands to build/develop this project 
├── README.md
├── backend                    Scala code for RESTful api 
│   └── src
│       ├── main
│       └── test
│
├── build.sbt                  Dependency manager 
├── docker                     Scripts to build Docker images 
├── docker_pg_vol              Docker volume for Postgres DB
├── frontend                   Scala code that generates `main.js` for the webserver
│   ├── src
│   │   └── main
│   └── target
│       └── scala-3.1.3        main.js will be generated here
│
├── html                      Javasript webserver using vite/Node
│   ├── index.html
│   ├── main.js
│   ├── main.scss
│   ├── medio/                 CSS/JS UI Template folder, "Medio" custom theme
│   ├── node_modules/
│   ├── package.json
│   ├── postcss.config.js
│   ├── simplex/               CSS/JS UI Template folder, "Simplex" Bootstrap theme
│   ├── tailwind.config.js
│   ├── vite.config.js
│   └── yarn.lock
│
├── kubernetes                 Files to deploy to Kube Cluster (locally) 
├── project                    The only project directory to be concerned with
│   ├── build.properties       sbt version  
│   └── plugins.sbt            plugins
│
├── sem-version                x.x.x
└── shared                     Scala code shared by backend and frontend, models 
    └── src
        ├── main
        └── test

Response HTML Tempate