Skip to content

About

Blue Hill Observatory Repo

Resources

Stars

2 stars

Watchers

0 watching

Forks

 
 

Latest commit

 

History

158 Commits

Folders and files

Repository files navigation

Blue Hill Observatory (BHO) Platform

Automated digital platform for the Blue Hill Observatory to centralize 141 years of weather data, automate live data collection from BHO's Davis Vantage Pro station, and modernize the daily manual-observation workflow currently done by hand in a spreadsheet.

A Code-4-Community (C4C) project, in partnership with Blue Hill Observatory.

Setup

Requires Node 24 an .nvmrc is checked in, so if you have nvm, run nvm use (or nvm install if you don't have 24 yet) before installing dependencies. Without it, yarn install fails.

Clone this repo and run yarn at the root to install this project's dependencies.

You can optionally install nx globally with npm install -g nx - if you don't, you'll just need to prefix the commands below with npx (e.g. npx nx serve frontend).

Architecture

The backend is Lambda-only. Three independent Lambda functions live under apps/backend/:

  • internal-serving-lambda — the authenticated API the frontend calls (staff/admin)
  • upload-lambda — S3-upload-triggered, parses and imports spreadsheet/CSV data
  • public-lambda — serve the public dashboard

Database

The data lives in PostgreSQL. The schema is shared by all the Lambdas and is defined by Kysely migrations in db/. For local development, db/ also provides a disposable Postgres container. The Kysely client (createDb) and table types (Database) live in libs/db-client; import them from @bho/db-client.

nx run db:install   # one-time install of db/'s dependencies
nx run db:up        # start the local Postgres container (needs Docker)
nx run db:migrate   # apply migrations
nx run db:make <name>   # create a new migration
nx run db:reset     # wipe the local database and re-apply everything

See db/README.md for details, writing migrations, and troubleshooting.

Frontend development

Run it

To run just the frontend (port 4200):

nx serve frontend

Project layout

Path What
src/containers/ Pages
src/components/ Shared components
src/api/ apiClient, the axios client. It attaches the Cognito access token when auth is on.
src/hooks/ Data hooks used by pages (import as @hooks/...)
src/auth/ Amplify and Cognito configuration
src/styles/tokens.css Design tokens from Figma
src/utils/ Helpers
src/providers.tsx App-wide providers (Chakra)

To add a page, add a new file in /src/containers/ then a route in src/app.tsx.

Tests

The frontend uses vitest and Testing Library. Put tests next to the code as *.spec.tsx. Tests for Chakra components should render with renderWithProviders from src/test/render.tsx, which wraps them in Providers.

# run all frontend tests
nx run frontend:test
# To run one file (example app.spec.tsx)
npx vitest run src/app.spec.tsx

Lint and format checking

# lint on frontend only
nx lint frontend
nx run frontend:typecheck

Frontend styles

Colors, type, spacing and radii from the Figma design system are CSS variables in apps/frontend/src/styles/tokens.css, loaded globally through src/styles.css. Use the semantic tokens in components, not the raw palette or hex values:

.card {
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-4);
}
.tile-value {
  font: var(--text-tile-number);
}

Named type styles (--text-page-title, --text-section-title, --text-body, --text-caption, --text-tile-number) are font shorthands. While nx serve frontend is running, http://localhost:4200/design shows every token for comparing against Figma.

Backend

Run it locally

Starts Postgres, the internal API and file uploads on http://localhost:3000. Needs Docker.

cp example.env .env                         # once; Nx loads .env into every task
nx run internal-serving-lambda:local:up     # start Postgres, migrate, seed, then serve the API
nx run internal-serving-lambda:local:down   # stop Postgres (Ctrl+C stops the API)

The API restarts when a source file changes. With Postgres already up, nx run internal-serving-lambda:serve starts just the API.

  • Signed-in user: every request runs as DEV_USER_ID from .env. The seed creates an admin (1) and a standard user (2 on a fresh database; docker exec db-db-1 psql -U postgres -c 'select id, email, status from users' shows the ids). Restart the API after changing .env.
  • Uploads: with LOCAL_UPLOAD_DIR set, POST /imports/upload-url/{kind} returns a http://localhost:3000/local-uploads/<key> URL, and a PUT to it saves the file in that folder. Unset it to use S3. Local uploads don't trigger the upload Lambda.
curl localhost:3000/health
curl -X POST localhost:3000/imports/upload-url/daily -d '{"fileName":"obs.csv"}'
# Send the file as text/csv, as S3 requires
curl -X PUT -H 'Content-Type: text/csv' --data-binary @obs.csv '<uploadUrl from the response>'
curl localhost:3000/imports

Tests

nx test internal-serving-lambda
# or run all three at once:
nx run-many -t test -p internal-serving-lambda upload-lambda public-lambda

Helpful commands

# check formatting and lint on the whole repo
yarn run prepush
# fix formatting and lint on the whole repo
yarn run prepush:fix

Run git submodule update --remote to pull the latest changes from the component library

When cloning the repo, make sure to add the --recurse-modules flag to also clone the component library submodule (e.g. git clone --recurse-submodules https://github.com/Code-4-Community/bho.git)

About

Blue Hill Observatory Repo

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages