High-Level Architecture
Relevant source files
The following files were used as context for generating this wiki page:- CLAUDE.md
- package.json
- README.md
- packages/twenty-docs/README.md
- packages/twenty-server/src/engine/core-modules/open-api/utils/base-schema.utils.ts
- packages/create-twenty-app/README.md
- packages/twenty-apps/community/webmetic/README.md
- packages/twenty-docker/k8s/README.md
- packages/twenty-ui/package.json
- packages/twenty-docs/docs.json
- packages/twenty-apps/community/meeting-transcript/README.md
The Twenty project is an open-source CRM built with a modern technology stack and organized within a monorepo structure. The architecture is designed to be modular, scalable, and extensible, separating concerns between the frontend, backend, shared libraries, and external applications. The entire codebase is managed as an Nx workspace, which facilitates code sharing, dependency management, and streamlined development workflows across various packages.
The core system consists of a React frontend, a NestJS backend, and several supporting services and libraries. It leverages technologies like PostgreSQL for data persistence, Redis for caching and job queues, and GraphQL for its primary API. This modular design allows for independent development and deployment of components and encourages the creation of a broader ecosystem through plugins and community apps.
Sources: CLAUDE.md:5-7, README.md:92-96
Monorepo Structure
The project is managed as an Nx monorepo using Yarn workspaces. This structure centralizes all packages, simplifies dependency management, and allows for consistent tooling across the entire codebase.
Sources: CLAUDE.md:7, package.json:221-239
The diagram below illustrates the high-level package organization within the packages/ directory.
This diagram shows the main packages and some of their key dependencies.
Sources: CLAUDE.md:46-56, package.json:221-239
Key Packages
The monorepo contains several key packages, each with a distinct responsibility:
| Package | Description |
|---|---|
twenty-front | The main React frontend application. |
twenty-server | The NestJS backend API server. |
twenty-ui | A shared library of React UI components used across frontend applications. |
twenty-shared | A package for common types, utilities, and constants shared between frontend and backend. |
twenty-emails | Contains email templates built with React Email. |
twenty-docs | The Mintlify-powered documentation site. |
twenty-apps | A directory for community and official applications that extend Twenty's functionality. |
twenty-sdk | The Software Development Kit for building Twenty applications. |
create-twenty-app | A CLI tool for scaffolding new Twenty applications. |
twenty-zapier | The official Zapier integration package. |
Sources: CLAUDE.md:46-56, package.json:221-239
Technology Stack
The project utilizes a modern, TypeScript-centric technology stack.
| Category | Technology | Purpose |
|---|---|---|
| Monorepo | Nx, Yarn 4 | Workspace management, task running, dependency optimization. |
| Frontend | React 18, Vite | UI library and build tooling. |
| Recoil | Global state management. | |
| Emotion | CSS-in-JS styling. | |
| Lingui | Internationalization (i18n). | |
| Backend | NestJS | Node.js framework for building the server-side application. |
| GraphQL (GraphQL Yoga) | Primary API for client-server communication. | |
| TypeORM | Object-Relational Mapper (ORM) for database interaction. | |
| BullMQ | Background job processing. | |
| Database | PostgreSQL | Primary relational database. |
| Redis | Caching, session management, and message broker for BullMQ. | |
| ClickHouse | Optional database for analytics. |
Sources: CLAUDE.md:39-41, README.md:92-96
Core Application Architecture
The core of Twenty is divided into a frontend application (twenty-front) and a backend server (twenty-server), which communicate primarily via a GraphQL API.
This diagram shows the interaction between the frontend, backend, worker, and databases.
Sources: CLAUDE.md:39-41, 65-70
Frontend (twenty-front)
The frontend is a single-page application built with React.
- State Management: It uses Recoil for global state and standard React hooks for component-level state. The Apollo Client also manages the GraphQL cache.
- Styling: Emotion is used for styling, following a styled-components pattern.
- API Communication: It communicates with the backend via GraphQL, with types generated from the backend schema.
Sources: CLAUDE.md:39, 59-62
Backend (twenty-server)
The backend is a modular application built with NestJS.
- API Layer: It exposes a GraphQL API using a code-first approach with GraphQL Yoga. It also provides a REST API for integrations and webhooks.
- Data Access: TypeORM is used as the ORM to interact with the PostgreSQL database.
- Background Jobs: BullMQ is used for handling asynchronous tasks and background jobs, with Redis as the message broker.
- Caching & Sessions: Redis is used for both caching data to improve performance and for managing user sessions.
Sources: CLAUDE.md:40, 65-70
API Architecture
Twenty provides two primary APIs: GraphQL for the main application and a REST API for integrations.
REST API
The REST API is designed for external services and integrations. It is documented via an OpenAPI schema.
Key features of the REST API include:
- Authentication: Requires a
Bearertoken in theAuthorizationheader for all requests. - Pagination: Uses cursor-based pagination with
limit,starting_after, andending_beforeparameters. - Filtering: Supports complex filtering via the
filterquery parameter with comparators likeeq,gte,in,ilike, etc. - Ordering: Results can be sorted using the
order_byparameter.
Sources: packages/twenty-server/src/engine/core-modules/open-api/utils/base-schema.utils.ts:13-68
The following sequence diagram shows a typical REST API call to fetch a list of companies.
This diagram illustrates a filtered and paginated request to the REST API.
Sources: packages/twenty-server/src/engine/core-modules/open-api/utils/base-schema.utils.ts:13-68
Extensibility via Apps
A core architectural principle of Twenty is its extensibility through "Twenty Apps". These are standalone packages that can add new functionality, integrate with third-party services, or create custom objects and workflows.
The create-twenty-app CLI tool provides a scaffold for building new apps, which are then managed via the twenty-sdk.
Sources: packages/create-twenty-app/README.md:13-17
App Architecture Example: Webhook Integration
Many apps, like the webmetic and meeting-transcript integrations, operate via webhooks. An external service sends a POST request to a specific endpoint in Twenty, which triggers a serverless function to process the data and interact with the Twenty API.
This flow shows how an external service can push data into Twenty via a custom app triggered by a webhook.
Sources: packages/twenty-apps/community/webmetic/README.md:68-72, packages/twenty-apps/community/meeting-transcript/README.md:63-71
Deployment
While the core team officially supports Docker for deployment, the community provides and maintains configurations for other environments like Kubernetes.
Kubernetes (Community-Maintained)
The packages/twenty-docker/k8s directory contains manifests and Terraform files for deploying Twenty on a Kubernetes cluster. The setup typically involves:
- A
Secretto store server tokens. - Deployments for the
twenty-serverand other components. - Services to expose the application.
- Persistent Volumes for databases.
Sources: packages/twenty-docker/k8s/README.md:5-8, 47-52
Documentation System
The project's documentation, located in packages/twenty-docs, is built using Mintlify.
- Content: Written in MDX files.
- Navigation: The structure is defined in
navigation/base-structure.json. This file is the source of truth for the English navigation structure. - Build Process: A script generates a final
docs.jsonconfiguration file from the base structure and translated labels, which Mintlify then uses to build the static site. - Internationalization: Navigation labels are translated via Crowdin, with translated files stored in
l/<language>/navigation.json.
Sources: packages/twenty-docs/README.md:19-31, packages/twenty-docs/docs.json
Conclusion
The high-level architecture of Twenty is that of a modern, modular, and extensible web application. By leveraging a monorepo managed with Nx, it maintains a clean separation of concerns between its React frontend, NestJS backend, and a growing ecosystem of shared libraries and external apps. The dual GraphQL/REST API approach serves both the primary application and third-party integrations effectively. This robust foundation is designed to support both core CRM functionality and a wide range of community-driven extensions.
Sources: CLAUDE.md:5-7, 39-41, README.md:18-26