Giter Club home page Giter Club logo

hastl's Introduction


Production ready, modern web-application starter template

hastl is a modern Haskell web application using (H)tmx, (A)lpine.js, (S)ervant, (T)ailwind-css and (L)ucid. It is based on the awesome servant-persistent example and is licensed under MIT and is entirely free and open source.

Built with

Haskell Htmx Alpine Servant Tailwind Lucid

hastl is primarily tested with PostgreSQL but it uses the popular persistent haskell library as an ORM and therefore can be used with most popular databases.

Features

Type-safe APIs - hastl uses Servant to define APIs that make up the application, providing type safety and consistency across the application, with the haskell type-checker keeping you honest as you develop

Modern frontend with htmx - the use of htmx in hastl allows you to build modern user interfaces with the simplicity and power of hypertext, with haskell and lucid2 doing the heavy lifting

Live reloading with GHCID - since we're writing almost all of our code in the backend, hastl uses GHCID to instantly reload your project as you make changes

Integration testing with TestContainers - hastl uses testcontainers to spin up a database on the fly to run integration tests and give you confidence in your business logic

Get Started

Start by creating a new repo from the hastl template by clicking "Use this template" in the top right corner.

Setting up dependencies

Hastl requires the tailwindcss standalone CLI executable locally in the root folder as described here. In addition, it expects a local postgreSQL database to be running on port 5432, alternatively use the provided compose.yaml file to run either Podman or Docker to spin it up.

The project includes a Makefile to provide you with convenient targets for running the server in development mode as well as running the tailwindcss CLI in watch mode to generate stylesheets on the fly.

Navigate into your cloned repo and run:

make run

This will build and run hastl and you should be able to navigate to localhost:8081 in your browser and see the hastl demo application:

Screenshot from 2024-06-08 15-41-54

To run the development live reloading mode, make sure that ghcid is installed and then use the ghcid-devel target:

make ghcid-devel

Running unit tests

The unit tests of the project can be found in the test directory and can assert things like HTML generation from database types.

You can run all the unit tests with:

make test

Running integration tests

Hastl ships with built-in integration tests that use testcontainers to start a local postgreSQL database inside a container (using docker or podman) on-the-fly, as well as running the project web-server, allowing the tests to exercise the actual HTTP endpoints to assert correctness.

The integration tests manage the containers, starting them and tearing them down as the tests complete.

You can run all the integration tests with:

make test-integration

Changing the routes and templates

Hastl allows you to combine strongly-typed Servant APIs to make up your application. To add a new route and endpoint, you can create a new file similar to lib/Api/User.hs e.g. if you wanted to create a Todo-list API you could create lib/Api/Todo.hs. Additionally, you can create a new directory within lib/Api/Templates to store your Lucid-powered Haskell template files. Within the template files, you have access to the full power of HTMX and Alpine through helper functions.

If you wish to use persistent models in your application, you can define your models in lib/Models.hs and persistent will automatically create the Haskell types, as well as handling the database migrations for DEVELOPMENT setups (note: is it recommended to use a more robust migration mechanism for production).

hastl's People

Contributors

sigrdrifa avatar kushagarr avatar

Stargazers

JustinW avatar mohsenNz avatar Sourabh avatar  avatar  avatar Zakariya Stasa avatar Thành Hạ avatar Fabio S. avatar Bernhard Mayr avatar Greg Wedow avatar Astodialo avatar Mark avatar Avi Press avatar Lynton avatar Ken Aguilar avatar Russell Dillin avatar Robertino avatar Alexander Biehl avatar Lewis Brown avatar Sam Smucny avatar Hong Minhee (洪 民憙) avatar David Mazarro avatar Rodrigo Mesquita avatar Marco Z avatar Sebastián Estrella avatar kaelnor avatar Peter Siska avatar George Takumi Crary avatar  avatar Tim Kersey avatar Alfredo Di Napoli avatar Jess avatar Adelar da Silva Queiróz avatar Igor Spasić avatar Solomon avatar  avatar Tobi Oloke avatar zoool avatar Larry Diehl avatar Tobias Sandmann avatar Andrei Dziahel avatar  avatar Drew Hess avatar Andrejs Agejevs avatar Laurent P. René de Cotret avatar Slawomir Sledz avatar Josh Miller avatar Gustavo Bicalho avatar Can Evgin avatar Aaron Allen avatar Md Imrul Hassan avatar Gleb Dobzhansky avatar Tristan de Cacqueray avatar 姚文强 avatar Dániel László avatar Alexander Bondarenko avatar Sam Toth avatar Daniel Díaz Carrete avatar Adrian Sieber avatar Mark Wotton avatar Leonhard Riedißer avatar  avatar

Watchers

Lucian avatar Adelar da Silva Queiróz avatar  avatar

Forkers

fanshi1028

hastl's Issues

Table name user is a reserved word (postgresql)

hastl=> \d
            List of relations
 Schema |    Name     |   Type   | Owner 
--------+-------------+----------+-------
 public | user        | table    | hastl
 public | user_id_seq | sequence | hastl
(2 rows)

hastl=> select * from user;
 current_user 
--------------
 hastl
(1 row)

hastl=> select * from "user";
 id |     name      |         email         |          created_at           
----+---------------+-----------------------+-------------------------------
  1 | Alley Cats    | Alley.cats@invalid    | 2024-07-23 21:15:55.25558+02
  2 | Pigs in Space | pigs.in.space@invalid | 2024-07-24 10:32:23.08098+02
  3 | Dogs of War   | dogs.of.war@invalid   | 2024-07-24 10:32:36.920221+02
(3 rows)

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.