Skip to content

This is the multi-page printable view of this section. .

Return to the regular view of this page.

Concept

Understand the core concepts, architecture, and design philosophy behind Piglet Run.

Concept documentation helps you understand the principles and architecture behind Piglet Run.

What You’ll Learn

  • How Piglet Run works under the hood
  • The design philosophy and architecture
  • Key concepts like snapshots, cloning, and storage

Topics

Topic Description
Overview What is Piglet Run and why use it
Architecture System architecture and components
Storage JuiceFS and shared storage
Snapshot Time machine and PITR
Clone Copy-on-Write database cloning
Monitor Observability stack
Security Access control and encryption

1 - Overview

What is Piglet Run?

Piglet Run is a lightweight runtime environment from Pigsty, designed as a cloud coding sandbox for AI Web Coding. It integrates PostgreSQL database, JuiceFS distributed storage, VS Code, JupyterLab, and more into a unified environment.

Why Piglet Run?

In the age of AI-assisted development, developers need:

  • Instant development environments that just work
  • Powerful databases with all extensions available
  • Safe experimentation with easy rollback
  • Seamless collaboration between humans and AI agents

Piglet Run provides all of this in a single package.

Key Features

Feature Description
🤖 AI Coding Pre-installed Claude Code, OpenCode, VS Code, Jupyter
🐘 Data Powerhouse PostgreSQL 18 + 400+ extensions
💾 Shared Storage JuiceFS stores workspace in database
⏱️ Time Machine Database PITR + filesystem snapshots
🔀 Instant Clone Copy-on-Write database forking
🌐 One-Click Deploy Built-in Nginx with auto SSL
📊 Full Observability VictoriaMetrics + Grafana
🇨🇳 China Friendly Global CDN + China mirrors

Who is it for?

  • Solo developers who want a powerful dev environment
  • Teams that need shared development infrastructure
  • AI developers using Claude Code or similar tools
  • Data scientists working with PostgreSQL and Jupyter
  • Learners exploring PostgreSQL and web development

How it works

┌─────────────────────────────────────────────────────────────┐
│                      Piglet Run                             │
├─────────────────────────────────────────────────────────────┤
│  ┌─────────┐  ┌─────────┐  ┌─────────┐  ┌─────────┐       │
│  │ VS Code │  │ Jupyter │  │ Claude  │  │  Nginx  │       │
│  │ Server  │  │   Lab   │  │  Code   │  │ Proxy   │       │
│  └────┬────┘  └────┬────┘  └────┬────┘  └────┬────┘       │
│       │            │            │            │             │
│       └────────────┴────────────┴────────────┘             │
│                         │                                   │
│  ┌──────────────────────┴──────────────────────┐           │
│  │              JuiceFS (Shared Storage)       │           │
│  └──────────────────────┬──────────────────────┘           │
│                         │                                   │
│  ┌──────────────────────┴──────────────────────┐           │
│  │         PostgreSQL 18 + 400+ Extensions     │           │
│  └─────────────────────────────────────────────┘           │
│                                                             │
│  ┌─────────────────────────────────────────────┐           │
│  │      VictoriaMetrics + Grafana (Monitoring) │           │
│  └─────────────────────────────────────────────┘           │
└─────────────────────────────────────────────────────────────┘

Next Steps

2 - Architecture

System Architecture

Piglet Run is built on top of Pigsty, providing a streamlined development environment.

Components

Component Role Port
Nginx Reverse proxy, SSL termination 80, 443
VS Code Server Web-based IDE /code
JupyterLab Data science notebook /jupyter
PostgreSQL Primary database 5432
JuiceFS Distributed filesystem -
VictoriaMetrics Metrics storage 8428
Grafana Monitoring dashboards /ui

Network Architecture

Internet
    │
    ▼
┌─────────┐
│  Nginx  │ :80, :443
└────┬────┘
     │
     ├──────────────┬──────────────┬──────────────┐
     │              │              │              │
     ▼              ▼              ▼              ▼
┌─────────┐   ┌─────────┐   ┌─────────┐   ┌─────────┐
│ VS Code │   │ Jupyter │   │ Grafana │   │   App   │
│ /code   │   │/jupyter │   │  /ui    │   │   /*    │
└─────────┘   └─────────┘   └─────────┘   └─────────┘

Storage Architecture

All development work is stored in PostgreSQL via JuiceFS:

┌─────────────────────────────────────┐
│          Working Directory          │
│         ~/workspace                 │
└──────────────┬──────────────────────┘
               │
               ▼
┌─────────────────────────────────────┐
│            JuiceFS                  │
│     (POSIX-compatible FS)           │
└──────────────┬──────────────────────┘
               │
               ▼
┌─────────────────────────────────────┐
│          PostgreSQL                 │
│     (Metadata + Data Chunks)        │
└─────────────────────────────────────┘

Next Steps

3 - Storage

JuiceFS Shared Storage

Piglet Run uses JuiceFS to provide a distributed filesystem backed by PostgreSQL.

Why JuiceFS?

  • POSIX Compatible: Works like a normal filesystem
  • Database-Backed: Data stored in PostgreSQL
  • Snapshots: Point-in-time recovery support
  • Multi-User: Share workspace across sessions

How It Works

┌────────────────────────────────────────────┐
│              Application Layer             │
│   (VS Code, Jupyter, Claude Code, etc.)    │
└──────────────────┬─────────────────────────┘
                   │ POSIX API
                   ▼
┌────────────────────────────────────────────┐
│               JuiceFS FUSE                 │
│         (Filesystem in Userspace)          │
└──────────────────┬─────────────────────────┘
                   │
        ┌──────────┴──────────┐
        │                     │
        ▼                     ▼
┌───────────────┐    ┌───────────────┐
│   Metadata    │    │  Data Chunks  │
│  (PostgreSQL) │    │  (PostgreSQL) │
└───────────────┘    └───────────────┘

Features

Feature Description
Transparent Use like local filesystem
Durable Data stored in database
Concurrent Multiple users/agents access
Snapshots Point-in-time recovery

Next Steps

4 - Snapshot

Time Machine

Piglet Run provides point-in-time recovery for both database and filesystem.

Database PITR

PostgreSQL’s built-in PITR (Point-in-Time Recovery) allows you to restore the database to any point in time. Managed by pgBackRest.

# Show backup information
pig pb info

# List all backups
pig pb ls

# Create a full backup
pig pb backup full

# Restore to latest backup
pig pb restore

# Restore to specific time
pig pb restore -t "2025-01-29 10:00:00"

Filesystem Snapshots

JuiceFS snapshots preserve the state of your workspace:

# Create a snapshot (using juicefs CLI)
juicefs snapshot create /jfs/data snapshot-before-experiment

# List snapshots
juicefs snapshot list /jfs/data

# Restore from snapshot
juicefs snapshot restore /jfs/data snapshot-before-experiment

Use Cases

Scenario Solution
AI broke code Restore filesystem snapshot
Bad database migration Use pig pb restore -t <time>
Experiment failed Roll back entire environment
Need clean state Restore to baseline snapshot

Backup Management

# View backup status
pig pb info

# View backup logs
pig pb log tail

# Create incremental backup
pig pb backup incr

# Create differential backup
pig pb backup diff

Next Steps

5 - Clone

Instant Cloning

Piglet Run supports Copy-on-Write (CoW) cloning for rapid database forking.

How It Works

Copy-on-Write means:

  • Zero copy at clone time
  • Only changed blocks consume storage
  • TB-scale databases clone in milliseconds
Original Database
┌─────────────────────┐
│ Block A │ Block B │ Block C │
└────┬────┴────┬────┴────┬────┘
     │         │         │
     ▼         ▼         ▼
┌────────────────────────────┐
│      Shared Storage        │
└────────────────────────────┘
     ▲         ▲         ▲
     │         │         │
┌────┴────┬────┴────┬────┴────┐
│ Block A │ Block B │ Block C │ (shared)
│         │ Block B'│         │ (changed in clone)
└─────────┴─────────┴─────────┘
Cloned Database

Use Cases

Use Case Benefit
Development Clone prod for testing
AI Experiments Branch for each experiment
Feature Branches Database per branch
Training Each learner gets own copy

Database Cloning

Using PostgreSQL utilities:

# Create database from template
pig pg psql -c "CREATE DATABASE dev TEMPLATE prod"

# Or using pg_dump/pg_restore for cross-server clone
pg_dump -Fc prod > prod.dump
pg_restore -d dev prod.dump

Using pgBackRest for Cloning

# Restore to a new cluster as a clone
pig pb restore --target-pgdata=/data/pg-clone

# Or restore to specific time point
pig pb restore -t "2025-01-29 10:00:00" --target-pgdata=/data/pg-clone

Filesystem Cloning with JuiceFS

# Clone directory using JuiceFS snapshot
juicefs snapshot create /jfs/workspace ws-snapshot
juicefs snapshot restore /jfs/workspace-clone ws-snapshot

Next Steps

6 - Monitoring

Full Observability

Piglet Run includes a complete monitoring stack based on VictoriaMetrics and Grafana.

Components

Component Role
VictoriaMetrics Time-series database
Grafana Visualization dashboards
node_exporter System metrics
pg_exporter PostgreSQL metrics

Dashboards

Access Grafana at http://<ip>/ui

Available dashboards:

  • Claude Code: AI agent monitoring
  • PostgreSQL: Database performance
  • System: Host metrics
  • JuiceFS: Filesystem statistics

Metrics

Over 3000+ metrics collected:

  • Database queries, connections, locks
  • System CPU, memory, disk, network
  • Application-specific metrics

Alerts

Configure alerts for:

  • High CPU/memory usage
  • Database connection limits
  • Disk space warnings
  • Query performance issues

Next Steps

7 - Security

Security Model

Piglet Run provides multiple layers of security for your development environment.

Access Control

Layer Mechanism
Network Firewall, VPN support
Web Nginx authentication
Database PostgreSQL roles
Filesystem Unix permissions

Authentication

Default authentication methods:

  • VS Code: Password or token
  • Jupyter: Token-based
  • Grafana: Username/password
  • PostgreSQL: Role-based access

Encryption

Type Support
In Transit SSL/TLS
At Rest Database encryption
Backup Encrypted backups

Best Practices

  1. Change default passwords immediately
  2. Enable SSL for all services
  3. Restrict network access
  4. Regular security updates

Next Steps