# SyncTide — Local Server Installation

This package is for the **local-machine server** deployment model.

In this model, one Windows machine inside the client site runs:
- PostgreSQL 17 + TimescaleDB
- FastAPI backend (also serves the React web UI at `/ui`)
- report generation
- scheduled jobs
- CSV ingestion
- protocol pollers (Modbus TCP, OPC UA, IEC 60870-5-104, MQTT — one
  Windows service per protocol)

Users do **not** install the app on their own PCs. They access the UI from a browser over the local network.

## Installation

The platform ships as a single Windows installer,
`SyncTideSetup-1.4.0.exe` (Inno Setup). It bundles everything needed —
PostgreSQL 17 + TimescaleDB, the embedded Python runtime, and the
compiled application — so there is no separate project folder to lay out
by hand and no Streamlit UI to start.

1. Copy `SyncTideSetup-1.4.0.exe` to the local server machine.
2. Run the installer. It detects an existing install and performs an
   in-place auto-upgrade, or runs the first-install wizard on a clean
   machine.
3. During setup you create the initial **admin** account and set the
   database password.

The installer will:
- install the bundled PostgreSQL 17 + TimescaleDB and create the
  `synctide` database
- install the embedded Python runtime and the compiled application
- register the Windows services (see below)
- create the runtime folders, `.env`, and default report templates
- start the services automatically

Database schema migrations run **automatically** when the backend starts —
there is no manual `schema.sql` bootstrap step for a normal install.

## Accessing the UI

There is **no separate UI process to start**. The FastAPI backend serves
the React single-page UI directly. Once the services are running, open a
browser on the server (or any PC on the LAN — see below):

```text
http://localhost/          (via the bundled Caddy reverse proxy on port 80)
http://localhost:8000/ui   (directly from the backend)
```

Log in with the admin account created during setup.

## Windows services

The installer registers eleven NSSM-managed Windows services that
auto-start on boot and restart on crash:

- `SyncTideBackend` — FastAPI backend, also serves the React UI at `/ui`
- `SyncTideAlarms` — alarm evaluation engine
- `SyncTideIngestion` — CSV ingestion worker
- `SyncTideModbus` — Modbus TCP poller
- `SyncTideOPCUA` — OPC UA poller
- `SyncTideIEC104` — IEC 60870-5-104 poller
- `SyncTideMQTT` — MQTT / Sparkplug B subscriber
- `SyncTideProxy` — Caddy reverse proxy (port 80)
- `SyncTideTelegramInbound` — inbound Telegram message handler
- `SyncTideHealthMonitor` — service health monitor
- `SyncTideBackup` — automated database/runtime backups

Polling Modbus TCP, OPC UA, IEC 104 or MQTT devices requires a licence
that includes the `protocol_ingestion` module — CSV-only customers are
unaffected.

## Access from other PCs

From another PC on the same LAN, open the UI in the browser using the local server IP, for example:

```text
http://192.168.1.50
```

The Caddy reverse proxy (port 80) serves the React web UI and forwards `/` to `/ui/`; no port number is needed.

## Database notes

- Schema migrations run automatically when `SyncTideBackend` starts; the
  numbered `NNN_*.sql` migrations are bundled in the installer and the
  runner is idempotent (already-applied migrations are skipped).
- The default report templates are installed and registered automatically.
- There is no manual bootstrap step for a normal install.

## Security recommendations for the local server

- Use a dedicated Windows user for running the platform.
- Limit RDP/admin access to trusted administrators only.
- Keep PostgreSQL accessible only locally if possible.
- Back up the database and report templates regularly.
- Back up `reports_output/` and `logs/` according to retention needs.
