Skip to content

marcusmonteirodesouza/dart-shelf-realworld-example-app

 
 

Repository files navigation

RealWorld Example App

Dart codebase containing real world examples (CRUD, auth, advanced patterns, etc) that adheres to the RealWorld spec and API.

This codebase was created to demonstrate a fully fledged backend application built with Dart including CRUD operations, authentication, routing, pagination, and more.

We've gone to great lengths to adhere to the Dart community styleguides & best practices.

For more information on how to this works with other frontends/backends, head over to the RealWorld repo.

How it works

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

  • PostgreSQL as the database, and uses some of it's specific features such as Arrays.
  • SQL instead of an ORM. See for example.
  • 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 master branch.

Getting started

Install the Dart SDK.

Running the App

Define the environment variables

Create a .env file according to the template.

Run the app

$ ./dev.sh

Running the tests

Run the test script

$ ./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.

Releases

No releases published

Packages

No packages published

Languages

  • Dart 94.7%
  • HCL 4.4%
  • Other 0.9%