@@ -128,6 +128,212 @@ Note: Open a pull request to the STAGING branch
128128
129129## Code Style
130130
131- - Use Biome for linting and formatting
132- - Follow the coding standards in the README
133- - Keep it simple and type-safe
131+ ### Linting and Formatting
132+
133+ - ** Use Ultracite** for linting (not ESLint)
134+ - ** Use Prettier** for code formatting
135+ - ** Use Biome** for fast linting and formatting where applicable
136+ - Run ` bun run lint ` before committing to ensure code quality
137+ - Run ` bun run format ` to auto-format your code
138+
139+ ### Coding Standards
140+
141+ Follow the coding standards outlined in the README and ` .cursor/rules/ ` :
142+
143+ ** Required Tools & Libraries:**
144+ - ** Bun** - Required for all development (never use npm/pnpm/Node CLI)
145+ - ** Zod v4** - Use ` zod/v4 ` everywhere (not Zod v3)
146+ - ** Phosphor Icons** - Use only Phosphor icons (not Lucide)
147+ - ** Dayjs** - Use for all date handling (never date-fns)
148+ - ** TanStack Query** - Use for data fetching hooks (never SWR)
149+
150+ ** Style Guidelines:**
151+ - ** Border Radius** : Use ` rounded ` (never ` rounded-xl ` or ` rounded-md ` )
152+ - ** Type Safety** : Always ensure type-safety and use shared types
153+ - ** Error Handling** : Never throw errors in server actions; use try/catch and return errors
154+ - ** Error Boundaries** : Always use error boundaries properly
155+ - ** Console Usage** : Use appropriate console methods (` console.error ` , ` console.time ` , ` console.json ` , ` console.table ` )
156+ - ** useEffect** : Almost never use ` useEffect ` unless critical
157+ - ** No Placeholders** : Never add placeholders or mock data
158+
159+ See ` .cursor/rules/ ` for the complete enforced ruleset.
160+
161+ ## Testing
162+
163+ ### Running Tests
164+
165+ ``` bash
166+ # Run all tests
167+ bun run test
168+
169+ # Run tests in watch mode
170+ bun run test:watch
171+
172+ # Run tests with coverage
173+ bun run test:coverage
174+
175+ # Run specific test file
176+ bun test path/to/test.test.ts
177+ ```
178+
179+ ### Writing Tests
180+
181+ ** Unit Tests:**
182+ - Use Vitest for unit testing
183+ - Place tests next to the code they test (` *.test.ts ` )
184+ - Aim for >80% code coverage
185+ - Mock external dependencies
186+
187+ ** Example unit test:**
188+ ``` typescript
189+ import { describe , it , expect , vi } from ' vitest'
190+ import { calculateMetrics } from ' ./analytics'
191+
192+ describe (' calculateMetrics' , () => {
193+ it (' should calculate basic metrics correctly' , () => {
194+ const events = [
195+ { type: ' pageview' , timestamp: Date .now () },
196+ { type: ' pageview' , timestamp: Date .now () }
197+ ]
198+
199+ const metrics = calculateMetrics (events )
200+
201+ expect (metrics .pageviews ).toBe (2 )
202+ })
203+
204+ it (' should handle empty events array' , () => {
205+ const metrics = calculateMetrics ([])
206+
207+ expect (metrics .pageviews ).toBe (0 )
208+ })
209+ })
210+ ```
211+
212+ ** Integration Tests:**
213+ - Test API endpoints and database operations
214+ - Use test database and Redis instances
215+ - Clean up test data after each test
216+
217+ ** E2E Tests:**
218+ - Use Playwright for end-to-end testing
219+ - Test critical user flows
220+ - Run in CI/CD pipeline
221+
222+ ### Test Coverage Requirements
223+
224+ Maintain test coverage above these thresholds:
225+ - ** Statements** : 80%
226+ - ** Branches** : 75%
227+ - ** Functions** : 80%
228+ - ** Lines** : 80%
229+
230+ ## Code Review Process
231+
232+ All contributions go through code review before merging:
233+
234+ 1 . ** Automated Checks** : CI/CD runs tests, linting, and type checking
235+ 2 . ** CodeRabbit Review** : Automated AI review for common issues
236+ 3 . ** Manual Review** : Maintainer reviews code for:
237+ - Code quality and style adherence
238+ - Test coverage
239+ - Security considerations
240+ - Performance implications
241+ - Documentation completeness
242+
243+ ### Review Checklist
244+
245+ Before requesting review, ensure:
246+ - [ ] All tests pass
247+ - [ ] Code is formatted and linted
248+ - [ ] Types are correct (no ` any ` types)
249+ - [ ] Documentation is updated
250+ - [ ] Changeset created
251+ - [ ] Security considerations addressed
252+ - [ ] Performance impact considered
253+ - [ ] Error handling implemented
254+
255+ ## Architecture Guidelines
256+
257+ ### Monorepo Structure
258+
259+ ```
260+ Databuddy/
261+ ├── apps/
262+ │ ├── web/ # Main dashboard application
263+ │ ├── docs/ # Documentation site
264+ │ └── dashboard/ # Analytics dashboard
265+ ├── packages/
266+ │ ├── sdk/ # Client-side SDK
267+ │ ├── tracker/ # Event tracking
268+ │ ├── db/ # Database utilities
269+ │ ├── validation/ # Shared validation schemas
270+ │ └── ui/ # Shared UI components
271+ └── infrastructure/ # Deployment configurations
272+ ```
273+
274+ ### Adding New Features
275+
276+ ** 1. Plan your feature:**
277+ - Discuss in GitHub Issues first for major features
278+ - Consider backward compatibility
279+ - Plan database migrations if needed
280+
281+ ** 2. Implement incrementally:**
282+ - Start with types and schemas (Zod v4)
283+ - Implement core logic with tests
284+ - Add UI components
285+ - Update documentation
286+
287+ ** 3. Database Changes:**
288+ ``` bash
289+ # Make schema changes in packages/db/schema/
290+
291+ # Generate migration
292+ bun run db:generate
293+
294+ # Apply to local database
295+ bun run db:push
296+
297+ # Test migration
298+ bun run db:migrate
299+ ```
300+
301+ ** 4. Add appropriate tests:**
302+ - Unit tests for utilities and logic
303+ - Integration tests for API endpoints
304+ - E2E tests for user-facing features
305+
306+ ### Performance Considerations
307+
308+ - ** Database** : Index frequently queried columns
309+ - ** Caching** : Use Redis for expensive queries
310+ - ** Bundle Size** : Keep client bundles small (<200KB)
311+ - ** Batching** : Batch analytics events (use built-in batching)
312+ - ** Images** : Use Next.js Image optimization
313+
314+ ## Documentation
315+
316+ ### When to Update Docs
317+
318+ Update documentation when:
319+ - Adding new features
320+ - Changing APIs or behavior
321+ - Fixing bugs that affect usage
322+ - Adding configuration options
323+ - Changing deployment procedures
324+
325+ ### Documentation Files
326+
327+ - ** README.md** - Project overview and quick start
328+ - ** CONTRIBUTING.md** - This file
329+ - ** DEPLOYMENT.md** - Deployment and operations
330+ - ** apps/docs/** - User-facing documentation site
331+ - ** Code comments** - Document complex logic
332+
333+ ### Writing Good Documentation
334+
335+ - Use clear, concise language
336+ - Include code examples
337+ - Add screenshots for UI features
338+ - Keep it up-to-date
339+ - Test all examples
0 commit comments