Project Structure
- Applies to
- Gatewayruntime for API, AI, and MCP gateways
- Hosting
- Managed EdgeManaged DedicatedSelf-Hosted
A Zuplo project is a standard Node.js-style project managed via Git. Here is the typical layout. Select a file to see what it does.
Holds the JSON files that define your gateway: which routes it serves, what handles each request, and which policies run along the way. The Zuplo Portal route designer and policy editor read and write these files, so changes you make in the Portal and changes you push from Git end up in the same place.
- Keep everything that describes the API's shape here, and put code in
modules/. - Split a large API into several
*.oas.jsonfiles, for example one per resource or team.
An OpenAPI 3.1 document that defines your API routes. Each operation
specifies the HTTP method, path, handler, and policies to apply. Zuplo
extends the OpenAPI spec with x-zuplo-route to attach a handler and
policies to each operation.
- Routes match in the order they appear in the file, so put specific paths
such as
/users/adminbefore/users/{userId}. - With several OpenAPI files, Zuplo checks them in alphabetical order.
- The same document powers the API reference in your Developer Portal, so add summaries and descriptions as you go.
This route forwards GET /users/{userId} to a backend and runs two
policies first:
config/routes.oas.json
Defines each policy instance by name, type, and configuration. Routes list
these names in their policies.inbound and policies.outbound arrays, so
one definition can protect any number of routes.
- Give each instance a descriptive name, such as
rate-limit-free-tier, and reuse it across routes instead of copying options. - Read secrets in
optionsfrom environment variables with$env(VARIABLE_NAME)rather than writing them into the file. - Point
moduleat$import(./modules/...)to run your own code as a policy.
This file defines an API key check and a rate limit of 100 requests per minute per IP address:
config/policies.json
See Policies for the full list of built-in policies.
Contains your custom TypeScript code: request handlers, custom policies, and
shared helpers. Routes and policies point to these modules with
$import(./modules/...).
- Import from
@zuplo/runtimefor request, context, and environment types. - Put shared helpers in their own files and import them with relative paths.
- Add a
zuplo.runtime.tsfile here to run code once when the gateway starts, for example to register plugins.
A request handler receives the incoming request and returns a response.
Return a Response for full control, or any other value and Zuplo
serializes it to JSON with an application/json content type.
modules/my-handler.ts
Wire it to a route by pointing the route's handler at the module and export:
config/routes.oas.json
- Read path parameters from
request.paramsand query strings fromrequest.query. - Log with
context.logso messages appear in your gateway logs.
See Function Handler for details.
Present when your project includes a Developer Portal. It holds the portal
configuration and any custom pages, and has its own package.json. The
portal generates its API reference from your config/*.oas.json files, so
route changes show up in the docs automatically.
- Put Markdown and MDX pages here to add guides next to the API reference.
- The portal reads its own
docs/.envfor local development, not the gateway's.env. - Delete the portal's configuration file and redeploy to turn the Developer Portal off.
See Developer Portal for details.
Configures the Developer Portal: navigation, theme, authentication, and which OpenAPI files become the API reference.
- Only environment variables that start with
ZUPLO_PUBLIC_orZUDOKU_PUBLIC_are available to the portal. - Start with navigation and branding, then add authentication when you're ready to issue API keys.
See the configuration file reference for every option.
Project-level settings, such as the runtime compatibility date and the hosting type. New projects get this file by default.
zuplo.jsonc
compatibilityDatelocks runtime behavior, so platform updates don't change how your project works until you move the date forward.projectTypeismanaged-edge(the default),managed-dedicated, orself-hosted, matching where the project deploys.
- Read the compatibility dates changes before you move the date forward.
- The Zuplo Portal doesn't show this file. Edit it in your repository and push the change.
See Project Configuration for all options.
A standard Node.js package.json. It lists the zuplo package, any npm
packages your modules import, and the scripts you use day to day.
- Run
npm run devto start the gateway locally. - Add npm packages your modules need here. See Installing packages.
- Commit the lockfile so local runs and deployments use the same versions.
Local development can't read the environment variables you set in the Zuplo Portal, so put the values your gateway needs locally here.
.env
Your code reads them the same way in every environment:
modules/my-handler.ts
- Never commit this file. Add
.envto your.gitignore. - Set the same variable names in the Zuplo Portal for deployed environments.
- When you run
zuplo dev,ZUPLO_ENVIRONMENT_STAGEislocal.
zuplo link writes this file with details about the
linked account, project, and environment. zuplo dev loads it along with
.env.
- Don't edit it:
zuplo linkreplaces it each time it runs. Put your own variables in.env. - Don't commit it. Each developer links their own environment.
How the files relate
zuplo.jsoncsets project-wide configuration (runtime version, deployment type)config/routes.oas.jsondefines API routes and wires each route to a handler and policies by nameconfig/policies.jsondefines the named policy instances with their configuration and points to either built-in modules (@zuplo/runtime) or custom modules in./modulesmodules/contains the TypeScript implementations for custom handlers and policies
All of this lives in Git and deploys automatically when you push.
The $import() syntax
JSON configuration files (routes.oas.json and policies.json) use the
$import() syntax to reference code modules. This is a Zuplo-specific syntax
that resolves module references at build time.
Code
References starting with @zuplo/runtime point to built-in Zuplo modules
(policies, handlers, and utilities).
Code
References starting with ./modules/ point to your custom TypeScript files in
the modules/ directory. The export field specifies which named export to use
from that module.