Local Development Setup
Relevant source files
The following files were used as context for generating this wiki page:
The Twenty project is an open-source CRM built as a monorepo managed by Nx and Yarn. Setting up a local development environment allows developers to work on the core application, which includes a React frontend, a NestJS backend, and various other packages. This guide covers the prerequisites, project structure, and key commands for a complete local development workflow.
The architecture is centered around a modern tech stack, including TypeScript, React, NestJS, PostgreSQL, and Redis. The monorepo structure facilitates code sharing and streamlined development across different parts of the application, from the main CRM to documentation and extension SDKs. For information on deploying, see the Self-hosting documentation.
Sources: CLAUDE.md:3-5, README.md:100-104
Prerequisites
Before setting up the local environment, ensure the following dependencies are installed and running on your system.
| Dependency | Required Version | Notes | Source |
|---|---|---|---|
| Node.js | ^24.5.0 | Recommended version for compatibility. | [package.json:232](https://github.com/twentyhq/twenty/blob/HEAD/package.json#L232) |
| Yarn | >=4.0.2 | The project uses Yarn 4 for package management. | [package.json:234](https://github.com/twentyhq/twenty/blob/HEAD/package.json#L234) |
| Docker | ≥ v2 | Required for running database services (PostgreSQL, Redis). Docker Compose plugin is necessary. | [packages/twenty-docker/scripts/install.sh:3-12](https://github.com/twentyhq/twenty/blob/HEAD/packages/twenty-docker/scripts/install.sh#L3-L12) |
| curl | Any | Used by installation scripts to download configuration files. | [packages/twenty-docker/scripts/install.sh:17-21](https://github.com/twentyhq/twenty/blob/HEAD/packages/twenty-docker/scripts/install.sh#L17-L21) |
Sources: package.json:232-234, packages/twenty-docker/scripts/install.sh:3-21
Project Structure
Twenty is organized as an Nx workspace, with individual applications and libraries located in the packages/ directory. This structure separates concerns and allows for independent development and testing of each component.
The diagram below illustrates the high-level package structure within the monorepo.
Sources: CLAUDE.md:58-68, package.json:242-258
Key packages include:
twenty-front: The main React frontend application.twenty-server: The NestJS backend API server.twenty-ui: A shared library of UI components.twenty-shared: Common types and utilities used across packages.twenty-sdk: The SDK for building custom Twenty applications.create-twenty-app: A scaffolding tool to bootstrap new Twenty apps.twenty-docs: The official documentation site.
Sources: CLAUDE.md:59-67, package.json:242-258
Core Application Development
This section covers the workflow for developing the main Twenty CRM application, which consists of the frontend, backend, and background worker.
Starting the Environment
The simplest way to start all core services is with a single command. This command concurrently starts the frontend dev server, the backend server, and the background worker.
# Start development environment (frontend + backend + worker)
yarn start
Sources: CLAUDE.md:10-11, package.json:240
This flow chart shows the services started by yarn start.
Sources: CLAUDE.md:10-11, package.json:240
Alternatively, you can start each service individually:
# Start frontend dev server
npx nx start twenty-front
# Start backend server
npx nx start twenty-server
# Start background worker
npx nx run twenty-server:worker
Sources: CLAUDE.md:13-16
Database Operations
The backend relies on PostgreSQL. Nx provides commands to manage the database schema and data.
| Command | Description |
|---|---|
npx nx database:reset twenty-server | Resets the database to a clean state. |
npx nx run twenty-server:database:init:prod | Initializes the database for production. |
npx nx run twenty-server:database:migrate:prod | Runs all pending database migrations. |
npx nx run twenty-server:typeorm migration:generate ... | Generates a new TypeORM migration file. |
npx nx run twenty-server:command workspace:sync-metadata | Synchronizes workspace metadata. |
Sources: CLAUDE.md:40-48
To generate a new migration, use the following command structure, replacing [name] with a descriptive name for your migration:
npx nx run twenty-server:typeorm migration:generate src/database/typeorm/core/migrations/common/[name] -d src/database/typeorm/core/core.datasource.ts
Sources: CLAUDE.md:45-46
Code Generation & Quality
The project uses code generation for GraphQL types and has a strict set of quality checks.
| Command | Description |
|---|---|
npx nx run twenty-front:graphql:generate | Generates GraphQL types for the frontend. |
npx nx lint twenty-front / twenty-server | Runs ESLint for the specified package. |
npx nx typecheck twenty-front / twenty-server | Runs TypeScript type checking. |
npx nx fmt twenty-front / twenty-server | Formats code using Prettier. |
Sources: CLAUDEmd:29-38, 51-52
Testing
The repository contains unit, integration, and Storybook tests.
| Command | Description |
|---|---|
npx nx test twenty-front | Runs frontend unit tests with Jest. |
npx nx test twenty-server | Runs backend unit tests with Jest. |
npx nx run twenty-server:test:integration:with-db-reset | Runs backend integration tests, resetting the database first. |
npx nx storybook:build twenty-front | Builds the Storybook for the UI component library. |
Sources: CLAUDE.md:20-26
Developing Custom Apps
Twenty supports custom applications built with the twenty-sdk. The create-twenty-app package provides a scaffolding tool to quickly set up a new project.
Scaffolding a New App
To create a new app, run the following command and follow the prompts:
npx create-twenty-app@latest my-twenty-app
cd my-twenty-app
Sources: packages/create-twenty-app/README.md:27-28
Development Workflow for Apps
The typical workflow for developing a custom app involves authenticating, generating typed clients, and syncing changes to your Twenty workspace.
The following sequence diagram illustrates the app development and sync process.
Key commands for app development:
yarn auth: Authenticate the CLI with your Twenty workspace using an API key.yarn create-entity: A guided prompt to add a new entity to your application.yarn generate: Generates a typed Twenty client and TypeScript definitions.yarn dev: Starts a development server that automatically syncs local changes to your workspace.yarn sync: Performs a one-time sync of local changes.
Sources: packages/create-twenty-app/README.md:31-48
Other Development Setups
Documentation Site
The documentation is built with Mintlify. To run the documentation site locally:
# From the twenty monorepo root
npx nx run twenty-docs:dev
The site will be available at http://localhost:3000.
Sources: packages/twenty-docs/README.md:19-23
Marketing Website
The marketing website (twenty.com) is a Next.js application. To run it locally, first set up the .env file and run the database migrations.
- Copy
.env.exampleto.envand fill in the values. - Run migrations:
npx nx run twenty-website:database:migrate - Start the dev server:
npx nx run twenty-website:dev
The site will be available at http://localhost:3000.
Sources: packages/twenty-website/README.md:10-19
Docker-based Quick Start
For a fast setup without cloning the entire monorepo, an installation script is provided. This script downloads a docker-compose.yml file and a pre-configured .env file to run Twenty in Docker containers.
# Run this in your terminal
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/twentyhq/twenty/main/packages/twenty-docker/scripts/install.sh)"
This script will:
- Check for Docker and Docker Compose dependencies.
- Create a new directory for the project.
- Download
docker-compose.ymland.env. - Configure the
.envfile with the latest image tag and generated secrets. - Prompt to start the application via
docker compose up -d.