8.2 KiB
AGENTS.md
Status
Scaffold is in place: Turborepo monorepo with apps/api, apps/web and packages/shared.
No CI, no database migrations and no product features yet.
Stack (source of truth: STACK.md)
- Monorepo orchestrated with Turborepo
- Backend: Bun + Hono, Prisma against Postgres, Zod for validation, Pino for logging
- Frontend: React + Vite + TypeScript, UI components from shadcn/ui
- Auth: BetterAuth
Conventions
- Package manager: Bun —
bun install,bun run <script>. Do not introduce npm/pnpm/yarn lockfiles. - Bun is configured with
minimumReleaseAge(see~/.bunfig.toml), so brand new releases are rejected during install. If a dependency fails to resolve, pin the newest version that is at least a few days old instead of reaching for the very latest. - Workspaces:
apps/api— Bun backend (Prisma schema + migrations live here)apps/web— React/Vite frontendpackages/shared— shared code (@superlist/shared: Result pattern, Problem Details helpers/types)
- Verification commands, run from the repo root:
bun run buildbun run lint→bun run typecheck→bun run test(in that order)
- Lint with Biome (
biome.jsonat the repo root, one config for every workspace):bun run lint(per-package via turbo),bun run lint:fix(apply safe fixes),bun run lint:ci(whole repo, for CI). - Format with Prettier (
bun run format). Biome's formatter and assist are deliberately disabled inbiome.jsonso the two tools never fight each other. apps/web/src/components/ui/**is excluded from Biome's recommended preset through anoverridesentry: those files are vendored shadcn/ui source and get regenerated by the CLI.- Generated files are gitignored and must never be edited by hand:
apps/web/src/routeTree.gen.ts,apps/api/src/generated/.
Backend architecture (Hono)
Endpoints are grouped into modules, and each module into features. Example: an alerts module with
features list, create, update, delete:
apps/api/src/modules/alerts/
list/
route.ts # Hono route declaration + Zod validation + call to the use case
use-case.ts # class with a single execute() method
create/
route.ts
use-case.ts
route.tsholds only the Hono route declaration, input validation (Zod), and the call to the use case'sexecute. No business logic, no DB access.- Business logic lives in a use case class with a single
executemethod (one class per feature), named after the action:ListAlerts,CreateAlert. Dependencies (e.g. the Prisma client) are injected through the constructor and instantiated in the route. - Use cases return the Result pattern (
Ok/Failurefrom@superlist/shared). Never throw for expected outcomes; reserve exceptions for truly unexpected failures. - Failures are Problem Details payloads built with the
problemsfactories from@superlist/shared(problems.notFound(...),problems.validation(...),problems.conflict(...), …). - Routes never check
result.okby hand: every route ends withresultJson(c, result), which serializesOkas JSON (200 by default, override with{ status: 201 }) and mapsFailureto the matching RFC 9457application/problem+jsonresponse.
// apps/api/src/modules/alerts/list/route.ts
import { validate } from '@/lib/validate'
import { resultJson } from '@/lib/result-json'
import { AlertQuerySchema } from './schema'
import { ListAlerts } from './use-case'
export const listAlertsRoute = new Hono<AppEnv>().get(
'/',
validate.query(AlertQuerySchema),
async (c) => {
const query = c.req.valid('query') // typed straight from the schema, no cast
const result = await new ListAlerts(prisma).execute(query)
return resultJson(c, result)
},
)
-
Validation always goes through
validate.*(validate.query,validate.json,validate.param,validate.header,validate.cookie,validate.form). It answers invalid input with a 422 Problem Details payload containing per-fielderrors. -
All responses follow RFC 9457 (Problem Details) — errors use the
application/problem+jsonmedia type withtype,title,status,detailfields. Problem builders live inpackages/shared/src/problem-details.ts; the HTTP helpers inapps/api/src/lib/. -
Zod is the only validation library. Define schemas next to the feature that uses them; share them through
@superlist/sharedonly when more than one module needs them. -
Logging: Pino — one shared logger in
apps/api/src/lib/logger.ts, reachable from handlers asc.get('logger'); neverconsole.login the backend. -
Unexpected throws are turned into Problem Details by
app.onErrorinapps/api/src/app.ts. -
Prisma: after changing the schema, run
bun run db:migrate(fromapps/api, orbun run db:migrateat the root) and commit the generated migration — never edit migration files by hand.
Frontend architecture (React + Vite)
apps/web/src/
routes/ # file-based TanStack Router routes; routeTree.gen.ts is generated
components/ui/ # shadcn/ui components (checked in, editable source)
components/layout # app shell: sidebar, header, user menu
hooks/ # query hooks (e.g. use-health.ts)
lib/ # api-client, auth-client, query-client, utils
- Routing: TanStack Router with file-based routes. Add a file under
src/routesand the route tree is regenerated (bun run routes:generate, also run bydev,buildandtypecheck). Never editrouteTree.gen.ts.(auth)/sign-in.tsx— public routes._authenticated/route.tsx— pathless layout for signed-in pages; it guards on the BetterAuth session and redirects to/sign-inwhen there is none.
- Server state: TanStack Query only. Never call
fetchfrom a component; add a hook undersrc/hooksthat exportsqueryOptions(<entity>QueryOptions()) plus ause<Entity>()wrapper, and useapiFetchfromsrc/lib/api-client.tsas thequeryFn. Exporting the options lets route loaders prefetch withcontext.queryClient.ensureQueryData(...)(the client is passed through the router context frommain.tsx). - Forms: React Hook Form + Zod (
zodResolver). Render errors with the shadcnField/FieldErrorcomponents — this registry version shipsfieldinstead of the olderformcomponent. - shadcn/ui: components live in
src/components/uiand are source, not generated output — edit them directly. Add new ones withcd apps/web && ../../node_modules/.bin/shadcn add <component>(this registry needs the@shadcn/prefix for some items, e.g.@shadcn/field). cncomes from thecnpackage;src/lib/utils.tsre-exports it for local imports.- Prefer small feature components over one large route file.
- Biome does not flag the
Routeexport of route files, so route files stay clean; only the vendoredcomponents/uifiles are exempted from the recommended preset.
This is NOT the Turborepo you know
Turborepo configuration, task behavior, and CLI commands can vary between installed versions and may differ from your training data. Resolve the turbo package from this file's directory or relevant workspace; in monorepos, it may not be visible from the repository root. For example, run node -p "require.resolve('turbo/package.json')" from a workspace that depends on turbo.
Read docs/README.md inside that installed package first, then read the relevant pages from its docs/ directory before changing Turborepo configuration or commands. Heed deprecation notices. These bundled docs match the installed package version and are available without network access.
This block is written and re-added by turbo before repository-scoped commands when an AI agent is detected. In the Turborepo source repository, its template is defined in crates/turborepo-cli/src/cli/agent_guidance.rs. Removing the managed block while updates are enabled means a later qualifying invocation will add it again. Set "agentGuidance": false in the root turbo.json or turbo.jsonc to opt out; this does not remove an existing block. Keep the block committed with your work to avoid an uncommitted change on the next agent invocation.