@mikulgohil/ai-kit 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +73 -0
- package/commands/accessibility-audit.md +143 -0
- package/commands/api-route.md +203 -0
- package/commands/commit-msg.md +127 -0
- package/commands/dep-check.md +148 -0
- package/commands/design-tokens.md +146 -0
- package/commands/document.md +175 -0
- package/commands/env-setup.md +165 -0
- package/commands/error-boundary.md +254 -0
- package/commands/extract-hook.md +237 -0
- package/commands/figma-to-code.md +152 -0
- package/commands/fix-bug.md +112 -0
- package/commands/migrate.md +174 -0
- package/commands/new-component.md +121 -0
- package/commands/new-page.md +113 -0
- package/commands/optimize.md +120 -0
- package/commands/pre-pr.md +159 -0
- package/commands/prompt-help.md +175 -0
- package/commands/refactor.md +219 -0
- package/commands/responsive-check.md +164 -0
- package/commands/review.md +120 -0
- package/commands/security-check.md +175 -0
- package/commands/sitecore-debug.md +216 -0
- package/commands/test.md +154 -0
- package/commands/token-tips.md +72 -0
- package/commands/type-fix.md +224 -0
- package/commands/understand.md +84 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1425 -0
- package/dist/index.js.map +1 -0
- package/docs-scaffolds/component-doc.md +35 -0
- package/docs-scaffolds/decisions-log.md +15 -0
- package/docs-scaffolds/mistakes-log.md +15 -0
- package/docs-scaffolds/time-log.md +14 -0
- package/guides/figma-workflow.md +135 -0
- package/guides/getting-started.md +61 -0
- package/guides/prompt-playbook.md +64 -0
- package/guides/token-saving-tips.md +50 -0
- package/guides/when-to-use-ai.md +44 -0
- package/package.json +58 -0
- package/templates/claude-md/base.md +173 -0
- package/templates/claude-md/figma.md +62 -0
- package/templates/claude-md/monorepo.md +17 -0
- package/templates/claude-md/nextjs-app-router.md +29 -0
- package/templates/claude-md/nextjs-pages-router.md +28 -0
- package/templates/claude-md/sitecore-xmc.md +46 -0
- package/templates/claude-md/tailwind.md +18 -0
- package/templates/claude-md/typescript.md +19 -0
- package/templates/cursorrules/base.md +84 -0
- package/templates/cursorrules/figma.md +32 -0
- package/templates/cursorrules/monorepo.md +7 -0
- package/templates/cursorrules/nextjs-app-router.md +8 -0
- package/templates/cursorrules/nextjs-pages-router.md +7 -0
- package/templates/cursorrules/sitecore-xmc.md +9 -0
- package/templates/cursorrules/tailwind.md +8 -0
- package/templates/cursorrules/typescript.md +8 -0
- package/templates/header.md +4 -0
- package/templates/token-dashboard.html +732 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# When to Use AI (and When Not To)
|
|
2
|
+
|
|
3
|
+
## Great for AI ✅
|
|
4
|
+
|
|
5
|
+
| Task | Why |
|
|
6
|
+
|------|-----|
|
|
7
|
+
| Scaffolding components/pages | Repetitive structure, follows patterns |
|
|
8
|
+
| Writing tests | Tedious, pattern-based |
|
|
9
|
+
| Bug investigation | AI can trace data flow faster than reading |
|
|
10
|
+
| Code review | Catches things humans miss |
|
|
11
|
+
| Refactoring | Structural changes with clear rules |
|
|
12
|
+
| Understanding unfamiliar code | AI explains faster than reading docs |
|
|
13
|
+
| Boilerplate (types, configs, API clients) | Pattern-heavy, low creativity needed |
|
|
14
|
+
| Documentation | Summarizing what code does |
|
|
15
|
+
|
|
16
|
+
## Not Great for AI ❌
|
|
17
|
+
|
|
18
|
+
| Task | Why |
|
|
19
|
+
|------|-----|
|
|
20
|
+
| Architecture decisions | Needs business context AI doesn't have |
|
|
21
|
+
| Complex state machines | Hard to describe in a prompt |
|
|
22
|
+
| Design/UX decisions | AI can implement designs, not create them |
|
|
23
|
+
| Security-critical auth flows | Too risky to trust AI alone |
|
|
24
|
+
| Performance tuning (without data) | Needs profiling, not guessing |
|
|
25
|
+
| Merge conflict resolution | AI doesn't know your intent |
|
|
26
|
+
|
|
27
|
+
## Decision Flow
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
Is this task...
|
|
31
|
+
├── Repetitive/Pattern-based? → Use AI
|
|
32
|
+
├── Creative/Design? → Do it yourself, use AI to implement
|
|
33
|
+
├── Security-critical? → Do it yourself, use AI to review
|
|
34
|
+
├── Investigation? → Use AI to explore, verify yourself
|
|
35
|
+
└── Architectural? → Discuss with team, use AI for implementation
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Cost-Effective Usage
|
|
39
|
+
|
|
40
|
+
1. **One focused task per conversation** — don't let conversations drift
|
|
41
|
+
2. **Point to files** — "read src/X.tsx" is cheaper than pasting code
|
|
42
|
+
3. **Use slash commands** — they include the right context automatically
|
|
43
|
+
4. **Don't iterate forever** — if AI can't get it in 2 tries, take over
|
|
44
|
+
5. **Review before accepting** — faster to fix during review than debug later
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mikulgohil/ai-kit",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "AI-assisted development setup kit. Auto-detects your tech stack and generates tailored CLAUDE.md, .cursorrules, slash commands, and developer guides.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"ai-kit": "./dist/index.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"dist",
|
|
11
|
+
"templates",
|
|
12
|
+
"commands",
|
|
13
|
+
"guides",
|
|
14
|
+
"docs-scaffolds"
|
|
15
|
+
],
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "tsup",
|
|
18
|
+
"dev": "tsup --watch",
|
|
19
|
+
"test": "vitest",
|
|
20
|
+
"test:run": "vitest run",
|
|
21
|
+
"typecheck": "tsc --noEmit",
|
|
22
|
+
"lint": "eslint src/",
|
|
23
|
+
"prepublishOnly": "npm run build"
|
|
24
|
+
},
|
|
25
|
+
"keywords": [
|
|
26
|
+
"ai",
|
|
27
|
+
"claude-code",
|
|
28
|
+
"cursor",
|
|
29
|
+
"developer-tools",
|
|
30
|
+
"cli",
|
|
31
|
+
"nextjs",
|
|
32
|
+
"tailwind",
|
|
33
|
+
"sitecore"
|
|
34
|
+
],
|
|
35
|
+
"author": "Mikul Gohil",
|
|
36
|
+
"license": "MIT",
|
|
37
|
+
"repository": {
|
|
38
|
+
"type": "git",
|
|
39
|
+
"url": "https://github.com/mikulgohil/ai-kit.git"
|
|
40
|
+
},
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": ">=18.0.0"
|
|
43
|
+
},
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"@inquirer/prompts": "^7.0.0",
|
|
46
|
+
"chalk": "^5.4.0",
|
|
47
|
+
"commander": "^13.0.0",
|
|
48
|
+
"fs-extra": "^11.0.0",
|
|
49
|
+
"ora": "^8.0.0"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@types/fs-extra": "^11.0.0",
|
|
53
|
+
"@types/node": "^22.0.0",
|
|
54
|
+
"tsup": "^8.0.0",
|
|
55
|
+
"typescript": "^5.8.0",
|
|
56
|
+
"vitest": "^3.0.0"
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
# Core Rules
|
|
2
|
+
|
|
3
|
+
## Workflow
|
|
4
|
+
1. **Read before writing** — always read existing files before modifying
|
|
5
|
+
2. **Understand → Plan → Code** — never jump straight to implementation
|
|
6
|
+
3. **Ask when unclear** — if the task is ambiguous, ask clarifying questions before proceeding
|
|
7
|
+
4. **Stay in scope** — only change what was requested, no unsolicited refactors
|
|
8
|
+
|
|
9
|
+
## Prompt Quality Guard
|
|
10
|
+
|
|
11
|
+
When a developer's request is vague or missing critical context, you MUST push back before proceeding. This prevents wasted time and bad output.
|
|
12
|
+
|
|
13
|
+
**If the request is missing a target file or scope**, ask:
|
|
14
|
+
> "Which file or component should I focus on?"
|
|
15
|
+
|
|
16
|
+
**If the request is ambiguous** (e.g., "fix this", "make it work", "improve this"), ask 1-2 targeted questions:
|
|
17
|
+
> "What specifically is broken — what's the expected vs actual behavior?"
|
|
18
|
+
|
|
19
|
+
**If the request could produce very different outputs** (e.g., "create a component"), ask for constraints:
|
|
20
|
+
> "Should this be a Server or Client Component? What props does it need?"
|
|
21
|
+
|
|
22
|
+
**Never guess when you can ask.** A 10-second clarification saves 10 minutes of wrong output.
|
|
23
|
+
|
|
24
|
+
### Self-Enforcement Rules
|
|
25
|
+
- When creating or modifying a component with >50 lines or >3 props, you MUST create/update its `.docs.md` file — do not skip this even if the developer doesn't ask for it
|
|
26
|
+
- When fixing a bug, you MUST add a test that reproduces the bug before fixing it
|
|
27
|
+
- When generating code, you MUST add JSDoc comments to all exported functions
|
|
28
|
+
- After completing a task that modifies a documented component, you MUST append an entry to the component's Change Log
|
|
29
|
+
- When you encounter a `// TODO` without a ticket number, flag it to the developer
|
|
30
|
+
|
|
31
|
+
## Coding Standards
|
|
32
|
+
|
|
33
|
+
These standards are enforced across all projects to ensure consistency.
|
|
34
|
+
|
|
35
|
+
### Naming Conventions
|
|
36
|
+
- **Components**: PascalCase (`ProductCard.tsx`, `HeroBanner.tsx`)
|
|
37
|
+
- **Utilities/Hooks**: camelCase (`useAuth.ts`, `formatDate.ts`)
|
|
38
|
+
- **Constants**: UPPER_SNAKE_CASE (`API_BASE_URL`, `MAX_RETRY_COUNT`)
|
|
39
|
+
- **CSS classes**: kebab-case for custom classes, Tailwind utilities where available
|
|
40
|
+
- **Files**: Match the default export name — one component per file
|
|
41
|
+
|
|
42
|
+
### Code Structure
|
|
43
|
+
- Keep components under 200 lines — split into sub-components if larger
|
|
44
|
+
- Colocate related files (component, types, tests, styles, docs) in the same directory
|
|
45
|
+
- Separate business logic from UI — use custom hooks for logic
|
|
46
|
+
- Props interface defined directly above or alongside the component
|
|
47
|
+
|
|
48
|
+
### Component Documentation
|
|
49
|
+
- **Doc file required for complex components** — components over 50 lines OR with more than 3 props must have a colocated `ComponentName.docs.md` or `docs/components/ComponentName.md`
|
|
50
|
+
- **Simple components** (≤50 lines AND ≤3 props) — a JSDoc comment above the component is sufficient; no separate doc file needed
|
|
51
|
+
- **Doc file reference in component** — when a doc file exists, add a comment at the top:
|
|
52
|
+
```
|
|
53
|
+
// Docs: ./ComponentName.docs.md
|
|
54
|
+
```
|
|
55
|
+
- **Doc file contents** — include: purpose, props table, usage examples, edge cases, design decisions
|
|
56
|
+
- **Update log** — every modification to a documented component must be logged at the bottom of its doc file:
|
|
57
|
+
```
|
|
58
|
+
## Change Log
|
|
59
|
+
- YYYY-MM-DD: [what changed] — [why]
|
|
60
|
+
```
|
|
61
|
+
- If a complex component lacks a doc file when you modify it, create one
|
|
62
|
+
|
|
63
|
+
### Code Comments
|
|
64
|
+
- Add a brief JSDoc comment above every exported function and component explaining its purpose
|
|
65
|
+
- Comment non-obvious logic — if you had to think about it, the next developer will too
|
|
66
|
+
- Use `// TODO(author):` with a name for anything intentionally deferred
|
|
67
|
+
- Do NOT add obvious comments like `// increment counter` — comment the *why*, not the *what*
|
|
68
|
+
- Add `@example` in JSDoc for utility functions showing input → output
|
|
69
|
+
|
|
70
|
+
### Import Order
|
|
71
|
+
1. External packages (`react`, `next/...`, third-party)
|
|
72
|
+
2. Internal shared utilities (`@/lib`, `@/utils`, `@/hooks`)
|
|
73
|
+
3. Local relative imports (`./`, `../`)
|
|
74
|
+
4. Type imports (use `import type` for type-only imports)
|
|
75
|
+
|
|
76
|
+
### Error Handling
|
|
77
|
+
- Always handle error states in components — never show blank screens
|
|
78
|
+
- Use error boundaries for unexpected failures
|
|
79
|
+
- Log errors with context (what failed, what input caused it)
|
|
80
|
+
- Show user-friendly messages, not raw error strings
|
|
81
|
+
|
|
82
|
+
### Accessibility
|
|
83
|
+
- Use semantic HTML (`<button>`, `<nav>`, `<main>`, `<section>`)
|
|
84
|
+
- Add `alt` text to all images
|
|
85
|
+
- Ensure keyboard navigation works for interactive elements
|
|
86
|
+
- Use ARIA labels when semantic HTML isn't sufficient
|
|
87
|
+
- Maintain color contrast ratio of at least 4.5:1
|
|
88
|
+
|
|
89
|
+
### Git Practices
|
|
90
|
+
- Write descriptive commit messages: `feat:`, `fix:`, `refactor:`, `docs:`, `test:`
|
|
91
|
+
- One logical change per commit
|
|
92
|
+
- Never commit `.env`, secrets, or `node_modules`
|
|
93
|
+
- Pull and rebase before pushing
|
|
94
|
+
|
|
95
|
+
### Performance Awareness
|
|
96
|
+
- Avoid unnecessary re-renders — memoize expensive computations with `useMemo`, callbacks with `useCallback`
|
|
97
|
+
- Lazy load heavy components and below-the-fold content
|
|
98
|
+
- Prefer Server Components for data-heavy, non-interactive sections
|
|
99
|
+
- Watch for N+1 data fetching — batch where possible
|
|
100
|
+
- Images must use `next/image` or equivalent with proper width/height/loading attributes
|
|
101
|
+
|
|
102
|
+
### Dependency Discipline
|
|
103
|
+
- Do NOT add new packages without checking if an existing dependency already solves the problem
|
|
104
|
+
- Prefer native browser APIs over utility libraries when reasonable (e.g., `URLSearchParams` over `qs`)
|
|
105
|
+
- Pin dependency versions — avoid `^` or `~` for critical packages
|
|
106
|
+
- When adding a new dependency, note the reason in the component's doc file or PR description
|
|
107
|
+
|
|
108
|
+
## Code Quality
|
|
109
|
+
- Match existing patterns, naming conventions, and file structure
|
|
110
|
+
- Keep changes minimal — don't refactor surrounding code unless asked
|
|
111
|
+
- No placeholder or TODO comments — write complete, working code
|
|
112
|
+
- Handle edge cases at system boundaries (user input, API responses)
|
|
113
|
+
- No unnecessary abstractions — 3 similar lines > premature helper function
|
|
114
|
+
|
|
115
|
+
## Safety
|
|
116
|
+
- Never commit secrets, API keys, or credentials — use environment variables
|
|
117
|
+
- Never run destructive git commands without confirmation
|
|
118
|
+
- Check for XSS, injection, and OWASP Top 10 vulnerabilities in any code you write
|
|
119
|
+
- Validate all external input; trust internal function contracts
|
|
120
|
+
|
|
121
|
+
### Testing Expectations
|
|
122
|
+
- Every new component and utility should have a corresponding test file
|
|
123
|
+
- Test file colocated: `ComponentName.test.tsx` or `utilName.test.ts`
|
|
124
|
+
- Cover: happy path, error states, edge cases, accessibility (role queries)
|
|
125
|
+
- Use React Testing Library — test behavior, not implementation details
|
|
126
|
+
- Mock external dependencies, not internal functions
|
|
127
|
+
|
|
128
|
+
## File Conventions
|
|
129
|
+
- Prefer editing existing files over creating new ones
|
|
130
|
+
- Maximum 3–7 files changed per task unless explicitly approved
|
|
131
|
+
- Document significant changes in `docs/` if the directory exists
|
|
132
|
+
- When modifying a component, update its doc file's change log
|
|
133
|
+
|
|
134
|
+
## Commands
|
|
135
|
+
Available at: `.claude/commands/`
|
|
136
|
+
|
|
137
|
+
**Getting Started**
|
|
138
|
+
- `/prompt-help` — Interactive prompt builder (start here if unsure how to ask)
|
|
139
|
+
- `/understand` — Explain code in detail
|
|
140
|
+
|
|
141
|
+
**Building**
|
|
142
|
+
- `/new-component` — Scaffold a new component with proper structure
|
|
143
|
+
- `/new-page` — Scaffold a new page/route
|
|
144
|
+
- `/api-route` — Scaffold an API route with validation, error handling, and auth
|
|
145
|
+
- `/error-boundary` — Generate error boundaries, loading states, and fallback UI
|
|
146
|
+
- `/extract-hook` — Extract component logic into a reusable custom hook
|
|
147
|
+
- `/figma-to-code` — Structured Figma-to-code implementation workflow
|
|
148
|
+
- `/design-tokens` — Design token management and mapping
|
|
149
|
+
|
|
150
|
+
**Quality & Review**
|
|
151
|
+
- `/review` — Deep code review following team standards
|
|
152
|
+
- `/pre-pr` — Pre-PR checklist (type safety, console cleanup, a11y, security)
|
|
153
|
+
- `/test` — Generate tests for a file or function
|
|
154
|
+
- `/accessibility-audit` — WCAG 2.1 AA compliance check
|
|
155
|
+
- `/security-check` — XSS, injection, secrets, and OWASP Top 10 review
|
|
156
|
+
- `/responsive-check` — Responsive design audit (breakpoints, touch targets, overflow)
|
|
157
|
+
- `/type-fix` — Fix TypeScript issues (replace `any`, add null checks, generate types)
|
|
158
|
+
|
|
159
|
+
**Maintenance**
|
|
160
|
+
- `/fix-bug` — Guided bug fix workflow
|
|
161
|
+
- `/refactor` — Safe refactoring (split components, extract hooks, remove duplication)
|
|
162
|
+
- `/optimize` — Performance optimization review
|
|
163
|
+
- `/migrate` — Guided migration helper (Next.js, Tailwind, Sitecore upgrades)
|
|
164
|
+
- `/dep-check` — Dependency audit (unused, outdated, security, bundle size)
|
|
165
|
+
- `/sitecore-debug` — Sitecore XM Cloud debugging (placeholders, fields, GraphQL)
|
|
166
|
+
|
|
167
|
+
**Workflow**
|
|
168
|
+
- `/document` — Generate documentation for existing code
|
|
169
|
+
- `/commit-msg` — Generate conventional commit message from staged changes
|
|
170
|
+
- `/env-setup` — Generate .env.example and validate environment variables
|
|
171
|
+
|
|
172
|
+
## Scripts
|
|
173
|
+
{{scripts}}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# Figma-to-Code Workflow
|
|
2
|
+
|
|
3
|
+
## Before Writing Any Code from a Figma Design
|
|
4
|
+
|
|
5
|
+
1. **Extract design context** — Use Figma MCP `get_design_context` with the Figma node URL to get structured layout, colors, typography, and spacing
|
|
6
|
+
2. **Get a visual reference** — Use `get_screenshot` to see what you're building
|
|
7
|
+
3. **Identify reusable components** — Check `src/components/` for existing components that match parts of the design. Reuse, don't recreate.
|
|
8
|
+
4. **Map design tokens** — Match Figma colors, spacing, and typography to the project's Tailwind theme tokens. Never hardcode values.
|
|
9
|
+
|
|
10
|
+
## Design Token Rules
|
|
11
|
+
|
|
12
|
+
- **Colors**: Use semantic tokens (`bg-primary-500`, `text-neutral-800`) — never hardcode hex values (`#3b82f6`)
|
|
13
|
+
- **Spacing**: Use scale tokens (`p-4`, `gap-6`, `mt-12`) — never use arbitrary values (`mt-[47px]`)
|
|
14
|
+
- **Typography**: Use type scale tokens (`text-h1`, `text-b1`) — never set raw `font-size`
|
|
15
|
+
- **Border radius**: Use named tokens (`rounded-card`, `rounded-button`) — not arbitrary `rounded-[8px]`
|
|
16
|
+
- **Shadows/Effects**: Use predefined shadow tokens if available
|
|
17
|
+
|
|
18
|
+
If a Figma value doesn't match any existing token, use the **nearest** token — don't create arbitrary values. Flag to the developer that the design uses an off-scale value.
|
|
19
|
+
|
|
20
|
+
## Component Mapping
|
|
21
|
+
|
|
22
|
+
Before creating a new component:
|
|
23
|
+
1. Read existing components in `src/components/` to check for matches
|
|
24
|
+
2. Map Figma component variants to React props (e.g., Figma variant "Style=Primary" → `variant="primary"`)
|
|
25
|
+
3. Match Figma layer names to semantic HTML elements (`<nav>`, `<section>`, `<article>`, `<button>`)
|
|
26
|
+
4. Preserve Figma Auto Layout as flexbox/grid — do not use absolute positioning
|
|
27
|
+
5. Figma's "Spacing between items" = CSS `gap`, Figma's "Padding" = CSS `padding`
|
|
28
|
+
|
|
29
|
+
## Content Container Pattern
|
|
30
|
+
|
|
31
|
+
Full-width backgrounds with constrained content:
|
|
32
|
+
```tsx
|
|
33
|
+
<div className="w-full bg-neutral-100">
|
|
34
|
+
<div className="max-w-[1320px] mx-auto w-full px-4 md:px-6 lg:px-0">
|
|
35
|
+
{/* content */}
|
|
36
|
+
</div>
|
|
37
|
+
</div>
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Responsive Implementation
|
|
41
|
+
|
|
42
|
+
- **Never assume** mobile is "desktop but smaller" — check every breakpoint in Figma separately
|
|
43
|
+
- Mobile may have completely different layouts (row → stack, hidden elements, different spacing)
|
|
44
|
+
- Implement mobile-first: base styles → `sm:` → `md:` → `lg:` → `xl:`
|
|
45
|
+
- Verify all breakpoints independently against Figma
|
|
46
|
+
|
|
47
|
+
## Visual Verification (Mandatory)
|
|
48
|
+
|
|
49
|
+
After generating a component from Figma:
|
|
50
|
+
1. Compare your output visually against the Figma design
|
|
51
|
+
2. Check: layout/spacing accuracy (95%+), color accuracy (98%+), typography (90%+)
|
|
52
|
+
3. Verify both desktop (1440px) and mobile (375px) if responsive
|
|
53
|
+
|
|
54
|
+
## Common Figma-to-Code Mistakes
|
|
55
|
+
|
|
56
|
+
- Don't hardcode colors — use design tokens
|
|
57
|
+
- Don't use arbitrary Tailwind values when a token exists
|
|
58
|
+
- Don't ignore Auto Layout — it maps directly to flex/grid
|
|
59
|
+
- Don't skip visual verification
|
|
60
|
+
- Don't create new components when existing ones can be reused
|
|
61
|
+
- Don't forget hover/focus/active states shown in Figma variants
|
|
62
|
+
- Don't ignore spacing between sections — Figma padding/gap = CSS padding/gap
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Monorepo
|
|
2
|
+
|
|
3
|
+
## Structure
|
|
4
|
+
- This is a monorepo — be aware of package boundaries
|
|
5
|
+
- Shared packages live in `packages/` — app-specific code lives in `apps/`
|
|
6
|
+
- Import shared code through package names, not relative paths across boundaries
|
|
7
|
+
|
|
8
|
+
## Rules
|
|
9
|
+
- Changes to shared packages affect all consumers — be cautious
|
|
10
|
+
- Run commands from the repo root using the workspace tool (e.g., `{{packageManager}} run build --filter=<package>`)
|
|
11
|
+
- Don't duplicate dependencies across packages — hoist shared deps to root
|
|
12
|
+
- Check which packages are affected before making cross-cutting changes
|
|
13
|
+
|
|
14
|
+
## Common Mistakes to Avoid
|
|
15
|
+
- Don't use relative imports (`../../packages/ui`) — use package names (`@scope/ui`)
|
|
16
|
+
- Don't modify shared packages without checking downstream impact
|
|
17
|
+
- Don't forget to update the workspace dependency if you change a shared package's exports
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Next.js App Router
|
|
2
|
+
|
|
3
|
+
## Conventions
|
|
4
|
+
- Use Server Components by default — only add `'use client'` when needed (event handlers, hooks, browser APIs)
|
|
5
|
+
- Colocate `loading.tsx`, `error.tsx`, and `not-found.tsx` alongside `page.tsx`
|
|
6
|
+
- Use `generateMetadata` for SEO — never hardcode `<title>` or `<meta>` tags
|
|
7
|
+
- Prefer `fetch()` with `next: { revalidate }` for data fetching in Server Components
|
|
8
|
+
- Use Route Handlers (`app/api/`) for API endpoints, not Pages Router API routes
|
|
9
|
+
|
|
10
|
+
## Data Fetching
|
|
11
|
+
- Server Components: fetch directly at the component level, no `useEffect`
|
|
12
|
+
- For mutations: use Server Actions (`'use server'`) or Route Handlers
|
|
13
|
+
- Always handle loading and error states with Suspense boundaries or file conventions
|
|
14
|
+
|
|
15
|
+
## File Structure
|
|
16
|
+
```
|
|
17
|
+
app/
|
|
18
|
+
layout.tsx ← Root layout (wrap with providers here)
|
|
19
|
+
page.tsx ← Home page
|
|
20
|
+
(group)/ ← Route groups for organization
|
|
21
|
+
[slug]/page.tsx ← Dynamic routes
|
|
22
|
+
api/ ← Route Handlers
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Common Mistakes to Avoid
|
|
26
|
+
- Don't use `useEffect` for data fetching in Server Components
|
|
27
|
+
- Don't import server-only code in Client Components
|
|
28
|
+
- Don't use `router.push` for simple navigation — use `<Link>`
|
|
29
|
+
- Don't forget to add `loading.tsx` for route transitions
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Next.js Pages Router
|
|
2
|
+
|
|
3
|
+
## Conventions
|
|
4
|
+
- Use `getStaticProps` for static data, `getServerSideProps` for per-request data
|
|
5
|
+
- Keep API routes in `pages/api/` — use proper HTTP method checking
|
|
6
|
+
- Use `next/head` for page-level `<title>` and `<meta>` tags
|
|
7
|
+
- Use `next/link` and `next/image` for navigation and images
|
|
8
|
+
|
|
9
|
+
## Data Fetching
|
|
10
|
+
- `getStaticProps` → build-time data (use `revalidate` for ISR)
|
|
11
|
+
- `getServerSideProps` → per-request server-side data
|
|
12
|
+
- `getStaticPaths` → pre-render dynamic routes
|
|
13
|
+
- Client-side: use SWR or React Query, not raw `useEffect` + `fetch`
|
|
14
|
+
|
|
15
|
+
## File Structure
|
|
16
|
+
```
|
|
17
|
+
pages/
|
|
18
|
+
_app.tsx ← App wrapper (providers, global styles)
|
|
19
|
+
_document.tsx ← Custom HTML document
|
|
20
|
+
index.tsx ← Home page
|
|
21
|
+
[slug].tsx ← Dynamic routes
|
|
22
|
+
api/ ← API routes
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Common Mistakes to Avoid
|
|
26
|
+
- Don't mix App Router and Pages Router patterns unless this is a hybrid project
|
|
27
|
+
- Don't return large payloads from `getServerSideProps` — serialize only what the page needs
|
|
28
|
+
- Don't forget to handle the `fallback` prop in `getStaticPaths`
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Sitecore XM Cloud
|
|
2
|
+
|
|
3
|
+
## Architecture
|
|
4
|
+
- This is a headless CMS project using Sitecore XM Cloud with Next.js as the rendering host
|
|
5
|
+
- Components receive data through Sitecore Layout Service via `ComponentRendering` props
|
|
6
|
+
- Use `@sitecore-jss/sitecore-jss-nextjs` or `@sitecore-content-sdk/nextjs` for component bindings
|
|
7
|
+
|
|
8
|
+
## Component Patterns
|
|
9
|
+
```typescript
|
|
10
|
+
// Standard Sitecore component pattern
|
|
11
|
+
import { Text, RichText, Image, Link } from '@sitecore-jss/sitecore-jss-nextjs';
|
|
12
|
+
import type { ComponentRendering, ComponentFields } from '@sitecore-jss/sitecore-jss-nextjs';
|
|
13
|
+
|
|
14
|
+
interface MyComponentFields extends ComponentFields {
|
|
15
|
+
heading: Field<string>;
|
|
16
|
+
body: Field<string>;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
type MyComponentProps = {
|
|
20
|
+
rendering: ComponentRendering;
|
|
21
|
+
fields: MyComponentFields;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const MyComponent = ({ fields }: MyComponentProps): JSX.Element => (
|
|
25
|
+
<div>
|
|
26
|
+
<Text field={fields.heading} tag="h2" />
|
|
27
|
+
<RichText field={fields.body} />
|
|
28
|
+
</div>
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
export default MyComponent;
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Rules
|
|
35
|
+
- Always use Sitecore field helpers (`<Text>`, `<RichText>`, `<Image>`, `<Link>`) — never render field values directly
|
|
36
|
+
- This enables Experience Editor / Pages inline editing
|
|
37
|
+
- Component names must match Sitecore rendering item names exactly
|
|
38
|
+
- Place components in `src/components/` following existing naming patterns
|
|
39
|
+
- Use `withDatasourceCheck` HOC for components that require a datasource
|
|
40
|
+
- GraphQL queries go in `.graphql` files alongside components
|
|
41
|
+
|
|
42
|
+
## Common Mistakes to Avoid
|
|
43
|
+
- Don't render `fields.heading.value` directly — use `<Text field={fields.heading} />`
|
|
44
|
+
- Don't hardcode content that should come from Sitecore fields
|
|
45
|
+
- Don't forget to register new components in the component factory
|
|
46
|
+
- Don't use `getStaticProps` directly — use Sitecore's built-in SSG/SSR integration
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Tailwind CSS
|
|
2
|
+
|
|
3
|
+
## Conventions
|
|
4
|
+
- Use Tailwind utility classes — avoid writing custom CSS unless absolutely necessary
|
|
5
|
+
- Follow mobile-first responsive design: `base` → `sm:` → `md:` → `lg:` → `xl:`
|
|
6
|
+
- Use the project's design tokens from `tailwind.config` (colors, spacing, fonts) — don't use arbitrary values like `text-[#ff0000]` when a token exists
|
|
7
|
+
- Group utility classes logically: layout → spacing → typography → colors → effects
|
|
8
|
+
|
|
9
|
+
## Patterns
|
|
10
|
+
- Use `cn()` or `clsx()` for conditional classes if available in the project
|
|
11
|
+
- Extract repeated class combinations into component props, not `@apply`
|
|
12
|
+
- Use `@apply` sparingly — only in global styles for base elements
|
|
13
|
+
|
|
14
|
+
## Common Mistakes to Avoid
|
|
15
|
+
- Don't use inline styles when a Tailwind class exists
|
|
16
|
+
- Don't use arbitrary values (`w-[347px]`) — use nearest standard value or define a token
|
|
17
|
+
- Don't forget dark mode variants if the project supports it
|
|
18
|
+
- Don't mix Tailwind with component-library CSS — pick one approach per component
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# TypeScript
|
|
2
|
+
|
|
3
|
+
## Conventions
|
|
4
|
+
- Use explicit types for function parameters and return values
|
|
5
|
+
- Prefer `interface` for object shapes, `type` for unions and intersections
|
|
6
|
+
- Use `unknown` over `any` — narrow types with type guards
|
|
7
|
+
- No `@ts-ignore` or `@ts-expect-error` without a comment explaining why
|
|
8
|
+
|
|
9
|
+
## Patterns
|
|
10
|
+
- Define prop types directly above or alongside the component
|
|
11
|
+
- Use `satisfies` for type-safe object literals when the type is known
|
|
12
|
+
- Use discriminated unions for state management (loading/success/error)
|
|
13
|
+
- Prefer `as const` for literal type inference
|
|
14
|
+
|
|
15
|
+
## Common Mistakes to Avoid
|
|
16
|
+
- Don't use `any` to bypass type errors — fix the underlying type issue
|
|
17
|
+
- Don't create unnecessary generic types — use them only when the type genuinely varies
|
|
18
|
+
- Don't duplicate types — import from a shared types file
|
|
19
|
+
- Don't use optional chaining as a substitute for proper null checking
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# Project Rules
|
|
2
|
+
|
|
3
|
+
You are working on **{{projectName}}** — a {{framework}} project.
|
|
4
|
+
|
|
5
|
+
## Prompt Quality Guard
|
|
6
|
+
- If the request is vague (e.g., "fix this", "make it work"), ask 1-2 clarifying questions before proceeding
|
|
7
|
+
- If no target file is specified, ask which file to focus on
|
|
8
|
+
- Never guess when you can ask — a quick clarification saves rework
|
|
9
|
+
|
|
10
|
+
## Self-Enforcement
|
|
11
|
+
- When creating/modifying complex components (>50 lines or >3 props), always create/update the `.docs.md` file
|
|
12
|
+
- When fixing bugs, add a regression test before fixing
|
|
13
|
+
- Always add JSDoc to exported functions in generated code
|
|
14
|
+
- After modifying a documented component, append to its Change Log
|
|
15
|
+
- Flag `// TODO` comments without ticket numbers
|
|
16
|
+
|
|
17
|
+
## Coding Standards
|
|
18
|
+
|
|
19
|
+
These standards are enforced across all projects.
|
|
20
|
+
|
|
21
|
+
### Naming
|
|
22
|
+
- Components: PascalCase (`ProductCard.tsx`) | Utilities/Hooks: camelCase (`useAuth.ts`)
|
|
23
|
+
- Constants: UPPER_SNAKE_CASE | CSS: kebab-case for custom, Tailwind where available
|
|
24
|
+
- Files match default export name — one component per file
|
|
25
|
+
|
|
26
|
+
### Structure
|
|
27
|
+
- Components under 200 lines — split if larger
|
|
28
|
+
- Colocate related files (component, types, tests, styles, docs)
|
|
29
|
+
- Separate logic from UI — custom hooks for business logic
|
|
30
|
+
- Import order: external → internal shared → local relative → type imports
|
|
31
|
+
|
|
32
|
+
### Component Documentation
|
|
33
|
+
- **Complex components** (>50 lines OR >3 props) must have a colocated doc file (`ComponentName.docs.md`)
|
|
34
|
+
- **Simple components** (≤50 lines AND ≤3 props) — a JSDoc comment is sufficient; no separate doc file needed
|
|
35
|
+
- When a doc file exists, add reference comment at top: `// Docs: ./ComponentName.docs.md`
|
|
36
|
+
- Doc file includes: purpose, props, usage examples, edge cases, design decisions
|
|
37
|
+
- Every modification to a documented component must be logged in the doc file's Change Log section
|
|
38
|
+
- If a complex component lacks a doc file when modifying, create one
|
|
39
|
+
|
|
40
|
+
### Code Comments
|
|
41
|
+
- JSDoc comment above every exported function/component explaining purpose
|
|
42
|
+
- Comment the *why*, not the *what* — skip obvious comments
|
|
43
|
+
- Use `// TODO(author):` with a name for deferred items
|
|
44
|
+
- Add `@example` in JSDoc for utility functions
|
|
45
|
+
|
|
46
|
+
### Testing
|
|
47
|
+
- Every new component/utility needs a colocated test file
|
|
48
|
+
- Cover: happy path, error states, edge cases, accessibility
|
|
49
|
+
- React Testing Library — test behavior, not implementation
|
|
50
|
+
- Mock external deps, not internal functions
|
|
51
|
+
|
|
52
|
+
### Performance
|
|
53
|
+
- Memoize expensive computations (`useMemo`) and callbacks (`useCallback`)
|
|
54
|
+
- Lazy load heavy/below-fold components
|
|
55
|
+
- Use `next/image` with proper width/height/loading
|
|
56
|
+
- Watch for N+1 data fetching — batch where possible
|
|
57
|
+
|
|
58
|
+
### Dependencies
|
|
59
|
+
- Check if an existing dep solves the problem before adding new ones
|
|
60
|
+
- Prefer native browser APIs over utility libraries when reasonable
|
|
61
|
+
- Note the reason for new dependencies in the doc file or PR
|
|
62
|
+
|
|
63
|
+
### Quality
|
|
64
|
+
- Read existing code before modifying — match patterns, naming, and structure
|
|
65
|
+
- Keep changes minimal and scoped to the request
|
|
66
|
+
- No placeholder TODOs — write complete, working code
|
|
67
|
+
- Handle edge cases at boundaries (user input, APIs), trust internal code
|
|
68
|
+
- Maximum 3–7 files per change unless approved
|
|
69
|
+
- Always handle error states — never show blank screens
|
|
70
|
+
- Use semantic HTML, add alt text, ensure keyboard navigation
|
|
71
|
+
- When modifying a component, update its doc file's change log
|
|
72
|
+
|
|
73
|
+
### Safety
|
|
74
|
+
- Never commit secrets or credentials
|
|
75
|
+
- Check for XSS, injection, and OWASP Top 10 vulnerabilities
|
|
76
|
+
- Use environment variables for all config values
|
|
77
|
+
|
|
78
|
+
### Git
|
|
79
|
+
- Commit messages: `feat:`, `fix:`, `refactor:`, `docs:`, `test:`
|
|
80
|
+
- One logical change per commit
|
|
81
|
+
- Never commit `.env`, secrets, or `node_modules`
|
|
82
|
+
|
|
83
|
+
## Scripts
|
|
84
|
+
{{scripts}}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Figma-to-Code Rules
|
|
2
|
+
|
|
3
|
+
## Workflow
|
|
4
|
+
1. Extract design context from Figma (MCP or screenshot) before coding
|
|
5
|
+
2. Map Figma values to project's Tailwind design tokens — never hardcode hex/px
|
|
6
|
+
3. Check `src/components/` for reusable components before creating new ones
|
|
7
|
+
4. Preserve Auto Layout as flexbox/grid — no absolute positioning
|
|
8
|
+
5. Verify output visually against Figma (desktop 1440px + mobile 375px)
|
|
9
|
+
|
|
10
|
+
## Token Mapping
|
|
11
|
+
- Colors: semantic tokens (`bg-primary-500`) not hex (`#3b82f6`)
|
|
12
|
+
- Spacing: scale tokens (`p-4`, `gap-6`) not arbitrary (`mt-[47px]`)
|
|
13
|
+
- Typography: type scale (`text-h1`, `text-b1`) not raw font-size
|
|
14
|
+
- Border radius: named tokens (`rounded-card`) not arbitrary
|
|
15
|
+
|
|
16
|
+
## Component Mapping
|
|
17
|
+
- Figma variants → React props (e.g., "Style=Primary" → `variant="primary"`)
|
|
18
|
+
- Figma layer names → semantic HTML (`<nav>`, `<section>`, `<button>`)
|
|
19
|
+
- Figma spacing = CSS gap/padding, Figma constraints = flexbox alignment
|
|
20
|
+
- Reuse existing components — don't recreate what already exists
|
|
21
|
+
|
|
22
|
+
## Responsive
|
|
23
|
+
- Never assume mobile = smaller desktop — check each breakpoint in Figma
|
|
24
|
+
- Implement mobile-first: base → sm → md → lg → xl
|
|
25
|
+
- Mobile may have different layout, hidden elements, different spacing
|
|
26
|
+
|
|
27
|
+
## Mistakes to Avoid
|
|
28
|
+
- No hardcoded colors or spacing — always use tokens
|
|
29
|
+
- No skipping visual verification
|
|
30
|
+
- No arbitrary Tailwind values when a token exists
|
|
31
|
+
- No absolute positioning where flex/grid works
|
|
32
|
+
- No new components when existing ones match
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Monorepo Rules
|
|
2
|
+
|
|
3
|
+
- Respect package boundaries — import through package names, not relative paths
|
|
4
|
+
- Changes to shared packages affect all consumers — be cautious
|
|
5
|
+
- Run commands from root: `{{packageManager}} run build --filter=<package>`
|
|
6
|
+
- Don't duplicate dependencies — hoist shared deps to root
|
|
7
|
+
- Check downstream impact before modifying shared packages
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# Next.js App Router Rules
|
|
2
|
+
|
|
3
|
+
- Default to Server Components — only use `'use client'` for interactivity
|
|
4
|
+
- Use `generateMetadata` for SEO, not hardcoded `<head>` tags
|
|
5
|
+
- Colocate `loading.tsx`, `error.tsx`, `not-found.tsx` with pages
|
|
6
|
+
- Data fetching: use `fetch()` in Server Components, Server Actions for mutations
|
|
7
|
+
- Use `<Link>` for navigation, `next/image` for images
|
|
8
|
+
- No `useEffect` for data fetching in Server Components
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Next.js Pages Router Rules
|
|
2
|
+
|
|
3
|
+
- Use `getStaticProps` for static data, `getServerSideProps` for per-request data
|
|
4
|
+
- API routes in `pages/api/` with proper HTTP method checking
|
|
5
|
+
- Use `next/head` for page metadata, `next/link` for navigation
|
|
6
|
+
- Client-side data: use SWR or React Query, not raw `useEffect` + `fetch`
|
|
7
|
+
- Handle `fallback` in `getStaticPaths` for dynamic routes
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# Sitecore XM Cloud Rules
|
|
2
|
+
|
|
3
|
+
- Use Sitecore field helpers (`<Text>`, `<RichText>`, `<Image>`, `<Link>`) — never render `.value` directly
|
|
4
|
+
- Component names must match Sitecore rendering items exactly
|
|
5
|
+
- Use `withDatasourceCheck` HOC for datasource-dependent components
|
|
6
|
+
- Register new components in the component factory
|
|
7
|
+
- GraphQL queries go in `.graphql` files alongside components
|
|
8
|
+
- Don't use `getStaticProps` directly — use Sitecore's SSG/SSR integration
|
|
9
|
+
- Don't hardcode content that should come from Sitecore fields
|