# Setting up coreapp-dev

> Step by step: install the Core App Development Kit, run a Core in a VM on your computer, make it reachable, provision it, and deploy your first app.

- Web page: https://documentation.federated.computer/developer-tools/core-app-development-kit/setting-up-coreapp-dev/

By the end of this page you'll have a real Federated Core running in a
virtual machine on your computer, reachable from the internet, and a first
app deployed to it. Do the parts in order: each one ends with a check, and
the next part assumes it passed.

It takes about an hour, most of it waiting for downloads and provisioning.

## What you need before you start

Gather these first:

- **Your computer:** CoreDesktop installed, hardware virtualization (VT-x
  or AMD-V) turned on in the firmware, and room for the VM: about 4 CPUs,
  8 GB of memory and 60 GB of disk.
- **Your You host account:** its **account ID** (in the template you got
  at signup) and its **SSH public key** (in the dashboard, under **Cores**).
- **A small VPS with a public IP address,** running Arch Linux with
  MiniServer. Use one that does nothing else: its ports 22, 80 and 443 will
  belong to your Core. If your cloud provider has its own firewall (a
  "security group"), allow TCP 22, 80, 443 and 2222, and UDP 51820 (the
  tunnel). MiniServer opens these on the VPS itself.
- **A name for your Core** (the `subdomain`), such as `dev`. Federated adds
  a domain to it, so the Core's address will be something like
  `dev.fedcom.net`.

Why the VPS: the VM lives on a private network inside your computer, so
nothing on the internet can reach it directly. Federated's Provisioner
needs to reach it over SSH, and your apps need to be reachable over HTTPS.
**corerelay** gives the VM your VPS's public address through an encrypted
tunnel.

## Part 1: Install coreapp-dev

1. On your computer, run:

   ```
   sibling add https://gitea.federated.computer/Federated_Computer/coreapp-dev.git
   ```

   This installs libvirt, QEMU/KVM and Docker, sets up the VM's private
   network (`10.123.0.0/24`), and adds the `coreapp-vm` and `coreapp`
   commands and the Claude Code skill.

2. **Log out and log back in.** This puts you in the `libvirt` group. The
   VM commands fail until you do.

**Check:** open a new terminal and run:

```
coreapp-vm list
```

It should run without an error. It lists no VMs yet.

## Part 2: Give the VM Federated's SSH key

Federated's Provisioner logs in to your Core with your account's SSH key,
so the VM has to have it from the start.

1. In the dashboard, open **Cores** and copy your account's **SSH public
   key**. It's one line starting with `ssh-ed25519` or `ssh-rsa`.
2. Save it on your computer:

   ```
   mkdir -p ~/.config/coreapp-dev
   nano ~/.config/coreapp-dev/authorized_keys
   ```

   Paste the key as one line, then save and close the editor.

**Check:**

```
cat ~/.config/coreapp-dev/authorized_keys
```

It shows the key on one line.

## Part 3: Create the VM

1. Run:

   ```
   coreapp-vm create
   ```

   The first time, it downloads the CoreServer image (1.3 GB). Then it
   creates a VM called `coreserver` at `10.123.0.10`.

2. Watch for these lines:
   - `Root's SSH keys: 2 (coreapp-dev's, plus .../authorized_keys)`. If it
     says `Note: ... authorized_keys is missing` instead, the VM doesn't have
     Federated's key: run `coreapp-vm delete`, go back to Part 2, and create
     it again.
   - `Created 'coreserver'. Waiting for an IP...`, then `Log in: coreapp-vm ssh`.

3. Wait one more minute while the VM finishes its first boot.

**Check:**

```
coreapp-vm ssh hostname
```

It prints the VM's name.

## Part 4: Make the VM reachable through your VPS

You'll install corerelay on both the VPS and your computer, then each side
learns the other's key. Keep a terminal open on each.

### 4a. Install corerelay on the VPS

1. Log in to the VPS and run:

   ```
   sibling add https://gitea.federated.computer/Federated_Computer/corerelay.git
   ```

   If it says you were added to the `docker` group, log out of the VPS and
   back in.

2. **Check that you can still log in to the VPS on port 2222.** Once the
   relay runs, the VPS's port 22 goes to your Core, so from then on you log
   in to the VPS itself on port 2222. corerelay sets that up. From your
   computer, in a new terminal:

   ```
   ssh -p 2222 <you>@<vps-ip>
   ```

   Don't continue until this works, or you could lock yourself out of the
   VPS.

### 4b. Set up the VPS side

On the VPS:

```
corerelay setup
```

- Accept the role it suggests: **server** (it sees MiniServer).
- Accept the ports it offers: TCP 22, 80 and 443.
- It prints the VPS's **address** and **public key**. Keep them for the
  next step.

### 4c. Set up your computer's side

1. On your computer:

   ```
   sibling add https://gitea.federated.computer/Federated_Computer/corerelay.git
   corerelay setup
   ```

2. Answer the questions:
   - The role: accept **client**, which it suggests.
   - The VPS's address and public key, from 4b.
   - The Core's IP address: `10.123.0.10`.

3. It prints your computer's **public key**. Keep it for the next step.

### 4d. Give the VPS your computer's key

Back on the VPS, run `corerelay setup` again and enter your computer's
public key from 4c. Each side starts the relay once it has the other's key.

**Check:** on your computer, run:

```
corerelay status
```

The tunnel should show a **latest handshake** a few seconds ago. Then, from
a computer elsewhere on the internet (a phone hotspot will do), run:

```
ssh -o BatchMode=yes root@<vps-ip> true
```

`Permission denied (publickey)` is the right answer here: it means you
reached the VM, which accepts only Federated's key. A timeout means the
relay isn't working; see "If something goes wrong" below.

## Part 5: Provision the Core

1. Run `core-create`, filling in your account ID, **the VPS's public IP**
   (not `10.123.0.10`) and your Core's name:

   ```
   curl -k -N -X POST https://178.156.242.210:4445/core-create \
     -H "Content-Type: application/json" \
     -d '{
     "account_id": "<your account ID>",
     "ip": "<the VPS public IP>",
     "subdomain": "<your Core name, e.g. dev>",
     "apps": "nextcloud",
     "backups": "no",
     "monitoring": "no"
   }'
   ```

   One app is enough for a development Core. The full list of fields is in
   [Provisioning a Core](https://documentation.federated.computer/hosting/cores/provisioning-a-core/).

2. It prints progress lines as it goes, each with
   `"status":"provisioning"`. Leave it running until the last line says:

   ```
   data: {"message":"Success.","status":"done"}
   ```

3. The Core appears as **Active** under **Cores** in the dashboard, with its
   domain (for example `dev.fedcom.net`).

**Check:** on your computer, run:

```
coreapp core
```

It shows your Core's domain and what it offers apps: its PostgreSQL and
MariaDB versions, sign-in and mail, and the names apps can't use. If the
domain is empty and the versions show `?`, provisioning hasn't finished.

## Part 6: Deploy your first app

1. Make an app with a database and Core sign-in:

   ```
   coreapp new hello --postgres --sso
   cd hello
   ```

2. Build it and install it on your Core:

   ```
   coreapp deploy
   ```

   It ends with `Installed: https://hello.<your Core's domain>/`.

3. Check it from the internet:

   ```
   coreapp check
   ```

   It shows HTTP 200 and a valid certificate. A new certificate can take a
   minute; `coreapp check` keeps trying for two.

4. Check sign-in with the Core's test account:

   ```
   coreapp signin
   ```

   It ends with `Signed in`.

5. Open `https://hello.<your Core's domain>/` in a browser, choose **Sign in
   with Core SSO**, and sign in as your Core's admin, `admin@<your Core's
   domain>`.

Your development setup is done. Next:
- [Building a Coreapp](https://documentation.federated.computer/developer-tools/core-app-development-kit/building-a-coreapp/):
  making your own app, or porting an existing one.
- [Publishing a Coreapp](https://documentation.federated.computer/developer-tools/core-app-development-kit/publishing-a-coreapp/):
  releasing it so any Core can install it.

> **Using Claude Code**
>
> coreapp-dev installed a Claude Code skill, `coreapp`. In an app's
> repository, ask Claude Code to "make this a Coreapp". It builds the app,
> deploys it to your Core and tests it, then reports what works and what's
> left for you.

## Day to day

- **After a restart of your computer:** start the VM with `coreapp-vm start`.
  corerelay starts by itself.
- **Stopping the VM:** `coreapp-vm stop`.
- **Updates:** CoreDesktop's `update` keeps coreapp-dev and corerelay
  current.

## If something goes wrong

| What you see | What to do |
|---|---|
| `coreapp-vm` says permission denied, or can't connect to libvirt | You haven't logged out and back in since installing (Part 1). |
| `coreapp-vm create` says `authorized_keys is missing` | Run `coreapp-vm delete`, add the key (Part 2), and create the VM again. |
| You can't log in to the VPS any more | Use port 2222: `ssh -p 2222 <you>@<vps-ip>`. Port 22 now goes to your Core. |
| `corerelay status` shows no handshake | Check that UDP 51820 is allowed in your cloud provider's firewall. Then run `corerelay setup` on both sides again, and check that each side has the other's current key. `corerelay logs` shows what the relay is doing. |
| `ssh root@<vps-ip>` times out from elsewhere | The relay isn't forwarding. Check `corerelay status` on both sides, and that the VM is running (`coreapp-vm list`). |
| `core-create` fails to connect to the Core | Federated can't reach the VM. Run the Part 4 check again, and use the VPS's IP as `ip`. |
| `coreapp deploy` says the Core isn't provisioned yet | Wait for `core-create` to print `"status":"done"`. |
| `coreapp check` fails right after the first deploy | Wait a minute for the certificate and run it again. |
