FriendChise Docs

Backend / API

API reference, architecture notes, and data documentation for FriendChise

FriendChise is a single Next.js app. There is no separate backend service. "Backend" here means everything under app/api, app/actions, lib/services, and prisma.

API reference

Architecture and internals

Shape of a write

Most state changes do not go through app/api. Instead:

  1. A client component calls a server action in app/actions/*.
  2. The action authenticates the caller (via lib/authz/action.ts), validates input, and calls into a service in lib/services/*.
  3. The service performs the actual database work (often in a transaction), writes an audit log entry where relevant, and returns a typed result.
  4. The action calls revalidatePath/redirects as needed for the UI.

app/api is reserved for cases a server action cannot cover: mobile authentication, bearer-token-scoped identity endpoints, org-scoped task routes (/api/orgs/[orgId]/tasks/*), mobile tool routes (/api/orgs/[orgId]/tools/scan-to-task/*), lazy-loading helpers (pagination, roster weeks, memberships), image and storage URL helpers, and account management.

Authorization

See Authentication for the full guard layer (lib/authz/api.ts, page.ts, action.ts) and RBAC for the permission model.