Coder Social home page Coder Social logo

rikuvan / bantamweight Goto Github PK

View Code? Open in Web Editor NEW
4.0 2.0 1.0 198 KB

A http4k & Svelte template/example app

Home Page: https://bantamweight.ninja/

Kotlin 37.54% HTML 0.39% CSS 1.37% Svelte 41.10% TypeScript 13.67% JavaScript 2.21% Dockerfile 1.65% Shell 2.07%

bantamweight's Introduction

Bantamweight

This is an http4k and Svelte starter template, which is still under development. "Bantamweight" because it is a lighter stack but still packs a punch.

To get started, you should have JDK 11, nodejs (at least v14) and pnpm. If you don't want to use in-memory sqlite, install sqlite if needed and create a bantamweight.db.

Features

This app is still under development but it already includes a good part of the front and backend code for JWT auth, including token refresh with an httpOnly cooke, log-in and -out, password change, admin user management. On the auth side, the user signup and password reset flow is missing. Further features will be added to demonstrate other ways to do things with http4k and Svelte.

Backend

The app will use application-dev.yaml by default if a file path to application.yaml is not added to the ConfigDelegate.Kt file. You must also set, at a minimum, the BANTAMWEIGHT_DB_FILEPATH. There are a number of ways to override the yaml values. Use env variables such as APP__ENV or for another methods see hoplite. See Parameters below for list of every possible flag.

...start the backend

  ./gradlew runShadow

The app will be available at localhost:9000

New dependencies should be added to versions.properties, see refreshVersions

To make the app even lighter-weight, I have used sqlite with sqldelight. While sqldelight is easy to get started with and gives you typed queries. The migrations happen programmatically. It does not support all of sqlites's latest features. A more heavyweight ORM solution would be e.g. jooq plus flyway for migrations, which also supports other dbs like postgres well.

Command-line flags

Flag Meaning Default Value
APP__ENV Set "DEV" or "PROD" for backend config "DEV"
APP__PORT Server port in development 9000
DATABASE__FILE_PATH Path to the sqlite db file "/data/bantamweight.db"
DATABASE__USER__LAST_NAME Seed user last name Super
DATABASE__USER__FIRST_NAME Seed user first name User
DATABASE__USER__EMAIL Seed user email [email protected]
DATABASE__USER__PASSWORD Seed user password password
DATABASE__USER__ROLES Seed user roles [admin]
AUTH__SECRET Long random string for encrypting JWT tokens changeme-[randomletters]
AUTH__ROLES User roles [admin, user]

Docker build args

You can adjust behavior of the Docker container by passing these parameters with docker run -e:

Environment Variable Meaning
GOOGLE_APPLICATION_CREDENTIALS Path to the Google storage credentials needed for storing replicas
REPLICA_URL The address for Litestream to find the correct storage, e.g. gcs://bantamweight

Frontend

...to run in development

  cd frontend && pnpm install && pnpm run dev

This will proxy requests from the frontend through a development server. If you build the app with pnpm run build, you can see the app served from localhost:9000

This Svelte + Vite app is very light-weight in terms of bundle size. The dependencies have been kept to a minimum. The build also creates an public/assets-manifest.js file with a list of the static assets which can be used to precache resources in a service worker. I plan to add a service-worker starter in the future. SvelteKit is not used here because the story for SPA's at this point is fairly poor--it is more focused on server-rendered apps. This may change in the future.

If you feel the need for a Svelte component library, Carbon components Svelte is fairly large and has typescript definitions.

Deployment

Using the Dockerfile in the project root, the app can be run in a container and persist the sqlite database via Litestream at low-cost and without the need for a volume. Use any cloud providers that run docker images that you like, fly.io or Heroku are good choices (this app is deployed currently to Heroku). Litestream will replicate the database to a storage bucket like Google Cloud Storage. When the server is rebuilt, the database will be restored in the container. While this is easy and cheap, it is probably not what you want for highly-available apps where data-integrity and security is the first concern. In this case, you may want to consider a database outside of the container.

bantamweight's People

Contributors

bonsmik avatar rikuvan avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

bonsmik

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.