# stefan-garofalo/foodwise architecture

> Architecture diagram of the GitHub repository stefan-garofalo/foodwise, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/stefan-garofalo/foodwise
- Repository: https://github.com/stefan-garofalo/foodwise

## Overview

Foodwise is a personal food-inventory web app intended to track expiration dates, reduce waste, and suggest recipes. The visible product workflow covers signing in, reaching protected settings, and managing user-specific categories; the API and database provide the supporting settings and category operations. The README documents inventory and recipe capabilities, but the supplied source excerpts do not show their runtime workflows, so only the ingredient data model is represented. Edges are limited to documented or indexed references and explicit excerpts; backend routing details are not shown.

Main entry points: [`packages/api/src/trpc/context.ts`](https://github.com/stefan-garofalo/foodwise/blob/main/packages/api/src/trpc/context.ts) (API context), [`packages/db/src/client.ts`](https://github.com/stefan-garofalo/foodwise/blob/main/packages/db/src/client.ts) (Database client), [`packages/auth/src/server.ts`](https://github.com/stefan-garofalo/foodwise/blob/main/packages/auth/src/server.ts) (Authentication), [`apps/backend/src/index.ts`](https://github.com/stefan-garofalo/foodwise/blob/main/apps/backend/src/index.ts) (Backend API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web experience"]
  node_login["Login page<br/>[page.tsx]"]
  node_authroute["Auth route<br/>[route.ts]"]
  node_protected["Protected app<br/>[page.tsx]"]
  node_categoryui["Category settings UI<br/>[page.tsx]"]
  node_categoryform["Category create form<br/>[index.tsx]"]
  node_trpcserver["Server tRPC client<br/>[server.tsx]"]
  node_trpcclient["tRPC transport<br/>[clients.ts]"]
  node_foodcapabilities["Inventory and recipes"]
end

subgraph group_identity["Identity"]
  node_auth["Authentication<br/>[server.ts]"]
  node_authstore[("Auth database")]
end

subgraph group_api["API services"]
  node_backend["Backend API<br/>[index.ts]"]
  node_context["API context<br/>[context.ts]"]
  node_userservice["User settings service<br/>[service.ts]"]
  node_usersrepo["User settings repository<br/>[repository.ts]"]
  node_settingsrouter["Settings router<br/>[router.ts]"]
  node_categoryrouter["Category router<br/>[router.ts]"]
  node_categoryservice["Category service<br/>[service.ts]"]
  node_categoryrepo["Category repository<br/>[repository.ts]"]
  node_crud["Generic CRUD<br/>[service.ts]"]
end

subgraph group_data["Data model"]
  node_dbclient["Database client<br/>[client.ts]"]
  node_settingschema["User settings schema<br/>[categories.ts]"]
  node_ingredients["Ingredient schema<br/>[ingredients.ts]"]
  node_database[("SQLite database")]
end

node_user(("Foodwise user"))

node_user -->|"signs in"| node_login
node_login -.->|"submits auth"| node_authroute
node_authroute -.->|"handles auth"| node_auth
node_auth -->|"uses LibSQL"| node_authstore
node_user -.->|"uses app"| node_protected
node_protected -.->|"opens settings"| node_categoryui
node_categoryui -.->|"offers create"| node_categoryform
node_trpcserver -->|"creates context"| node_context
node_trpcserver -->|"targets API"| node_backend
node_backend -->|"uses auth"| node_auth
node_backend -->|"uses API"| node_context
node_context -->|"uses database"| node_dbclient
node_context -->|"checks sessions"| node_auth
node_settingsrouter -->|"registers categories"| node_categoryrouter
node_settingsrouter -->|"builds procedures"| node_crud
node_categoryrouter -->|"routes calls"| node_categoryservice
node_categoryservice -->|"delegates create"| node_categoryrepo
node_categoryrepo -->|"loads settings"| node_usersrepo
node_categoryrepo -->|"creates category"| node_crud
node_userservice -->|"reads settings"| node_usersrepo
node_usersrepo -->|"queries settings"| node_dbclient
node_dbclient -->|"loads schemas"| node_settingschema
node_dbclient -.->|"connects"| node_database
node_settingschema -->|"relates categories"| node_ingredients
node_foodcapabilities -.->|"documents inventory"| node_ingredients
node_foodcapabilities -->|"serves"| node_user

click node_login "https://github.com/stefan-garofalo/foodwise/blob/main/apps/frontend/app/%5Blang%5D/(public)/login/page.tsx"
click node_auth "https://github.com/stefan-garofalo/foodwise/blob/main/packages/auth/src/server.ts"
click node_authroute "https://github.com/stefan-garofalo/foodwise/blob/main/apps/frontend/app/api/auth/%5B...all%5D/route.ts"
click node_protected "https://github.com/stefan-garofalo/foodwise/blob/main/apps/frontend/app/%5Blang%5D/(protected)/page.tsx"
click node_categoryui "https://github.com/stefan-garofalo/foodwise/blob/main/apps/frontend/app/%5Blang%5D/(protected)/settings/categories/page.tsx"
click node_categoryform "https://github.com/stefan-garofalo/foodwise/blob/main/apps/frontend/features/users/settings/categories/create/form/index.tsx"
click node_trpcserver "https://github.com/stefan-garofalo/foodwise/blob/main/apps/frontend/modules/trpc/server.tsx"
click node_trpcclient "https://github.com/stefan-garofalo/foodwise/blob/main/apps/frontend/modules/trpc/lib/clients.ts"
click node_backend "https://github.com/stefan-garofalo/foodwise/blob/main/apps/backend/src/index.ts"
click node_context "https://github.com/stefan-garofalo/foodwise/blob/main/packages/api/src/trpc/context.ts"
click node_userservice "https://github.com/stefan-garofalo/foodwise/blob/main/packages/api/src/features/users/service.ts"
click node_usersrepo "https://github.com/stefan-garofalo/foodwise/blob/main/packages/api/src/features/users/repository.ts"
click node_settingsrouter "https://github.com/stefan-garofalo/foodwise/blob/main/packages/api/src/features/users/modules/settings/router.ts"
click node_categoryrouter "https://github.com/stefan-garofalo/foodwise/blob/main/packages/api/src/features/users/modules/settings/modules/categories/router.ts"
click node_categoryservice "https://github.com/stefan-garofalo/foodwise/blob/main/packages/api/src/features/users/modules/settings/modules/categories/service.ts"
click node_categoryrepo "https://github.com/stefan-garofalo/foodwise/blob/main/packages/api/src/features/users/modules/settings/modules/categories/repository.ts"
click node_crud "https://github.com/stefan-garofalo/foodwise/blob/main/packages/api/src/lib/crud/service.ts"
click node_dbclient "https://github.com/stefan-garofalo/foodwise/blob/main/packages/db/src/client.ts"
click node_settingschema "https://github.com/stefan-garofalo/foodwise/blob/main/packages/db/src/schema/users/settings/categories.ts"
click node_ingredients "https://github.com/stefan-garofalo/foodwise/blob/main/packages/db/src/schema/ingredients.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_login,node_authroute,node_protected,node_categoryui,node_categoryform,node_trpcserver,node_trpcclient,node_foodcapabilities,node_user toneBlue
class node_auth,node_authstore toneAmber
class node_backend,node_context,node_userservice,node_usersrepo,node_settingsrouter,node_categoryrouter,node_categoryservice,node_categoryrepo,node_crud toneMint
class node_dbclient,node_settingschema,node_ingredients,node_database toneRose
```

## Components

### Web experience

- [Login page](https://github.com/stefan-garofalo/foodwise/blob/main/apps/frontend/app/%5Blang%5D/(public)/login/page.tsx): `apps/frontend/app/[lang]/(public)/login/page.tsx`
- [Auth route](https://github.com/stefan-garofalo/foodwise/blob/main/apps/frontend/app/api/auth/%5B...all%5D/route.ts): `apps/frontend/app/api/auth/[...all]/route.ts`
- [Protected app](https://github.com/stefan-garofalo/foodwise/blob/main/apps/frontend/app/%5Blang%5D/(protected)/page.tsx): `apps/frontend/app/[lang]/(protected)/page.tsx`
- [Category settings UI](https://github.com/stefan-garofalo/foodwise/blob/main/apps/frontend/app/%5Blang%5D/(protected)/settings/categories/page.tsx): `apps/frontend/app/[lang]/(protected)/settings/categories/page.tsx`
- [Category create form](https://github.com/stefan-garofalo/foodwise/blob/main/apps/frontend/features/users/settings/categories/create/form/index.tsx): `apps/frontend/features/users/settings/categories/create/form/index.tsx`
- [Server tRPC client](https://github.com/stefan-garofalo/foodwise/blob/main/apps/frontend/modules/trpc/server.tsx): `apps/frontend/modules/trpc/server.tsx`
- [tRPC transport](https://github.com/stefan-garofalo/foodwise/blob/main/apps/frontend/modules/trpc/lib/clients.ts): `apps/frontend/modules/trpc/lib/clients.ts`
- **Inventory and recipes**

### Identity

- [Authentication](https://github.com/stefan-garofalo/foodwise/blob/main/packages/auth/src/server.ts): `packages/auth/src/server.ts`
- **Auth database**

### API services

- [Backend API](https://github.com/stefan-garofalo/foodwise/blob/main/apps/backend/src/index.ts): `apps/backend/src/index.ts`
- [API context](https://github.com/stefan-garofalo/foodwise/blob/main/packages/api/src/trpc/context.ts): `packages/api/src/trpc/context.ts`
- [User settings service](https://github.com/stefan-garofalo/foodwise/blob/main/packages/api/src/features/users/service.ts): `packages/api/src/features/users/service.ts`
- [User settings repository](https://github.com/stefan-garofalo/foodwise/blob/main/packages/api/src/features/users/repository.ts): `packages/api/src/features/users/repository.ts`
- [Settings router](https://github.com/stefan-garofalo/foodwise/blob/main/packages/api/src/features/users/modules/settings/router.ts): `packages/api/src/features/users/modules/settings/router.ts`
- [Category router](https://github.com/stefan-garofalo/foodwise/blob/main/packages/api/src/features/users/modules/settings/modules/categories/router.ts): `packages/api/src/features/users/modules/settings/modules/categories/router.ts`
- [Category service](https://github.com/stefan-garofalo/foodwise/blob/main/packages/api/src/features/users/modules/settings/modules/categories/service.ts): `packages/api/src/features/users/modules/settings/modules/categories/service.ts`
- [Category repository](https://github.com/stefan-garofalo/foodwise/blob/main/packages/api/src/features/users/modules/settings/modules/categories/repository.ts): `packages/api/src/features/users/modules/settings/modules/categories/repository.ts`
- [Generic CRUD](https://github.com/stefan-garofalo/foodwise/blob/main/packages/api/src/lib/crud/service.ts): `packages/api/src/lib/crud/service.ts`

### Data model

- [Database client](https://github.com/stefan-garofalo/foodwise/blob/main/packages/db/src/client.ts): `packages/db/src/client.ts`
- [User settings schema](https://github.com/stefan-garofalo/foodwise/blob/main/packages/db/src/schema/users/settings/categories.ts): `packages/db/src/schema/users/settings/categories.ts`
- [Ingredient schema](https://github.com/stefan-garofalo/foodwise/blob/main/packages/db/src/schema/ingredients.ts): `packages/db/src/schema/ingredients.ts`
- **SQLite database**

### Other components

- **Foodwise user**

## Connections

- Foodwise user → Login page: signs in (evidence: `apps/frontend/app/[lang]/(public)/login/page.tsx`)
- Login page → Auth route: submits auth
- Auth route → Authentication: handles auth
- Authentication → Auth database: uses LibSQL (evidence: `packages/auth/src/server.ts`)
- Foodwise user → Protected app: uses app
- Protected app → Category settings UI: opens settings
- Category settings UI → Category create form: offers create
- Server tRPC client → API context: creates context (evidence: `apps/frontend/modules/trpc/server.tsx`)
- Server tRPC client → Backend API: targets API
- Backend API → Authentication: uses auth
- Backend API → API context: uses API
- API context → Database client: uses database (evidence: `packages/api/src/trpc/context.ts`)
- API context → Authentication: checks sessions (evidence: `packages/api/src/trpc/context.ts`)
- Settings router → Category router: registers categories (evidence: `packages/api/src/features/users/modules/settings/router.ts`)
- Settings router → Generic CRUD: builds procedures (evidence: `packages/api/src/features/users/modules/settings/router.ts`)
- Category router → Category service: routes calls (evidence: `packages/api/src/features/users/modules/settings/modules/categories/router.ts`)
- Category service → Category repository: delegates create (evidence: `packages/api/src/features/users/modules/settings/modules/categories/service.ts`)
- Category repository → User settings repository: loads settings (evidence: `packages/api/src/features/users/modules/settings/modules/categories/repository.ts`)
- Category repository → Generic CRUD: creates category (evidence: `packages/api/src/features/users/modules/settings/modules/categories/repository.ts`)
- User settings service → User settings repository: reads settings (evidence: `packages/api/src/features/users/service.ts`)
- User settings repository → Database client: queries settings (evidence: `packages/api/src/features/users/repository.ts`)
- Database client → User settings schema: loads schemas (evidence: `packages/db/src/client.ts`)
- Database client → SQLite database: connects
- User settings schema → Ingredient schema: relates categories (evidence: `packages/db/src/schema/users/settings/categories.ts`)
- Inventory and recipes → Ingredient schema: documents inventory (evidence: `README.md`)
- Inventory and recipes → Foodwise user: serves (evidence: `README.md`)
