photovault

module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 28, 2026 License: MIT

README

PhotoVault

Lightweight, Nextcloud-compatible self-hosted photo & video backup server written in Go — bit-exact raw originals, streaming SHA-256 verification, native Nextcloud iOS/Android auto-upload, and a fast web gallery.

CI Go Reference PostgreSQL Redis Nextcloud Compatible

PhotoVault implements the Nextcloud handshake, Login Flow v2, and WebDAV Chunked Upload v2 protocol in a single lightweight Go binary so you can back up unmodified, byte-for-byte original photos and videos from your iPhone or Android device directly to your own server using the free, official Nextcloud mobile app — without running the heavy PHP Nextcloud stack.

Disclaimer: PhotoVault is an independent open-source project and is not affiliated with or endorsed by Nextcloud GmbH. It implements Nextcloud-compatible client endpoints solely to interoperate with standard Nextcloud mobile clients.


Why PhotoVault?

Many self-hosted photo managers (such as Immich) transcode media, reorganize folders, or tightly couple files to an application database. PhotoVault is designed either as a standalone lightweight backup server or as a second immutable safety layer alongside Immich:

  • Bit-Exact Raw Originals — Writes the exact uploaded bytes straight to disk (YYYYMM folders). Zero transcoding, zero compression, zero EXIF modification.
  • Free Native iOS & Android Auto-Upload — Works out of the box with the official Nextcloud mobile apps (Login Flow v2, WebDAV PROPFIND/MKCOL/PUT/MOVE/DELETE/SEARCH, Chunked Upload v2 for large videos, OC-FileId support, and in-app Media tab previews).
  • 4-Layer Data Integrity:
    1. Atomic writes: Streams to temporary *.part files, verifies OC-Total-Length, fsyncs, and atomically renames into place.
    2. Streaming SHA-256 & Deduplication: Computes SHA-256 on the fly during upload with race-safe deduplication and stale-chunk cleanup.
    3. Bit-rot detection (verify): Re-hashes every file on disk and compares against PostgreSQL to catch silent corruption or missing files.
    4. Disk-first recovery (reindex): Files on disk are always the source of truth — lose PostgreSQL or Redis and rebuild the entire index from disk with one command.
  • Fast Infinite-Scroll Web Dashboard (/dashboard) — Virtualized Justified Gallery with keyset pagination, viewport lazy-loading (IntersectionObserver), lightbox viewer, EXIF-aware rotation, and a soft-delete Recycle Bin (delete & restore).
  • Fast, Low-RAM Thumbnails — Uses libvips (vipsthumbnail) (including HEIC/HEIF/WebP shrink-on-load) and FFmpeg (video cover frames) with disk caching, a low-priority (nice 19) background warmer, and a pure-Go fallback for JPEG/PNG.
  • Immich-Friendly Resource Footprint — Static Go binary (CGO_ENABLED=0) with bounded memory (GOMEMLIMIT + systemd MemoryMax), designed to safely share an existing PostgreSQL instance (separate database) and Redis instance (separate DB index + key prefix).

Architecture

┌───────────────────────────┐       LAN (HTTP / HTTPS via Caddy)       ┌──────────────────────────────────────┐
│  iPhone / Android         │ ────────────────────────────────────────▶│  PhotoVault (Single Go Binary)       │
│  Official Nextcloud App   │   1. Discovery (/status.php, OCS caps)   │                                      │
│  (Auto Upload & Media)    │   2. Login Flow v2 → App Password        │  • Nextcloud Compat & Login Flow v2  │
│                           │   3. WebDAV PUT / Chunked Upload v2      │  • WebDAV Files, Uploads & SEARCH    │
└───────────────────────────┘   4. Previews (/core/preview)            │  • Atomic Writer + Streaming SHA-256 │
                                                                       └──────────┬───────────────┬───────────┘
                                                                                  │ raw bytes     │ tokens
                                                                                  ▼               ▼
                                                                       ┌────────────────┐  ┌──────────────┐
                                                                       │  Local Disk    │  │    Redis     │
                                                                       │  (Source of    │  │ (Dedicated   │
                                                                       │   Truth)       │  │  DB + Prefix)│
                                                                       └───────┬────────┘  └──────────────┘
                                                                               │ index + SHA-256
                                                                               ▼
                                                                       ┌────────────────┐
                                                                       │  PostgreSQL    │◀── Web Dashboard
                                                                       │  (Rebuildable  │    /dashboard
                                                                       │   via reindex) │    (libvips/ffmpeg)
                                                                       └────────────────┘

For deep design rationale and protocol notes, see ARCHITECTURE.md.


Quick Start (Ubuntu / Linux)

Prerequisites
  • Go 1.22+
  • PostgreSQL (dedicated database, e.g. photovault)
  • Redis (dedicated DB index, e.g. 15, and key prefix photovault:)
  • (Optional, recommended) libvips-tools (vipsthumbnail for fast JPEG/HEIC/WebP thumbnails) and ffmpeg (for video thumbnails):
    sudo apt install -y libvips-tools ffmpeg
    
1. Clone & Configure
git clone https://github.com/hotroso/photovault.git
cd photovault
cp .env.example .env

Edit .env with your PostgreSQL DSN, Redis address, data directory, and LAN URL (see Configuration).

2. Build & Run
chmod +x deploy.sh
./deploy.sh

Run PhotoVault automatically in the background with memory limits and auto-restart on boot:

./deploy.sh install-service
journalctl -u photovault -f
Available deploy.sh Commands
Command Description
./deploy.sh Run go mod tidy, go vet, build static binaries (server, verify, reindex), and start the server
./deploy.sh build Build binaries into ./bin/ without starting the server
./deploy.sh run Start the server (builds first if needed)
./deploy.sh verify Scan disk and verify every file's SHA-256 against PostgreSQL
./deploy.sh reindex Rebuild the PostgreSQL metadata index from files on disk
./deploy.sh install-service Build and install/enable the systemd background service

Configuration

Copy .env.example to .env:

Variable Default Description
APP_LISTEN_ADDR 0.0.0.0:8081 Address/port the Go server listens on (127.0.0.1:8080 when behind Caddy)
APP_PUBLIC_URL https://192.168.1.55:8081 Public URL reachable from your phone (must match HTTP/HTTPS scheme)
APP_USER me Single-user login username
APP_DISPLAY_NAME Me Display name returned to Nextcloud clients
APP_DATA_DIR ./data Root directory where raw media and .thumbs/ cache are stored
APP_TLS_CERT / APP_TLS_KEY (empty) Optional TLS cert/key if serving HTTPS directly from Go
APP_PG_DSN (required) PostgreSQL connection string (e.g. postgres://user:pass@127.0.0.1:5432/photovault?sslmode=disable)
APP_REDIS_ADDR 127.0.0.1:6379 Redis host and port
APP_REDIS_PASSWORD (empty) Redis password (if enabled)
APP_REDIS_DB 15 Dedicated Redis DB index
APP_REDIS_PREFIX photovault: Redis key prefix
APP_NC_VERSION 28.0.0.0 Emulated Nextcloud version advertised during client handshake
APP_LOG_LEVEL debug Log level (debug, info, warn, error)

Connecting the Nextcloud iOS / Android App

  1. (Optional HTTPS on LAN) Place Caddy in front of PhotoVault using Caddyfile.example (local_certs), or run plain HTTP on a trusted LAN. If using Caddy's local CA with iOS, install and trust Caddy's root.crt on your iPhone (Settings → General → About → Certificate Trust Settings).
  2. Open the official Nextcloud app → Log in → enter your APP_PUBLIC_URL (e.g. http://192.168.1.55:8081 or https://192.168.1.55:8081).
  3. Approve access in the Login Flow v2 browser prompt.
  4. Enable Auto Upload in the Nextcloud app settings.
  5. Browse your backed-up library anytime at <APP_PUBLIC_URL>/dashboard.

Tip for iOS users: Enable Download and Keep Originals under iPhone Settings → Photos so iOS provides full-resolution originals rather than iCloud-optimized copies.


Integrity Verification & Disaster Recovery

Run periodic integrity checks (e.g. via cron) to verify that no files have suffered bit rot or accidental modification:

./deploy.sh verify

If your PostgreSQL database is ever lost or migrated, rebuild the entire metadata index directly from your raw files on disk:

./deploy.sh reindex

Project Structure

photovault/
├── cmd/
│   ├── server/          # HTTP/WebDAV/Nextcloud-compat server entrypoint
│   ├── verify/          # SHA-256 disk-vs-database integrity checker
│   └── reindex/         # Rebuild PostgreSQL index from disk files
├── internal/
│   ├── auth/            # Basic Auth & Redis-backed app password verification
│   ├── compat/          # Nextcloud /status.php, OCS capabilities/user, Login Flow v2
│   ├── config/          # .env configuration loader
│   ├── dashboard/       # Infinite-scroll Justified Gallery, lightbox, libvips/FFmpeg thumbnails, recycle bin
│   ├── httpx/           # Request logging middleware & JSON/OCS response helpers
│   ├── integrity/       # Verification & reindex helpers
│   ├── server/          # HTTP router & graceful shutdown lifecycle
│   ├── storage/         # Atomic raw-byte disk writer, SHA-256 hashing, YYYYMM organization
│   ├── store/           # PostgreSQL metadata store & Redis token store
│   └── webdav/          # WebDAV files, Chunked Upload v2, deduplication & Media SEARCH
├── Caddyfile.example    # Sample Caddy reverse proxy config (up to 5 GB uploads)
├── photovault.service   # Production systemd unit with GOMEMLIMIT & MemoryMax
├── deploy.sh            # Build, run, verify, reindex & systemd installer script
└── ARCHITECTURE.md      # Problem statement, architecture & protocol documentation

Non-Goals (Keeping It Fast & Minimal)

To stay small, fast, and reliable as a raw backup vault, PhotoVault intentionally does not include:

  • Media transcoding or destructive edits on original files
  • Public sharing links or multi-tenant collaboration
  • CalDAV / CardDAV / Talk / Notes suites

Development

# Install binaries directly via Go
go install github.com/hotroso/photovault/cmd/server@latest
go install github.com/hotroso/photovault/cmd/verify@latest
go install github.com/hotroso/photovault/cmd/reindex@latest

# Run unit tests
go test ./...

# Run server locally
go run ./cmd/server -env .env

License

Released under the MIT License.


Contributing

Issues, protocol compatibility fixes (when Nextcloud mobile clients update), and pull requests are welcome!

Directories

Path Synopsis
cmd
reindex command
Command reindex scans the PhotoVault data directory and rebuilds the PostgreSQL metadata index directly from files on disk.
Command reindex scans the PhotoVault data directory and rebuilds the PostgreSQL metadata index directly from files on disk.
server command
Command server starts the PhotoVault Nextcloud-compatible raw photo and video backup server along with its built-in web gallery dashboard.
Command server starts the PhotoVault Nextcloud-compatible raw photo and video backup server along with its built-in web gallery dashboard.
verify command
Command verify scans the PhotoVault data directory, recomputes SHA-256 checksums, and compares them against the PostgreSQL index to detect corrupted, bit-rotted, or missing files.
Command verify scans the PhotoVault data directory, recomputes SHA-256 checksums, and compares them against the PostgreSQL index to detect corrupted, bit-rotted, or missing files.
internal
auth
Package auth provides cryptographic token generation and WebDAV authentication.
Package auth provides cryptographic token generation and WebDAV authentication.
compat
Package compat implements the Nextcloud-compatible discovery, OCS, and Login Flow v2 handshake endpoints required by official Nextcloud mobile apps.
Package compat implements the Nextcloud-compatible discovery, OCS, and Login Flow v2 handshake endpoints required by official Nextcloud mobile apps.
config
Package config loads runtime configuration from a .env file and OS environment variables using only the Go standard library.
Package config loads runtime configuration from a .env file and OS environment variables using only the Go standard library.
dashboard
Package dashboard serves the web UI for browsing backed-up photos: thumbnails + date filtering.
Package dashboard serves the web UI for browsing backed-up photos: thumbnails + date filtering.
httpx
Package httpx provides shared HTTP middleware and JSON/OCS response helpers.
Package httpx provides shared HTTP middleware and JSON/OCS response helpers.
integrity
Package integrity implements PhotoVault's data protection workflows (ARCHITECTURE.md §7):
Package integrity implements PhotoVault's data protection workflows (ARCHITECTURE.md §7):
server
Package server wires up the HTTP router and manages server lifecycle.
Package server wires up the HTTP router and manages server lifecycle.
storage
Package storage writes raw photos and videos to disk with two core integrity guarantees (ARCHITECTURE.md §7):
Package storage writes raw photos and videos to disk with two core integrity guarantees (ARCHITECTURE.md §7):
store
Package store manages the PostgreSQL metadata index and Redis token/cache store.
Package store manages the PostgreSQL metadata index and Redis token/cache store.
webdav
Package webdav implements the WebDAV subset required for Nextcloud auto-upload: PROPFIND, MKCOL, PUT, MOVE, DELETE under /remote.php/dav/files/<user>/...
Package webdav implements the WebDAV subset required for Nextcloud auto-upload: PROPFIND, MKCOL, PUT, MOVE, DELETE under /remote.php/dav/files/<user>/...

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL