hotdog45 / eg-dart-shelf

Example Web Service use Dart with Shelf and PostgreSQL as database.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

eg-dart-shelf

This codebase was created to demonstrate a fully fledged backend application built with Dart-Shelf including CRUD operations, authentication, routing, pagination, and more. I've gone to great lengths to adhere to the Dart community style guides & best practices.

How it works

This is a monolithic application structures by components. It uses:

  • Dart a client-optimized language for fast apps on any platform.
  • Shelf a server app using package:shelf.
  • PostgreSQL as the database, and uses some of it's specific features such as Arrays.
  • SQL instead of an ORM.
  • Docker Compose to run tests and the application locally. For the testing strategy, I opted to not use mocks and the such to unit test individual functions: instead, I applied a honeycomb testing strategy to run the tests against the actual app connected with an actual database. I felt that this:
    • Gave me more confidence that the application is working correctly.
    • Allowed me to refactor more easily as I test only the public interface and not the implementation details. This talk by Dan Abramov, for example, illustrates very well the importance of this.
  • Github Actions to run tests on Pull Requests and Merges to the main branch.

For more detailed information in pubspec.yml

Getting Started

  • Install Dart SDK.
  • Clone this project.
  • On terminal project run dart pub get.
  • Create a .env file according to the example.
## RUN THE APP
$ ./dev.sh

## RUN THE TEST
$ ./test.sh

Deployment

Deploy to Google Cloud Platform (GCP)

  1. Install terraform.
  2. Install the gcloud-cli.
  3. Login with gcloud.
  4. Go to the dev bootstrap directory, change the locals.tf values to your own and run terraform apply.
  5. Go the scripts directory and run build-and-push-container-image.sh <YOUR_PROJECT_ID> <YOUR_ARTIFACT_REPOSITORY>.
  6. Go to the dev directory, change the locals.tf values to your own and run terraform apply.

About

Example Web Service use Dart with Shelf and PostgreSQL as database.

License:MIT License


Languages

Language:Dart 94.4%Language:HCL 4.4%Language:Shell 0.6%Language:Makefile 0.4%Language:Dockerfile 0.3%