# Deploying to SmallRun

This project runs on SmallRun, a runtime for small server apps.
Docs for agents: https://www.smallrun.app/llms.txt

## Rules

- For a new app, do not build login, signup, sessions or password storage.
  SmallRun signs the visitor in before a request reaches the app.
- Read the signed-in person from the request headers and trust them as they are:
  `X-SmallRun-User-Email`, `X-SmallRun-User-Name`, `X-SmallRun-User-Id`.
- Identify a person by `X-SmallRun-User-Id`, not by email. The email can change.
- Roles inside the app, such as "HR manager", are the app's own data. Store
  them by user id. SmallRun has no roles and sends none.
- On a private app (the default) the headers are present on every request.
  SmallRun has already decided that this person may use the app: a coworker
  on the owner's company domain, or a person the owner invited. Do not build
  an allow-list.
- On a public app the headers are present only for a signed-in visitor. Treat
  a request without `X-SmallRun-User-Id` as anonymous. To sign a visitor in,
  link to `/.smallrun/login?next=<path>`.
- A public app has no company-only pages. If the user wants internal pages,
  deploy them as a separate private app. Never decide access by the domain
  of an email address.
- Keep data in SQLite or in files, anywhere the app likes: every file the app
  writes is kept across restarts and deploys. Or declare `database: postgres`
  or `database: mysql` in the manifest and read `DATABASE_URL`.
- Listen on one HTTP port. Read `PORT` if the framework supports it; SmallRun
  also finds the port by itself. Plain HTTP: TLS ends at the edge.
- The real client IP is in `X-Forwarded-For` and `X-Real-IP`.
- If the project already has its own login, keep it. Tell the user to make the
  app public (`smallrun visibility public`) so visitors do not sign in twice.
- There is no shell access: no SSH, no exec, no database shell. Debug from
  the logs. Run schema changes from the app at startup.
- A `.env` file is deployed with the source unless it is listed in
  `.smallrunignore`. For values that must not be in the source, use
  `smallrun secrets` and refer to them in the manifest as `${secrets.NAME}`.
- If the app expects database variables other than `DATABASE_URL`, map them
  in the manifest's `env:`, for example `DB_PASSWORD: ${database.password}`.
- Background workers run in the same microVM. If they are not detected,
  declare them in the manifest under `workers:`.
- Scheduled tasks (cron) are not run. If the deploy output warns
  `schedule_not_supported`, tell the user which task will not run.
- Do not write a Dockerfile; it is ignored. The build is detected from the source. If
  detection fails, set `build:` and `start:` in the manifest.

## Deploy

```sh
smallrun deploy --json
```

- Authentication is the `SMALLRUN_TOKEN` environment variable. Do not run
  `smallrun login`; it is interactive.
- The command blocks until the deployment is `RUNNING` or `FAILED`.
- On `RUNNING`, report the URL to the user.
- On `FAILED`, read the error code and the suggested next action in the
  output, fix the cause, and deploy again.
- The app is owned by the account the token belongs to. Only that account
  can manage it.
- To let in a person from outside the company, or to approve an access
  request: `smallrun share <email>`. Pending requests: `smallrun access --json`.
  Invite a person only when the user asks for it. The command sends the
  person an invite email; `smallrun access --json` shows whether it arrived
  and whether the person has opened the app.
- Do not run `smallrun visibility public` unless the user asks for the app to
  be open to everyone.
- A rollback does not revert data.
