|
1 | | -# Repository Contribution Guidelines |
| 1 | +## Onlook Agents Guide |
2 | 2 |
|
3 | | -This file contains instructions for automated agents interacting with the Onlook repository. |
| 3 | +Actionable rules for repo agents—keep diffs minimal, safe, token‑efficient. |
4 | 4 |
|
5 | | -## Commit Requirements |
6 | | -- Run `bun format` to ensure consistent formatting. |
7 | | -- Run `bun lint` and `bun test` for any packages you modify. Tests may require running `bun install` first. |
8 | | -- Use clear, descriptive commit messages. |
| 5 | +### Purpose & Scope |
9 | 6 |
|
10 | | -## Pull Request Guidelines |
11 | | -- Use `.github/pull_request_template.md` when creating PRs. |
12 | | -- Link related issues using GitHub keywords like `closes #123`. |
13 | | -- Provide a concise summary of the changes and any relevant testing steps. |
| 7 | +- Audience: automated coding agents working within this repository. |
| 8 | +- Goal: small, correct diffs aligned with the project’s architecture. |
| 9 | +- Non-goals: editing generated artifacts, lockfiles, or `node_modules`. |
14 | 10 |
|
15 | | -## Additional Notes |
16 | | -- Follow the [CODE_OF_CONDUCT.md](CODE_OF_CONDUCT.md) and [CONTRIBUTING.md](CONTRIBUTING.md) documents. |
17 | | -- If tests fail due to missing dependencies or environment limitations, note this in the PR description. |
| 11 | +### Repo Map |
| 12 | + |
| 13 | +- Monorepo managed by Bun workspaces (see root `package.json`). |
| 14 | +- App: `apps/web/client` (Next.js App Router + TailwindCSS). |
| 15 | +- API routes: `apps/web/client/src/server/api/routers/*`, aggregated in |
| 16 | + `apps/web/client/src/server/api/root.ts`. |
| 17 | +- Shared utilities: `packages/*` (e.g., `packages/utility`). |
| 18 | + |
| 19 | +### Stack & Runtimes |
| 20 | + |
| 21 | +- UI: Next.js App Router, TailwindCSS. |
| 22 | +- API: tRPC + Zod (`apps/web/client/src/server/api/*`). |
| 23 | + |
| 24 | +### Agent Priorities |
| 25 | + |
| 26 | +- Correctness first: minimal scope and targeted edits. |
| 27 | +- Respect client/server boundaries in App Router. |
| 28 | +- Prefer local patterns and existing abstractions; avoid one-off frameworks. |
| 29 | +- Do not modify build outputs, generated files, or lockfiles. |
| 30 | +- Use Bun for all scripts; do not introduce npm/yarn. |
| 31 | +- Avoid running the local dev server in automation contexts. |
| 32 | +- Respect type safety and |
| 33 | + |
| 34 | +### Next.js App Router |
| 35 | + |
| 36 | +- Default to Server Components. Add `use client` when using events, |
| 37 | + state/effects, browser APIs, or client-only libs. |
| 38 | +- App structure: `apps/web/client/src/app/**` (`page.tsx`, `layout.tsx`, |
| 39 | + `route.ts`). |
| 40 | +- Client providers live behind a client boundary (e.g., |
| 41 | + `apps/web/client/src/trpc/react.tsx`). |
| 42 | +- Example roots: `apps/web/client/src/app/layout.tsx` (RSC shell, providers |
| 43 | + wired, scripts gated by env). |
| 44 | +- Components using `mobx-react-lite`'s `observer` must be client components |
| 45 | + (include `use client`). |
| 46 | + |
| 47 | +### tRPC API |
| 48 | + |
| 49 | +- Routers live in `apps/web/client/src/server/api/routers/**` and must be |
| 50 | + exported from `apps/web/client/src/server/api/root.ts`. |
| 51 | +- Use `publicProcedure`/`protectedProcedure` from |
| 52 | + `apps/web/client/src/server/api/trpc.ts`; validate inputs with Zod. |
| 53 | +- Serialization handled by SuperJSON; return plain objects/arrays. |
| 54 | +- Client usage via `apps/web/client/src/trpc/react.tsx` (React Query + tRPC |
| 55 | + links). |
| 56 | + |
| 57 | +### Auth & Supabase |
| 58 | + |
| 59 | +- Server-side client: `apps/web/client/src/utils/supabase/server.ts` (uses Next |
| 60 | + headers/cookies). Use in server components, actions, and routes. |
| 61 | +- Browser client: `apps/web/client/src/utils/supabase/client/index.ts` for |
| 62 | + client components. |
| 63 | +- Never pass server-only clients into client code. |
| 64 | + |
| 65 | +### Env & Config |
| 66 | + |
| 67 | +- Define/validate env vars in `apps/web/client/src/env.ts` via |
| 68 | + `@t3-oss/env-nextjs`. |
| 69 | +- Expose browser vars with `NEXT_PUBLIC_*` and declare in the `client` schema. |
| 70 | +- Prefer `env` from `@/env`. In server-only helpers (e.g., base URL in |
| 71 | + `src/trpc/helpers.ts`), read `process.env` only for deployment vars like |
| 72 | + `VERCEL_URL`/`PORT`. Never use `process.env` in client code; in shared |
| 73 | + modules, guard with `typeof window === 'undefined'`. |
| 74 | +- Import `./src/env` in `apps/web/client/next.config.ts` to enforce validation. |
| 75 | + |
| 76 | +### Imports & Paths |
| 77 | + |
| 78 | +- Use path aliases: `@/*` and `~/*` map to `apps/web/client/src/*` (see |
| 79 | + `apps/web/client/tsconfig.json`). |
| 80 | +- Do not import server-only modules into client components. Limited exception: |
| 81 | + editor modules that already use `path`; reuse only there. Never import |
| 82 | + `process` in client code. |
| 83 | +- Split code by environment if needed (server file vs client file). |
| 84 | + |
| 85 | +### MobX + React Stores |
| 86 | + |
| 87 | +- Create store instances with `useState(() => new Store())` for stability across |
| 88 | + renders. |
| 89 | +- Keep active store in `useRef`; clean up async with |
| 90 | + `setTimeout(() => storeRef.current?.clear(), 0)` to avoid route-change races. |
| 91 | +- Avoid `useMemo` for store instances; React may drop memoized values leading to |
| 92 | + data loss. |
| 93 | +- Avoid putting the store instance in effect deps if it loops; split concerns |
| 94 | + (e.g., project vs branch). |
| 95 | +- `observer` components are client-only. Place one client boundary at the |
| 96 | + feature entry; child observers need not include `use client` (e.g., |
| 97 | + `apps/web/client/src/app/project/[id]/_components/main.tsx`). |
| 98 | +- Example store: `apps/web/client/src/components/store/editor/engine.ts:1` (uses |
| 99 | + `makeAutoObservable`). |
| 100 | + |
| 101 | +### Styling & UI |
| 102 | + |
| 103 | +- TailwindCSS-first styling; global styles are already imported in |
| 104 | + `apps/web/client/src/app/layout.tsx`. |
| 105 | +- Prefer existing UI components from `@onlook/ui` and local patterns. |
| 106 | +- Preserve dark theme defaults via `ThemeProvider` usage in layout. |
| 107 | + |
| 108 | +### Internationalization |
| 109 | + |
| 110 | +- `next-intl` is configured; provider lives in |
| 111 | + `apps/web/client/src/app/layout.tsx`. |
| 112 | +- Strings live in `apps/web/client/messages/*`. Add/modify keys there; avoid |
| 113 | + hardcoded user-facing text. |
| 114 | +- Keep keys stable; prefer additions over breaking renames. |
| 115 | + |
| 116 | +### Common Pitfalls |
| 117 | + |
| 118 | +- Missing `use client` where needed (events/browser APIs) causes unbound events; |
| 119 | + a single boundary at the feature root is sufficient. |
| 120 | +- New tRPC routers not exported in `src/server/api/root.ts` (endpoints |
| 121 | + unreachable). |
| 122 | +- Env vars not typed/exposed in `src/env.ts` cause runtime/edge failures. Prefer |
| 123 | + `env`; avoid new `process.env` reads in client code. |
| 124 | +- Importing server-only code into client components (bundling/runtime errors). |
| 125 | + Note: `path` is already used in specific client code-editor modules; avoid |
| 126 | + expanding Node API usage beyond those areas. |
| 127 | +- Bypassing i18n by hardcoding strings instead of using message files/hooks. |
| 128 | +- Avoid `useMemo` to create MobX stores (risk of lost references); avoid |
| 129 | + synchronous cleanup on route change (race conditions). |
| 130 | + |
| 131 | +### Context Discipline (for Agents) |
| 132 | + |
| 133 | +- Search narrowly with ripgrep; open only files you need. |
| 134 | +- Read small sections; avoid `node_modules`, `.next`, large assets. |
| 135 | +- Propose minimal diffs aligned with existing conventions; avoid wide refactors. |
| 136 | + |
| 137 | +### Notes |
| 138 | + |
| 139 | +- Unit tests can be run with `bun test` |
| 140 | +- Run type checking with `bun run typecheck` |
| 141 | +- Apply database updates to local dev with `bun run db:push` |
| 142 | +- Refrain from running the dev server |
| 143 | +- DO NOT run `db:gen`. This is reserved for the maintainer. |
| 144 | +- DO NOT use any type unless necessary |
0 commit comments