neutral_diet

module
v0.0.0-...-64e57e2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 17, 2023 License: MIT

README

Neutral Diet

Carbon footprint food journal

Live webapp

Getting started

Prerequisites
Environment

The application includes .env.development files with sample working development environment variables. Not all required environment variables are included in .env.development, i.e. Firebase environment variables.

  • GOOGLE_APPLICATION_CREDENTIALS: path to Google Cloud service account key (JSON)

Refer to .env.example for the complete list of required environment variables.

The application follows the dotenv convention for managing multiple environments. The order is summarised below:

.env                # loaded in all cases
.env.local          # loaded in all cases, ignored by git
.env.[mode]         # only loaded in specified mode
.env.[mode].local   # only loaded in specified mode, ignored by git

The mode is set using the APP_ENV variable on the backend and NODE_ENV variable on the frontend.

Once the environment is setup, run the following commands to setup and run the application.

# Start postgres server (and application server)
# Use .env.docker unless you want to run the application server another way
docker-compose --env-file .env.[mode] up

Alternatively, you can run the application directly:

# Start application server
go run cmd/app/main.go
# OR for live reloading
air

Once the database and server are running, you can create the database schema using the migration files:

make migrate-up
Database

Before starting to use the application, you need to pre-populate the database. To populate the database with food items, follow these steps.

The database relies on materialized views for querying the aggregate food items used for the search functionality. Ensure you run the following to setup the materialized views:

REFRESH MATERIALIZED VIEW aggregate_food_item;
REFRESH MATERIALIZED VIEW regional_aggregate_food_item;
UI

Once the database and server instances are setup and running, you can follow the UI setup guide.

Services

The application server exposes various services:

  • FoodService
    • Used to create food items and list respective information
    • No authentication
    • RPCs
  • JobService
    • Used to run scheduled jobs
    • OIDC authentication (Google Cloud Scheduler)
    • RPCs
  • UserService
    • Used by web application's private routes
    • JWT authentication (Firebase Authentication)
    • RPCs

License

MIT

Credits

Directories

Path Synopsis
cmd
app
Package config contains custom configuration types.
Package config contains custom configuration types.
app
Package app provides the entry point to neutral-diet application.
Package app provides the entry point to neutral-diet application.
app/connectgo
Package connectgo implements utilities for building and serving neutral-diet services.
Package connectgo implements utilities for building and serving neutral-diet services.
app/firebase
Package firebase provides wrapper functions for Firebase App initialisers.
Package firebase provides wrapper functions for Firebase App initialisers.
app/logging
Package logging implements logging utilities.
Package logging implements logging utilities.
app/service
Package service implements service requirements.
Package service implements service requirements.
app/sql
Package sql provides functions for working with PostgreSQL databases.
Package sql provides functions for working with PostgreSQL databases.
service
Package service implements the RPCs for neutral-diet services
Package service implements the RPCs for neutral-diet services
service/db
Package db implements database interactions for neutral-diet service RPCs.
Package db implements database interactions for neutral-diet service RPCs.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL