Skip to content

Commit 16869a3

Browse files
authored
Better cursor rules (twentyhq#10431)
Move to the new cursor rule folder style and make it more granular
1 parent 1b64f87 commit 16869a3

10 files changed

+1654
-99
lines changed

.cursor/rules/README.md

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Twenty Development Rules
2+
3+
This directory contains Twenty's development guidelines and best practices. The rules are organized into several key categories:
4+
5+
## Guidelines Structure
6+
7+
### 1. Architecture and Structure
8+
- `architecture.md`: Project overview, technology stack, and infrastructure setup
9+
- `file-structure-guidelines.md`: File and directory organization patterns
10+
11+
### 2. Code Style and Development
12+
- `typescript-guidelines.md`: TypeScript best practices and conventions
13+
- `code-style-guidelines.md`: General coding standards and style guide
14+
15+
### 3. React Development
16+
- `react-general-guidelines.md`: Core React development principles and patterns
17+
- `react-state-management-guidelines.md`: State management approaches and best practices
18+
19+
### 4. Testing
20+
- `testing-guidelines.md`: Testing strategies, patterns, and best practices
21+
22+
### 5. Internationalization
23+
- `translations.md`: Translation workflow, i18n setup, and string management
24+
25+
## Common Development Commands
26+
27+
### Frontend Commands
28+
```bash
29+
# Testing
30+
npx nx test twenty-front # Run unit tests
31+
npx nx storybook:build twenty-front # Build Storybook
32+
npx nx storybook:serve-and-test:static # Run Storybook tests
33+
34+
# Development
35+
npx nx lint twenty-front # Run linter
36+
npx nx typecheck twenty-front # Type checking
37+
npx nx run twenty-front:graphql:generate # Generate GraphQL types
38+
```
39+
40+
### Backend Commands
41+
```bash
42+
# Database
43+
npx nx database:reset twenty-server # Reset database
44+
npx nx run twenty-server:database:init:prod # Initialize database
45+
npx nx run twenty-server:database:migrate:prod # Run migrations
46+
47+
# Development
48+
npx nx run twenty-server:start # Start the server
49+
npx nx run twenty-server:lint # Run linter (add --fix to auto-fix)
50+
npx nx run twenty-server:typecheck # Type checking
51+
npx nx run twenty-server:test # Run unit tests
52+
npx nx run twenty-server:test:integration:with-db-reset # Run integration tests
53+
54+
# Migrations
55+
npx nx run twenty-server:typeorm migration:generate src/database/typeorm/metadata/migrations/[name] -d src/database/typeorm/metadata/metadata.datasource.ts
56+
57+
# Workspace
58+
npx nx run twenty-server:command workspace:sync-metadata -f # Sync metadata
59+
```
60+
61+
## Usage
62+
63+
These rules are automatically attached to relevant files in your workspace through Cursor's context system. They help maintain consistency and quality across the Twenty codebase.
64+
65+
For the most up-to-date version of these guidelines, always refer to the files in this directory.

.cursor/rules/architecture.md

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# Twenty Project Architecture
2+
3+
## Overview
4+
Twenty is an open-source CRM built with modern technologies, using TypeScript for both frontend and backend development. This document outlines the core architectural decisions and structure of the project.
5+
6+
## Monorepo Structure
7+
The project is organized as a monorepo using nx, with the following main packages:
8+
9+
### Main Packages
10+
- `packages/twenty-front`: Main Frontend application
11+
- Technology: React
12+
- Purpose: Provides the main user interface for the CRM
13+
- Key responsibilities: User interactions, state management, data display
14+
15+
- `packages/twenty-server`: Main Backend application
16+
- Technology: NestJS
17+
- Purpose: Handles business logic, data persistence, and API
18+
- Key responsibilities: Data processing, authentication, API endpoints
19+
20+
- `packages/twenty-website`: Marketing Website and Documentation
21+
- Technology: NextJS
22+
- Purpose: Public-facing website and documentation
23+
- Key responsibilities: Marketing content, documentation, SEO
24+
25+
- `packages/twenty-ui`: UI Component Library
26+
- Technology: React
27+
- Purpose: Shared UI components and design system
28+
- Key responsibilities: Reusable components, design consistency
29+
30+
- `packages/twenty-shared`: Shared Utilities
31+
- Purpose: Cross-package shared code between frontend and backend
32+
- Contents: Utils, constants, types, interfaces
33+
34+
## Core Technology Stack
35+
36+
### Package Management
37+
- Package Manager: yarn
38+
- Monorepo Tool: nx
39+
- Benefits: Consistent dependency management, shared configurations
40+
41+
### Database Layer
42+
- Primary Database: PostgreSQL
43+
- Schema Structure:
44+
- Core schema: Main application data
45+
- Metadata schema: Configuration and customization data
46+
- Workspace schemas: One schema per tenant, containing tenant-specific data
47+
- ORM Layer:
48+
- TypeORM: For core and metadata schemas
49+
- Purpose: Type-safe database operations for system data
50+
- Benefits: Strong typing, migration support
51+
- TwentyORM: For workspace schemas
52+
- Purpose: Manages tenant-specific entities and customizations
53+
- Benefits: Dynamic entity management, per-tenant customization
54+
- Example: Entities like CompanyWorkspaceEntity are managed per workspace
55+
56+
### State Management
57+
- Frontend State: Recoil
58+
- Purpose: Global state management
59+
- Use cases: User preferences, UI state, cached data
60+
61+
### Data Layer
62+
- API Technology: GraphQL
63+
- Client: Apollo Client
64+
- Purpose: Data fetching and caching
65+
- Benefits: Type safety, efficient data loading
66+
67+
### Infrastructure
68+
- Cache: Redis
69+
- Purpose: High-performance caching layer
70+
- Use cases: Session data, frequent queries
71+
72+
- Authentication: JWT
73+
- Purpose: Secure user authentication
74+
- Implementation: Token-based auth flow
75+
76+
- Queue System: BullMQ
77+
- Purpose: Background job processing
78+
- Use cases: Emails, exports, imports
79+
80+
- Storage: S3/Local Filesystem
81+
- Purpose: File storage and management
82+
- Flexibility: Configurable for cloud or local storage
83+
84+
### Testing Infrastructure
85+
- Backend Testing:
86+
- Framework: Jest
87+
- API Testing: Supertest
88+
- Coverage: Unit tests, integration tests
89+
90+
- Frontend Testing:
91+
- Framework: Jest
92+
- Component Testing: Storybook
93+
- API Mocking: MSW (Mock Service Worker)
94+
95+
- End-to-End Testing:
96+
- Framework: Playwright
97+
- Coverage: Critical user journeys

0 commit comments

Comments
 (0)