Install Node directly or using NVM
https://nodejs.org/en/download
Please use verison 24. If you do node --version and it doesn't show 24, please keep trying until it uses the correct version.
Do npm --version to confirm you have npm.
Install dependencies with Yarn using the repo’s pinned version:
npm exec --yes yarn@1.22.19 installYou 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).
Because I am using a Windows computer and I know many of you use Macs, we are doing to run things using containers in order to reduce cross-OS friction.
Please download Docker Desktop https://www.docker.com/products/docker-desktop/
This repo now includes Dockerfiles for both the backend and frontend so you can run those services in containers.
Make your own env file based off of example.env
Determine your postgres password. It is best to use numbers, letters, and the followign characters ".", "-", and "_" using any other special characters will give you a headache.
Since it is just for local development, you can fill in whatever password you want. Please fill it in the env.
Every variable in .env must be filled in. Env vars are validated at startup, so the backend, yarn migration:run, and the frontend Docker build fail with an error naming any variable that is missing or blank.
This project uses PostgreSQL. You'll need a running Postgres instance before starting the backend.
On Docker Desktop for Windows/macOS, use host.docker.internal in .env so the backend container can reach the Postgres container on the host machine.
docker run --name proj-fh-db \
--env-file .env \
-p 5432:5432 \
-d postgres:18-alpineYou can keep this container running forever if you want.
We will not be using PgAdmin on this team - the reason is because PgAdmin is so slow that I've seen it take a whole 5 minutes to startup on computers. Not only is connecting to PSQL using the terminal much faster, but it is a much more marketable skill than relying on the PgAdmin UI as a clutch.
To connect to your database, let's install the PSQL cli:
https://www.postgresql.org/download/
JUST SELECT the command line tools and unselect everything else. Then add the /bin folder to your environmental varables.
Install Postgres 18.
Run migrations:
yarn migration:runTo generate a new migration after changing entities:
name=your_migration_name yarn migration:generateWindows users: The
name=...syntax above only works on Mac/Linux. On Windows, runset name=your_migration_name && yarn migration:generatein Command Prompt, or$env:name="your_migration_name"; yarn migration:generatein PowerShell.
To revert the most recent migration:
yarn migration:revertSeed sample data (optional, development only):
After running migrations, fill your local database with fictional resources and users:
POSTGRES_HOST=localhost yarn seedWindows users: In PowerShell, run
$env:POSTGRES_HOST="localhost"; yarn seed.
- The seed refuses to run unless
POSTGRES_HOSTislocalhost,127.0.0.1, orhost.docker.internal, so it can't touch a remote database. - It inserts sample users (5 admins, 5 community staff, 5 patients) with
@c4cneu.comemails, plus sample resources. - It is safe to run again. Each run truncates all resources and scores, and replaces the seed users (matched by exact email). Other users and all tags are left untouched.
- User ids come from the database, so seeding never collides with other users.
- Seed users exist only in the database, not in Cognito. To sign in as one, create a matching Cognito account with the same email.
Build and run the containers from the repo root.
docker run --name proj-fh-db \
--env-file .env \
-p 5432:5432 \
-d postgres:18-alpineThe backend and the frontend imaged both start from the same base image that holds the projects baseline dependencies. Build it once from the repo root, before building either the frontend or the backend:
docker build -f Dockerfile.base -t fh-base:latest .The base image is local-only. It is not pushed anywehre, so every dev has to build it on their own machine.
Rebuild the base image (re-run the same command) when:
yarn.lockchanges onmain, for example after you pull new changes.- your builds start failing because of missing dependencies.
If you see "pull access denied" or "not found" for fh-base: you haven't built the base image yet. Because fh-base only exists on your machine, Docker doesn't find it locally and tries to pull it from Docker Hub, where it doesn't exist, so the build fails with an error like:
pull access denied, repository does not exist or may require authorization
The fix is to build the base image first, then re-run the frontend/backend build:
docker build -f Dockerfile.base -t fh-base:latest .docker build -f apps/backend/Dockerfile -t proj-fh-backend .
docker run --rm -it \
--env-file .env \
-p 3000:3000 \
--name proj-fh-backend \
proj-fh-backend
.envshould usePOSTGRES_HOST=host.docker.internalwhen running the backend inside Docker on Windows/macOS. That lets the container reach the Postgres instance published on port 5432.
Features that create or delete staff accounts call the Cognito admin APIs, so the backend needs your personal AWS access key. AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY are required backend env vars like the others.
-
Your IAM user already has permission to call the Cognito admin APIs on the project's user pool, so you do not need any extra access.
-
In the AWS console, go to IAM > Users > your user > Security credentials > Create access key (choose the CLI use case). Use your own key and never share it.
-
Add the key to your local
.env(it is gitignored; never commit keys):AWS_ACCESS_KEY_ID=<your access key id> AWS_SECRET_ACCESS_KEY=<your secret access key>--env-file .envpasses them into the container, and the AWS SDK picks them up automatically. The backend reads the region fromREGIONand the pool fromAUTH_COGNITO_USER_POOL_ID. -
Restart the backend container.
To check that your key works, run aws cognito-idp admin-get-user --user-pool-id <pool id> --username <email> with your credentials. Because the pool is shared, test with throwaway addresses.
Vite bakes the VITE_ variables into the frontend at build time, and .env is not copied into the image, so pass them as build args. The build fails if any are missing.
macOS (reads the values from .env):
(set -a; . ./.env; set +a; docker build -f apps/frontend/Dockerfile -t proj-fh-frontend \
--build-arg VITE_API_BASE_URL \
--build-arg VITE_COGNITO_USER_POOL_ID \
--build-arg VITE_COGNITO_APP_CLIENT_ID .)Windows - copy the values from your .env:
docker build -f apps/frontend/Dockerfile -t proj-fh-frontend `
--build-arg VITE_API_BASE_URL=http://localhost:3000 `
--build-arg VITE_COGNITO_USER_POOL_ID=<value from .env> `
--build-arg VITE_COGNITO_APP_CLIENT_ID=<value from .env> .Then run it:
docker run --rm -it \
-p 4200:80 \
--name proj-fh-frontend \
proj-fh-frontendOpen your browser and navigate to http://localhost:4200/.
Rebuilding the frontend image on every change is slow. While working on the frontend, run only the backend and database in Docker (steps 1-3 above) and serve the frontend locally with Vite's dev server, which hot-reloads on save.
- Complete steps 1-3 above so the database and backend container are running (backend on http://localhost:3000).
- Make sure
.envin the repo root contains theVITE_variables, e.g.VITE_API_BASE_URL=http://localhost:3000. The dev server reads them from.envat startup, so no build args are needed. Restart the dev server after changing them. - Do not run the frontend container (step 4); it would conflict on port 4200.
- From the repo root, start the dev server:
npx nx serve frontendOpen http://localhost:4200/. Frontend edits appear in the browser immediately without a rebuild. You only need to rebuild the backend image when you change backend code.
Use the Docker containers above for normal development. If you need to run a task locally for debugging, use the repo's existing nx commands only temporarily.
All env vars are read through one utility per app, never through process.env or import.meta.env directly:
| App | Utility | Which vars | Example |
|---|---|---|---|
| Backend | apps/backend/src/utils/env.ts |
Everything without the VITE_ prefix |
envUtility.POSTGRES_PORT |
| Frontend | apps/frontend/src/utils/env.ts |
Everything with the VITE_ prefix |
envUtility.VITE_API_BASE_URL |
Each utility validates its variables as soon as it is imported. If any are missing, blank, or the wrong format, the app stops with one error that lists every bad variable by name (never by value).
Never put secrets in a
VITE_variable. Vite copies everyVITE_value into the JavaScript sent to the browser, where anyone can read it.
-
Front or Backend? If the browser needs it (and it is safe to be public), prefix it with
VITE_and use the frontend utility. Otherwise, no prefix, backend utility. -
Add it to
example.envwith a short comment and also your own local .env -
Add it to the schema (
backendEnvSchemaorfrontendEnvSchema) with one of the validators defined right above it. The validator decides both what counts as valid and the TypeScript type you get back:Validator App Accepts Type requiredStringboth any non-empty text (trimmed) stringportbackend whole number 1-65535 numberbooleanFlagbackend true/false,1/0,yes/no,on/offbooleanurlfrontend http://orhttps://URLstring
The following is an example of adding the env var REDIS_PORT:
const backendEnvSchema = zod.object({
// ...existing vars
REDIS_PORT: port,
});If none fits, add a new validator next to the others, built on requiredString so it stays required. For example:
export const logLevel = requiredString.pipe(zod.enum(['debug', 'info', 'warn', 'error']));- Use it as
envUtility.REDIS_PORT. - Update the tests. Add it to
validEnvin that either the back or frontend'sutils/env.spec.ts. In any other spec that mocks the utility (jest.mock('.../utils/env', ...)) and uses the new variable, add it to the mock object. - Frontend only: add it to the Docker build. In
apps/frontend/Dockerfile, add anARG, anENVline, and the name to the missing-args check. Then add a--build-argfor it to both frontend build commands above. - Tell the team in your PR to add the new variable to their own
.env. Until they do, their app will fail at startup naming it.