How starryeyedjas/photoprism works
Purpose and Entrypoints
PhotoPrism is a self-hosted, AI-assisted photo/video library: it imports and indexes local media, extracts metadata, generates derivatives, supports search/organization/sharing, and serves a PWA plus machine-facing APIs. The Go executable starts at cmd/photoprism/photoprism.go; command dispatch and long-running server startup are in internal/commands/commands.go and internal/commands/start.go. Docker/Compose are primary deployment surfaces: Dockerfile, compose.yaml, and setup/docker/compose.yaml.
Runtime Composition and HTTP Boundary
The Go server owns routing, TLS/proxy concerns, static delivery, WebDAV, API, and the browser app shell. internal/server/server.go, internal/server/routes.go, and internal/server/routes_webapp.go establish this boundary; internal/api/api.go and internal/api/server.go expose the authenticated application API. Static templates/assets are server-rendered or embedded from assets/templates/app.gohtml and assets/static/. WebSocket support carries server events to active clients through internal/api/websocket.go and internal/event/hub.go.
Browser Client
The frontend is a Vue-based PWA, compiled independently and served by the Go runtime. Its bootstrap, routing, and session lifecycle are in frontend/src/app.js, frontend/src/app/routes.js, and frontend/src/app/session.js. Client models map REST resources such as photos, albums, files, faces, and services (frontend/src/model/photo.js, frontend/src/model/rest.js); pages/components consume these models to browse, edit, upload, administer, and share media. The client-server contract is thus HTTP/WebSocket, rather than direct database access.
Media Ingestion, Indexing, and Derivatives
Media enters via watched/imported originals, uploads, WebDAV, and configured services. Workers schedule asynchronous import, indexing, metadata, backup/share, synchronization, and vision jobs in internal/workers/workers.go, internal/workers/auto/index.go, and internal/workers/sync.go. The core PhotoPrism domain service coordinates scanning, deduplication/file hashing, metadata resolution, persistence, related-media handling, and search-ready records in internal/photoprism/index.go, internal/photoprism/index_mediafile.go, and internal/photoprism/mediafile.go. Metadata parsing and normalization are isolated in internal/meta/meta.go, internal/meta/exif.go, and internal/meta/xmp.go; thumbnails are created/cached through internal/thumb/generator.go and internal/photoprism/thumbs.go. RAW conversion and video transcoding use external media tooling behind internal/raw/convert.go and internal/ffmpeg/ffmpeg.go.
Persistence, Search, and Domain Model
The relational system of record is represented by ORM entities and query/search layers. Core records—photos, files, folders, albums, labels, faces, subjects, users, sessions, and services—live in internal/entity/photo.go, internal/entity/file.go, and internal/entity/entity.go; migrations support MySQL/MariaDB and SQLite in internal/entity/migrate/migrate.go. API handlers validate forms, enforce scope, then call entity/query/search or domain services; complex media search is implemented in internal/entity/search/photos.go and projected by internal/api/photos_search.go. Compose variants indicate MySQL/MariaDB deployments (compose.mysql.yaml, compose.mariadb.yaml); qdrant.yaml and vector search filters indicate optional vector-search infrastructure.
Identity, Authorization, and Sharing
Request processing crosses authentication and authorization before resource handlers. ACL roles/scopes are defined in internal/auth/acl/acl.go; JWT issuing/verification is in internal/auth/jwt/manager.go; persisted/browser sessions are managed by internal/auth/session/session.go. The server also supports OIDC login and OAuth/OIDC provider endpoints via internal/auth/oidc/oidc.go, internal/api/oauth_handlers.go, and internal/server/wellknown/openid.go. Public sharing is a distinct route/API concern (internal/api/share.go, internal/server/routes_sharing.go), while WebDAV has its own authentication and path-security boundary (internal/server/webdav.go, internal/server/webdav_auth.go).
AI, External Services, and Cluster Features
Local AI supports classification, NSFW detection, and face embeddings/clustering through internal/ai/classify/classify.go, internal/ai/nsfw/nsfw.go, and internal/ai/face/engine.go; TensorFlow and ONNX-backed models are packaged/configured separately. Vision can instead call Ollama or OpenAI-compatible external services via internal/ai/vision/engine_ollama.go and internal/ai/vision/engine_openai.go. Additional integrations include privacy-oriented places/geocoding through internal/service/hub/places/places.go, WebDAV clients/services through internal/service/webdav/client.go, and optional multi-node cluster registration/provisioning in internal/service/cluster/cluster.go and internal/service/cluster/provisioner/provisioner.go.
Main entry points: api.go Authenticated API · server.go HTTP server & routes · index.go Media indexing domain · entity.go ORM domain records
Components 18
Server Runtime
- Go CLI
cmd/photoprism/photoprism.go - Command startup
internal/commands/start.go - HTTP server & routes · Owns routing, TLS/proxy handling, static delivery, WebDAV, and app shell.
internal/server/server.go - Authenticated API
internal/api/api.go - Identity & access · ACL, JWT, sessions, and OIDC flows.
internal/auth/acl/acl.go - Public sharing & WebDAV
internal/server/routes_sharing.go - Event hub / WebSocket
internal/event/hub.go
Browser Client
- Vue PWA · Uses REST and WebSocket contracts only.
frontend/src/app.js
Media Pipeline
- Background workers · Schedules import, indexing, sync, backup/share, and vision jobs.
internal/workers/workers.go - Media indexing domain · Coordinates scanning, deduplication, metadata, persistence, and search-ready media.
internal/photoprism/index.go - Metadata extraction
internal/meta/meta.go - Thumbnails & media tools · Creates cached thumbnails and invokes RAW/video tooling.
internal/thumb/generator.go
Data & Search
- ORM domain records · Photos, files, folders, albums, labels, faces, users, sessions, and services.
internal/entity/entity.go - Photo search
internal/entity/search/photos.go - MySQL/MariaDB or SQLite · System of record with migrations.
internal/entity/migrate/migrate.go
AI & Integrations
- Local & remote vision · Classification, NSFW, face embeddings, or Ollama/OpenAI-compatible vision.
internal/ai/vision/engine_ollama.go - External & cluster services · Places, WebDAV clients, and optional cluster provisioning.
internal/service/cluster/cluster.go
Other components
- Docker / Compose · Primary self-hosted deployment surface.
compose.yaml
Connections 21
- Docker / Compose → Go CLI: runs
- Go CLI → Command startup: dispatches
- Command startup → HTTP server & routes: starts
- HTTP server & routes → Authenticated API: routes requests to
- HTTP server & routes → Vue PWA: serves app shell/assets
- Vue PWA → Authenticated API: REST
- Vue PWA → Event hub / WebSocket: WebSocket
- Authenticated API → Identity & access: authenticates / authorizes
- HTTP server & routes → Public sharing & WebDAV: separate routes
- Authenticated API → Event hub / WebSocket: publishes events
- Authenticated API → Photo search: searches
- Authenticated API → ORM domain records: reads / updates
- Background workers → Media indexing domain: runs import/index jobs
- Media indexing domain → Metadata extraction: extracts
- Media indexing domain → Thumbnails & media tools: generates
- Media indexing domain → ORM domain records: persists records
- ORM domain records → MySQL/MariaDB or SQLite: ORM persistence
- Photo search → MySQL/MariaDB or SQLite: queries
- Background workers → Local & remote vision: runs vision jobs
- Local & remote vision → ORM domain records: stores annotations
- Background workers → External & cluster services: syncs / provisions