> This page is for SDK, version Current (default).
> For other versions, use one of these documentation indexes:
> - Current (default): https://buildwithfern.com/learn/sdks/current/llms.txt
> - Legacy: https://buildwithfern.com/learn/sdks/legacy/llms.txt

> For clean Markdown content of this page, append .md to this URL. For the complete documentation index, see https://buildwithfern.com/learn/llms.txt.

# 项目结构

> 了解如何使用 Fern 构建 SDK 项目结构。设置多仓库架构、配置 generators.yml 和组织 API 定义。

在使用 Fern 生成 SDK 之前，需要设置正确的 GitHub 仓库结构来存放您的 API 定义和 SDK 代码，这样您和您的用户可以直观地访问、维护和更新代码。

## 仓库架构

Fern 建议使用多仓库结构，包含：

* **源仓库**：包含您的 API 定义和 SDK 生成配置
* **SDK 仓库**：每个 SDK 一个仓库（TypeScript、Python、Go 等）

这种分离方式允许您集中管理 API 定义，同时将每个 SDK 保持在自己的仓库中，实现独立的版本管理和分发。

> **示例**
>
> 查看 Cohere 的 [fern 文件夹](https://github.com/cohere-ai/cohere-developer-experience/tree/23d6c541a01eb6b54dd9bb3588c805bb0e307713/fern) 以及 [TypeScript](https://github.com/cohere-ai/cohere-typescript) 和 [Python](https://github.com/cohere-ai/cohere-python) SDK 仓库。

## 核心配置文件

源仓库包含一个 `fern/` 文件夹，其中初始化了您的 API 定义和顶级 `generators.yml` 文件。

### `fern.config.json`

`fern.config.json` 文件存储您的组织名称和 Fern CLI 版本。固定版本提供确定性构建。

**`fern.config.json`**

```json title="fern.config.json"
{
  "organization": "plant-catalog",
  "version": "5.23.3"
}
```

> **Info**
>
> 当使用本地安装的 CLI 时，将 `version` 设置为 `"*"`。详见[本地安装 Fern CLI](/learn/zh/cli-api-reference/cli-reference/overview#install-fern-cli-locally)。

### `generators.yml`

`generators.yml` 文件在 `api.specs` 部分声明您的 API 规范位置，并在 `groups` 部分配置 SDK 生成。

**`generators.yml`**

```yaml title="generators.yml"
# API 声明
api:
  specs:
    - openapi: ./openapi/openapi.yml

# SDK 生成
groups:
  ts-sdk:
    generators:
      - name: fern-typescript-sdk
        version: 3.108.0
        github:
          repository: your-organization/typescript-sdk-repo

  python-sdk:
    generators:
      - name: fern-python-sdk
        version: 5.41.10
        github:
          repository: your-organization/python-sdk-repo
```

> **示例**
>
> 查看 Cohere 的 [`generators.yml` 文件](https://github.com/cohere-ai/cohere-developer-experience/blob/23d6c541a01eb6b54dd9bb3588c805bb0e307713/fern/apis/sdks/generators.yml) 和 Vapi 的 [`generators.yml` 文件](https://github.com/VapiAI/docs/blob/9c674c2b16ba03e864e26673c5290c88048c9a7a/fern/apis/api/generators.yml)。

完整的配置选项请参阅 [`generators.yml` 参考页](/learn/zh/sdks/reference/generators-yml)。

### API 定义文件

有关组织 API 定义文件和处理多个 API 的详细信息，请参阅[项目结构（API 定义）](/learn/zh/api-definitions/overview/project-structure)。