checkmarble / marble-backend

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Introduction

This repo is the Marble backend implementation:

  • 1 single go app
  • Postgres DB

Getting Started

Setup your environment

Install Go on your laptop (see the version in go.mod).

NB: To handle different versions, you can look at Managing Go installations or use a version manager tool like asdf

Create you own .env file based on .env.example. You can fill it with your own values but it should work locally with the default values (except for third-party services functionalities).

Setup the DB

Launch the postgres DB used by the backend:

docker compose up -d

NB: it creates a marble-backend_postgres-db volume to store PG data.

Firebase emulator suite for local development

Install the Firebase tools:

curl -sL firebase.tools | bash

Then start it using (replace GOOGLE_CLOUD_PROJECT with the value from your .env file):

firebase --project GOOGLE_CLOUD_PROJECT emulators:start --import=./firebase-local-data

NB: The --import flag is used to import the local data into the emulator.

Launch the project

Export your .env file and run the root of the project:

go run . --migrations --server

Using VSCode, you can also run the Migrate and Launch (.env) task in the "Run and debug" tab. This will load your env file, migrate the DB and start the server.

Application flags

The application can be run with the following flags:

  • --migrations: run the migrations
  • --server: run the server
    • in development, it also runs the SeedZorgOrganization usecase script from usecases/seed_usecase
  • --scheduler: run the scenario scheduling job
  • --scheduled-executer: execute scheduled scenario job
  • --data-ingestion: run data ingestion job

NB: .vscode/launch.json contains the configuration to run the app with these flags.

API

The rooting of the application is defined inside api/routes.go.

For further information on the API, you can also refer to the following resources:

  • our API docs for public facing reference
  • the Open API Specification defined in the frontend repository here.

DB Seed and migrations

The application uses goose to manage migrations.

Migrations are located in the repositories/migrations folder.

Execute the program with flags -migrations to run migrations

FAQ

How to update firebase local data ?

  • Run firebase emulator with paramater: --export-on-exit
  • Add user, change options...
  • Exit the emulator
  • commit

How to reset the DB ?

docker volume rm marble-backend_postgres-db deletes the PG volume, useful to reset the app to a known state

In practice, this single-line will delete the stack and create a new one: docker compose down && docker volume rm marble-backend_postgres-db && docker compose up -d

About

License:Other


Languages

Language:Go 99.6%Language:PLpgSQL 0.4%Language:Dockerfile 0.0%