@activatus/code-standards 0.0.0-stage → 3.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.
Files changed (180) hide show
  1. package/README.md +199 -2
  2. package/docs/Guides/_category_.json +4 -0
  3. package/docs/Guides/component-library-workflow.md +182 -0
  4. package/docs/Guides/migrating.md +161 -0
  5. package/docs/Guides/setup.md +158 -0
  6. package/docs/Standards/_category_.json +4 -0
  7. package/docs/Standards/agent-skills.md +125 -0
  8. package/docs/Standards/agent-specs.md +74 -0
  9. package/docs/Standards/direnv.mdx +249 -0
  10. package/docs/Standards/documentation.md +314 -0
  11. package/docs/Standards/editorconfig.md +74 -0
  12. package/docs/Standards/eslint.md +900 -0
  13. package/docs/Standards/human-readable-names.md +274 -0
  14. package/docs/Standards/lint-errors.md +171 -0
  15. package/docs/Standards/prettier.md +106 -0
  16. package/docs/Standards/readable-code.md +570 -0
  17. package/docs/Standards/stylelint.md +193 -0
  18. package/docs/Standards/styling.md +290 -0
  19. package/docs/Standards/tech-stack.md +158 -0
  20. package/docs/Structure/_category_.json +4 -0
  21. package/docs/Structure/api-routes.md +118 -0
  22. package/docs/Structure/component-organization.md +526 -0
  23. package/docs/Structure/folder-structure.md +366 -0
  24. package/docs/Structure/import-organization.md +158 -0
  25. package/docs/Structure/naming-conventions.md +334 -0
  26. package/docs/design-system-components.md +117 -0
  27. package/docs/intro.md +44 -0
  28. package/docs/ontology.md +127 -0
  29. package/docs/templates.mdx +396 -0
  30. package/docs/version-history.md +338 -0
  31. package/package.json +60 -3
  32. package/scripts/renameSymbol.mjs +188 -0
  33. package/static/templates/.editorconfig +25 -0
  34. package/static/templates/.envrc +25 -0
  35. package/static/templates/.nvmrc +1 -0
  36. package/static/templates/AGENTS.md +163 -0
  37. package/static/templates/decision-doc.md +19 -0
  38. package/static/templates/docs/ai/agent-harness.md +17 -0
  39. package/static/templates/docs/ai/agents.md +17 -0
  40. package/static/templates/docs/ai/architecture.md +17 -0
  41. package/static/templates/docs/ai/context.md +17 -0
  42. package/static/templates/docs/ai/model-routing.md +17 -0
  43. package/static/templates/docs/ai/models.md +17 -0
  44. package/static/templates/docs/ai/retrieval.md +17 -0
  45. package/static/templates/docs/ai/tools.md +17 -0
  46. package/static/templates/docs/architecture/authentication.md +17 -0
  47. package/static/templates/docs/architecture/backend.md +17 -0
  48. package/static/templates/docs/architecture/background-jobs.md +17 -0
  49. package/static/templates/docs/architecture/backups.md +17 -0
  50. package/static/templates/docs/architecture/caching.md +17 -0
  51. package/static/templates/docs/architecture/ci-cd.md +17 -0
  52. package/static/templates/docs/architecture/disaster-recovery.md +17 -0
  53. package/static/templates/docs/architecture/environments.md +17 -0
  54. package/static/templates/docs/architecture/frontend.md +17 -0
  55. package/static/templates/docs/architecture/hosting.md +17 -0
  56. package/static/templates/docs/architecture/observability.md +17 -0
  57. package/static/templates/docs/architecture/realtime.md +17 -0
  58. package/static/templates/docs/architecture/search.md +17 -0
  59. package/static/templates/docs/architecture/services.md +17 -0
  60. package/static/templates/docs/architecture/state-management.md +17 -0
  61. package/static/templates/docs/architecture/storage.md +17 -0
  62. package/static/templates/docs/architecture/system.md +17 -0
  63. package/static/templates/docs/business/buying-trigger.md +17 -0
  64. package/static/templates/docs/business/customer-value.md +17 -0
  65. package/static/templates/docs/business/customer.md +17 -0
  66. package/static/templates/docs/business/defensibility.md +17 -0
  67. package/static/templates/docs/business/growth.md +17 -0
  68. package/static/templates/docs/business/pricing.md +17 -0
  69. package/static/templates/docs/business/revenue-model.md +17 -0
  70. package/static/templates/docs/business/unit-economics.md +17 -0
  71. package/static/templates/docs/data/analytics.md +17 -0
  72. package/static/templates/docs/data/audit.md +17 -0
  73. package/static/templates/docs/data/database.md +17 -0
  74. package/static/templates/docs/data/indexing.md +17 -0
  75. package/static/templates/docs/data/migrations.md +17 -0
  76. package/static/templates/docs/data/model.md +17 -0
  77. package/static/templates/docs/data/retention.md +17 -0
  78. package/static/templates/docs/data/schema.md +17 -0
  79. package/static/templates/docs/deployment/approval.md +17 -0
  80. package/static/templates/docs/deployment/live-verification.md +17 -0
  81. package/static/templates/docs/deployment/process.md +17 -0
  82. package/static/templates/docs/deployment/rollback.md +17 -0
  83. package/static/templates/docs/design/design-system.md +17 -0
  84. package/static/templates/docs/design/errors.md +17 -0
  85. package/static/templates/docs/design/feedback.md +17 -0
  86. package/static/templates/docs/design/interactions.md +17 -0
  87. package/static/templates/docs/design/layout.md +17 -0
  88. package/static/templates/docs/design/navigation.md +17 -0
  89. package/static/templates/docs/design/principles.md +17 -0
  90. package/static/templates/docs/design/responsive.md +17 -0
  91. package/static/templates/docs/development/branching.md +17 -0
  92. package/static/templates/docs/development/code-quality.md +17 -0
  93. package/static/templates/docs/development/coding-standards.md +21 -0
  94. package/static/templates/docs/development/commits.md +17 -0
  95. package/static/templates/docs/development/merge-strategy.md +17 -0
  96. package/static/templates/docs/development/process.md +17 -0
  97. package/static/templates/docs/development/pull-requests.md +17 -0
  98. package/static/templates/docs/experience/accessibility.md +17 -0
  99. package/static/templates/docs/experience/aha-moment.md +17 -0
  100. package/static/templates/docs/experience/anti-experience.md +17 -0
  101. package/static/templates/docs/experience/friction.md +17 -0
  102. package/static/templates/docs/experience/outcomes.md +17 -0
  103. package/static/templates/docs/experience/principles.md +17 -0
  104. package/static/templates/docs/experience/retention.md +17 -0
  105. package/static/templates/docs/experience/sharing.md +17 -0
  106. package/static/templates/docs/overview/how-it-works.md +17 -0
  107. package/static/templates/docs/overview/what-is-it.md +17 -0
  108. package/static/templates/docs/overview/writing-docs.md +16 -0
  109. package/static/templates/docs/pitch/alternatives.md +17 -0
  110. package/static/templates/docs/pitch/assumptions.md +17 -0
  111. package/static/templates/docs/pitch/audience.md +17 -0
  112. package/static/templates/docs/pitch/concept.md +17 -0
  113. package/static/templates/docs/pitch/differentiators.md +17 -0
  114. package/static/templates/docs/pitch/outcomes.md +17 -0
  115. package/static/templates/docs/pitch/problem.md +17 -0
  116. package/static/templates/docs/pitch/product-market-fit.md +17 -0
  117. package/static/templates/docs/pitch/success-criteria.md +17 -0
  118. package/static/templates/docs/pitch/validation.md +17 -0
  119. package/static/templates/docs/pitch/value-proposition.md +17 -0
  120. package/static/templates/docs/pitch/vision.md +17 -0
  121. package/static/templates/docs/scope/core.md +17 -0
  122. package/static/templates/docs/scope/exclusions.md +17 -0
  123. package/static/templates/docs/scope/future.md +17 -0
  124. package/static/templates/docs/scope/launch.md +17 -0
  125. package/static/templates/docs/scope/post-launch.md +17 -0
  126. package/static/templates/docs/scope/priorities.md +17 -0
  127. package/static/templates/docs/scope/quality-bar.md +17 -0
  128. package/static/templates/docs/security/audit.md +17 -0
  129. package/static/templates/docs/security/data-access.md +17 -0
  130. package/static/templates/docs/security/logging.md +17 -0
  131. package/static/templates/docs/security/privacy.md +17 -0
  132. package/static/templates/docs/security/secrets.md +17 -0
  133. package/static/templates/docs/security/threat-model.md +17 -0
  134. package/static/templates/docs/testing/end-to-end.md +17 -0
  135. package/static/templates/docs/testing/integration.md +17 -0
  136. package/static/templates/docs/testing/regression.md +17 -0
  137. package/static/templates/docs/testing/security.md +17 -0
  138. package/static/templates/docs/testing/strategy.md +17 -0
  139. package/static/templates/docs/testing/test-data.md +17 -0
  140. package/static/templates/docs/testing/unit.md +17 -0
  141. package/static/templates/docs/uat/checks.md +17 -0
  142. package/static/templates/docs/uat/strategy.md +17 -0
  143. package/static/templates/docs/users/permissions.md +17 -0
  144. package/static/templates/docs/users/roles.md +17 -0
  145. package/static/templates/docs/users/user-types.md +17 -0
  146. package/static/templates/docs/workflows/assignment.md +17 -0
  147. package/static/templates/docs/workflows/bugfix.md +17 -0
  148. package/static/templates/docs/workflows/dependencies.md +17 -0
  149. package/static/templates/docs/workflows/deployment.md +17 -0
  150. package/static/templates/docs/workflows/development.md +17 -0
  151. package/static/templates/docs/workflows/planning.md +17 -0
  152. package/static/templates/docs/workflows/review.md +17 -0
  153. package/static/templates/docs/workflows/uat.md +17 -0
  154. package/static/templates/docsSite/docusaurus.config.mjs +144 -0
  155. package/static/templates/docsSite/gitignore.txt +3 -0
  156. package/static/templates/docsSite/package.json.txt +42 -0
  157. package/static/templates/docsSite/pnpm-workspace.yaml +2 -0
  158. package/static/templates/docsSite/sidebars.mjs +7 -0
  159. package/static/templates/docsSite/src/css/custom.css +7 -0
  160. package/static/templates/docsSite/src/pages/index.tsx +9 -0
  161. package/static/templates/docsSite/static/images/logo.svg +4 -0
  162. package/static/templates/docsSite/tsconfig.json +7 -0
  163. package/static/templates/eslint/base/eslint.config.mjs +104 -0
  164. package/static/templates/eslint/nextjs/eslint.config.mjs +181 -0
  165. package/static/templates/eslint/react/eslint.config.mjs +173 -0
  166. package/static/templates/eslint/typescript/eslint.config.mjs +154 -0
  167. package/static/templates/globals.css +16 -0
  168. package/static/templates/husky/pre-commit +1 -0
  169. package/static/templates/next.config.mjs +21 -0
  170. package/static/templates/prettier.config.mjs +26 -0
  171. package/static/templates/skills/codeReview.md +31 -0
  172. package/static/templates/skills/format.md +18 -0
  173. package/static/templates/skills/lint.md +21 -0
  174. package/static/templates/skills/lintFix.md +24 -0
  175. package/static/templates/skills/securityAudit.md +28 -0
  176. package/static/templates/skills/test.md +24 -0
  177. package/static/templates/skills/typescript.md +28 -0
  178. package/static/templates/skills/updateLayout.md +20 -0
  179. package/static/templates/stylelint/css/stylelint.config.mjs +40 -0
  180. package/static/templates/stylelint/scss/stylelint.config.mjs +13 -0
@@ -0,0 +1,366 @@
1
+ ---
2
+ sidebar_position: 3
3
+ ---
4
+
5
+ # Folder Structure
6
+
7
+ This guide defines standard folder organization patterns for Activatus projects.
8
+
9
+ ## Principles
10
+
11
+ 1. **Predictability** - Developers should know where to find things
12
+ 2. **Scalability** - Structure should work for small and large projects
13
+ 3. **Consistency** - Same patterns across all projects
14
+ 4. **Clarity** - Folder names should describe their purpose
15
+
16
+ ---
17
+
18
+ ## 📁 Recommended Next.js Structure
19
+
20
+ For Next.js projects using App Router, use the **root-level `app/` directory**. This is the modern Next.js standard.
21
+
22
+ ```text
23
+ project-root/
24
+ ├── app/ # Next.js App Router pages & layouts
25
+ │ ├── (routes)/ # Route groups (kebab-case)
26
+ │ │ ├── account-settings/
27
+ │ │ │ ├── components/ # Route-specific components
28
+ │ │ │ │ └── accountForm/ # Example component structure
29
+ │ │ │ │ ├── AccountForm.tsx # Component implementation
30
+ │ │ │ │ ├── AccountForm.test.tsx # Unit tests
31
+ │ │ │ │ ├── types.ts # Component types
32
+ │ │ │ │ └── index.ts # Export file
33
+ │ │ │ └── page.tsx
34
+ │ │ └── page.tsx
35
+ │ ├── api/ # API routes (kebab-case)
36
+ │ │ ├── users/
37
+ │ │ │ └── route.ts
38
+ │ │ └── webhooks/
39
+ │ │ └── stripe/
40
+ │ │ └── route.ts
41
+ │ ├── layout.tsx
42
+ │ └── page.tsx
43
+ ├── components/ # React components
44
+ │ ├── ui/ # Design System Components
45
+ │ │ └── button/ # Example component structure
46
+ │ │ ├── Button.tsx # Component implementation
47
+ │ │ ├── Button.test.tsx # Unit tests
48
+ │ │ ├── Button.stories.tsx # Storybook stories
49
+ │ │ ├── types.ts # Component types
50
+ │ │ └── index.ts # Export file
51
+ │ └── shared/ # Used by more than one page
52
+ ├── lib/ # Outside connections and app-wide setup
53
+ │ ├── permissions/ # Who may do what
54
+ │ │ ├── index.ts # Main definitions
55
+ │ │ ├── api.ts # API permissions
56
+ │ │ ├── page.ts # Page permissions
57
+ │ │ └── plan.ts # Plan permissions
58
+ │ ├── integrations/ # The only code that talks to outside services
59
+ │ │ ├── stripe.ts # Payment processing
60
+ │ │ └── supabase/ # Database integration
61
+ │ │ ├── client.ts
62
+ │ │ └── mock/
63
+ │ ├── middleware/ # Code that runs on every request
64
+ │ │ ├── cors.ts
65
+ │ │ ├── rateLimit.ts
66
+ │ │ └── session.ts
67
+ │ ├── validation/ # Schemas that check input
68
+ │ ├── constants/ # Constants shared across the app
69
+ │ ├── errors/ # Error types and handlers shared across the app
70
+ │ └── types/ # Types shared across the app; a component's own types stay in its types.ts
71
+ ├── utils/ # Reusable functions used across the app
72
+ │ ├── formatCurrency/ # One folder per function
73
+ │ │ ├── formatCurrency.ts
74
+ │ │ ├── formatCurrency.test.ts
75
+ │ │ └── index.ts
76
+ │ ├── formatDate/
77
+ │ │ ├── formatDate.ts
78
+ │ │ ├── formatDate.test.ts
79
+ │ │ └── index.ts
80
+ │ └── index.ts # Exports every function
81
+ ├── hooks/ # Custom React hooks
82
+ ├── services/ # Business logic: what the app does
83
+ ├── stores/ # State management stores
84
+ ├── styles/ # Global styles
85
+ ├── public/ # Static assets
86
+ ├── tests/ # Test files
87
+ ├── docs/ # Project documentation — every file is a Decision Doc
88
+ │ ├── overview/ # What the project is and how it works
89
+ │ ├── architecture/ # How the system is built
90
+ │ ├── scope/ # What is in, out and later
91
+ │ └── ... # The other standard folders
92
+ ├── docsSite/ # Docusaurus viewer for docs/ (config only)
93
+ ├── package.json
94
+ ├── next.config.mjs
95
+ ├── tsconfig.json
96
+ └── eslint.config.mjs
97
+ ```
98
+
99
+ ---
100
+
101
+ ## 📁 Next.js Project Structure
102
+
103
+ **Next.js modern standard** (App Router) uses root-level directories:
104
+
105
+ ```text
106
+ project-root/
107
+ ├── app/ # Next.js App Router
108
+ ├── components/ # React components
109
+ ├── lib/ # Outside connections and app-wide setup
110
+ ├── utils/ # Reusable functions
111
+ ├── public/ # Static assets
112
+ ├── docs/ # Project documentation (Markdown)
113
+ ├── docsSite/ # Docusaurus viewer for docs/
114
+ ├── package.json
115
+ ├── next.config.mjs
116
+ └── tsconfig.json
117
+ ```
118
+
119
+ ### 💡 Why root-level for Next.js?
120
+
121
+ - **Next.js standard** - Official documentation uses root-level
122
+ - **Simpler imports** - Cleaner import paths
123
+ - **Faster development** - No abstraction layer
124
+ - **Better Next.js integration** - Optimized for the framework
125
+ - **Easier for beginners** - Less complexity
126
+ - **Framework conventions** - Matches Next.js ecosystem
127
+
128
+ ---
129
+
130
+ ## 🧩 Where components live
131
+
132
+ **A component lives where it is used.** There are no feature folders: a component either belongs to one page, to one section, or is shared.
133
+
134
+ | Used by | Lives in | Example |
135
+ | ------------------------------------------------------------------------------------------ | ---------------------------------------------------- | ---------------------------------------------- |
136
+ | **Every project the same way** — the [Design System Components](/design-system-components) | `components/ui/` | `components/ui/button/` |
137
+ | **More than one page** of this project | `components/shared/` | `components/shared/siteHeader/` |
138
+ | **A few pages in one section** | A `components/` folder in that section's route group | `app/(billing)/components/invoiceTable/` |
139
+ | **One page only** | A `components/` folder in that page's route folder | `app/account-settings/components/accountForm/` |
140
+
141
+ A route group is a folder in brackets, such as `(billing)`. It groups pages without changing their URLs: `app/(billing)/invoices/page.tsx` is served at `/invoices`.
142
+
143
+ ```text
144
+ project-root/
145
+ ├── app/
146
+ │ ├── (billing)/ # A section: groups pages, not part of the URL
147
+ │ │ ├── components/ # Used by more than one billing page
148
+ │ │ │ └── invoiceTable/
149
+ │ │ ├── invoices/
150
+ │ │ │ └── page.tsx # /invoices
151
+ │ │ └── payments/
152
+ │ │ └── page.tsx # /payments
153
+ │ └── account-settings/
154
+ │ ├── components/ # Used only by this page
155
+ │ │ └── accountForm/
156
+ │ │ ├── AccountForm.tsx
157
+ │ │ ├── AccountForm.test.tsx
158
+ │ │ ├── types.ts
159
+ │ │ └── index.ts
160
+ │ └── page.tsx # /account-settings
161
+ └── components/
162
+ ├── ui/ # Design System Components: Button, Card, Modal
163
+ │ └── button/
164
+ └── shared/ # Used by more than one page of this project
165
+ └── siteHeader/
166
+ ```
167
+
168
+ ### Rules
169
+
170
+ - **Start where it is used, and move it when it is shared.** A new component goes in its page's `components/` folder. When a second page in the same section needs it, move it to the section's `components/` folder. When a page in another section needs it, move it to `components/shared/`.
171
+ - **`components/ui/` is only for [Design System Components](/design-system-components).** They take everything through props and import nothing from the project, so they can be copied into another project unchanged. See [Reusable by design](/Structure/component-organization#reusable-by-design).
172
+ - **A page or shared component wraps Design System Components.** It holds this project's logic and data, and passes props down.
173
+ - **Never group by type** (`atoms/`, `molecules/`, `organisms/`). Group by where a component is used.
174
+
175
+ Other frameworks follow the same rule with their own folders. In a React app without Next.js, a page's folder is the folder for that screen.
176
+
177
+ ---
178
+
179
+ ## 🗂️ utils, services and lib {#utils-services-and-lib}
180
+
181
+ Three folders hold functions that are not components. Each function belongs in exactly one of them:
182
+
183
+ | Folder | What goes in it | Ask yourself | Examples |
184
+ | --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------- | ----------------------------------------------------------------- |
185
+ | **`utils/`** | Small reusable functions with no side effects. The same input always gives the same output: formatting, calculating, sorting, checking | "Does it only work with what it is given?" | `formatCurrency`, `calculateInvoiceTotal`, `sortInvoicesByDate` |
186
+ | **`services/`** | The business logic: what the app actually does. Its rules and operations, which may read and write data | "Is this a rule or an action of the product itself?" | `createInvoice`, `decideNextActions`, `sendWelcomeEmail` |
187
+ | **`lib/`** | Code that connects the app to something outside it, and the app-wide setup around that: integration clients, permissions, middleware, validation schemas, constants, errors and shared types | "Does it talk to another system, or set up something the whole app uses?" | `lib/integrations/stripe/`, `lib/permissions/`, `lib/validation/` |
188
+
189
+ - **Pages, API routes and server actions stay thin.** They take the request, call a function in `services/`, and return the result. Business logic never lives in them.
190
+ - **`services/` uses `lib/` to reach the outside world.** A service that charges a card calls the Stripe client in `lib/integrations/stripe/`, never the Stripe package directly.
191
+ - **`utils/` uses nothing outside itself.** If a function needs a database, an API or the environment, it is not a util: it belongs in `services/` or `lib/`.
192
+ - **Group `services/` by the [Ontology](/ontology) word it works on**, one folder per function: `services/invoice/createInvoice/`.
193
+
194
+ ## 🧰 Utils
195
+
196
+ **Every reusable function lives in a `utils/` folder**, never inside a UI file. Where it goes depends on who uses it:
197
+
198
+ | Used by | Location | Example |
199
+ | ------------- | ------------------------------------------------ | ----------------------------------------------------------------- |
200
+ | The whole app | Global `utils/` folder at the project root | `utils/formatCurrency/` |
201
+ | One section | A `utils/` folder in that section's route group | `app/(billing)/utils/calculateInvoiceTotal/` |
202
+ | One component | A `utils/` folder inside that component's folder | `app/(billing)/components/invoiceTable/utils/sortInvoicesByDate/` |
203
+
204
+ Every `utils/` folder has the same shape, at every level: **one folder per function**, holding the function, its test file and an `index.ts` — and an **`index.ts`** in the `utils/` folder that exports them all.
205
+
206
+ ```text
207
+ project-root/
208
+ ├── utils/ # Global: used across the app
209
+ │ ├── formatCurrency/
210
+ │ │ ├── formatCurrency.ts
211
+ │ │ ├── formatCurrency.test.ts
212
+ │ │ └── index.ts
213
+ │ ├── formatDate/
214
+ │ │ ├── formatDate.ts
215
+ │ │ ├── formatDate.test.ts
216
+ │ │ └── index.ts
217
+ │ └── index.ts
218
+ └── app/
219
+ └── (billing)/
220
+ ├── utils/ # Section: used only by billing pages
221
+ │ ├── calculateInvoiceTotal/
222
+ │ │ ├── calculateInvoiceTotal.ts
223
+ │ │ ├── calculateInvoiceTotal.test.ts
224
+ │ │ └── index.ts
225
+ │ └── index.ts
226
+ └── components/
227
+ └── invoiceTable/
228
+ ├── InvoiceTable.tsx
229
+ └── utils/ # Component: used only by InvoiceTable
230
+ ├── sortInvoicesByDate/
231
+ │ ├── sortInvoicesByDate.ts
232
+ │ ├── sortInvoicesByDate.test.ts
233
+ │ └── index.ts
234
+ └── index.ts
235
+ ```
236
+
237
+ ### The `index.ts` files
238
+
239
+ Each function folder has an `index.ts` that exports its function, and the `utils/` folder has an `index.ts` that exports every function, so imports stay neat:
240
+
241
+ ```ts title="utils/formatCurrency/index.ts"
242
+ export { formatCurrency } from "./formatCurrency";
243
+ ```
244
+
245
+ ```ts title="utils/index.ts"
246
+ export { formatCurrency } from "./formatCurrency";
247
+ export { formatDate } from "./formatDate";
248
+ ```
249
+
250
+ ```ts
251
+ // ✅ Good — import from the utils folder
252
+ import { formatCurrency, formatDate } from "@/utils";
253
+ import { sortInvoicesByDate } from "./utils";
254
+
255
+ // ❌ Bad — reaching into the function's folder
256
+ import { formatCurrency } from "@/utils/formatCurrency/formatCurrency";
257
+ ```
258
+
259
+ Add the export to `utils/index.ts` whenever you add a function.
260
+
261
+ ### Rules
262
+
263
+ - **Start local, promote when shared.** A function begins in the component's `utils/`. When another component in the same section needs it, move its folder to the section's `utils/`. When anything outside the section needs it, move it to the global `utils/`.
264
+ - **One function per folder**, with the folder and file named after the function (`formatCurrency/formatCurrency.ts`), plus its test file and an `index.ts`.
265
+ - **Every function has a test file** in the same folder. See [Readable Code](/Standards/readable-code#every-function-and-component-has-a-test-file).
266
+ - **Import from the `utils` folder**, never from the files inside it.
267
+ - **Keep UI files clean.** If a function could be written in another file, it does not belong in the component file. See [Writing a component](/Structure/component-organization#-writing-a-component).
268
+
269
+ ---
270
+
271
+ ## 🧪 Test Placement
272
+
273
+ **Co-locate tests** with the code they test:
274
+
275
+ ```text
276
+ components/
277
+ ├── button/
278
+ │ ├── Button.tsx
279
+ │ ├── Button.test.tsx
280
+ │ ├── Button.stories.tsx
281
+ │ └── index.ts
282
+ hooks/
283
+ ├── useUserData/
284
+ │ ├── useUserData.ts
285
+ │ ├── useUserData.test.ts
286
+ │ └── index.ts
287
+ utils/
288
+ ├── formatCurrency/
289
+ │ ├── formatCurrency.ts
290
+ │ ├── formatCurrency.test.ts
291
+ │ └── index.ts
292
+ └── index.ts
293
+ ```
294
+
295
+ ---
296
+
297
+ ## 📝 Project Documentation
298
+
299
+ **Keep project documentation in a root-level `docs/` folder.** Every file in it is a Decision Doc, and every project uses the same folders. The Docusaurus viewer that displays it at `/docs` lives beside it in `docsSite/`:
300
+
301
+ ```text
302
+ project-root/
303
+ ├── docs/ # The docs: plain Markdown only. Every file is a Decision Doc
304
+ │ ├── overview/ # What the project is, how it works, how to write docs
305
+ │ ├── architecture/ # How the system is built
306
+ │ ├── design/ # How it looks and behaves
307
+ │ ├── scope/ # What is in, out and later
308
+ │ ├── ... # The other standard folders
309
+ │ └── product/ # Decisions specific to this product
310
+ └── docsSite/ # The viewer: Docusaurus config, no content
311
+ ```
312
+
313
+ See [Documentation](/Standards/documentation) for the full list of folders, the doc format, and how docs are displayed and kept up to date.
314
+
315
+ Name documentation folders and files in **kebab-case** (`background-jobs.md`), not camelCase (`backgroundJobs.md`). The name becomes the page's URL on the docs site.
316
+
317
+ ---
318
+
319
+ ## 📄 Configuration Files
320
+
321
+ **Keep configuration at the root** where tools expect it:
322
+
323
+ ```text
324
+ /root
325
+ ├── eslint.config.mjs # ESLint configuration
326
+ ├── prettier.config.mjs # Prettier configuration
327
+ ├── tsconfig.json # TypeScript configuration
328
+ ├── next.config.mjs # Next.js configuration
329
+ ├── package.json # Dependencies & scripts
330
+ └── .env.local # Environment variables (gitignored)
331
+ ```
332
+
333
+ ---
334
+
335
+ ## 🚨 Red Flags
336
+
337
+ Avoid these anti-patterns:
338
+
339
+ - ❌ **Deep nesting** - More than 4-5 levels deep
340
+ - ❌ **Scattered logic** - Related code in multiple unrelated folders
341
+ - ❌ **Vague names** - `helpers/`, `misc/`, `stuff/` without organization
342
+ - ❌ **Inconsistent patterns** - Different structures for similar things
343
+
344
+ ---
345
+
346
+ ## 📚 Naming Conventions
347
+
348
+ See [Naming Conventions](/Structure/naming-conventions) for detailed file and folder naming rules.
349
+
350
+ **Quick reference:**
351
+
352
+ - **Component files**: PascalCase (`UserProfile.tsx`)
353
+ - **Utils files**: camelCase (`apiUtils.ts`)
354
+ - **Hook files**: camelCase with `use` prefix (`useUserData.ts`)
355
+ - **Service files**: camelCase with `Service` suffix (`apiService.ts`)
356
+ - **Route Folder names**: kebab-case (`user-management/`, `api-routes/`)
357
+ - **Component Folder names**: camelCase (`header/`, `model/`)
358
+ - **Documentation files**: kebab-case (`background-jobs.md`)
359
+
360
+ ---
361
+
362
+ ## 📚 Resources
363
+
364
+ - [Next.js App Router](https://nextjs.org/docs/app)
365
+ - [Next.js Project Structure](https://nextjs.org/docs/app/building-your-application/routing/colocation)
366
+ - [Monorepo Patterns](https://monorepo.tools/)
@@ -0,0 +1,158 @@
1
+ ---
2
+ sidebar_position: 4
3
+ ---
4
+
5
+ # Import Organization
6
+
7
+ Consistent import organization makes code easier to read and understand.
8
+
9
+ ## Import Order
10
+
11
+ Follow this order in all files:
12
+
13
+ 1. **React and core packages**
14
+ 2. **Internal workspace packages** (the project's own scope, e.g. `@acme/*`)
15
+ 3. **External packages**
16
+ 4. **Side effect imports**
17
+ 5. **Parent imports** (`../`)
18
+ 6. **Same-folder imports** (`./`)
19
+ 7. **Style imports** (`.css`, `.module.css`)
20
+
21
+ ## Example
22
+
23
+ ```tsx
24
+ // 1. React and core packages
25
+ import React, { useState, useEffect } from "react";
26
+ import { Link } from "@radix-ui/react-navigation-menu";
27
+
28
+ // 2. Internal workspace packages
29
+ import { Button } from "@acme/ui";
30
+ import { useAuthentication } from "@acme/authentication";
31
+
32
+ // 3. External packages
33
+ import { format } from "date-fns";
34
+ import clsx from "clsx";
35
+
36
+ // 4. Side effect imports
37
+ import "prismjs/themes/prism-tomorrow.css";
38
+
39
+ // 5. Parent imports
40
+ import { formatDate } from "../utils";
41
+
42
+ // 6. Same-folder imports
43
+ import { Header } from "./Header";
44
+ import { useUserData } from "./useUserData";
45
+
46
+ // 7. Style imports
47
+ import "./UserProfile.css";
48
+ import styles from "./styles.module.css";
49
+ ```
50
+
51
+ ## Why This Order?
52
+
53
+ 1. **React first** - Most important dependency, immediately visible
54
+ 2. **Internal packages** - Your team's code, separate from third-party
55
+ 3. **External packages** - Third-party dependencies
56
+ 4. **Side effects** - Imports that don't export values (CSS, polyfills)
57
+ 5. **Parent imports** - Code from parent directories
58
+ 6. **Same-folder** - Code from the current directory
59
+ 7. **Styles last** - Visual separation, easy to find style imports
60
+
61
+ ## Rules
62
+
63
+ - ✅ **Alphabetized** within each group
64
+ - ✅ **Blank lines** between groups
65
+ - ✅ **No duplicates** - Import each module once
66
+
67
+ ## Import Safety
68
+
69
+ These four rules **are** enforced, and they are not about tidiness. They stop a whole class of bug: code that runs before the thing it needs exists.
70
+
71
+ ### 1. No circular imports
72
+
73
+ **A file never imports a file that imports it back** — directly, or through a chain of other files.
74
+
75
+ ```ts
76
+ // ❌ Bad — userService imports orderService, which imports userService
77
+ // services/userService.ts
78
+ import { getOrdersForUser } from "./orderService";
79
+
80
+ // services/orderService.ts
81
+ import { getUserById } from "./userService";
82
+ ```
83
+
84
+ When two files import each other, one of them has to load first, and it sees the other half-finished. The code may work today and break when an unrelated import changes the loading order.
85
+
86
+ **The fix is to move the shared part into a third file** that both import, so the dependency runs one way:
87
+
88
+ ```ts
89
+ // ✅ Good — both services import from a third file; neither imports the other
90
+ // services/userService.ts
91
+ import { findUserRecord } from "./userRecords";
92
+
93
+ // services/orderService.ts
94
+ import { findUserRecord } from "./userRecords";
95
+ ```
96
+
97
+ Enforced by ESLint `import-x/no-cycle`.
98
+
99
+ ### 2. Inside a folder, import files directly
100
+
101
+ **A folder's `index.ts` is for code outside the folder.** Code inside the folder imports its neighbours by file, never through the folder's own `index.ts`. Importing through your own index is the most common way a circular import is created by accident.
102
+
103
+ ```ts
104
+ // card/cardHeader/CardHeader.tsx
105
+
106
+ // ✅ Good — import the file directly
107
+ import type { CardProps } from "../types";
108
+
109
+ // ❌ Bad — the card index imports CardHeader, so this is a circle
110
+ import { Card } from "..";
111
+ ```
112
+
113
+ | Importing from | Import through |
114
+ | ---------------------- | ---------------------------------------------------------------------- |
115
+ | **Outside** the folder | The folder's `index.ts`: `import { Card } from "@/components/ui/card"` |
116
+ | **Inside** the folder | The file itself: `import type { CardProps } from "../types"` |
117
+
118
+ A parent component imports its sub-components. **A sub-component never imports its parent.** If a child needs something from the parent, the parent passes it as a prop.
119
+
120
+ ### 3. Define before use
121
+
122
+ **A function or variable is written above the code that uses it.** Read top to bottom, a file never refers to something that has not been defined yet.
123
+
124
+ ```ts
125
+ // ✅ Good
126
+ const formatReport = () => "report";
127
+
128
+ export const sendReport = () => formatReport();
129
+ ```
130
+
131
+ ```ts
132
+ // ❌ Bad — formatReport is used above where it is defined
133
+ export const sendReport = () => formatReport();
134
+
135
+ const formatReport = () => "report";
136
+ ```
137
+
138
+ Enforced by ESLint `no-use-before-define`.
139
+
140
+ ### 4. Files define things; they do not run things
141
+
142
+ **A file declares its functions and exports them. It does not call them as it loads.** The calling happens later, inside a component or another function.
143
+
144
+ ```ts
145
+ // ✅ Good — nothing runs when this file is imported
146
+ export const connectToDatabase = () => createConnection(DATABASE_URL);
147
+
148
+ // ❌ Bad — importing this file opens a database connection
149
+ export const database = createConnection(DATABASE_URL);
150
+ ```
151
+
152
+ Code that runs on import makes the order files load in matter. Code that only defines things does not.
153
+
154
+ Enforced by ESLint `unicorn/no-top-level-side-effects`.
155
+
156
+ ## Import Order Is Not Enforced
157
+
158
+ The **order of the import lines** is a convention, not a lint rule. Follow the same pattern in every file so imports are easy to read, but ESLint will not report an error if the order differs.