How zubayer-hossain/household-finance works
1. This is a Next.js 15 App Router application backed by Supabase. The repo is a household-first budgeting MVP, with a clear split between public auth flows, an onboarding path, and the authenticated app area.
2. The route structure is intentionally segmented:
- src/app/(public)-style pages for login, signup, password reset, invite acceptance, and callback handling
- src/app/onboarding for first-time household setup
- src/app/app for the authenticated workspace, including dashboard, household, members, transactions, categories, and budgets
- src/app/api/household/* for server-only household invite utilities
3. Authentication and session handling are isolated in src/features/auth. That feature owns forms, session listeners, profile fetching, password setup for invite flows, and auth guards/redirect components. It uses the Supabase client split in src/services/supabase-browser.ts, supabase-server.ts, and supabase-middleware.ts depending on whether code runs in the browser, server, or middleware.
4. The household subsystem is the core domain boundary. It covers household creation, membership management, member rosters, invite workflows, permission gates, onboarding/bootstrap UI, and deletion/rename flows. The invite lifecycle has a server-side helper for sending mail and an API layer for invite, resend, and invited-name updates. There is also a shared library for finalizing pending household invites.
5. Feature modules follow a consistent layered shape:
- components for UI composition
- hooks for query/mutation orchestration
- services for Supabase/RPC access
- schemas for validation
- lib for domain calculations and selectors
- tests for logic and policy coverage
This makes the architecture easy to diagram as UI → hooks → services → Supabase/database.
6. Budgets is the largest product module. It includes index/detail routes, budget summary and category cards, health/status indicators, permission gates, monthly close, approval, reallocation, and adjustment flows. The lib layer holds budget aggregates, selectors, and health calculations, while the tests focus on permissions, reallocation, adjustment, and derived-state correctness.
7. Categories is a separate household-level domain. It handles category CRUD, archive/unarchive, reorder, draft-budget cleanup, and templates/prefill behavior. The feature includes its own permission gates, lifecycle dialogs, and a dedicated service layer, which suggests categories are a foundational model shared by later budgeting flows.
8. Transactions is another major subsystem and is more interaction-heavy than the others. It supports transaction lists, filtering, create/edit/delete, detail sheets, quick-add expense UI, category assignment, and attachment upload/delete. The attachment flow is likely backed by Supabase Storage, while transaction permissions and list statistics live in the feature’s lib and tests.
9. Dashboard and shell are cross-cutting presentation layers. src/components/shell provides the authenticated app chrome: desktop nav, mobile bottom nav, header, logo link, profile menu, and shell content layout. The dashboard feature is mostly derived stats and route composition, feeding a simple landing view inside the authenticated area.
10. Shared infrastructure and utilities live outside the product features:
- src/lib for formatting, query keys, timeout helpers, and invite finalization
- src/components/ui for reusable primitives and dialogs
- src/stores for small app-level UI state
- src/app/providers.tsx for top-level client providers
These are the main shared boundaries allowed to cross feature lines.
11. The database layer is designed around Supabase migrations and server-enforced rules. The supabase/migrations/ folder contains schema creation, RLS policies, security-definer helpers, and RPCs for household creation/listing/deletion, membership roster access, invite finalization, and private enforcement. Several migrations also show domain logic pushed into the database rather than the client.
12. A key architectural constraint is enforced by linting and folder boundaries: auth and household are not supposed to import each other directly. Cross-feature coupling is meant to go through shared libs/components or route/API layers. That is important for drawing the diagram: each feature is a bounded context, with Supabase and app routes acting as the integration points.
13. Tests are colocated with feature logic and mostly validate domain rules, permissions, selectors, and derived calculations rather than full end-to-end flows. That suggests the architecture relies on modular business logic in services/lib files, with UI as a relatively thin layer over the domain.
Main entry points: page.tsx Workspace · supabase-client.ts Supabase clients · layout.tsx Root app · HouseholdBootstrap.tsx Household
Components 20
App Router
Next.js route boundaries for public auth, onboarding, workspace, and API flows.
- Root app · Top-level layout, providers, and global routing entrypoints.
src/app/layout.tsx - Public auth · Login, signup, password reset, callback, and invite password setup.
src/app/login/page.tsx - Onboarding · First-time household setup flow.
src/app/onboarding/page.tsx - Workspace · Authenticated app area for dashboard, household, members, budgets, categories, and transactions.
src/app/app/page.tsx - Household API · Server-only invite, resend, and invited-name update endpoints.
src/app/api/household/invite/route.ts
Feature Modules
Bounded contexts for auth, household, budgets, categories, dashboard, and transactions.
- Auth · Session handling, auth forms, guards, and profile loading.
src/features/auth/components/AuthGuard.tsx - Household · Household creation, membership, onboarding bootstrap, invites, and permission gates.
src/features/household/components/HouseholdBootstrap.tsx - Budgets · Budget views, health, approvals, reallocation, and monthly close.
src/features/budgets/components/BudgetsRouteIndex.tsx - Categories · Category CRUD, lifecycle controls, reorder, and draft-budget cleanup.
src/features/categories/components/CategoriesRoute.tsx - Transactions · Transaction lists, filtering, editing, category assignment, and attachments.
src/features/transactions/components/TransactionsRoute.tsx - Dashboard · Derived summary stats and the authenticated landing view.
src/features/dashboard/components/DashboardRoute.tsx
Shared Infra
Reusable shell, UI primitives, app state, and Supabase client wrappers.
- App shell · Authenticated navigation, header, profile menu, and shell layout.
src/components/shell/AppShell.tsx - UI kit · Reusable buttons, dialogs, forms, and other shared UI building blocks.
src/components/ui/button.tsx - Supabase clients · Browser, server, middleware, and shared Supabase access wrappers.
src/services/supabase-client.ts - Shared lib · Formatting, query keys, timeout helpers, and pending invite finalization.
src/lib/finalize-pending-household-invites.ts
Supabase
Database migrations, RLS, RPCs, and server-enforced domain rules.
- Migrations · Schema, RLS, security-definer helpers, and RPC/domain logic in Postgres.
supabase/migrations/20260202120000_household_finance_foundation.sql - Auth & RLS · Profile, membership, household, and private-enforcement policies and RPCs.
supabase/migrations/20260502153000_onboarding_profile_and_membership_rls.sql - Household RPCs · Create/list/delete household and membership roster helpers.
supabase/migrations/20260506194500_delete_my_household_rpc.sql - Invite finalize · Invite finalization and roster-access helpers for pending household invites.
supabase/migrations/20260511120000_finalize_pending_household_invites_rpc.sql - Category budget SQL · Draft-budget cleanup and transaction-category related domain rules.
supabase/migrations/20260520120000_household_categories_draft_budget_delete.sql
Connections 26
- Root app → Public auth: routes · Public pages mount through the root Next app.
- Root app → Onboarding: routes · Onboarding is a dedicated route segment.
- Root app → Workspace: routes · Authenticated workspace routes live under the app area.
- Root app → Household API: api · Route handlers are exposed from the same app tree.
- Workspace → App shell: uses · Workspace pages render inside the authenticated shell.
- Public auth → Auth: uses · Login, signup, reset, callback, and invite flows are handled by auth feature components.
- Onboarding → Household: uses · Household bootstrap and onboarding guard drive first-run setup.
- Workspace → Dashboard: uses · Workspace landing composes dashboard stats.
- Workspace → Household: uses · Household settings and members screens are built from the household feature.
- Workspace → Budgets: uses · Budgets route composes the budgeting feature.
- Workspace → Categories: uses · Categories route composes the categories feature.
- Workspace → Transactions: uses · Transactions route composes the transaction feature.
- Auth → Supabase clients: data · Auth state, profile queries, and session listeners use Supabase adapters.
- Household → Supabase clients: data · Household membership and invite flows query Supabase through service wrappers.
- Budgets → Supabase clients: data · Budget hooks and services read/write through Supabase.
- Categories → Supabase clients: data · Category CRUD and draft-budget operations use Supabase services.
- Transactions → Supabase clients: data · Transactions and attachment flows use Supabase and storage-backed services.
- Dashboard → Shared lib: calc · Dashboard stats rely on shared utilities and selectors.
- Household API → Shared lib: invites · Invite endpoints use shared pending-invite finalization and mail helpers.
- Shared lib → Invite finalize: supports · Shared invite finalization mirrors database-level invite RPC behavior.
- Supabase clients → Migrations: connects · Client adapters are constrained by the migrated schema and RLS rules.
- Auth → Auth & RLS: governed by · Session/profile behavior depends on auth and membership policies.
- Household → Household RPCs: governed by · Creation, listing, deletion, and roster access are backed by household RPCs.
- Household API → Invite finalize: server flow · Invite routes coordinate with invite finalization and membership helpers.
- Transactions → Category budget SQL: governed by · Transaction/category behavior depends on SQL rules for category cleanup and posting.
- Budgets → Category budget SQL: governed by · Budget lifecycle and category interactions depend on database-enforced rules.