# starryeyedjas/photoprism architecture

> Architecture diagram of the GitHub repository starryeyedjas/photoprism, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/starryeyedjas/photoprism
- Repository: https://github.com/starryeyedjas/photoprism

## Overview

#### 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: [`internal/api/api.go`](https://github.com/starryeyedjas/photoprism/blob/develop/internal/api/api.go) (Authenticated API), [`internal/server/server.go`](https://github.com/starryeyedjas/photoprism/blob/develop/internal/server/server.go) (HTTP server & routes), [`internal/photoprism/index.go`](https://github.com/starryeyedjas/photoprism/blob/develop/internal/photoprism/index.go) (Media indexing domain), [`internal/entity/entity.go`](https://github.com/starryeyedjas/photoprism/blob/develop/internal/entity/entity.go) (ORM domain records)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Server Runtime"]
  node_cli{{"Go CLI<br/>entrypoint<br/>[photoprism.go]"}}
  node_commands["Command startup<br/>command layer<br/>[start.go]"]
  node_server["HTTP server &amp; routes<br/>Go server<br/>[server.go]"]
  node_api["Authenticated API<br/>API layer<br/>[api.go]"]
  node_auth["Identity &amp; access<br/>auth subsystem<br/>[acl.go]"]
  node_sharing["Public sharing &amp; WebDAV<br/>access boundary<br/>[routes_sharing.go]"]
  node_events["Event hub / WebSocket<br/>realtime events<br/>[hub.go]"]
end

subgraph group_client["Browser Client"]
  node_pwa["Vue PWA<br/>browser client<br/>[app.js]"]
end

subgraph group_pipeline["Media Pipeline"]
  node_workers["Background workers<br/>job orchestration<br/>[workers.go]"]
  node_media["Media indexing domain<br/>PhotoPrism service<br/>[index.go]"]
  node_metadata["Metadata extraction<br/>EXIF/XMP parsing<br/>[meta.go]"]
  node_derivatives["Thumbnails &amp; media tools<br/>derivative pipeline<br/>[generator.go]"]
end

subgraph group_data["Data &amp; Search"]
  node_entities["ORM domain records<br/>entity model<br/>[entity.go]"]
  node_search["Photo search<br/>query layer<br/>[photos.go]"]
  node_database[("MySQL/MariaDB or SQLite<br/>relational database<br/>[migrate.go]")]
end

subgraph group_integrations["AI &amp; Integrations"]
  node_vision["Local &amp; remote vision<br/>AI inference<br/>[engine_ollama.go]"]
  node_services["External &amp; cluster services<br/>service integrations<br/>[cluster.go]"]
end

node_deploy["Docker / Compose<br/>deployment<br/>[compose.yaml]"]

node_deploy -->|"runs"| node_cli
node_cli -->|"dispatches"| node_commands
node_commands -->|"starts"| node_server
node_server -->|"routes requests to"| node_api
node_server -->|"serves app shell/assets"| node_pwa
node_pwa -->|"REST"| node_api
node_pwa -->|"WebSocket"| node_events
node_api -->|"authenticates / authorizes"| node_auth
node_server -->|"separate routes"| node_sharing
node_api -->|"publishes events"| node_events
node_api -->|"searches"| node_search
node_api -->|"reads / updates"| node_entities
node_workers -->|"runs import/index jobs"| node_media
node_media -->|"extracts"| node_metadata
node_media -->|"generates"| node_derivatives
node_media -->|"persists records"| node_entities
node_entities -->|"ORM persistence"| node_database
node_search -->|"queries"| node_database
node_workers -->|"runs vision jobs"| node_vision
node_vision -->|"stores annotations"| node_entities
node_workers -->|"syncs / provisions"| node_services

click node_deploy "https://github.com/starryeyedjas/photoprism/blob/develop/compose.yaml"
click node_cli "https://github.com/starryeyedjas/photoprism/blob/develop/cmd/photoprism/photoprism.go"
click node_commands "https://github.com/starryeyedjas/photoprism/blob/develop/internal/commands/start.go"
click node_server "https://github.com/starryeyedjas/photoprism/blob/develop/internal/server/server.go"
click node_api "https://github.com/starryeyedjas/photoprism/blob/develop/internal/api/api.go"
click node_auth "https://github.com/starryeyedjas/photoprism/blob/develop/internal/auth/acl/acl.go"
click node_sharing "https://github.com/starryeyedjas/photoprism/blob/develop/internal/server/routes_sharing.go"
click node_events "https://github.com/starryeyedjas/photoprism/blob/develop/internal/event/hub.go"
click node_pwa "https://github.com/starryeyedjas/photoprism/blob/develop/frontend/src/app.js"
click node_workers "https://github.com/starryeyedjas/photoprism/blob/develop/internal/workers/workers.go"
click node_media "https://github.com/starryeyedjas/photoprism/blob/develop/internal/photoprism/index.go"
click node_metadata "https://github.com/starryeyedjas/photoprism/blob/develop/internal/meta/meta.go"
click node_derivatives "https://github.com/starryeyedjas/photoprism/blob/develop/internal/thumb/generator.go"
click node_entities "https://github.com/starryeyedjas/photoprism/blob/develop/internal/entity/entity.go"
click node_search "https://github.com/starryeyedjas/photoprism/blob/develop/internal/entity/search/photos.go"
click node_database "https://github.com/starryeyedjas/photoprism/blob/develop/internal/entity/migrate/migrate.go"
click node_vision "https://github.com/starryeyedjas/photoprism/blob/develop/internal/ai/vision/engine_ollama.go"
click node_services "https://github.com/starryeyedjas/photoprism/blob/develop/internal/service/cluster/cluster.go"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cli,node_commands,node_server,node_api,node_auth,node_sharing,node_events toneBlue
class node_pwa toneAmber
class node_workers,node_media,node_metadata,node_derivatives toneMint
class node_entities,node_search,node_database toneRose
class node_vision,node_services toneIndigo
class node_deploy toneNeutral
```

## Components

### Server Runtime

- [Go CLI](https://github.com/starryeyedjas/photoprism/blob/develop/cmd/photoprism/photoprism.go): entrypoint · `cmd/photoprism/photoprism.go`
- [Command startup](https://github.com/starryeyedjas/photoprism/blob/develop/internal/commands/start.go): command layer · `internal/commands/start.go`
- [HTTP server & routes](https://github.com/starryeyedjas/photoprism/blob/develop/internal/server/server.go): Go server · Owns routing, TLS/proxy handling, static delivery, WebDAV, and app shell. · `internal/server/server.go`
- [Authenticated API](https://github.com/starryeyedjas/photoprism/blob/develop/internal/api/api.go): API layer · `internal/api/api.go`
- [Identity & access](https://github.com/starryeyedjas/photoprism/blob/develop/internal/auth/acl/acl.go): auth subsystem · ACL, JWT, sessions, and OIDC flows. · `internal/auth/acl/acl.go`
- [Public sharing & WebDAV](https://github.com/starryeyedjas/photoprism/blob/develop/internal/server/routes_sharing.go): access boundary · `internal/server/routes_sharing.go`
- [Event hub / WebSocket](https://github.com/starryeyedjas/photoprism/blob/develop/internal/event/hub.go): realtime events · `internal/event/hub.go`

### Browser Client

- [Vue PWA](https://github.com/starryeyedjas/photoprism/blob/develop/frontend/src/app.js): browser client · Uses REST and WebSocket contracts only. · `frontend/src/app.js`

### Media Pipeline

- [Background workers](https://github.com/starryeyedjas/photoprism/blob/develop/internal/workers/workers.go): job orchestration · Schedules import, indexing, sync, backup/share, and vision jobs. · `internal/workers/workers.go`
- [Media indexing domain](https://github.com/starryeyedjas/photoprism/blob/develop/internal/photoprism/index.go): PhotoPrism service · Coordinates scanning, deduplication, metadata, persistence, and search-ready media. · `internal/photoprism/index.go`
- [Metadata extraction](https://github.com/starryeyedjas/photoprism/blob/develop/internal/meta/meta.go): EXIF/XMP parsing · `internal/meta/meta.go`
- [Thumbnails & media tools](https://github.com/starryeyedjas/photoprism/blob/develop/internal/thumb/generator.go): derivative pipeline · Creates cached thumbnails and invokes RAW/video tooling. · `internal/thumb/generator.go`

### Data & Search

- [ORM domain records](https://github.com/starryeyedjas/photoprism/blob/develop/internal/entity/entity.go): entity model · Photos, files, folders, albums, labels, faces, users, sessions, and services. · `internal/entity/entity.go`
- [Photo search](https://github.com/starryeyedjas/photoprism/blob/develop/internal/entity/search/photos.go): query layer · `internal/entity/search/photos.go`
- [MySQL/MariaDB or SQLite](https://github.com/starryeyedjas/photoprism/blob/develop/internal/entity/migrate/migrate.go): relational database · System of record with migrations. · `internal/entity/migrate/migrate.go`

### AI & Integrations

- [Local & remote vision](https://github.com/starryeyedjas/photoprism/blob/develop/internal/ai/vision/engine_ollama.go): AI inference · Classification, NSFW, face embeddings, or Ollama/OpenAI-compatible vision. · `internal/ai/vision/engine_ollama.go`
- [External & cluster services](https://github.com/starryeyedjas/photoprism/blob/develop/internal/service/cluster/cluster.go): service integrations · Places, WebDAV clients, and optional cluster provisioning. · `internal/service/cluster/cluster.go`

### Other components

- [Docker / Compose](https://github.com/starryeyedjas/photoprism/blob/develop/compose.yaml): deployment · Primary self-hosted deployment surface. · `compose.yaml`

## Connections

- 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
