Skip to content

ram02z/neutral_diet

Repository files navigation

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