# Running a local platform

> Runs a full platform on your own machine — its own database, no account, no cloud, reachable only from your computer. It is the local runtime for the whole build-and-test loop: start it once, then build, test, and debug your app against it offline.

<!-- id: local-running-a-local-platform · area: local · stability: stable · html: https://osysharp.com/reference/local/running-a-local-platform/ -->

## Summary        {#summary}

Runs a complete platform on your own machine, with a database it starts and manages itself. Nothing outside your
computer can reach it, it needs no account and no cloud project, and the only difference from a hosted platform is which
address you point at. It is what [Running tests locally](https://osysharp.com/reference/testing/running-tests-locally/) and [Debugging tests locally](https://osysharp.com/reference/testing/debugging-tests-locally/) run against.

## Signature      {#signature}

```console
osyrin dev [--devname <name>] [--port <n>] [--keepalive <minutes>] [--reset]
```

## Description    {#description}

### Starting it   {#starting}

Run it from your project directory and leave it running in a terminal:

```console
osyrin dev
```

The first start downloads a small database bundle once; after that it is up in a few seconds. It binds to your machine
only, so nothing on the network can reach it. Your local data persists between runs — stop and restart and it is still
there. `--reset` throws that data away and rebuilds from your source.

A first start that is **interrupted** — stopped, or ended by another command, while it is still preparing its database —
costs nothing but the retry: the next start recognises its own unfinished work, discards it and prepares the database
again. It never refuses to start over something it left behind itself.

### One server per project, on a stable address   {#address}

Each project gets its own local platform, and it always answers on the same address — the port is derived from the
project, so a bookmark keeps working across restarts and two projects (or two checkouts of the same repo) never fight
over a port. `--port` overrides that when you need a specific one. Because the address is derived, the other commands
find the running server on their own; you never have to tell them where it is.

Starting `osyrin dev` again for the same project **reclaims** the one already running rather than leaving it stranded:
there is only ever one server per project, and a restart takes the place of the old one instead of piling up beside it.

`--devname <name>` gives the server an explicit identity instead of deriving it from the project directory — its data,
its address and its one-per-identity reclaim all follow the name. Use it to run a second, separately-named platform
from the same directory, or one shared platform from several. Every other command takes the same `--devname`, so point
`compile`, `test`, `launch` or `logs` at a named server with the flag, or set `OSY_DEVNAME` once for the whole shell.

A name is the **only** way to say which platform you mean: a command never takes a data directory, so the path is always
derived from the identity. That is deliberate — when two commands name the same identity they cannot reach different
platforms, so a compile can never quietly land somewhere other than the app you are looking at.

### It stops itself when you walk away   {#idle-exit}

By default a server that has gone **60 minutes with no requests exits on its own**, so an abandoned one does not keep a
whole platform and its database running until you notice. When it does, it says so plainly in its output — that it
exited because it was idle, and how to change the window — so a server that is gone when you come back is never a
mystery. `--keepalive <minutes>` sets the window; `--keepalive 0` turns the behaviour off and the server runs until you
stop it. An **attached debugger keeps it alive**: a paused breakpoint sends no requests, but the server will not be
reaped out from under you.

### Or let the loop start it for you   {#autostart}

You do not have to start it by hand. When you run [Compiling your app](https://osysharp.com/reference/local/compiling-your-app/), [Running tests locally](https://osysharp.com/reference/testing/running-tests-locally/), or
[Launching your app](https://osysharp.com/reference/local/launching-your-app/) and no local platform is running for the project, they start one for you in the background,
wait for it to be ready, and leave it running so the next command is fast. The whole loop is one command — you never
have to remember to start (or restart) a server. When you're done, [Stopping the local platform](https://osysharp.com/reference/local/stopping-the-local-platform/) shuts it down;
its database stops with it, so nothing is left running.

A server keeps the build it started with, so after you rebuild the platform these commands **replace** an older server
rather than talk to it. Several commands arriving at once — `compile` and `test` fired together, say — produce **one**
restart: the first to arrive does it, and the others wait for the new server and say so, however long a first start
takes on a busy machine. The same holds for a server that is still starting when a command arrives, whoever started
it: the command waits for it instead of starting a second one beside it.

### You are the administrator — no login   {#no-login}

On a machine-only platform the person at the keyboard is the administrator, so the operator commands need no
credentials: `login`, `whoami` and `connect` simply report that and continue. This applies **only** to the platform's
own operator commands. Your application's security is unchanged and behaves exactly as it does in production — a test
runs as an anonymous, secured caller, your app's own login works, and your access rules are enforced. Local is faster
and private; it is never a relaxed rulebook.

### An organization is already there   {#organization}

A local platform comes with a single ready-made organization, so there is no organization-and-user dance before you can
create an app. `org list` shows that one organization and `org create` reports it (there is nothing to create locally).
Apps you create belong to it, and are reachable by their plain name — an app named in your project is served at
`http://<app>.localhost:<port>/`.

### What works, and what says so when it can't   {#coverage}

Everything the local loop needs works: validate and build, run and debug tests, create and compile an app, launch it,
manage its users, read its logs, and set its secrets. A handful of commands describe operations a machine-only platform
cannot perform — taking cloud backups, publishing or deploying a release, and the like. Those **fail loudly with a
clear reason and a non-zero exit**; they never report success for something that did not happen. If a command can't do
the thing here, it tells you plainly.

### It is for development, not hosting   {#not-hosting}

A local platform is a fast, private place to build — not a place to run something for real. It has no backups, no
sharing, and no durability, and it is deliberately unsuitable for hosting. Durability lives on a hosted platform; keep
anything that matters there.

## Examples       {#examples}

The everyday loop — one platform, many runs, all offline:

```console
# terminal 1
osyrin dev

# terminal 2
osy test
osy test --filter Totals
```

Reset the local data and start fresh:

```console
osyrin dev --reset
```

Keep a server running with no idle timeout, on a port you choose:

```console
osyrin dev --keepalive 0 --port 8099
```

Run a second, separately-named platform from the same project, and point the other commands at it:

```console
# terminal 1
osyrin dev --devname scratch

# terminal 2
OSY_DEVNAME=scratch osy compile
```

## See also       {#see-also}

[Running tests locally](https://osysharp.com/reference/testing/running-tests-locally/) — run your app's tests against this local platform.

[Debugging tests locally](https://osysharp.com/reference/testing/debugging-tests-locally/) — debug a single test against it, with breakpoints in your editor.

[Launching your app](https://osysharp.com/reference/local/launching-your-app/) — open your app in a browser on this local platform.

[Compiling your app](https://osysharp.com/reference/local/compiling-your-app/) — compile your source into your app on this local platform.

[Stopping the local platform](https://osysharp.com/reference/local/stopping-the-local-platform/) — stop the local platform serving your project.
