How to Structure Projects

Functions are blocks of code that run on demand without the need to manage any infrastructure. Develop on your local machine, test your code from the command line (using doctl), then deploy to App Platform — no servers required. Learn more about functions.

To deploy functions to production, you need to structure your source code into a project and upload that project to a GitHub repository

A project is a collection of resources, including functions, which is stored on your local computer or in a GitHub repository. Projects have a prescriptive structure that they must follow in order to deploy them to App Platform.

You can create a project manually, but we recommend the following ways to get started:

Project Structure

The project root can either be the root of a Git repository or a subdirectory in a monorepo. This top-level project root must contain the following:

  • A project configuration file called project.yml.

  • A directory named packages containing one or more packages. A package is a collection of functions. Each package must have its own directory under packages.

    Each function must be in a package directory. Functions can be a single source code file or a directory with one or more source code files.

The packages directory can contain any number of packages, and each package can contain an arbitrary number of functions. This lets you organize your project in the way that makes the most sense to you.

The organization of packages determines the URL where functions are served. Functions components in App Platform are served at a URL with the structure app_url/component_route/package/function.

Example Project Structures

Here is a barebones example of the structure of a project:

├── project.yml
└── packages
    └── example-package
        └── example-function.php

Here is an example structure for project with two packages, example-package-1 and example-package-2. example-package-1 has three functions, and example-package-2 has one.

├── packages
│   ├── example-package-1
│   │   ├── example-function-a.php
│   │   ├── example-function-b
│   │   │   ├── package.json
│   │   │   └── example.js
│   │   └── example-function-c
│   │       └── index.php
│   └── example-package-2
│       └── example-function
│           ├── requirements.txt
│           ├──
│           └──
└── project.yml