How lus/pasty works
Project type and purpose
• Pasty is a full-stack web application: a lightweight pastebin service.
• Its purpose is to provide a REST API (v1/v2) and a static web frontend for creating, retrieving, modifying, and automatically deleting code/text pastes, with pluggable storage backends and optional reporting webhooks.
File structure
• Top-level “cmd/” contains two CLI entrypoints:
• cmd/pasty: the main web server binary
• cmd/transfer: a data migrator/transfer tool
• “internal/web” holds HTTP routing, controllers, and logger.
• “internal/storage” contains the storage driver interface and implementations (file, Postgres, MongoDB, S3). Migrations live under “postgres”.
• “internal/report” implements the report-webhook logic.
• “internal/config” and “internal/env” handle environment variables and configuration.
• “internal/utils” and “internal/shared” include shared helpers (ID generation, paste data model).
• The “web” directory contains the static SPA: HTML, CSS/SCSS, and JS modules.
• Dev containers: Dockerfile and docker-compose.dev.yml define Docker-based deployment and environment.
Extract insights from the README
• The service exposes HTTP endpoints for paste creation, retrieval, modification, deletion, and hastebin compatibility.
• It supports optional auto-delete (scheduled cleanup), rate-limiting, and report-webhook notifications.
• Multiple storage backends can be selected via PASTY_STORAGE_TYPE.
• Configuration is entirely via environment variables with sensible defaults.
Main components
a. Client tier
• Browser or CLI clients
• Static Web App served from /web/assets (HTML/CSS/JS SPA)
• Third-party clients/tools calling the REST API (/v1, /v2)
b. API Server tier
• HTTP server (net/http) in cmd/pasty
• Router & middleware (rate-limiting, logging)
• Controllers: v1 (incl. hastebin support) and v2
• AutoDelete scheduler (background goroutine)
• Report dispatcher (calls external webhook)
• Configuration loader (env/config modules)
c. Storage tier (pluggable)
• File system driver (local)
• Postgres driver + SQL migrations
• MongoDB driver
• S3 driver
• ID/generation and modification token logic
d. External services
• PostgreSQL database
• MongoDB cluster
• S3-compatible object store
• Optional report webhook endpoint
e. Utility binaries
• pasty CLI (same code as API server)
• transfer CLI (data migration tool)
Relationships and interactions
• Clients → HTTP(S) → API Server
• SPA static files served by the server
• AJAX calls from SPA to /api/v1/pastes, /api/v2/pastes, /documents endpoints
• API Server ↔ Storage driver
• Read/write paste data and metadata
• Use ID generation and modification tokens
• AutoDelete scheduler → Storage driver
• Periodic cleanup of expired pastes
• Report controller → External webhook
• POST JSON with Authorization token on each report
• Transfer CLI → Source Storage → Target Storage
• Reads data via shared paste interface, writes to new backend
• Docker Compose dev setup ties together the API server container, database containers, and exposes ports.
Architectural patterns and design principles
• Modular, pluggable storage drivers (interface + implementations)
• Layered architecture: config/env → API logic → storage → external services
• Separation of concerns: web controllers, reporting, auto-cleanup, migration CLI
• Twelve-factor style: all config via environment variables
• Single binary for CLI and server via Go’s cmd/ pattern