All Projects → cies → low-code-backend-dockered

cies / low-code-backend-dockered

Licence: other
Fully dockered starter kit for Elm with Hasura

Programming Languages

javascript
184084 projects - #8 most used programming language
elm
856 projects
Makefile
30231 projects
Dockerfile
14818 projects
PLpgSQL
1095 projects
HTML
75241 projects
SCSS
7915 projects

low-code-backend-dockered

Starter kit for rapid+typesafe web application development on open source foundations.

Features:

  • Postgres as the primary data store.
  • ZomboDB adds auto-synced full text search (including fuzzy matching and suggestions) to Postgres, by bridging to ElasticSearch.
  • Hasura to manage permissions (and usage limits), database migrations and provide GraphQL interface. Basically removing the need for server-side controller logic.
  • Elm with elm-graphql to demo the joy of type safe queries in the front end.

All together its a workflow that allows all effort to be focused in:

  • setting up database structure and permission (mostly no-code experience)
  • UX design and implementation (as exmaple in web UI Elm is provided)

Server-side updates may change the API and therefor break your app if the exact GraphQL spec is not enforced. Using elm-graphql and Hasura we can generate an Elm GraphQL client that exactly fits your data model, and thus only allows valid queries to be expressed in Elm. After changing the database schema simply regenerate the Elm GraphQL client library code. Any errors resulting from your change are now compile errors and should show up as such in your IDE. Good stuff.

Stop writing/debugging layers of error-prone boilerplate and focus on cranking out features!

Highlights:

  • Strong typesafety from database schema, through GraphQL API to frontend (with generated GraphQL client code).
  • Define database schema with a UI that creates migrations! (to aid collaboration and deployments)
  • Hot code reloading in development mode.
  • Optimized (pre-gzipped) production builds, served by Nginx in production mode.
  • And everything runs from containers:
    • No need to install any tooling on the local machine except for docker, docker-compose and make.
    • All versions are pinned, so it should work anywhere (if not please raise an issue).
    • Uninstalls cleanly.

Ingredients

This repo contains the following parts:

  • Dockered Postgres database
  • Dockered Hasura which provides:
    • a GraphQL frontend to Postgres
    • an API gateway with (row based) authorization
    • a UI for schema changes that also manages migrations (see /hasura/metadata and /hasura/migrations)
    • a basic UI for CRUD operations on data
  • Dockered type-safe Elm GraphQL API client generator
  • Dockered Webpack based setup providing:
    • hot code reloading in development
    • production builds (with pre-gzipped artifacts)
  • Dockered Nginx serving pre-gzipped production builds (to show the setup on full speed)
  • Container orchestration with docker-compose
  • A minimal demo Elm app that uses the generated GraphQL client (see /frontend)
  • Some migrations, seed data and basic role definitions (all Hasura managed)
  • A self-documenting Makefile for common tasks (run make help)
  • This README explaining what's inside and how it works

Get going

Assuming you have docker, docker-compose and make installed, let's go!

Start by running Postgres and Hasura with:

docker-compose up hasura

Once the hasura docker service is running, start Hasura's console with:

make hasura-console 

This console is only for local development use. To use it point your browser to:

http://localhost:9695

Any changes you make using the console may become migrations (in the /hasura/migrations directory) or may lead to changes to the metadata (in /hasura/metadata). By checking these folders into version control you will always keep the the schema definitions with your code. Hasura can help you in running/managing migrations.

The /hasura/migrations and /hasura/metadata directories are not empty. They contain a simple schema modelling posts that have tags with a many-to-many relationship over a join table. The posts also have a status that is modelled with what Hasura calls an "enum table".

The following command is used to generate the 100% type safe GraphQL client:

make generate-elm-graphql-client 

The code will be put in /frontend/src/HasuraClient which is not checked into version control, as it can be re-generated at any time (and needs to be regenerated on schema changes) using the command above.

The following command runs development-mode Webpack in the /frontend container:

docker-compose up frontend 

It proxies request for the hasura container (/v1/graphql) and watches filesystem on the host for changes in the /frontend directory which will be hot-reloaded to the browser on:

http://localhost:3000

Production builds are made with:

make frontend-run-prod

Which compiles/copies/gzips artifacts to /frontend/dist/, from there the production setup may pick it up:

docker-compose up nginx

Point your browser to:

http://localhost:3030

Now check the response times and rejoice!

Moving forward

Interesting ways to extend this setup?

Collaboration is encouraged. Feel free to fork, submit PRs and/or open issues (even if it is to discuss how to improve this setup)!

Caveats

  • Files on the host filesystem are owned by root when created from docker containers. Fix it with: chown $USER:$USER -R .

  • For integration with your IDE you may need to run some local tooling (like node, elm and elm-format).

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].