# Building a Coreapp

> For developers: make an app or port an existing one with coreapp-dev, and test it on a Core on your own computer.

- Web page: https://documentation.federated.computer/developer-tools/core-app-development-kit/building-a-coreapp/

**coreapp-dev** is the kit for making Coreapps. It runs a real Federated Core in a virtual machine on your computer, and its `coreapp` command builds your app, installs it on that Core, and tests it there: its address and certificate, sign-in with Core SSO, its database, and the mail it sends. When it works, you [publish it](https://documentation.federated.computer/developer-tools/core-app-development-kit/publishing-a-coreapp/) so any Core can install it.

A Coreapp is any web app that runs in one Docker container and serves HTTP on a port. It can be new, or an existing project: most self-hosted web apps can be ported by adding a `coreapp.toml` and adjusting their Dockerfile.

## Before you start

You need coreapp-dev installed and a development Core running in a VM on your computer, reachable from the internet. [Setting up coreapp-dev](https://documentation.federated.computer/developer-tools/core-app-development-kit/setting-up-coreapp-dev/) takes you through it step by step, and ends with a first app deployed.

## Make a new app

```
coreapp new my-app
cd my-app
coreapp deploy
coreapp check
```

`coreapp new` makes a folder with a working example: a `Dockerfile`, a `coreapp.toml`, an icon, and a README. Add what the app needs from the Core:

| Option | Gives the app |
|---|---|
| `--postgres` | Its own PostgreSQL database (with a Python example that uses it) |
| `--mysql` | Its own MariaDB database, instead of PostgreSQL |
| `--sso` | Sign-in with Core SSO (with a Python example of the whole sign-in) |
| `--email` | An account on the Core's mail server, for sending |

`coreapp deploy` builds the image, copies it to the Core in your VM, and installs it at `https://my-app.<your Core's domain>`. Run it again after each change: it updates the app and keeps its data. If the new version doesn't start, the update is rolled back. `coreapp check` confirms the app answers at its public address with a valid certificate.

## Port an existing app

Work in the app's repository. Add a `coreapp.toml` (see the [reference](https://documentation.federated.computer/developer-tools/core-app-development-kit/coreapp-toml/)), and make the Dockerfile fit the Core:

- **Serve plain HTTP** on `0.0.0.0` and the port in `coreapp.toml`. The Core's proxy adds HTTPS in front.
- **Use the Core's settings.** The app gets its address, a secret, and its database, sign-in, and mail settings as environment variables. Map them onto the app's own settings, in an entrypoint script if it's an upstream image.
- **Keep files in `/data`.** That folder is kept across updates; everything else in the container is replaced.
- **Run as a non-root user**, if the image allows it.
- **One container.** If the project ships a compose file with several services, keep only the app, and use the Core's database instead of its own. Services the Core doesn't offer, such as Redis, aren't available yet.

> **Using Claude Code**
>
> coreapp-dev installs a Claude Code skill, `coreapp`, with everything above in detail: how to fit each kind of app, the rules for sign-in, and how to test. Ask Claude Code to "make this a Coreapp" in an app's repository, and it builds, deploys, and tests it on your Core, then reports what works and what's left for you.

## Test it

| Command | Checks |
|---|---|
| `coreapp check` | The app answers at its public address, with a valid certificate |
| `coreapp signin` | Signs in with Core SSO as a browser would, with the Core's test account, and shows each step |
| `coreapp inbox` | The mail the test account received from your app (invitations, password resets), with its links |
| `coreapp mail` | What the Core's mail server did with the mail your app sent: accepted, delivered, deferred, or bounced |
| `coreapp logs -f` | The app's log |
| `coreapp shell` | A shell in the app's container |
| `coreapp status` | Its container, address, and needs |

The test account, `coreapp.test@<your Core's domain>`, is an ordinary Core account in no groups: use it to check what a newcomer sees. Before a release, also sign in once in a browser as the Core's admin, to check the admin gets the admin role.

### Rules for sign-in

Every Coreapp that signs in with Core SSO follows the same two rules, so a Core's owner knows what to expect from any app:

- **The Core's admin is the app's admin.** The address in `CORE_ADMIN_EMAIL` is made an admin each time it signs in with Core SSO, trusted only from the email the Core's sign-in gives. No setup page, no first person to sign up becomes the owner, and that account has no password of its own in the app.
- **Everyone else gets the lowest role that can look around**, usually read-only, without an invitation. In an app where each person only has their own private things, such as a feed reader, that's a regular user.

Label the sign-in button **Core SSO** (or **Authelia**), so it reads the same in every app.
