@sylphx/flow 0.2.1 → 0.2.3

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.
Files changed (102) hide show
  1. package/assets/agents/coder.md +1 -1
  2. package/assets/agents/orchestrator.md +1 -1
  3. package/assets/agents/reviewer.md +1 -1
  4. package/assets/agents/writer.md +13 -13
  5. package/assets/slash-commands/context.md +112 -0
  6. package/dist/assets/agents/coder.md +32 -0
  7. package/dist/assets/agents/orchestrator.md +36 -0
  8. package/dist/assets/agents/reviewer.md +30 -0
  9. package/dist/assets/agents/writer.md +30 -0
  10. package/dist/assets/knowledge/data/sql.md +216 -0
  11. package/dist/assets/knowledge/guides/saas-template.md +85 -0
  12. package/dist/assets/knowledge/guides/system-prompt.md +344 -0
  13. package/dist/assets/knowledge/guides/tech-stack.md +92 -0
  14. package/dist/assets/knowledge/guides/ui-ux.md +44 -0
  15. package/dist/assets/knowledge/stacks/nextjs-app.md +165 -0
  16. package/dist/assets/knowledge/stacks/node-api.md +220 -0
  17. package/dist/assets/knowledge/stacks/react-app.md +232 -0
  18. package/dist/assets/knowledge/universal/deployment.md +109 -0
  19. package/dist/assets/knowledge/universal/performance.md +121 -0
  20. package/dist/assets/knowledge/universal/security.md +79 -0
  21. package/dist/assets/knowledge/universal/testing.md +111 -0
  22. package/dist/assets/output-styles/silent.md +23 -0
  23. package/dist/assets/rules/core.md +144 -0
  24. package/dist/assets/slash-commands/commit.md +23 -0
  25. package/dist/assets/slash-commands/context.md +112 -0
  26. package/dist/assets/slash-commands/explain.md +35 -0
  27. package/dist/assets/slash-commands/mep.md +63 -0
  28. package/dist/assets/slash-commands/review.md +39 -0
  29. package/dist/assets/slash-commands/test.md +30 -0
  30. package/dist/chunk-1rptg3yg.js +4 -0
  31. package/dist/chunk-1rptg3yg.js.map +10 -0
  32. package/dist/{chunk-124wqbdb.js → chunk-4fr8q0jy.js} +3 -3
  33. package/dist/{chunk-124wqbdb.js.map → chunk-4fr8q0jy.js.map} +1 -1
  34. package/dist/{chunk-f6y5vttn.js → chunk-5szm4n3x.js} +3 -3
  35. package/dist/{chunk-f6y5vttn.js.map → chunk-5szm4n3x.js.map} +1 -1
  36. package/dist/chunk-7nht27vs.js +4 -0
  37. package/dist/{chunk-g9t3me0w.js.map → chunk-7nht27vs.js.map} +2 -2
  38. package/dist/chunk-8krxe10w.js +3 -0
  39. package/dist/{chunk-e966bjm5.js.map → chunk-8krxe10w.js.map} +2 -2
  40. package/dist/{chunk-wpe7rw5c.js → chunk-8z1sf25t.js} +3 -3
  41. package/dist/{chunk-wpe7rw5c.js.map → chunk-8z1sf25t.js.map} +1 -1
  42. package/dist/chunk-9c2nr2fz.js +25 -0
  43. package/dist/chunk-9c2nr2fz.js.map +61 -0
  44. package/dist/{chunk-4p754rhd.js → chunk-asr22mbn.js} +2 -2
  45. package/dist/{chunk-4p754rhd.js.map → chunk-asr22mbn.js.map} +2 -2
  46. package/dist/chunk-bnxtqetr.js +23 -0
  47. package/dist/chunk-bnxtqetr.js.map +11 -0
  48. package/dist/chunk-cs1s5c3g.js +54 -0
  49. package/dist/chunk-cs1s5c3g.js.map +53 -0
  50. package/dist/chunk-cv1nhr27.js +2 -0
  51. package/dist/{chunk-hshjnpm0.js.map → chunk-cv1nhr27.js.map} +1 -1
  52. package/dist/chunk-d4hj6d4t.js +6 -0
  53. package/dist/chunk-d4hj6d4t.js.map +11 -0
  54. package/dist/chunk-f06ma45b.js +15 -0
  55. package/dist/chunk-f06ma45b.js.map +16 -0
  56. package/dist/chunk-fs3f7acb.js +4 -0
  57. package/dist/chunk-fs3f7acb.js.map +12 -0
  58. package/dist/{chunk-5r4afhzp.js → chunk-gh83x9ya.js} +3 -3
  59. package/dist/{chunk-5r4afhzp.js.map → chunk-gh83x9ya.js.map} +1 -1
  60. package/dist/{chunk-qa8b725g.js → chunk-gyq335sw.js} +6 -5
  61. package/dist/{chunk-qa8b725g.js.map → chunk-gyq335sw.js.map} +1 -1
  62. package/dist/{chunk-hs3nxzyz.js → chunk-hft1735c.js} +2 -2
  63. package/dist/{chunk-hs3nxzyz.js.map → chunk-hft1735c.js.map} +2 -2
  64. package/dist/chunk-hj6r7703.js +3 -0
  65. package/dist/{chunk-78bfvh46.js.map → chunk-hj6r7703.js.map} +2 -2
  66. package/dist/chunk-hxj4eapp.js +14 -0
  67. package/dist/chunk-hxj4eapp.js.map +20 -0
  68. package/dist/chunk-jgsq3xax.js +23 -0
  69. package/dist/chunk-jgsq3xax.js.map +132 -0
  70. package/dist/{chunk-646h52kd.js → chunk-m9nt0bj3.js} +3 -3
  71. package/dist/{chunk-646h52kd.js.map → chunk-m9nt0bj3.js.map} +1 -1
  72. package/dist/{chunk-bd11hvvz.js → chunk-ndah8mn9.js} +2 -2
  73. package/dist/{chunk-bd11hvvz.js.map → chunk-ndah8mn9.js.map} +1 -1
  74. package/dist/chunk-s6g21d1g.js +27 -0
  75. package/dist/{chunk-0h7sfwq3.js.map → chunk-s6g21d1g.js.map} +4 -5
  76. package/dist/{chunk-hshjnpm0.js → chunk-sxy6vp20.js} +2 -2
  77. package/dist/chunk-sxy6vp20.js.map +9 -0
  78. package/dist/chunk-vjf57v4h.js +4 -0
  79. package/dist/chunk-vjf57v4h.js.map +10 -0
  80. package/dist/{chunk-jxny6xft.js → chunk-w2vbmr93.js} +2 -2
  81. package/dist/{chunk-jxny6xft.js.map → chunk-w2vbmr93.js.map} +1 -1
  82. package/dist/chunk-wd9qbbe5.js +5 -0
  83. package/dist/chunk-wd9qbbe5.js.map +10 -0
  84. package/dist/chunk-wnaa55wn.js +108 -0
  85. package/dist/chunk-wnaa55wn.js.map +24 -0
  86. package/dist/chunk-wrx1n6q6.js +16 -0
  87. package/dist/chunk-wrx1n6q6.js.map +16 -0
  88. package/dist/chunk-xata5rw6.js +119 -0
  89. package/dist/{chunk-878q8xdr.js.map → chunk-xata5rw6.js.map} +7 -18
  90. package/dist/chunk-z2rtyk3d.js +7 -0
  91. package/dist/{chunk-ygdr4fw7.js.map → chunk-z2rtyk3d.js.map} +2 -2
  92. package/dist/index.js +446 -482
  93. package/dist/index.js.map +301 -202
  94. package/package.json +4 -1
  95. package/dist/chunk-0h7sfwq3.js +0 -27
  96. package/dist/chunk-78bfvh46.js +0 -3
  97. package/dist/chunk-878q8xdr.js +0 -86
  98. package/dist/chunk-e966bjm5.js +0 -3
  99. package/dist/chunk-fxwaa2mg.js +0 -4
  100. package/dist/chunk-fxwaa2mg.js.map +0 -10
  101. package/dist/chunk-g9t3me0w.js +0 -4
  102. package/dist/chunk-ygdr4fw7.js +0 -7
@@ -0,0 +1,344 @@
1
+ ---
2
+ name: System Prompt Writing Guide
3
+ description: MEP (Minimal Effective Prompt) framework for writing high-signal, efficient prompts
4
+ ---
5
+
6
+ # Minimal Effective Prompt (MEP) Framework
7
+
8
+ > **Core Philosophy**: Find the smallest set of high-signal tokens that maximize desired outcomes.
9
+
10
+ ## Core Principles
11
+
12
+ ### The Three Golden Rules
13
+
14
+ **1. Trust LLM Intelligence**
15
+ Modern LLMs (GPT-4, Claude Sonnet 4+):
16
+ - Strong contextual reasoning and inference
17
+ - Pattern generalization from 1-2 examples
18
+ - Trained on common frameworks, standards, best practices
19
+ - Understand semantic compression
20
+
21
+ **2. Eliminate Redundancy**
22
+ Each concept appears **exactly once**.
23
+ - Stated in A → Don't repeat in B
24
+ - Implied by X → Don't state explicitly
25
+ - Common sense → Don't state at all
26
+
27
+ **3. Achieve Goldilocks Zone**
28
+ Balance:
29
+ - Too rigid: Hardcoded if-else, excessive checklists, brittle rules
30
+ - Too vague: "Be helpful", high-level platitudes, no concrete guidance
31
+ - **Goldilocks**: Specific guidance + flexible heuristics
32
+
33
+ ---
34
+
35
+ ## The MEP Framework
36
+
37
+ ### The Three Questions (For Every Token)
38
+
39
+ **1. Is this UNIQUE?**
40
+ - Can it be inferred from other parts?
41
+ - Is it in LLM's training data?
42
+ - Is it just a rewording?
43
+
44
+ **2. Is this ACTIONABLE?**
45
+ - Does it enable concrete behavior?
46
+ - Can LLM act on this?
47
+ - Is it specific enough?
48
+
49
+ **3. Is this HIGH-SIGNAL?**
50
+ - Does it directly impact outcome?
51
+ - Is it critical to success?
52
+ - Would removing it degrade performance?
53
+
54
+ **Decision Matrix:**
55
+ ```
56
+ All 3 YES → KEEP (essential)
57
+ Any 1 NO → REMOVE or MERGE
58
+ All 3 NO → DELETE immediately
59
+ ```
60
+
61
+ ### Signal Density Target
62
+
63
+ - **Good**: 60-70% high-signal
64
+ - **Great**: 70-80% high-signal
65
+ - **Exceptional**: 80-90% high-signal
66
+
67
+ Calculate: (High-signal tokens / Total tokens) × 100%
68
+
69
+ ---
70
+
71
+ ## Writing Process
72
+
73
+ ### Phase 1: Brain Dump
74
+ Capture all requirements, rules, guidance. Don't filter. Focus on completeness.
75
+
76
+ ### Phase 2: Structure
77
+ Organize into logical sections:
78
+ 1. Core Rules/Principles (always true)
79
+ 2. Identity/Role (who is LLM)
80
+ 3. Foundational Concepts (philosophy)
81
+ 4. Operational Guidance (how to work)
82
+ 5. Tools & Resources (available)
83
+ 6. Decision Support (when unclear)
84
+ 7. Standards (quality, security)
85
+ 8. Anti-Patterns (what to avoid)
86
+ 9. Output Format (what to deliver)
87
+
88
+ ### Phase 3: Identify Redundancy
89
+
90
+ **Type A - Exact Repetition**: Same concept, same wording → Keep 1st, delete all others
91
+
92
+ **Type B - Semantic Repetition**: Same concept, different wording → Keep clearest
93
+
94
+ **Type C - Implied Repetition**: B is logical consequence of A → Keep only A
95
+
96
+ **Type D - Section Redundancy**: Entire section restates another → Delete entire section
97
+
98
+ ### Phase 4: Apply The Three Questions
99
+
100
+ For each section, validate against uniqueness, actionability, high-signal.
101
+
102
+ **Remove common sense:**
103
+ ❌ "Never commit broken code", "Use descriptive names", "Test your code"
104
+
105
+ **Keep specific guidance:**
106
+ ✅ "Run tests after EVERY change", "Refactor on 3rd duplication", "Extract when >20 lines"
107
+
108
+ ### Phase 5: Optimize Expression
109
+
110
+ **Compact Syntax:**
111
+ ```
112
+ ❌ "First do A, then B, then C" → ✅ "A → B → C"
113
+ ❌ "Choose from: A, B, or C" → ✅ "Choose: A / B / C"
114
+ ❌ "If X then Y" → ✅ "X? → Y"
115
+ ❌ "Never X, never Y, never Z" → ✅ "Never: X / Y / Z"
116
+ ```
117
+
118
+ **List Consolidation:**
119
+ - **Bullets**: Complex items needing explanation
120
+ - **Commas**: Simple, parallel items
121
+
122
+ **Remove Filler:**
123
+ ```
124
+ ❌ "You should always make sure to test" → ✅ "Always test"
125
+ ❌ "It is important that you document" → ✅ "Document"
126
+ ❌ "Try to choose the simplest" → ✅ "Choose simplest"
127
+ ```
128
+
129
+ **Merge Related Sections:**
130
+ When sections are conceptually related, <50 tokens each, total merged <150 tokens.
131
+
132
+ ### Phase 6: Format & Polish
133
+
134
+ **Headers**: Use hierarchy (`#` > `##` > `###`), avoid excessive nesting
135
+
136
+ **Emphasis**: Bold for key terms (first mention only), emoji sparingly (section markers only)
137
+
138
+ **Code Blocks**: For templates, examples, specific formats only
139
+
140
+ **Tables**: For comparisons and decision matrices
141
+
142
+ ---
143
+
144
+ ## Judgment Criteria
145
+
146
+ ### What to KEEP
147
+
148
+ **Unique Information:**
149
+ - Custom conventions (document format, commit format, priority hierarchy)
150
+ - Novel frameworks (execution modes, decision frameworks)
151
+ - Specific guidance ("Refactor on 3rd duplication", "Extract when >20 lines")
152
+
153
+ **Actionable Directives:**
154
+ - Specific actions ("Run tests after every change", "Validate inputs at boundaries")
155
+ - Clear workflows ("Analyze → Check → Assume → Implement")
156
+ - Decision rules ("Ambiguous? → existing > conventions > standards")
157
+
158
+ **High-Signal Examples:**
159
+ 1-2 representative examples per concept (LLM generalizes)
160
+
161
+ ### What to REMOVE
162
+
163
+ **Redundant Content:**
164
+ - Exact repetition (same concept, same wording)
165
+ - Semantic repetition (same concept, different wording)
166
+ - Implied content (B follows from A)
167
+ - Redundant sections (duplicates another section)
168
+
169
+ **Low-Signal Content:**
170
+ - Common sense ("Write clean code", "Comment your code")
171
+ - Vague directives ("Be thoughtful", "Think carefully", "Consider context")
172
+ - Over-emphasis ("🔴 CRITICAL: MUST VERIFY" → "Verify")
173
+
174
+ **Verbose Expression:**
175
+ - Filler words ("You should always...", "It is important that...")
176
+ - Redundant explanations (LLM infers implications)
177
+
178
+ ---
179
+
180
+ ## Common Pitfalls
181
+
182
+ **Over-Specification**: 50+ conditional rules → Principles + heuristics instead
183
+
184
+ **Repetition for Emphasis**: Stating "Never block" 4 times → State once, trust LLM
185
+
186
+ **Excessive Examples**: 5+ examples of same pattern → 2 examples sufficient
187
+
188
+ **Common Sense Inclusion**: Universal programming knowledge → Omit
189
+
190
+ **Vague Directives**: "Be thoughtful" → Specific, actionable
191
+
192
+ **Format Overload**: Too many emoji/bold/emphasis → Minimal, purposeful
193
+
194
+ **Section Bloat**: 20+ tiny sections → Merge related (8-15 sections ideal)
195
+
196
+ ---
197
+
198
+ ## Quality Checklist
199
+
200
+ ### Before Optimization
201
+ - [ ] Brain dump complete
202
+ - [ ] Organized into sections
203
+ - [ ] All examples included
204
+ - [ ] All rules documented
205
+
206
+ ### During Optimization
207
+ - [ ] No concept appears >1 time
208
+ - [ ] Every statement passes 3 questions
209
+ - [ ] Compact syntax used
210
+ - [ ] Related sections merged
211
+
212
+ ### After Optimization
213
+ - [ ] All scenarios handleable
214
+ - [ ] All frameworks fully specified
215
+ - [ ] 40-60% token reduction
216
+ - [ ] 75-85% signal density
217
+ - [ ] 8-15 main sections
218
+ - [ ] 1-2 examples per concept
219
+ - [ ] Goldilocks Zone achieved (specific + flexible)
220
+ - [ ] Clean, scannable formatting
221
+
222
+ ---
223
+
224
+ ## Decision Trees
225
+
226
+ ### "Should I keep this content?"
227
+ ```
228
+ Is it unique (not inferable)?
229
+ ├─ NO → DELETE
230
+ └─ YES → Is it actionable?
231
+ ├─ NO → DELETE
232
+ └─ YES → Is it high-signal?
233
+ ├─ NO → DELETE
234
+ └─ YES → KEEP
235
+ ```
236
+
237
+ ### "Should I include this example?"
238
+ ```
239
+ How many examples already?
240
+ ├─ 0 → ADD 1-2 representative
241
+ ├─ 1-2 → GOOD, stop
242
+ └─ 3+ → TOO MANY, remove least representative
243
+ ```
244
+
245
+ ### "Should I merge these sections?"
246
+ ```
247
+ Are they related?
248
+ ├─ NO → Keep separate
249
+ └─ YES → Each <50 tokens?
250
+ ├─ NO → Keep separate
251
+ └─ YES → Total merged <150?
252
+ ├─ NO → Keep separate
253
+ └─ YES → MERGE
254
+ ```
255
+
256
+ ---
257
+
258
+ ## Practical Examples
259
+
260
+ ### Example 1: Optimizing Rules
261
+
262
+ **Before (110 tokens):**
263
+ ```markdown
264
+ ## Rule 1: Never Block On Uncertainty
265
+
266
+ **IMPORTANT**: You must never stop working due to missing information...
267
+
268
+ When you encounter uncertainty:
269
+ 1-8. [Long list of steps]
270
+
271
+ Remember: It is better to complete...
272
+ ```
273
+
274
+ **After (15 tokens, -86%):**
275
+ ```markdown
276
+ ## Rule 1: Never Block
277
+
278
+ Make reasonable assumptions, document them, complete task.
279
+ ```
280
+
281
+ ### Example 2: Optimizing Decisions
282
+
283
+ **Before (115 tokens):**
284
+ ```markdown
285
+ When you face an ambiguous requirement:
286
+ - You should choose the most reasonable...
287
+ [Multiple verbose bullet points]
288
+ ```
289
+
290
+ **After (30 tokens, -74%):**
291
+ ```markdown
292
+ **Ambiguous?** → existing patterns > conventions > standards. Document assumption.
293
+ **Missing info?** → Industry defaults, make configurable.
294
+ **Multiple options?** → Simplest. Note alternatives.
295
+ ```
296
+
297
+ ---
298
+
299
+ ## Token Budget Guidelines
300
+
301
+ **System Prompt Types:**
302
+
303
+ | Type | Target Tokens | Max Tokens | Focus |
304
+ |------|--------------|------------|-------|
305
+ | Shared Protocol | 150-250 | 300 | Lightweight, universal |
306
+ | Agent-Specific | 800-1200 | 1500 | Comprehensive, specialized |
307
+ | Task-Specific | 300-500 | 700 | Focused, actionable |
308
+
309
+ ---
310
+
311
+ ## Final Validation
312
+
313
+ **A great prompt should feel like:**
314
+ - ✅ Well-written manual (clear, concise, complete)
315
+ - ✅ Expert colleague conversation (professional, efficient)
316
+ - ✅ Set of principles (guiding, not restricting)
317
+
318
+ **A great prompt should NOT feel like:**
319
+ - ❌ Legal terms (exhaustive, repetitive, cautious)
320
+ - ❌ IKEA instructions (step-by-step, rigid, brittle)
321
+ - ❌ Drill sergeant (emphasis, repetition, no trust)
322
+
323
+ **The Ultimate Tests:**
324
+
325
+ **Can you explain your prompt's purpose in one sentence?**
326
+ - Yes → Focused ✅
327
+ - No → Tries to do too much ❌
328
+
329
+ **Can you identify high-signal vs noise?**
330
+ - 75%+ essential → Great ✅
331
+ - 50-75% essential → Good, can improve 🟡
332
+ - <50% essential → Too much noise ❌
333
+
334
+ **Would you want to read your prompt?**
335
+ - Yes → Clean, professional, scannable ✅
336
+ - No → Needs work ❌
337
+
338
+ ---
339
+
340
+ ## Conclusion
341
+
342
+ Great prompts = **Clarity** (each concept once) + **Trust** (LLM intelligence) + **Economy** (every token earns place) + **Effectiveness** (achieve outcomes)
343
+
344
+ Shorter. Clearer. More effective. 🎯
@@ -0,0 +1,92 @@
1
+ ---
2
+ name: Tech Stack (Recommended)
3
+ description: Opinionated stack (Next.js, PandaCSS, GraphQL, Pothos, Drizzle) - optimized for LLM accuracy
4
+ ---
5
+
6
+ # Technical Stack
7
+
8
+ Scalable, secure SaaS stack. Type safety, performance, serverless. Validate with E2E (Playwright), monitor with Sentry.
9
+
10
+ ## Domain-Driven Architecture
11
+
12
+ Feature-based layout: `src/features/<domain>/` (frontend), `src/graphql/<domain>/` (backend). Colocate related code. Cross-domain via explicit exports.
13
+
14
+ **Frontend domains**: `src/features/<domain>/` → `components/`, `hooks/`, `store/`, `services/`, `utils/`, `types.ts`
15
+ **Backend domains**: `src/graphql/<domain>/` → `types/`, `queries.ts`, `mutations.ts`, `subscriptions.ts`, `loaders.ts` (DataLoader for N+1)
16
+ **Shared infra**: `src/lib/` (clients), `src/app/` (routes, providers)
17
+
18
+ ## Frontend Stack
19
+
20
+ **Framework**: Next.js App Router (routing, SSR/SSG, Turbopack). `src/app/(app)/dashboard/page.tsx`
21
+
22
+ **UI**: React + Radix UI primitives (a11y). Prefer Radix for structural/interactive, custom only when Radix lacks. `src/features/<domain>/components/`
23
+
24
+ **State**: Zustand (global sessions). Avoid Redux. `src/features/<domain>/store/`
25
+
26
+ **Styling**: PandaCSS (type-safe atomic CSS-in-JS, zero-runtime, <10KB)
27
+ - **Tokens/Themes**: `panda.config.ts` semantics (`colors.primary.500`), `_dark`/CSS vars
28
+ - **Atomic**: Inline JSX (`bg-primary-500 p-4`), `css({ color: 'red' })` merges
29
+ - **Recipes**: `cva` (Button variants), `sva` slots (Card), `jsx: ['Button']` track
30
+ - **Merging**: `cx(recipe(), css({ bg: 'red' }))` overrides
31
+ - **Optimize**: `staticCss: { recipes: '*' }`, purge globs, `panda analyze`, Next.js plugins
32
+
33
+ **Hooks**: react-use (localStorage, useMeasure, useDebounce, sensors), urql (GraphQL cache, SSR, subscriptions, offline, batching)
34
+
35
+ **Auth**: Better Auth (passkey-first, 2FA), reCAPTCHA (bot mitigation)
36
+
37
+ ## Backend Stack
38
+
39
+ GraphQL-first, serverless. `src/graphql/<domain>/`
40
+
41
+ **Schema/Server**: Pothos (code-first), Yoga. `gql.tada` for all GraphQL docs (never raw templates), `graphql-scalars` for custom scalars
42
+ - Modular `queryField`, typed client hooks via `gql.tada`, colocate operations with components/pages, DataLoader in `loaders.ts` (batch, cache, prevent N+1)
43
+
44
+ **Auth**: Better Auth (JWT/Redis denylist), rotate tokens
45
+
46
+ **Request Context**: AsyncLocalStorage with `headers()`/`cookies()` → tiny accessors (`getAuthSession()`, `getLocale()`) instead of passing context objects
47
+
48
+ **ORM**: Drizzle (queries/migrations). **Never** raw SQL except unavoidable complex cases (use parameterized placeholders). Query builder methods (`eq`, `and`, `or`). Schemas/queries per domain: `src/domains/<domain>/data/`
49
+ - `db.select().from(users).where(eq(users.id, userId))`
50
+
51
+ **Security**: @simplewebauthn/server, Redis limits
52
+
53
+ ## Data Layer
54
+
55
+ **DB**: PostgreSQL (Neon/pgBouncer), RLS. Scale: Partition (logs/date)
56
+
57
+ **Cache/RT**: Upstash Redis (cache/pubsub/streams). TTL (24h), event streams
58
+
59
+ ## Payments
60
+
61
+ **Billing**: Stripe (Checkout/Portal/Invoices/webhooks idempotent). Wallet credit on session complete, 3x retry
62
+
63
+ ## DevOps
64
+
65
+ **Local**: Docker Compose (stack), bun, Biome (linting/formatting), Lefthook (Git hooks)
66
+ - **Biome Ignore**: Tests (`__tests__/**`, `*.test.*`), generated (`*.generated.*`, `dist/**`), project-specific (`styled-system`, `*.gql.tada.ts`, `drizzle`, `.next`)
67
+ - **Biome Config**: Recommended + custom flow, ignoreUnknown false
68
+ - **Lefthook**: Pre-commit (Biome, type-check), pre-push (tests). `bun add -D lefthook`, `lefthook install`
69
+ - **Entry**: `bun install && migrate && dev`, Lefthook auto-runs, `biome check .` in CI
70
+
71
+ **Deploy**: Serverless (Vercel), GraphQL BFF. CI: Actions, 99.9% SLO alerts
72
+
73
+ ## Framework Rules
74
+
75
+ ### GraphQL Standards
76
+ - **IDs**: Use `ID` scalar (not `String`). Base64 for keys.
77
+ - **Enums/Unions**: Enums for fixed (Role), unions for polymorphic (Result = Post | User). Limit depth 3-5.
78
+
79
+ ### GraphQL Document Placement
80
+ Colocate operations in domain services (`src/features/<domain>/services/`), `src/graphql/<domain>/`
81
+ - **Routes/pages**: Import from domain services for tree-shaking
82
+ - **Components**: Queries/mutations in domain services, export typed helpers
83
+ - **Stores**: GraphQL docs in domain services
84
+ - **Fragments**: `src/features/<domain>/services/fragments/` with barrel exports
85
+ - **Tests**: Colocate under `src/features/<domain>/`
86
+ - **Typed modules**: `.gql.ts` stay domain-local, enriched by `graphql-env.d.ts`
87
+
88
+ ### Pothos Best Practices
89
+ - **ID Handling**: `exposeId: false` by default (security), `exposeId: true` only when needed
90
+ - **Subscription Ordering**: `subscribe` before `resolve` for TS inference
91
+ - **Extensions**: `extendType` for modularity, integrate gql.tada for E2E types
92
+ - **Errors**: Custom scalars (graphql-scalars), try-catch with GraphQLError
@@ -0,0 +1,44 @@
1
+ ---
2
+ name: UI/UX Guidelines
3
+ description: Modern SPA design patterns, PandaCSS, Radix UI, conversational interfaces
4
+ ---
5
+
6
+ # Modern SPA UI/UX
7
+
8
+ Apply when designing/updating single-page application interfaces. Keep concise, modular, consistent with conversational products (chat-first SaaS).
9
+
10
+ ## Core Principles
11
+ - Minimalist functionalism: Remove clutter, highlight primary content/controls
12
+ - Balanced readability: Letter-spacing 1.2–1.5, line-height ≥1.5, clear hierarchy
13
+ - Global consistency: Reuse tokens for spacing, color, typography, radii
14
+ - Perceived fluidity: Transitions <200ms, never block input
15
+
16
+ ## Visual System
17
+ - **Color**: Dark backgrounds (#111–#1A1A), optional light mode. One accent for CTAs. WCAG AA contrast ≥4.5:1
18
+ - **Shapes**: 8–12px border radius. Cards with subtle shadows (0 1px 3px rgba(0,0,0,0.1))
19
+ - **Typography**: Sans-serif (Inter, SF Pro). Bold headings, progressively larger. Body 14–16px, 1.5 line-height
20
+
21
+ ## Micro-Interactions
22
+ - Duration: 200–400ms ease-in-out
23
+ - Hover: 1.03× scale or deeper shadow
24
+ - Active: 0.95–0.98× for tactile feedback
25
+ - Page transitions: Fade/slide, prefetch routes (<100ms latency)
26
+
27
+ ## Interaction Patterns
28
+ - **Conversational**: Messages top-to-bottom, timestamp/metadata aligned (chat UIs)
29
+ - **Input**: Pin primary composer at viewport bottom, minimal controls
30
+ - **Feedback**: Visual response on every submit/load/state change (spinners, progress, confirmations)
31
+ - **Expandable**: Collapse long sections, keep critical details visible
32
+
33
+ ## UX Guidelines
34
+ - Persistent nav (top/sidebar), limit to 5–7 items
35
+ - Eliminate distractions: No autoplay, reduce focal points
36
+ - Natural scrolling, lazy loading for long lists/media
37
+ - Reusable primitives (buttons, cards, inputs) with consistent props
38
+ - Mobile-first: Validate 320px, 768px, 1024px breakpoints, identical functionality
39
+
40
+ ## Validation
41
+ - Contrast/readability in dark/light (axe-core, Lighthouse ≥90)
42
+ - Hover/tap feedback within 50ms
43
+ - Responsive layouts on phone/tablet/desktop, adjust spacing/typography for overflow
44
+ - Document UI decisions (tokens, components) for reuse
@@ -0,0 +1,165 @@
1
+ ---
2
+ name: Next.js Application
3
+ description: Next.js App Router, Server Components, data fetching, routing, deployment
4
+ ---
5
+
6
+ # Next.js Development
7
+
8
+ ## When Next.js vs React SPA
9
+
10
+ **Next.js**: SEO matters, fast initial load, full-stack in one codebase
11
+ **React SPA**: Dashboard/admin, behind auth, separate backend exists
12
+
13
+ ## App Router vs Pages Router
14
+
15
+ **App Router (app/)** - Recommended:
16
+ - Server Components by default (less JS)
17
+ - Built-in layouts, loading, error states
18
+ - Better data fetching patterns
19
+
20
+ **Pages Router (pages/)**: Legacy maintenance only
21
+
22
+ ## Server vs Client Components
23
+
24
+ ### Decision Tree
25
+ ```
26
+ Needs interactivity? (onClick, useState, hooks)
27
+ ├─ YES → 'use client'
28
+ └─ NO → Server Component (default)
29
+ ```
30
+
31
+ **Server Components (default):**
32
+ - Render on server, direct DB access, zero client JS
33
+ - Can't use hooks/handlers
34
+
35
+ **Client Components ('use client'):**
36
+ - Hooks, handlers, interactivity, ships JS to browser
37
+
38
+ ### Composition Pattern
39
+ Server components wrap client components. Fetch data in server, pass as props to client.
40
+
41
+ ## Data Fetching
42
+
43
+ ### Cache Options
44
+ ```typescript
45
+ // Cached forever (default)
46
+ await fetch('https://api.example.com/data')
47
+
48
+ // Cache with revalidation
49
+ await fetch('...', { next: { revalidate: 3600 } })
50
+
51
+ // Never cache
52
+ await fetch('...', { cache: 'no-store' })
53
+ ```
54
+
55
+ ### Parallel Fetching
56
+ ```typescript
57
+ // BAD - Sequential
58
+ const posts = await getPosts()
59
+ const users = await getUsers()
60
+
61
+ // GOOD - Parallel
62
+ const [posts, users] = await Promise.all([getPosts(), getUsers()])
63
+ ```
64
+
65
+ ## Caching & Revalidation
66
+
67
+ **Time-based (ISR):**
68
+ ```typescript
69
+ export const revalidate = 3600 // Every hour
70
+ ```
71
+
72
+ **On-demand:**
73
+ ```typescript
74
+ import { revalidatePath, revalidateTag } from 'next/cache'
75
+ revalidatePath('/posts')
76
+ revalidateTag('posts')
77
+ ```
78
+
79
+ **Dynamic (no cache):**
80
+ ```typescript
81
+ export const dynamic = 'force-dynamic'
82
+ ```
83
+
84
+ ## Routing
85
+
86
+ ### File Structure
87
+ ```
88
+ app/page.tsx → /
89
+ app/about/page.tsx → /about
90
+ app/blog/[slug]/page.tsx → /blog/:slug
91
+ app/(marketing)/features/page.tsx → /features (route group)
92
+ ```
93
+
94
+ ### Special Files
95
+ - `layout.tsx`: Shared UI for segment + children
96
+ - `loading.tsx`: Loading UI (Suspense boundary)
97
+ - `error.tsx`: Error UI (must be 'use client')
98
+
99
+ ## Authentication
100
+
101
+ ### Middleware (Route Protection)
102
+ ```typescript
103
+ // middleware.ts
104
+ export function middleware(request: Request) {
105
+ const token = request.cookies.get('token')
106
+ if (!token) return NextResponse.redirect(new URL('/login', request.url))
107
+ }
108
+
109
+ export const config = { matcher: '/dashboard/:path*' }
110
+ ```
111
+
112
+ ### Server Actions (Form Handling)
113
+ ```typescript
114
+ // app/actions.ts
115
+ 'use server'
116
+
117
+ export async function createPost(formData: FormData) {
118
+ const title = formData.get('title')
119
+ if (!title) return { error: 'Missing title' }
120
+
121
+ const post = await db.posts.create({ data: { title } })
122
+ revalidatePath('/posts')
123
+ return { success: true, post }
124
+ }
125
+
126
+ // In component
127
+ <form action={createPost}>
128
+ <input name="title" />
129
+ <button type="submit">Create</button>
130
+ </form>
131
+ ```
132
+
133
+ ## Performance
134
+
135
+ **Image**: Use `<Image>` with `priority` for above-fold, `placeholder="blur"` for UX
136
+ **Font**: `next/font/google` for automatic optimization
137
+ **Code Splitting**: `dynamic(() => import('./Heavy'), { ssr: false })` for client-only heavy components
138
+
139
+ ## Common Pitfalls
140
+
141
+ ❌ **'use client' everywhere** → Only for interactivity
142
+ ❌ **Over-fetching** → Fetch once in layout/page, pass as props
143
+ ❌ **Not streaming** → Use Suspense boundaries
144
+ ❌ **Forgetting revalidation** → Always revalidate after mutations
145
+
146
+ ## Environment Variables
147
+
148
+ ```bash
149
+ DATABASE_URL="..." # Server only
150
+ NEXT_PUBLIC_API_URL="..." # Exposed to browser (must start with NEXT_PUBLIC_)
151
+ ```
152
+
153
+ ## Decision Guide
154
+
155
+ **Server Component:**
156
+ - Fetching data, backend access, large dependencies, non-interactive
157
+
158
+ **Client Component:**
159
+ - Interactive (clicks, state, hooks), browser APIs, event handlers
160
+
161
+ **API Route:**
162
+ - Hide API keys, webhooks, complex server logic, third-party integrations
163
+
164
+ **Server Action:**
165
+ - Form submissions, mutations (CRUD), simple server ops