Moduły i use-case’y
Jak budujemy moduły funkcji i jak je wywołujemy.
Pełna treść jest utrzymywana po angielsku i może być uzupełniana sukcesywnie. Poniżej znajduje się lokalna wersja / mapa tej strony.
Module layout
Typical module (user, product, session, …):
modules/user/
user.types.ts
user.zod.ts / user.validations.ts
user.schema.ts
user.utils.ts
use-cases/
get-users.use-case.ts
…
__test__/Use-case pattern
Mutations are server actions built from the single actionClient with .use(withAuth(permission?)); reads are plain server functions (e.g. getUsers) that check getCurrentSession() + hasPermission inline — failing with unauthorized() / forbidden() (authInterrupts) — and keep their query in a "use cache" core. They:
- Enforce authz
- Call Better Auth admin APIs and/or Drizzle
- Return typed results; throw
AppErrorfor expected failures
Example domains today: account, user, session, two-factor, verification, product, category.
Calling from UI
- RSC:
await getUsers()(or equivalent) and render - Client: call the exported actions directly; translate failures with
useActionError()
Never put SQL in a client component.