This is the multi-page printable view of this section. Click here to print.

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

TopicDescription
OverviewWhat is Piglet Run and why use it
ArchitectureSystem architecture and components
StorageJuiceFS and shared storage
SnapshotTime machine and PITR
CloneCopy-on-Write database cloning
MonitorObservability stack
SecurityAccess 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

FeatureDescription
🤖 AI CodingPre-installed Claude Code, OpenCode, VS Code, Jupyter
🐘 Data PowerhousePostgreSQL 18 + 400+ extensions
💾 Shared StorageJuiceFS stores workspace in database
⏱️ Time MachineDatabase PITR + filesystem snapshots
🔀 Instant CloneCopy-on-Write database forking
🌐 One-Click DeployBuilt-in Nginx with auto SSL
📊 Full ObservabilityVictoriaMetrics + Grafana
🇨🇳 China FriendlyGlobal 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

ComponentRolePort
NginxReverse proxy, SSL termination80, 443
VS Code ServerWeb-based IDE/code
JupyterLabData science notebook/jupyter
PostgreSQLPrimary database5432
JuiceFSDistributed filesystem-
VictoriaMetricsMetrics storage8428
GrafanaMonitoring 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

FeatureDescription
TransparentUse like local filesystem
DurableData stored in database
ConcurrentMultiple users/agents access
SnapshotsPoint-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

ScenarioSolution
AI broke codeRestore filesystem snapshot
Bad database migrationUse pig pb restore -t <time>
Experiment failedRoll back entire environment
Need clean stateRestore 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 CaseBenefit
DevelopmentClone prod for testing
AI ExperimentsBranch for each experiment
Feature BranchesDatabase per branch
TrainingEach 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

ComponentRole
VictoriaMetricsTime-series database
GrafanaVisualization dashboards
node_exporterSystem metrics
pg_exporterPostgreSQL 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

LayerMechanism
NetworkFirewall, VPN support
WebNginx authentication
DatabasePostgreSQL roles
FilesystemUnix permissions

Authentication

Default authentication methods:

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

Encryption

TypeSupport
In TransitSSL/TLS
At RestDatabase encryption
BackupEncrypted backups

Best Practices

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

Next Steps