Files
twenty/packages/twenty-docs/l/zh/developers/extend/apps/getting-started/project-structure.mdx
T
github-actions[bot] ebee7d71b9 i18n - docs translations (#22715)
Created by Github action

<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/twentyhq/twenty/pull/22715?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>
<!-- End of auto-generated description by cubic. -->

Co-authored-by: github-actions <github-actions@twenty.com>
2026-07-09 11:51:54 +02:00

78 lines
4.5 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
title: 项目结构
description: 脚手架生成的 Twenty 应用中包含哪些内容——文件、文件夹以及它们各自的作用。
icon: folder-tree
---
由 `npx create-twenty-app` 生成的新应用看起来是这样的:
```text filename="my-twenty-app/"
my-twenty-app/
package.json
src/
application-config.ts # Required — your app's entry point
default-role.ts # Permissions for logic functions
constants/
universal-identifiers.ts # Auto-generated UUIDs and metadata
front-components/
main-page.tsx # Welcome page component
navigation-menu-items/
main-page.navigation-menu-item.ts # Sidebar entry for the welcome page
page-layouts/
main-page.page-layout.ts # Standalone page hosting the component
__tests__/
application-config.test.ts # Unit test
global-setup.ts # Integration test setup (sync + uninstall)
schema.integration-test.ts # Integration test against a live server
.github/workflows/
ci.yml # Lint, typecheck, unit + integration tests
cd.yml # Deploy + install on push to main
public/
logo.svg # Static assets
vitest.config.ts # Integration test runner config
vitest.unit.config.ts # Unit test runner config
tsconfig.json, tsconfig.spec.json
.nvmrc, .yarnrc.yml, .oxlintrc.json
README.md, AGENTS.md, CLAUDE.md
```
## 关键文件
| 文件 / 文件夹 | 目的 |
| -------------------------------------------------------------------------- | --------------------------------------- |
| `src/application-config.ts` | **必需。** 应用的主配置文件。 |
| `src/default-role.ts` | 默认角色,用于控制你的逻辑函数可访问的内容。 |
| `src/constants/universal-identifiers.ts` | 自动生成的 UUID 和元数据(显示名称、描述)。 |
| `src/front-components/`, `src/navigation-menu-items/`, `src/page-layouts/` | 一个入门欢迎页面:由独立页面布局渲染的前端组件,可从侧边栏访问。 |
| `src/__tests__/` | 一个单元测试加一个集成测试(带有其全局设置),用于将应用与真实服务器进行同步。 |
| `public/` | 随应用一起提供的静态资源(图像、字体)。 |
| `AGENTS.md` / `CLAUDE.md` | 为在该应用上工作的 AI 编码代理提供指导。 |
<Note>
**文件组织由你决定。** 上述文件夹只是约定——SDK 通过对 `export default defineEntity(...)` 调用进行 AST 分析来检测实体,而不受文件所在位置影响。
</Note>
## 依赖项
这两个 Twenty SDK 软件包都应放在 `devDependencies` 下,而不是 `dependencies`
```json filename="package.json"
{
"dependencies": {},
"devDependencies": {
"twenty-client-sdk": "2.20.0",
"twenty-sdk": "2.20.0",
"twenty-ui": "1.0.0-alpha.1"
}
}
```
脚手架工具将 `twenty-sdk` 和 `twenty-client-sdk` 固定为与自身相同的版本——升级时请保持这两者同步。
* **`twenty-sdk`** 提供 `twenty` CLI 以及构建/脚手架工具。 它只在开发和构建阶段运行,且永远不会在已发布应用的运行时环境中被导入。
* **`twenty-client-sdk`** 会被你的应用代码(`CoreApiClient`、`MetadataApiClient`、`RestApiClient`)导入,但 Twenty 会在运行时提供它——逻辑函数从生成的 SDK 层获取它,前端组件则从服务器提供的模块中解析它。 你安装的副本仅用于类型检查和部署时的构建,因此不需要被打包进已部署的 bundle 中。
把任意一个软件包放在 `dependencies` 下,都会把它拉入已安装应用的运行时 bundle 中,在那里只是累赘。 当任一软件包仍然列在 `dependencies` 下时,`twenty dev:build` 会发出警告。
像往常一样,把你的应用自身的运行时依赖项(逻辑函数在运行时实际导入的库)添加到 `dependencies` 下。