Skip to content

Commit 6cf92c6

Browse files
Add AGENTS.md with guidelines (#7093)
1 parent 89ccc80 commit 6cf92c6

File tree

1 file changed

+123
-0
lines changed

1 file changed

+123
-0
lines changed

AGENTS.md

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
🤖 Codex Agent Guidelines for thirdweb-dev/js
2+
3+
Welcome, AI copilots! This guide captures the coding standards, architectural decisions, and workflow conventions that every automated agent (and human contributor!) must follow. Unless a rule explicitly targets a sub‑project, it applies repo‑wide.
4+
5+
6+
7+
1. GitHub Workflow & Etiquette
8+
9+
- Pull‑request titles must start with the affected workspace in brackets (e.g. [SDK], [Dashboard], [Portal], [Playground]).
10+
- Begin the PR description with a one‑sentence summary, then add a checklist of changes and reference issues with Fixes #123.
11+
- Keep commits small and topical – one logical change per commit.
12+
- Branch names should follow area/brief-topic (e.g. sdk/fix-gas-estimate). Avoid personal names.
13+
- Request at least one core maintainer review. Do not self‑merge unless you are the sole owner of that package.
14+
- All CI checks (type‑check, Biome, tests) must pass before merging.
15+
16+
17+
18+
2. Formatting & Linting
19+
20+
- Biome governs formatting and linting; its rules live in biome.json.
21+
- Run pnpm biome check --apply before committing.
22+
- Avoid editor‑specific configs; rely on the shared settings.
23+
24+
25+
26+
3. TypeScript Style Guide
27+
28+
- Write idiomatic TypeScript: explicit function declarations and return types.
29+
- Limit each file to one stateless, single‑responsibility function for clarity and testability.
30+
- Re‑use shared types from @/types or local types.ts barrels.
31+
- Prefer type aliases over interface except for nominal shapes.
32+
- Avoid any and unknown unless unavoidable; narrow generics whenever possible.
33+
- Choose composition over inheritance; leverage utility types (Partial, Pick, etc.).
34+
35+
36+
37+
4. Testing Strategy
38+
39+
- Co‑locate tests: foo.ts ↔ foo.test.ts.
40+
- Use real function invocations with stub data; avoid brittle mocks.
41+
- For network interactions, use Mock Service Worker (MSW) to intercept fetch/HTTP calls, mocking only scenarios that are hard to reproduce.
42+
- Keep tests deterministic and side‑effect free; Jest is pre‑configured.
43+
44+
45+
46+
5. packages/thirdweb
47+
48+
5.1 Public API Surface
49+
50+
- Export everything via the exports/ directory, grouped by feature.
51+
- Every public symbol must have comprehensive TSDoc:
52+
- Include at least one @example block that compiles.
53+
- Tag with one custom annotation (@beta, @internal, @experimental, etc.).
54+
- Comment only ambiguous logic; avoid restating TypeScript in prose.
55+
56+
5.2 Performance
57+
58+
- Lazy‑load heavy dependencies inside async paths to keep the initial bundle lean:
59+
60+
`const { jsPDF } = await import("jspdf");`
61+
62+
63+
64+
6. apps/dashboard & apps/playground
65+
66+
6.1 Core UI Toolkit
67+
68+
- Import primitives from @/components/ui/\_ (e.g. Button, Input, Select, Tabs, Card, Sidebar, Badge, Separator).
69+
- Use NavLink for internal navigation so active states are handled automatically.
70+
- Group feature‑specific components under feature/components/\_ and expose a barrel index.ts when necessary.
71+
72+
6.2 Styling Conventions
73+
74+
- Tailwind CSS is the styling system – no inline styles or CSS modules.
75+
- Merge class names with cn() from @/lib/utils to keep conditional logic readable.
76+
- Stick to design tokens: backgrounds (bg-card), borders (border-border), muted text (text-muted-foreground), etc.
77+
- Expose a className prop on the root element of every component for overrides.
78+
79+
6.3 Component Patterns
80+
81+
- Server Components (run on the Node edge):
82+
-- Read cookies/headers with next/headers.
83+
-- Access server‑only environment variables or secrets.
84+
-- Perform heavy data fetching that should not ship to the client.
85+
-- Implement redirect logic with redirect() from next/navigation.
86+
-- Start files with import "server-only"; to prevent client bundling.
87+
- Client Components (run in the browser):
88+
-- Begin files with 'use client'; before imports.
89+
-- Handle interactive UI relying on React hooks (useState, useEffect, React Query, wallet hooks).
90+
-- Access browser APIs (localStorage, window, IntersectionObserver, etc.).
91+
-- Support fast transitions where data is prefetched on the client.
92+
93+
6.4 Data Fetching Guidelines
94+
95+
- Server Side
96+
-- Always call getAuthToken() to retrieve the JWT from cookies.
97+
-- Inject the token as an Authorization: Bearer header – never embed it in the URL.
98+
-- Return typed results (Project[], User[], …) – avoid any.
99+
- Client Side
100+
-- Wrap calls in React Query (@tanstack/react-query).
101+
-- Use descriptive, stable queryKeys for cache hits.
102+
-- Configure staleTime / cacheTime based on freshness requirements (default ≥ 60 s).
103+
-- Keep tokens secret by calling internal API routes or server actions.
104+
105+
106+
107+
7. Performance & Bundle Size
108+
109+
- Track bundle budgets via package.json#size-limit.
110+
- Lazy‑import optional features; avoid top‑level side‑effects.
111+
- De‑duplicate dependencies across packages through pnpm workspace hoisting.
112+
113+
114+
115+
8. Documentation & Developer Experience
116+
117+
- Each change in packages/\* should contain a changeset for the appropriate package, with the appropriate version bump
118+
119+
- patch for changes that don't impact the public API
120+
- minor for any new/modified public API
121+
122+
- Surface breaking changes prominently in PR descriptions.
123+
- For new UI components, add Storybook stories (\*.stories.tsx) alongside the code.

0 commit comments

Comments
 (0)