|
1 | | -# Repository Guidelines |
2 | | - |
3 | | -## Project Structure & Module Organization |
4 | | -- `apps/next.js/`: App Router lab; routes in `src/app`, shared UI in `src/components`, Jest specs in `test/` and `src/app/__tests__`. |
5 | | -- `apps/react/`: Vite SPA; screens in `src/pages`, services in `src/service`, Vitest specs in `src/test` or adjacent `*.test.tsx`. |
6 | | -- `apps/typescript/`: Type-only experiments; use the `error/` module and `jest.config.ts` as the template. |
7 | | -- `apps/blog/web/`: MDX blog; posts in `apps/blog/posts/`, Supabase SQL in `supabase/`. |
8 | | -- `apps/ga-proxy/`: Next.js proxy; handlers in `src/app` with shared utilities in `lib/`. |
9 | | -- Shared packages: UI in `packages/@design-system/ui`, Panda CSS tokens in `packages/@design-system/ui-lib`, configs/utilities in `packages/@package/*`. |
10 | | - |
11 | | -## Architecture & Shared Practices |
12 | | -- Turborepo + pnpm workspaces coordinate builds; edit `turbo.json` and `pnpm-workspace.yaml` together. |
13 | | -- Use `workspace:` protocol for internal deps and catalog aliases (`catalog:react19`, `catalog:typescript5`, `catalog:` for Panda CSS). |
14 | | -- Component folders follow the three-file pattern (`Component.tsx`, `Component.test.tsx`, `index.ts`). |
15 | | -- Panda CSS tokens are generated; rerun Panda instead of editing `packages/@design-system/ui-lib`. |
16 | | - |
17 | | -## Build, Test, and Development Commands |
18 | | -- `pnpm install` (Node 20+, pnpm 10.10.0) to bootstrap. |
19 | | -- `pnpm dev` runs everything; use `pnpm next`, `pnpm react`, `pnpm typescript`, or `pnpm blog-web` for focused dev. |
20 | | -- `pnpm build`, `pnpm lint`, and `pnpm check-types` run repo-wide gates; `pnpm blog-build` exports the blog. |
21 | | -- `pnpm test` runs all suites; add `--filter=next.js`, `--filter=react`, etc., when iterating. |
22 | | - |
23 | | -## Coding Style & Naming Conventions |
24 | | -- Prettier (2 spaces) plus per-app ESLint configs set formatting—run `pnpm lint` regularly. |
25 | | -- Components use PascalCase (`ArticleCard.tsx`), utilities camelCase, route folders and MDX slugs kebab-case. |
26 | | -- Use `data-testid` for critical selectors and promote reusable code into `packages/`. |
27 | | - |
28 | | -## Testing Guidelines |
29 | | -- Next.js → Jest + React Testing Library (`apps/next.js/test`, `src/app/__tests__`). |
30 | | -- React SPA → Vitest + MSW (`src/test`). |
31 | | -- TypeScript experiments → Jest + Babel (`apps/typescript`). |
32 | | -- Save specs as `*.test.ts` or `*.test.tsx`, extend existing MSW handlers, and update snapshots deliberately. |
33 | | - |
34 | | -## Commit & Pull Request Guidelines |
35 | | -- Follow `type(scope): summary` (e.g., `docs(blog): 내용 보강`); Korean summaries are fine if clear. |
36 | | -- Keep commits focused and note validation commands (`pnpm test --filter=next.js`) when behavior changes. |
37 | | -- PRs must include summary, impacted areas, validation steps, linked issue/doc, and screenshots or logs for UI work. |
38 | | -- Ensure Turbo, lint, and type checks succeed locally before requesting review. |
39 | | - |
40 | | -## Security & Configuration Tips |
41 | | -- Store Supabase keys, proxy tokens, and other secrets in local `.env.local`. |
42 | | -- Respect `pnpm.onlyBuiltDependencies`; avoid global installs or editing `node_modules`. |
43 | | -- Flag cascading impacts when tweaking `turbo.json`, workspace filters, or catalog entries. |
| 1 | +# AGENTS.md - Context & Rules for AI Agents |
| 2 | + |
| 3 | +This file provides the necessary context, commands, and standards for AI agents operating in this repository (`fe-lab`). |
| 4 | +**READ THIS FIRST** before making changes. |
| 5 | + |
| 6 | +## 1. Environment & Setup |
| 7 | + |
| 8 | +- **Package Manager**: `pnpm` (v10.10.0). strictly enforce `pnpm-lock.yaml`. |
| 9 | +- **Monorepo Tool**: `turborepo`. |
| 10 | +- **Node Version**: >= 20. |
| 11 | +- **Root Commands**: |
| 12 | + - `pnpm install`: Bootstrap dependencies. |
| 13 | + - `pnpm dev`: Start all apps in parallel. |
| 14 | + - `pnpm build`: Build all apps/packages. |
| 15 | + - `pnpm test`: Run all tests. |
| 16 | + - `pnpm lint`: Run ESLint across the repo. |
| 17 | + - `pnpm check-types`: Run TypeScript validation. |
| 18 | + |
| 19 | +## 2. Project Structure |
| 20 | + |
| 21 | +- **apps/** |
| 22 | + - `next.js/` (Next.js 16 + App Router): Core experimentation lab. |
| 23 | + - `react/` (Vite + React 19): SPA experimentation lab. |
| 24 | + - `typescript/` (Pure TS): Type challenges and logic experiments. |
| 25 | + - `blog/web/` (Next.js + MDX): Tech blog. |
| 26 | + - `ga-proxy/` (Next.js): Utility service. |
| 27 | +- **packages/** |
| 28 | + - `@design-system/ui`: Shared React components. |
| 29 | + - `@design-system/ui-lib`: Panda CSS generated tokens/styles (DO NOT EDIT directly). |
| 30 | + - `@package/core`: Shared utilities (HTTP client, etc.). |
| 31 | + - `@package/config`: Shared TS/ESLint configs. |
| 32 | + |
| 33 | +## 3. Development Commands (Crucial for Agents) |
| 34 | + |
| 35 | +### Running Specific Apps |
| 36 | + |
| 37 | +Do not run `pnpm dev` if you only need one app. Save resources. |
| 38 | + |
| 39 | +- `pnpm next`: Run `apps/next.js` |
| 40 | +- `pnpm react`: Run `apps/react` |
| 41 | +- `pnpm typescript`: Run `apps/typescript` |
| 42 | + |
| 43 | +### Running Tests (Targeted) |
| 44 | + |
| 45 | +**ALWAYS** run relevant tests after changes. Do not run the full suite unless necessary. |
| 46 | + |
| 47 | +**Pattern**: `pnpm test --filter=<app_name> -- <test_args>` |
| 48 | + |
| 49 | +- **Single App Suite**: |
| 50 | + |
| 51 | + ```bash |
| 52 | + pnpm test --filter=next.js # Run all Next.js tests (Jest) |
| 53 | + pnpm test --filter=react # Run all React tests (Vitest) |
| 54 | + ``` |
| 55 | + |
| 56 | +- **Single Test File** (Best for TDD/Debugging): |
| 57 | + |
| 58 | + ```bash |
| 59 | + # Jest (Next.js) |
| 60 | + pnpm test --filter=next.js -- src/app/some-feature.test.tsx |
| 61 | + |
| 62 | + # Vitest (React) |
| 63 | + pnpm test --filter=react -- src/features/some-feature.test.tsx |
| 64 | + ``` |
| 65 | + |
| 66 | +- **Watch Mode**: |
| 67 | + - `pnpm --filter=next.js run test:watch` |
| 68 | + |
| 69 | +## 4. Coding Standards |
| 70 | + |
| 71 | +### TypeScript |
| 72 | + |
| 73 | +- **Strictness**: `strict: true` is enabled. No `any`. Use `unknown` or specific types. |
| 74 | +- **Interfaces**: Prefer `interface` over `type` for object definitions. |
| 75 | +- **Exports**: Use named exports (`export const Foo = ...`) over default exports, except for Next.js Pages/Layouts. |
| 76 | + |
| 77 | +### React & Next.js |
| 78 | + |
| 79 | +- **Component Naming**: PascalCase (`UserCard.tsx`). |
| 80 | +- **Structure**: |
| 81 | + ```text |
| 82 | + UserCard/ |
| 83 | + ├── index.ts # Export barrel |
| 84 | + ├── UserCard.tsx # Component logic & view |
| 85 | + └── UserCard.test.tsx # Tests |
| 86 | + ``` |
| 87 | +- **Hooks**: Use `use` prefix. Encapsulate complex logic in custom hooks. |
| 88 | +- **Server Components**: In `apps/next.js`, default to Server Components. Add `"use client"` only when interactive state/hooks are needed. |
| 89 | + |
| 90 | +### Styling (Panda CSS) |
| 91 | + |
| 92 | +- **Zero Runtime**: Use Panda CSS recipes and patterns. |
| 93 | +- **Restricted Files**: **NEVER** edit files inside `styled-system/` or `packages/@design-system/ui-lib/dist`. |
| 94 | +- **Tokens**: Use semantic tokens (e.g., `css({ color: "text.primary" })`) instead of raw hex values. |
| 95 | + |
| 96 | +### Imports |
| 97 | + |
| 98 | +- **Order**: External deps -> Internal packages (`@package/*`) -> Local absolute (`@/*`) -> Relative. |
| 99 | +- **Absolute Imports**: Use `@/` alias for `src/` directory. |
| 100 | + |
| 101 | +### Error Handling |
| 102 | + |
| 103 | +- **Typed Errors**: Do not throw raw strings. Use `Error` instances or custom error classes. |
| 104 | +- **Boundaries**: Ensure UI components are wrapped in Error Boundaries where appropriate. |
| 105 | +- **Async**: Always handle Promise rejections (try/catch or `.catch`). |
| 106 | + |
| 107 | +## 5. Testing Guidelines |
| 108 | + |
| 109 | +- **Tools**: |
| 110 | + - `jest` + `react-testing-library` (Next.js) |
| 111 | + - `vitest` + `react-testing-library` (React/Vite) |
| 112 | + - `msw` (Network mocking) |
| 113 | +- **Selectors**: Prefer user-centric selectors: |
| 114 | + 1. `getByRole` (button, heading, etc.) |
| 115 | + 2. `getByLabelText` (forms) |
| 116 | + 3. `getByPlaceholderText` |
| 117 | + 4. `getByText` |
| 118 | + 5. `getByTestId` (Last resort: use `data-testid="identifier"`) |
| 119 | +- **Mocking**: Use MSW for API calls. Avoid mocking internal hook implementations if possible (test behavior, not implementation). |
| 120 | + |
| 121 | +## 6. Git & Workflow |
| 122 | + |
| 123 | +- **Commit Messages**: Conventional Commits. |
| 124 | + - `feat(scope): ...` |
| 125 | + - `fix(scope): ...` |
| 126 | + - `docs(scope): ...` |
| 127 | + - `refactor(scope): ...` |
| 128 | + - `test(scope): ...` |
| 129 | +- **Scope**: `next`, `react`, `ui`, `core`, etc. |
| 130 | +- **PRs**: Self-review required. Verify `pnpm lint` and `pnpm check-types` pass before submitting. |
| 131 | + |
| 132 | +## 7. Troubleshooting |
| 133 | + |
| 134 | +- **Lockfile Issues**: If dependencies are weird, run `pnpm install --frozen-lockfile`. |
| 135 | +- **Turbo Cache**: If builds are stale/broken, run `pnpm build --force`. |
| 136 | +- **Types**: If types are missing, check `pnpm-workspace.yaml` catalog versions. |
| 137 | + |
| 138 | +**Agent Action Checklist**: |
| 139 | + |
| 140 | +1. Read this file. |
| 141 | +2. Locate relevant files using `ls` and `find` (or `glob` tool). |
| 142 | +3. `pnpm install` if new deps are needed (rare). |
| 143 | +4. Make changes. |
| 144 | +5. **VERIFY**: Run specific tests (`pnpm test --filter=... -- <file>`). |
| 145 | +6. Lint/Typecheck changed files. |
0 commit comments