> ## Documentation Index
> Fetch the complete documentation index at: https://aeros-c1d071c8.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Local development

> Run the backend and frontend locally, build the single-process bundle, and run the tests.

## Prerequisites

* Node.js 20+ (22 LTS recommended) and npm.
* A Linux host with `systemd` to exercise `systemctl`, `journalctl`, and `/sys/class/` features. Windows and macOS work for the frontend and the backend unit tests. On those hosts, unit writes are skipped and return a warning.

## Run in development mode

**1. Start the backend**

```bash theme={null}
cd backend
npm install
npm run dev
```

`npm run dev` runs `tsx watch src/index.ts`. The server listens on `PORT` (default `3000`) and `HOST` (default `0.0.0.0`). The SQLite file is `backend/aeros.db` unless `AEROS_DB_PATH` is set.

**2. Start the frontend**

```bash theme={null}
cd frontend
npm install
npm run dev
```

Vite proxies `/api` and `/ws` to the backend dev server.

**3. Create the admin account**

Open the Vite URL. With an empty database, the panel shows the **Initial Admin Setup** screen. You can also seed a user from the environment before the first start:

```bash theme={null}
AEROS_ADMIN_USER=admin AEROS_ADMIN_PASSWORD=change-me-please npm run dev
```

`AEROS_ADMIN_PASSWORD` only creates a user when the `users` table is empty.

### Backend environment variables

| Variable | Default | Purpose |
| :- | :- | :- |
| `PORT` | `3000` | HTTP and WebSocket port. |
| `HOST` | `0.0.0.0` | Bind address. |
| `AEROS_DB_PATH` | `backend/aeros.db` | SQLite file path. |
| `AEROS_ADMIN_USER` | `admin` | Username used with `AEROS_ADMIN_PASSWORD`. |
| `AEROS_ADMIN_PASSWORD` | unset | Seeds the first admin when no user exists. |
| `CORS_ORIGIN` | unset | Comma-separated origins allowed for CORS, cross-origin mutations, and WebSocket connections. |

## Single-process production build

```bash theme={null}
cd frontend && npm ci && npm run build
cd ../backend && npm ci && npm run build && npm start
```

The backend serves `frontend/dist` itself. HTML is sent with `Cache-Control: no-cache` and hashed files under `assets/` with a one-year immutable cache. Any non-API `GET` falls back to `index.html`. If `frontend/dist` is missing, those requests return `503` with a hint to build the frontend.

Open `http://localhost:3000`.

## Tests and checks

Run these before opening a pull request. All must exit with code `0`.

```bash theme={null}
cd backend && npm run build && npm test
cd frontend && npm run lint && npm run build
```

Backend tests use Node's built-in test runner (`node --import tsx --test tests/*.test.ts`) and cover alerts, backups, Caddy, crypto, deploy, Git validation, `systemd`, templates, and webhook signatures. Some alert tests only run on Linux. The frontend is linted with `oxlint`.

## Load tests (k6)

The `tests/k6/` suite measures throughput, latency, and memory against a throwaway instance. Each script gets a fresh server and database, so the in-memory login rate limiter starts empty.

```bash theme={null}
cd backend && npm run build && cd ..
tests/k6/run.sh read.js mutations.js ws.js ratelimit.js auth.js
```

| Script | What it exercises |
| :- | :- |
| `read.js` | `GET /api/system/metrics`, `/api/system/info`, and `/api/projects`, ramping 10 to 100 VUs. |
| `mutations.js` | Mutations that cannot change the host: rejected unauthenticated and cross-origin requests, template previews, and requests against a project that does not exist. |
| `ws.js` | Concurrent `journalctl -f` log streams, plus unauthenticated sockets that must be closed with `4401`. |
| `ratelimit.js` | A concurrent burst of bad passwords against the 10 attempts per 15 minutes login limit. |
| `auth.js` | `GET /api/auth/status` under load, with login and logout cycles at a fixed rate on top. |

> [!NOTE]
>
> `ratelimit.js` leaves `127.0.0.1` locked out of login for 15 minutes on that server. `run.sh` starts a fresh server for each script, so this does not affect the next one.

`run.sh` needs `k6` on `PATH` (or `K6=/path/to/k6`) and `curl`. It starts the backend on `127.0.0.1:${PORT:-3099}` with `--expose-gc` and a memory probe, then prints the first and last memory samples for each script. `ADMIN_PASSWORD` overrides the seeded test password.

> [!TIP]
>
> Run k6 on the same class of hardware you target. Results from a fast desktop say little about an N3060.

## Contribution rules

Read [`CONTRIBUTING.md`](https://github.com/DevModee/Aeros-Panel/blob/main/CONTRIBUTING.md) before you open a pull request. In short:

* No Docker, containerd, or PM2 dependencies.
* No background polling loops. Idle memory should stay around 20 to 30 MB.
* Do not weaken the guards described in [Security](https://aeros-c1d071c8.mintlify.site/security.md).
* Do not commit `*.db`, `.env`, or `dist/`.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.