|
| 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