|
1 | 1 | --- |
2 | | -title: Structure your GitHub repositories |
3 | | -description: Set up GitHub repositories for your SDKs |
| 2 | +title: Project structure |
| 3 | +description: An overview of the file and folder structure of a Fern SDKs project |
4 | 4 | --- |
5 | 5 |
|
6 | | -Before generating SDKs with Fern, you'll need to set up the proper GitHub |
7 | | -repository structure to house your API definitions and SDK code so it's |
8 | | -intuitive for you and your users to access, maintain, and update code. |
| 6 | +Before generating SDKs with Fern, set up the proper GitHub repository structure to house your API definitions and SDK code so it's intuitive for you and your users to access, maintain, and update code. |
9 | 7 |
|
10 | | -<Steps> |
11 | | -## Structuring your top-level repository |
| 8 | +## Repository architecture |
12 | 9 |
|
13 | | -1. Identify or create a top-level GitHub repository where you want all of your |
14 | | - SDK and API code to live. |
15 | | -1. Install the [Fern GitHub App](https://github.com/apps/fern-api) on the |
16 | | - top-level repository and all SDK repositories. Select **Configure**, then |
17 | | - scroll down to **Repository Access**. Select **Only select repositories** and |
18 | | - in the dropdown select the repository for your SDK. Click **Save**. |
| 10 | +Fern recommends a parent-child repository structure containing: |
19 | 11 |
|
20 | | -For example, your basic GitHub file structure should look something like this: |
| 12 | +- **Parent repository**: Contains your API definitions and SDK generation configuration |
| 13 | +- **Child repositories**: Separate repositories for each SDK (TypeScript, Python, Go, etc.) |
21 | 14 |
|
| 15 | +```bash |
| 16 | +├─ company-repo # Parent repository |
| 17 | +│ └─ fern/ |
| 18 | +│ ├─ fern.config.json |
| 19 | +│ ├─ apis/ |
| 20 | +│ │ └─ sdks/ |
| 21 | +│ │ └─ generators.yml # References child repos |
| 22 | +├─ typescript-sdk-repo # Child repository |
| 23 | +├─ python-sdk-repo # Child repository |
| 24 | +└─ go-sdk-repo # Child repository |
22 | 25 | ``` |
23 | | -├─ company-repo # Top-level repo for all SDKs |
24 | | - ├─ fern/ |
25 | | - ├─ apis/ |
26 | | - ├─ sdks/ |
27 | | - └── generators.yml # Contains settings for all SDKs |
28 | | -``` |
29 | | -Your `generators.yml` file will contain a group for each of your SDKs. Each group points |
30 | | -to the GitHub repository for the relevant SDK. |
31 | 26 |
|
32 | | -For example, the `group` for a TypeScript SDK might look like this: |
| 27 | +This separation allows you to manage API definitions centrally while keeping each SDK in its own repository for independent versioning and distribution. |
33 | 28 |
|
34 | | -```yaml title="generators.yml" |
35 | | - ts-sdk: |
36 | | - generators: |
37 | | - - name: fernapi/fern-typescript-sdk |
38 | | - version: 2.6.3 |
39 | | - github: |
40 | | - repository: your-organization/your-typescript-repo |
| 29 | +<Info> |
| 30 | + For an example of this structure, see Cohere's [fern folder](https://github.com/cohere-ai/cohere-developer-experience/tree/23d6c541a01eb6b54dd9bb3588c805bb0e307713/fern) and [TypeScript](https://github.com/cohere-ai/cohere-typescript) and [Python](https://github.com/cohere-ai/cohere-python) child repositories. |
| 31 | +</Info> |
| 32 | + |
| 33 | +## Core configuration files |
| 34 | + |
| 35 | +[Initializing your `fern` folder](/sdks/overview/quickstart) creates two key configuration files: |
| 36 | + |
| 37 | +### `fern.config.json` |
| 38 | + |
| 39 | +This file stores your organization name and Fern CLI version: |
| 40 | + |
| 41 | +```json |
| 42 | +{ |
| 43 | + "organization": "your-organization", |
| 44 | + "version": "<Markdown src="/products/sdks/snippets/fern-config-json-version.mdx"/>" |
| 45 | +} |
41 | 46 | ``` |
42 | 47 |
|
43 | | -For additional examples, see Cohere's [`generators.yml` |
| 48 | +### `generators.yml` |
| 49 | + |
| 50 | +The `generators.yml` file specifies which SDKs to generate and where to publish them. It acts as the bridge between your API definitions and your SDK repositories. |
| 51 | + |
| 52 | +<Info> |
| 53 | +For examples, see Cohere's [`generators.yml` |
44 | 54 | file](https://github.com/cohere-ai/cohere-developer-experience/blob/23d6c541a01eb6b54dd9bb3588c805bb0e307713/fern/apis/sdks/generators.yml) |
45 | 55 | and Vapi's [`generators.yml` |
46 | 56 | file](https://github.com/VapiAI/docs/blob/9c674c2b16ba03e864e26673c5290c88048c9a7a/fern/apis/api/generators.yml). |
| 57 | +</Info> |
| 58 | + |
| 59 | + |
| 60 | +<Info> |
| 61 | + See the [`generators.yml` reference page](/sdks/reference/generators-yml) for complete configuration options. |
| 62 | +</Info> |
47 | 63 |
|
48 | | -<Info>You can also additionally configure the `github` section to whether Fern |
49 | | -should commit and release, create a pull request, or push code to a branch when |
50 | | -you make changes to your SDK code. See [GitHub |
51 | | -Configuration](/sdks/reference/generators-yml#github-configuration) for more |
52 | | -details. </Info> |
53 | | - |
54 | | -## Structuring SDK-specific repositories |
55 | | - |
56 | | -1. Create a new GitHub repository called `company-<language>` (or something |
57 | | - similar) for each of your SDKs, if you haven't done so already. |
58 | | -1. Install the [Fern GitHub App](https://github.com/apps/fern-api) on the |
59 | | - top-level repository and all SDK repositories. Select **Configure**, then |
60 | | - scroll down to **Repository Access**. Select **Only select repositories** and |
61 | | - in the dropdown select the repository for your SDK. Click **Save**. |
62 | | - |
63 | | - |
64 | | -The repository structure for a specific SDK should look similar to this: |
65 | | - |
66 | | -```{6-11} |
67 | | -├─ company-repo # Top-level repo for all SDKs |
68 | | - ├─ fern/ |
69 | | - ├─ apis/ |
70 | | - ├─ sdks/ |
71 | | - └── generators.yml # Contains settings for all SDKs |
72 | | - ├─ typescript-sdk-repo # Repository for a TypeScript SDK |
73 | | - ├─ .github/workflows/ # Contains GitHub Actions for publishing to package repositories, etc. |
74 | | - ├─ scripts/ |
75 | | - ├─ src/ |
76 | | - ├─ tests/ |
77 | | - └── .fernignore # Lists files that Fern shouldn't modify |
78 | | - ├─ python-sdk-repo |
79 | | - └── go-sdk-repo |
| 64 | +## Parent repository structure |
| 65 | + |
| 66 | +The parent repository contains your API definitions and the `generators.yml` file that references your child SDK repositories. |
| 67 | + |
| 68 | +<CodeBlock title="Parent repository structure"> |
| 69 | +```bash |
| 70 | +company-repo/ |
| 71 | +├─ fern/ |
| 72 | +│ ├─ fern.config.json |
| 73 | +│ ├─ apis/ |
| 74 | +│ │ └─ sdks/ |
| 75 | +│ │ └─ generators.yml # SDK generation configuration |
80 | 76 | ``` |
| 77 | +</CodeBlock> |
81 | 78 |
|
82 | | -Fern generates most of the SDK files listed in this example repository (`scripts/`, `src/`, `tests`, |
83 | | -`.fernignore`, etc.), including any custom code you added. You have to manually set up `.github/workflows` to execute actions, like publishing SDK versions to a package repository. |
| 79 | +Your `generators.yml` file contains a group for each SDK and points to the corresponding child repository: |
84 | 80 |
|
85 | | -For additional examples, see Cohere's [Python SDK repository](https://github.com/cohere-ai/cohere-python) and [Vapi's TypeScript SDK repository](https://github.com/VapiAI/server-sdk-typescript). |
| 81 | +```yaml title="generators.yml" |
| 82 | +groups: |
| 83 | + ts-sdk: |
| 84 | + generators: |
| 85 | + - name: fernapi/fern-typescript-sdk |
| 86 | + version: <Markdown src="/snippets/version-number-ts.mdx"/> |
| 87 | + github: |
| 88 | + repository: your-organization/typescript-sdk-repo |
86 | 89 |
|
87 | | -## Generate an SDK in your desired language |
88 | | - |
89 | | -Once you've set up your GitHub repository structure, you can proceed with generating SDKs in your desired languages. |
90 | | - |
91 | | - <CardGroup cols={3}> |
92 | | - <Card title="TypeScript" icon={<img src="./images/icons/ts-light.svg" alt="TypeScript logo" className="h-6 w-6" noZoom />} href="/sdks/generators/typescript/quickstart"> |
93 | | - </Card> |
94 | | - <Card title="Python" icon={<img src="./images/icons/python-light.svg" className="h-6 w-6" noZoom />} href="/sdks/generators/python/quickstart"> |
95 | | - </Card> |
96 | | - <Card title="Go" icon={<img src="./images/icons/go-light.svg" className="h-6 w-6" noZoom />} href="/sdks/generators/go/quickstart"> |
97 | | - </Card> |
98 | | - <Card title="Java" icon={<img src="./images/icons/java-light.svg" className="h-6 w-6" noZoom />} href="/sdks/generators/java/quickstart"> |
99 | | - </Card> |
100 | | - <Card title=".NET" icon={<img src="./images/icons/csharp-light.svg" className="h-6 w-6" noZoom />} href="/sdks/generators/csharp/quickstart"> |
101 | | - </Card> |
102 | | - <Card title="PHP" icon={<img src="./images/icons/php-light.svg" className="h-6 w-6" noZoom />} href="/sdks/generators/php/quickstart"> |
103 | | - </Card> |
104 | | - <Card title="Ruby" icon={<img src="./images/icons/ruby-light.svg" className="h-6 w-6" noZoom />} href="/sdks/generators/php/quickstart"> |
105 | | - </Card> |
106 | | - </CardGroup> |
107 | | - |
108 | | - </Steps> |
| 90 | + python-sdk: |
| 91 | + generators: |
| 92 | + - name: fernapi/fern-python-sdk |
| 93 | + version: <Markdown src="/snippets/version-number-python.mdx"/> |
| 94 | + github: |
| 95 | + repository: your-organization/python-sdk-repo |
| 96 | +``` |
| 97 | +
|
| 98 | +## Child repository structure |
| 99 | +
|
| 100 | +Each SDK has its own repository with the following structure: |
109 | 101 |
|
| 102 | +<CodeBlock title="Child repository structure"> |
| 103 | +```bash |
| 104 | +typescript-sdk-repo/ # Individual SDK repository |
| 105 | +├─ .github/workflows/ # Publishing workflows |
| 106 | +├─ scripts/ |
| 107 | +├─ src/ |
| 108 | +├─ tests/ |
| 109 | +└─ .fernignore # Files Fern shouldn't modify |
| 110 | +``` |
| 111 | +</CodeBlock> |
| 112 | + |
| 113 | +Fern generates most of these files automatically, including preserving any custom code you've added. |
| 114 | + |
| 115 | +## Setup instructions |
| 116 | + |
| 117 | +1. **Create repositories**: Set up your parent repository and one child repository for each SDK |
| 118 | +2. **Install Fern GitHub App**: Install the [Fern GitHub App](https://github.com/apps/fern-api) on all repositories (parent and children) |
| 119 | +3. **Configure generators.yml**: Add each child repository to your `generators.yml` file |
| 120 | + |
| 121 | +## Multiple API definitions |
| 122 | + |
| 123 | +For multiple APIs, organize them in separate folders within the `apis` directory: |
| 124 | + |
| 125 | +<Tabs> |
| 126 | +<Tab title="OpenAPI Definition"> |
| 127 | +```bash |
| 128 | +fern/ |
| 129 | + ├─ fern.config.json |
| 130 | + ├─ generators.yml |
| 131 | + └─ apis/ |
| 132 | + └─ imdb/ |
| 133 | + ├─ generators.yml |
| 134 | + └─ openapi/ |
| 135 | + ├─ openapi.yml |
| 136 | + └─ disney/ |
| 137 | + ├─ generators.yml |
| 138 | + └─ openapi/ |
| 139 | + ├─ openapi.yml |
| 140 | +``` |
| 141 | +</Tab> |
| 142 | +<Tab title="Fern Definition"> |
| 143 | +```bash |
| 144 | +fern/ |
| 145 | + ├─ fern.config.json |
| 146 | + ├─ generators.yml |
| 147 | + └─ apis/ |
| 148 | + └─ imdb/ |
| 149 | + ├─ generators.yml |
| 150 | + └─ definition/ |
| 151 | + ├─ api.yml |
| 152 | + └─ imdb.yml |
| 153 | + └─ disney/ |
| 154 | + ├─ generators.yml |
| 155 | + └─ definition/ |
| 156 | + ├─ api.yml |
| 157 | + └─ disney.yml |
| 158 | +``` |
| 159 | +</Tab> |
| 160 | +</Tabs> |
0 commit comments