Skip to content
orbitsLabPublic

Repository files navigation

BudgetCap Web

Next.js front-end for BudgetCap, an envelope-budgeting application for households. The repository contains the authenticated app in apps/app and the marketing site in apps/www. The app owns no database connection: every account, budget, envelope and transaction is read and written through the BudgetCap API over HTTP.

Next.js React TypeScript NextAuth TanStack Query Biome

Contents

Requirements

Tool Version Notes
Node.js >= 22.12 engines.node in package.json
pnpm 11.17.0 Pinned via packageManager; enable with corepack enable
BudgetCap API This repo's sibling budgetcap-server Must be running; it owns PostgreSQL

The web app does not need Docker, PostgreSQL, DATABASE_URL, Prisma or bcrypt.

Quick start

The API and the web app run in two terminals. Start the API first.

# Terminal 1 — API (see budgetcap-server/README.md)
cd budgetcap-server
pnpm install
cp .env.example .env          # fill in the secrets
pnpm db:up
pnpm db:deploy                # apply the database migrations
pnpm db:generate
pnpm db:seed
pnpm dev
# Terminal 2 — web
cd budgetcap
corepack enable
pnpm install
cp apps/app/.env.example apps/app/.env.local
# fill AUTH_SECRET and OAUTH_EXCHANGE_SECRET, see below
pnpm dev

Open http://localhost:3001 for the landing page; the app is at /app/dashboard. Sign in with a seeded account such as priya@budgetcap.dev / secret123, or create a new account from /auth/signup.

Setup in detail

1. Install

cd budgetcap
corepack enable
pnpm install

pnpm install also runs husky, which installs the pre-commit hook. The hook runs Biome through lint-staged on staged .ts, .tsx, .js, .json and .css files.

2. Configure the environment

cp apps/app/.env.example apps/app/.env.local

Next.js loads apps/app/.env.local automatically. Fill in:

openssl rand -base64 48   # AUTH_SECRET
openssl rand -base64 48   # OAUTH_EXCHANGE_SECRET

AUTH_SECRET encrypts the NextAuth session cookie. OAUTH_EXCHANGE_SECRET must be identical to the value in budgetcap-server/.env; it is the shared secret the web server presents to POST /api/auth/oauth.

Google sign-in is optional. Leave AUTH_GOOGLE_ID and AUTH_GOOGLE_SECRET unset to keep it disabled; the sign-in buttons are hidden. To enable it, fill both variables and add this redirect URI in the Google console:

http://localhost:3001/api/auth/callback/google

3. Start the API first

curl http://localhost:8080/api/health

The response must say "database": "up". If it does not, fix the API before starting the web app; every login and data request depends on it.

4. Run the web app

pnpm dev

Turborepo starts both Next.js apps: the authenticated app on port 3001 and the marketing site on port 3000. To run only the authenticated app:

pnpm --filter app dev

5. Sign in

Use a seeded account, or register at http://localhost:3001/auth/signup. Registration creates the user and first household through the API, then sends you to /auth/signin.

Environment variables

All values live in apps/app/.env.local and are server-side only. No secret uses a NEXT_PUBLIC_ name.

Variable Required Default Description
AUTH_SECRET Yes — Minimum 32 characters; encrypts the NextAuth session cookie
AUTH_GOOGLE_ID No — Google OAuth client id; Google sign-in is enabled only when both Google variables are set
AUTH_GOOGLE_SECRET No — Google OAuth client secret
NEST_API_URL No http://127.0.0.1:8080 Base URL of the Nest API
OAUTH_EXCHANGE_SECRET Yes — Minimum 32 characters; must match budgetcap-server/.env

Restart the dev server after changing any value; Next.js does not hot-reload env files.

How authentication works

  • NextAuth runs a JWT session with no database adapter. The API tokens are stored only in the encrypted, httpOnly NextAuth cookie.
  • Credentials sign-in calls the API's POST /api/auth/login from the Next server. Google sign-in (when enabled) verifies the Google email, then calls the API's secret-guarded POST /api/auth/oauth.
  • Browser code calls same-origin /api/proxy/*. That route attaches the bearer token, refreshes it server-side when it is near expiry, and rewrites the session cookie.
  • localStorage holds only the display profile and the active household id; it never holds a token.
  • Logout revokes the API refresh token before clearing the cookie.

Money and currency

  • Each household picks one currency (INR, USD, EUR or GBP) during onboarding. It can't be changed later.
  • The API sends amounts as integer minor units (paise, cents, pence).
  • All conversion and formatting goes through apps/app/src/lib/currency.ts. Don't divide or multiply by 100 anywhere else.

To add a currency, add it on the API first (see the server README), then to the currencies list in lib/currency.ts and the starter amounts in components/onboarding/onboarding-wizard.tsx.

Scripts

Run these from the repository root:

Script Purpose
pnpm dev Start every workspace dev server (app on 3001, www on 3000)
pnpm build Build every workspace package
pnpm typecheck Type-check every workspace package
pnpm lint Run Biome over the repository
pnpm lint:fix Apply Biome fixes
pnpm check / pnpm check:fix Biome lint and format together
pnpm dev:server Start the sibling API in watch mode
pnpm server:build Build the sibling API
pnpm server:test Run the sibling API's tests

App-only commands:

pnpm --filter app dev
pnpm --filter app build
pnpm --filter app typecheck

Project structure

budgetcap/
├── apps/app/
│   ├── src/
│   │   ├── app/
│   │   │   ├── page.tsx         Landing page at /
│   │   │   ├── app/             Authenticated pages under /app, onboarding included
│   │   │   ├── auth/            Sign-in and sign-up pages under /auth
│   │   │   ├── api/auth/        NextAuth handlers
│   │   │   └── api/proxy/       Bearer-token proxy and server-side refresh
│   │   ├── actions/             Server actions (register, login, profile sync)
│   │   ├── components/          UI components and client pages
│   │   ├── hooks/               TanStack Query hooks and session helpers
│   │   ├── lib/                 API client, NextAuth config, session helpers
│   │   └── middleware.ts        Cookie-presence routing guard
│   └── public/                  Static files served from the site root
├── apps/www/                    Marketing site on port 3000 (source in src/)
└── packages/ui/                 Shared UI components

Verification

pnpm lint
pnpm typecheck
pnpm --filter app build

The web repository has no unit-test runner today. Check these by hand after a change:

  1. Credentials login with a seeded user.
  2. A budget page loading through /api/proxy.
  3. A forced access-token expiry (short JWT_ACCESS_TTL on the API) refreshing once and keeping the session.
  4. Logout revoking the refresh token (POST /api/auth/logout succeeds).
  5. Registration with a duplicate email showing the field error.

Troubleshooting

Symptom Cause and fix
"Budget server unreachable" on login The API is not running or NEST_API_URL is wrong. Check curl http://localhost:8080/api/health.
"Invalid email or password" with seed credentials The database was reset without seeding. Run pnpm db:seed in budgetcap-server.
Requests fail with 500 and the API logs a missing column The API database is behind. Run pnpm db:deploy and pnpm db:generate in budgetcap-server, then restart the API.
Instant logout or repeated 401s The API's JWT secrets changed or its database was reset. Sign in again.
Google button is missing Expected: set both AUTH_GOOGLE_ID and AUTH_GOOGLE_SECRET, then restart the dev server.
NextAuth reports a missing secret AUTH_SECRET is unset or shorter than 32 characters in apps/app/.env.local.
Changes to .env.local have no effect Restart pnpm dev; env files are read at startup.
Port 3001 already in use Stop the other process, or change the --port flag in apps/app/package.json.
Build fails on a missing API URL The build does not need the API; check that apps/app/.env.local is syntactically valid.

Documentation

  • API reference — request and response shapes, error format and rate limits
  • Server setup — database, seed users and API commands

Releases

Packages

Used by

Contributors

Languages