Modern open-source CRM alternative to Salesforce built with TypeScript, NestJS, React, GraphQL, and PostgreSQL.
- Language
- TypeScript
- Database
- PostgreSQL
- Hosting
- Docker
- Running for
- 1 year 8 months
- Team
- 6-20 people
Why this architecture
Twenty provides an extensible, modern CRM architecture featuring metadata-driven custom objects, GraphQL APIs, and clean UI design.
Tech stack by layer
8 technologies · audited Sep 17, 2026- ReactSingle-page application rendering customer views, pipeline boards, and table grids
- TypeScriptPrimary codebase language shared across server, front, UI, and SDK packages
- NestJSModular backend framework organizing CRM business logic, auth, and worker queues
- GraphQLPrimary client-server API layer powered by GraphQL Yoga and Apollo Client
- PostgreSQLRelational system storage for workspace schemas, custom objects, and core CRM records
- ClickHouseColumnar data store for analytics, event telemetry, and timeline audit logs
- RedisIn-memory cache, pub/sub broker for GraphQL subscriptions, and BullMQ queues
- DockerProduction container images and Postgres Spilo clustering setups
Twenty architecture diagram
Open SVGDiagram as text
- CRM app (React · Apollo Client) → Server (NestJS · GraphQL Yoga): GraphQL
- Server (NestJS · GraphQL Yoga) → Metadata engine (custom objects): workspace schema
- Metadata engine (custom objects) → PostgreSQL (workspace schemas): DDL
- Server (NestJS · GraphQL Yoga) → PostgreSQL (workspace schemas): records
- Server (NestJS · GraphQL Yoga) → Redis (cache · pub/sub · queues): subscriptions
- Redis (cache · pub/sub · queues) → Workers (BullMQ): jobs
- Workers (BullMQ) → ClickHouse (events · audit logs): events
Key architectural decisions
4 decisions- 01
Dynamic Metadata-Driven Object Architecture
Stores user-defined custom objects and fields as runtime metadata in PostgreSQL, synthesizing typed GraphQL schemas and database tables dynamically.
- 02
Dual-Database Persistence with PostgreSQL and ClickHouse
Uses PostgreSQL for transactional CRM entities while streaming timeline events, activity logs, and analytics metrics to ClickHouse.
- 03
GraphQL Yoga and Apollo Client Communication
Standardizes frontend data fetching on GraphQL with live SSE subscriptions, replacing traditional REST endpoint proliferation.
- 04
Nx Workspace and Yarn Berry Monorepo
Manages twenty-front, twenty-server, twenty-ui, and twenty-sdk in a unified monorepo with strict module boundaries and Oxlint caching.
How Twenty is built
How Twenty is structured
Twenty is built as an Nx monorepo utilizing Yarn Berry (v4) with explicit package boundaries:
packages/twenty-server: The core NestJS backend application providing authentication, workspace multi-tenancy, dynamic metadata management, and worker job runners.packages/twenty-front: The React single-page frontend application featuring contact management tables, sales pipelines, Kanban boards, and timeline views.packages/twenty-ui: A reusable UI design system containing primitives, form elements, buttons, and popovers consumed across front, companion, and website packages.packages/twenty-sdk&packages/twenty-client-sdk: Public SDKs and CLI utilities enabling developers to extend Twenty through custom apps and logic functions.packages/twenty-companion: A desktop companion application built with Electron for calendar integration and automated meeting note capture.
Frontend
The user interface in packages/twenty-front is implemented in React 19 and compiled with Vite:
- Data Fetching: Uses Apollo Client (
@apollo/client) to query and mutate records via GraphQL schemas. - State & Routing: Employs Jotai for atomic UI state alongside React Router for client-side navigation.
- Rich Text & Notes: Integrates BlockNote and Tiptap for collaborative note-taking and customer activity logs.
- Data Grids: Combines custom virtualized grids with
@dnd-kitfor drag-and-drop Kanban pipeline views and inline spreadsheet-style data editing.
Backend & APIs
The backend server is implemented with NestJS in packages/twenty-server:
- GraphQL Yoga Integration: Exposes unified GraphQL endpoints (
@graphql-yoga/nestjs) that dynamically serve core CRM schemas and customer-defined custom objects. - REST & Webhooks: Provides standard REST APIs alongside outbound webhook pipelines for integration with third-party tools like Zapier.
- Background Jobs: Runs distributed background queues via BullMQ and Redis for calendar synchronization, email ingestion, and search index updates.
- AI Integrations: Uses the Vercel AI SDK (
ai) with adapters for Anthropic, OpenAI, Mistral, and Amazon Bedrock to power automated email drafting and data summarization.
Data & persistence
Twenty implements a multi-tenant persistence layer:
- PostgreSQL: Serves as the primary database managed via TypeORM. Each workspace operates with its own logical schema or metadata tables, ensuring data isolation.
- ClickHouse: Dedicated columnar storage capturing historical timelines, audit logs, and analytics metrics for high-volume customer interaction records.
- Object Storage: Integrates AWS S3 or MinIO (
@aws-sdk/client-s3) for storing file attachments, profile photos, and document exports.
Realtime / collaboration
Twenty provides realtime updates across collaborative CRM workspaces:
- GraphQL Subscriptions: Utilizes Server-Sent Events (SSE) via
graphql-sseand Redis pub/sub to stream record mutations to open browser sessions. - Presence & Lock Tracking: Broadcasts active user editing states across shared contact cards to prevent conflicting simultaneous updates.
Build, test & deploy
The build system is managed with Nx:
- Builds are cached through Nx project dependencies (
nx.json), executing Vite compilations and TypeScript builds in parallel. - Linting and code formatting are accelerated using Oxlint and Oxfmt.
- Testing includes Jest unit suites, Playwright end-to-end testing (
packages/twenty-e2e-testing), and Storybook visual regression checks. - Docker packaging is configured in
packages/twenty-dockerwith specialized PostgreSQL images including foreign data wrappers (mysql_fdw).
Self-hosting notes
Twenty supports containerized self-hosting:
- Launch locally or in staging environments using Docker Compose (
docker-compose.yml), provisioning the server, web frontend, PostgreSQL, Redis, and ClickHouse. - Environment variables control database connection URLs (
PG_DATABASE_URL), secret tokens (APP_SECRET), and storage adapters (local vs S3).
What to copy (and what not to)
What to copy:
- The dynamic metadata architecture that stores custom field definitions in relational tables and dynamically generates GraphQL resolvers without redeploying code.
- Splitting transactional records (PostgreSQL) from timeline and event streams (ClickHouse) for scalable CRM telemetry.
- Building a standalone design system package (
twenty-ui) that is reused across web, marketing, and desktop Electron applications.
What not to copy:
- Relying on extensive Yarn Berry package resolution patches for third-party libraries across modern Node versions when standard upstream releases are available.
Sources & repo audit
- Audited
- Sep 17, 2026
- Commit
- 2692a40
- License
- NOASSERTION
- package.json (Nx monorepo workspace dependencies and engines)
- packages/twenty-server/package.json (NestJS backend, GraphQL Yoga, and database drivers)
- packages/twenty-front/package.json (React frontend, Apollo Client, and UI dependencies)
- packages/twenty-ui/package.json (Shared design system and component library)
Independent analysis of repository at github.com/twentyhq/twenty. Spotted an inaccuracy? Use the claim form to request a correction.
Show this stack on your README or website
[](https://stackitfast.com/project/twenty)Paste it into your README. It shows your current stack and links to this page.
Scaffold it with your agent
Paste this prompt into Claude Code, Cursor, Windsurf or AGY to start a project with Twenty's architecture.
- 1Copy the promptThe full markdown spec, with every layer and decision.
- 2Open your AI toolClaude Code, Cursor, Windsurf or Copilot, in a new repo.
- 3Paste and scaffoldUse it as the first instruction; review before you ship.
# MISSION: Scaffold "Twenty" Production Architecture
You are an expert Senior Staff Software Architect and Full-Stack Engineer. Your mission is to scaffold and implement a production-grade, highly reliable, and modular codebase following the proven architecture of **Twenty**.
---
## 1. PROJECT SPECIFICATIONS & BENCHMARK
- **Reference Architecture**: Twenty
- **What It Does**: Modern open-source CRM alternative to Salesforce built with TypeScript, NestJS, React, GraphQL, and PostgreSQL.
- **Domain & Category**: CRM SaaS
- **Production Scale**: 6-20 people
- **Development Mode**: HYBRID
- **Architectural Rationale**: Twenty provides an extensible, modern CRM architecture featuring metadata-driven custom objects, GraphQL APIs, and clean UI design.
- **Live Website Reference**: https://twenty.com
- **Source Repository**: https://github.com/twentyhq/twenty
---
## 2. PRODUCTION TECH STACK
- **Full Stack Array**: TypeScript, React, NestJS, PostgreSQL, ClickHouse, Redis, GraphQL, Docker
- **Primary Language(s)**: TypeScript, MDX, JavaScript, Python, CSS, SCSS
- **License of the reference repo**: NOASSERTION
- **Frontend**: React — Single-page application rendering customer views, pipeline boards, and table grids
- **Backend & APIs**: TypeScript — Primary codebase language shared across server, front, UI, and SDK packages; NestJS — Modular backend framework organizing CRM business logic, auth, and worker queues; GraphQL — Primary client-server API layer powered by GraphQL Yoga and Apollo Client
- **Data & persistence**: PostgreSQL — Relational system storage for workspace schemas, custom objects, and core CRM records; ClickHouse — Columnar data store for analytics, event telemetry, and timeline audit logs; Redis — In-memory cache, pub/sub broker for GraphQL subscriptions, and BullMQ queues
- **Infrastructure & deploy**: Docker — Production container images and Postgres Spilo clustering setups
---
## 3. KEY ARCHITECTURAL DECISIONS (audited from https://github.com/twentyhq/twenty @ 2692a40)
1. **Dynamic Metadata-Driven Object Architecture**: Stores user-defined custom objects and fields as runtime metadata in PostgreSQL, synthesizing typed GraphQL schemas and database tables dynamically.
2. **Dual-Database Persistence with PostgreSQL and ClickHouse**: Uses PostgreSQL for transactional CRM entities while streaming timeline events, activity logs, and analytics metrics to ClickHouse.
3. **GraphQL Yoga and Apollo Client Communication**: Standardizes frontend data fetching on GraphQL with live SSE subscriptions, replacing traditional REST endpoint proliferation.
4. **Nx Workspace and Yarn Berry Monorepo**: Manages twenty-front, twenty-server, twenty-ui, and twenty-sdk in a unified monorepo with strict module boundaries and Oxlint caching.
---
## 4. NON-NEGOTIABLE ARCHITECTURAL GUARDRAILS
1. **Monorepo & Modular Separation**:
- Structure as a Turborepo monorepo with strict package boundaries:
- `apps/web`: Application UI, routing, layouts, and server endpoints.
- `packages/ui`: Shared design tokens, CSS variables, and Radix UI primitive components.
- `packages/db`: Database schemas, client singleton, declarative migrations, and seed scripts.
- `packages/config`: Shared TypeScript, ESLint, and build configurations.
2. **Strict Type Safety & Zero `any` Policy**:
- Enable `strict: true`, `noImplicitAny: true`, and `strictNullChecks: true`.
- Validate ALL external inputs, API request bodies, and query parameters with **Zod** schemas before execution.
3. **Frontend & Rendering Guidelines**:
- Isolate interactive UI state to leaf components. Keep core pages lightweight and performant.
4. **Design System & Aesthetics**:
- Keep every color, radius, shadow and font in a single token file (CSS variables) and consume tokens everywhere; never hardcode hex values in components.
- Prefer crisp 1px borders and one subtle shadow scale over blurry default shadows. Pair one sans-serif for body/headings with one monospace for tags, badges, metrics, and code.
5. **Data Layer & Reliability**:
- Write declarative schema definitions with foreign keys, composite indexes on queried filters, and automated timestamp triggers.
- Use connection pooling and prepared statements for serverless database execution.
---
## 5. STEP-BY-STEP SCAFFOLDING ROADMAP
- **Phase 1: Workspace & Root Config**: Initialize package manager, monorepo configuration (`turbo.json`, `tsconfig.base.json`, `package.json`).
- **Phase 2: Database Schema & Client**: Set up the data layer (PostgreSQL, ClickHouse, Redis): client, connection pool, models, and migration scripts.
- **Phase 3: Design Tokens & UI Primitives**: Build accessible `Button`, `Input`, `Card`, `Badge`, and layout wrappers inside `packages/ui`.
- **Phase 4: Core Application Routes & Handlers**: Implement primary authentication, user session handling, and application routes.
- **Phase 5: Quality Assurance & Build Verification**: Run `tsc --noEmit`, ESLint, Prettier, and smoke test suites to ensure zero compilation or runtime errors.
---
## 6. EXECUTION INSTRUCTIONS
1. Review all specifications, architectural guardrails, and stack choices above.
2. Present the full monorepo directory tree structure.
3. Systematically generate the complete, production-ready codebase according to the 5-phase roadmap above — starting with the root workspace setup, followed by the database schema, UI design system package, and full-stack application routes until the repository is fully scaffolded and ready to run.Frequently asked about Twenty
How does Twenty support custom CRM fields without requiring server restarts?
Twenty maintains a dynamic metadata engine that alters PostgreSQL schemas and regenerates GraphQL types at runtime per workspace.
Can Twenty be self-hosted using standard container infrastructure?
Yes, Twenty ships production Docker compose configurations and Kubernetes manifests connecting to external PostgreSQL, Redis, and ClickHouse.
One email a month: new deep dives and stack trends
New source-audited architectures, head-to-head comparisons and the monthly stack report. No spam, unsubscribe anytime.
Similar architectures
- ToolJetHybridLow-Code Developer Tool Platform · 6-20 peopleShares TypeScript · React · NestJS
- Cal.comClassicScheduling SaaS · 6-20 peopleShares TypeScript · React · PostgreSQL
- InfisicalHybridSecret Management · 6-20 peopleShares React · TypeScript · PostgreSQL
- UmamiHybridWeb Analytics · SoloShares TypeScript · React · PostgreSQL
- ImmichHybridPhoto & Video Management Platform · 6-20 peopleShares TypeScript · NestJS · PostgreSQL
- Trigger.devHybridJob Queue / Dev Tool · 6-20 peopleShares TypeScript · PostgreSQL · ClickHouse