Architecture

Last updated


This page shows, in one overview diagram, how go-image-server layers edge caches, the Go service, libvips, and file storage.

System Overview


graph TB
    Client[Client] --> Browser[Browser Cache]
    Browser --> Worker[Cloudflare Worker]
    Browser --> Nginx[Nginx proxy_cache]
    Worker --> Nginx
    Nginx --> Gin[Gin routes]
    Gin --> Get[GetFromPath]
    Gin --> Post[PostToPath]
    Gin --> Del[DeleteFromPath]
    Get --> Vips[libvips govips]
    Get --> Cache[(storage/image/cache)]
    Get --> Upload[(storage/image/upload)]
    Post --> Upload
    Del --> Trash[(upload/.trash/YYYY-MM-DD)]
  1. graph TB
  2. Client[Client] --> Browser[Browser Cache]
  3. Browser --> Worker[Cloudflare Worker]
  4. Browser --> Nginx[Nginx proxy_cache]
  5. Worker --> Nginx
  6. Nginx --> Gin[Gin routes]
  7. Gin --> Get[GetFromPath]
  8. Gin --> Post[PostToPath]
  9. Gin --> Del[DeleteFromPath]
  10. Get --> Vips[libvips govips]
  11. Get --> Cache[(storage/image/cache)]
  12. Get --> Upload[(storage/image/upload)]
  13. Post --> Upload
  14. Del --> Trash[(upload/.trash/YYYY-MM-DD)]

Layers


LayerLocationResponsibility
Edgeworker/index.jsCaches images for 7 days keyed by the full URL including query
Reverse proxyconfig/nginx/nodes.conf/c/img/ caching, upload / delete forwarding, security headers
Routingapp/internal/routes/SetGET / SetPOST / SetDELETE register endpoints; Set404 handles unknown paths
Handlersapp/internal/handlers/Read and transform, upload, move to trash
Configapp/internal/configs/config.goEnvironment variables and storage paths
Utilitiesapp/internal/utils/Query alias lookup, error responses

Cross-Cutting Principles


PrincipleImplementation
30-second cap per requestAll three handlers wrap a goroutine in context.WithTimeout and return 408 timed out on expiry
Parameters are the cache keyLocal cache filenames concatenate size, quality, blur, brightness, and format parameters
Delete means moveDeletion always os.Renames into the date-bucketed .trash
Streamed outputImages go out with chunked transfer and a buffer sized by file size

Further Reading


中文