# User Manual & Technical Reference: yfork-lite

Welcome to the official documentation for **yfork-lite**, the ultra-lightweight perimeter gateway and reverse proxy with native ephemeral Cloudflare tunnels designed by **Calanor Labs** for agile development environments and rapid testing.

---

## 1. What is yfork-lite?

`yfork-lite` is an optimized reverse proxy distribution that packages:
- **High-Performance Nginx**: Local TLS routing with SSL termination on port 443 and automatic HTTP-to-HTTPS redirect from port 80.
- **Unified Single-Screen Dashboard**: Modern tabless web UI displaying gateway health, registered applications, and public tunnels side-by-side.
- **Ephemeral TryCloudflare Tunnels**: Instant public Internet exposure for your entire local app ecosystem in 1 click or command — no account creation, no DNS configuration.
- **Ultra-Lightweight Footprint**: Memory usage under ~25 MB RAM and cold starts in 2 seconds.

---

## 2. Prerequisites

- **Docker Engine**: Version 20.10 or higher (compatible with macOS Intel/Apple Silicon, Linux, and Windows WSL2).
- **Docker Compose**: Version 2.0 or higher (optional, for Compose deployments).
- Available ports `80` and `443` on your host machine.
- Local domain resolution for `yfork.local` pointing to `127.0.0.1` in `/etc/hosts`:
  ```bash
  127.0.0.1 yfork.local
  ```

---

## 3. Deployment and Installation Methods

### Method 1: Single-Line Docker CLI Deployment (Recommended)

Run the following command in your terminal to pull the official image from **GitLab Container Registry** and launch the container:

```bash
docker run -d \
  --name yfork-lite \
  --restart unless-stopped \
  -p 80:80 \
  -p 443:443 \
  -v yfork_registry:/app/registry \
  -v yfork_certs:/etc/nginx/certs \
  --add-host=host.docker.internal:host-gateway \
  registry.gitlab.com/calanor-labs/core/apps/yfork-lite/core:1.0.0
```

### Method 2: Docker Compose Deployment

Download the preconfigured `docker-compose.yml` file or create one with the following content:

```yaml
services:
  yfork-lite:
    image: registry.gitlab.com/calanor-labs/core/apps/yfork-lite/core:1.0.0
    container_name: yfork-lite
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - yfork_registry:/app/registry
      - yfork_certs:/etc/nginx/certs
    extra_hosts:
      - "host.docker.internal:host-gateway"

volumes:
  yfork_registry:
  yfork_certs:
```

Launch the service in background mode:

```bash
docker compose up -d
```

Verify that the container is active:

```bash
docker ps -f "name=yfork-lite"
```

---

## 4. Accessing and Using the Web Dashboard

Once the container has started, open your browser and navigate to:

👉 **[https://yfork.local/](https://yfork.local/)** (or `http://localhost`)

### Unified Dashboard Features:
1. **Status Indicators (Header)**: Real-time verification of SSL certificates, total registered applications, and online/offline health.
2. **TryCloudflare Tunnel Card**: Interactive `⚡ Generate Link` button to spin up an ephemeral public Cloudflare tunnel, and `🛑 Stop` to tear it down.
3. **Microservices Grid**: Interactive cards displaying millisecond latencies, direct links to each subroute, and quick removal.
4. **Visual App Registration**: Click `+ Register App` to add any local application specifying its ID slug, target port, and description.

---

## 5. Console Control: Terminal CLI

`yfork-lite` includes a command-line interface (CLI) to manage the gateway either from inside the Docker container or directly from your host machine via the portable `./yfork-lite` script.

### Running CLI Inside Docker Container:

```bash
docker exec -it yfork-lite node src/cli.js <command>
```

### Running CLI on Host (via downloaded script):

```bash
chmod +x yfork-lite
./yfork-lite <command>
```

### CLI Command Catalog:

| Command | Description | Example Usage |
| :--- | :--- | :--- |
| `status` | Displays Nginx, Node, and active tunnel health | `./yfork-lite status` |
| `list` | Lists all registered applications in a clean table | `./yfork-lite list` |
| `add <id> <port>` | Registers a new local service under `/id` | `./yfork-lite add api-orders 8080 --name "Orders API"` |
| `remove <id>` | Unregisters an application and reloads Nginx | `./yfork-lite remove api-orders` |
| `tunnel status` | Shows the active public tunnel URL | `./yfork-lite tunnel status` |
| `tunnel start temp` | Starts an ephemeral TryCloudflare tunnel | `./yfork-lite tunnel start temp` |
| `tunnel stop temp` | Stops the active ephemeral tunnel | `./yfork-lite tunnel stop temp` |
| `certs generate` | Regenerates local self-signed TLS certificates | `./yfork-lite certs generate` |

---

## 6. Ephemeral TryCloudflare Tunnels

### How Do They Work?
When activating an ephemeral tunnel from the dashboard or with `./yfork-lite tunnel start temp`:
1. The official `cloudflared` binary establishes an outbound secure connection over QUIC/HTTP2 to Cloudflare's edge network.
2. Cloudflare automatically provisions a public subdomain at `https://*.trycloudflare.com` with a universally trusted, valid TLS certificate.
3. Inbound traffic to that URL is routed directly to your local port 443.
4. **No user accounts, credit cards, domain registrations, or router port-forwarding (NAT) required.**

---

## 7. Client Validation & Certificate Management (mTLS)

`yfork-lite` features an integrated cryptographic architecture for **Mutual TLS Authentication (mTLS)** to safeguard critical applications against unauthorized access.

### How Does Client Validation Work?
1. **Certificate Authorities (CAs)**: Create internal CAs directly from the `Certificates & CAs` modal. yfork-lite automatically manages the hierarchy and unified Nginx trust bundle (`all_cas.crt`).
2. **Client Credential Issuance**: Issue certificates for devices, laptops, or developers selecting the issuing CA. The system generates an X.509 certificate (`.crt`) and a PKCS#12 bundle (`.p12`) protected by an optional password.
3. **Client Installation**:
   - **macOS**: Double-click the `.p12` file to import it into your **Keychain Access**.
   - **Browsers (Chrome / Edge / Firefox)**: Import under *Personal Certificates*.
4. **Per-App Activation**: In the dashboard, click the `mTLS` toggle on any service card to switch between public access or strict client validation. When active, any client without a valid certificate issued by one of your CAs receives an HTTP 403 Forbidden socket rejection.

---

## 8. License & Official Distribution

- **License**: `Calanor Community License` (Freeware).
- **Permissions**: Free for personal and commercial use in development and laboratory environments. Proprietary source code owned by Calanor Labs.
- **Official Registry**: [GitLab Container Registry](https://gitlab.com/calanor-labs/core/apps/yfork-lite/container_registry) (`registry.gitlab.com/calanor-labs/core/apps/yfork-lite/core:1.0.0`).
- **News Channel**: Official RSS feed available at `https://yfork.local/yfork-lite/feed.xml`.
