CartoSnap
Shared photos from every source, combined into one stream, filed under trips and put back on the map where they were taken.
Phoenix 1.8 / LiveView, Tailwind v4 + daisyUI with the shared sibling-app theme catalog, Leaflet maps on our own tile server (tiles.neiam.org), Oban for background work, and Backblaze B2 for storage.
Running it
You need Elixir 1.20 / OTP 28, Node (for the npm-managed map JS), ImageMagick 7
(magick on the PATH), and podman or docker for the database.
podman-compose up -d # PostGIS on localhost:5436
(cd assets && npm install)
mix setup # deps, database, assets
iex -S mix phx.server
Then visit localhost:4000 and register. Dev mail (magic links) lands in /dev/mailbox.
In dev, uploads are kept on disk under uploads/ and served at /uploads,
so no bucket is needed. To use the real B2 bucket instead, start with
STORAGE=s3 and set BUCKET_ID / BUCKET_SECRET (a B2 application key; it
doubles as the S3 key pair) and BUCKET_NAME (default cartosnap-dev).
Tests use an in-memory bucket.
How it fits together
- Upload (
UploadLive): each file is stored as<user>/<photo>/orig.<ext>. Its EXIF, GPS position and a blurhash are read on the spot (CartosnapApp.Photos.Images), and aCartosnapApp.Workers.ProcessImageOban job is queued in the same transaction as the photo row. - Processing: the worker makes the full, preview (640px) and thumbnail
(240x180) variants and records them. Open pages pick up the change over
PubSub.
CartosnapApp.Workers.ProcessImage.enqueue_missing/0re-queues anything left unprocessed. - Map (
CartosnapAppWeb.Components.PhotoMap+assets/js/photo_map.js): a LiveView hook around Leaflet. Pins are clustered thumbnails; panning reports the visible box back to the LiveView, which lists what’s in view. Tile style follows the app theme. - Trips are shared albums (
CartosnapApp.Trips): anyone in a trip invites friends, by address (mailed, and waiting on their Invites page) or by link; each invite lets one person in, lasts a week, and is stored hashed. An invite to an address with no account makes one on the spot (the link proves the address). Members file their own photos under the trip, so the album is everyone’s together. A photo can be in several trips; it stays its uploader’s, and only they edit it. Upload straight into a trip from its Add photos button. - Bulk: Select on the photo stream picks many photos to promote, unpromote, add to a trip or delete.
- Public trips (
/t/<id>): a trip its owner opens to everyone is listed on the front page, which maps the photos of every public trip. Separate from sharing by link. - Sharing by link (
/s/<token>, no account needed): for the people the link is sent to, never listed. Public and link viewers are in separate rooms, each with its own promoted-only setting. Either view is a slideshow of the album with a map. Anyone can follow anyone (click them in the roster); the trip’s owner hosts, and Bring everyone here makes every viewer follow them. Pointers over the photo are shared live through Presence. - Scopes: every context function takes the caller’s
%Scope{}; you see your own photos and the albums of trips you’re in.
Configuration
| Variable | What |
|---|---|
DATABASE_URL, SECRET_KEY_BASE, PHX_HOST |
as usual for Phoenix (prod) |
PHX_ORIGINS |
comma-separated origins allowed to open the LiveView socket, e.g. //cs.neiam.org |
BUCKET_ID, BUCKET_SECRET, BUCKET_NAME |
B2 key pair and bucket |
S3_HOST, S3_REGION, S3_ID, S3_SECRET |
override the B2 endpoint host, signing region and keys |
S3_ENDPOINT, S3_PUBLIC_URL |
a full endpoint URL (another S3-compatible), and where browsers fetch files from |
STORAGE=s3 |
dev only: use the bucket rather than uploads/ |
MAP_TILE_URL |
tile URL template; {style} is filled in per theme |
PHOTON_URL, PHOTON_FALLBACK_URL |
place search for pinning photos (empty fallback turns it off) |
POD_IP, POD_NAMESPACE, RELEASE_COOKIE |
clustering in Kubernetes (below) |
SMTP_RELAY, SMTP_PORT, SMTP_USERNAME, SMTP_PASSWORD, SMTP_TLS, SMTP_SSL, SMTP_AUTH |
outgoing mail (login links, trip invites), as in the sibling apps; without SMTP_RELAY, mail is only logged |
MAIL_FROM_NAME, MAIL_FROM_ADDRESS |
who mail comes from (default noreply@<PHX_HOST>) |
ANDROID_CERT_FINGERPRINTS |
the Android app’s signing-cert SHA-256s, for /.well-known/assetlinks.json (docs/app-login.md) |
APP_LOGIN_REDIRECT_URI, APP_LOGIN_OIDC_PROVIDER |
SSO from the Android app: where its code goes (default cartosnap://auth; empty turns it off) and which provider |
The Android app’s log-in
The Android app (android/) signs in by pairing (the code from Settings →
Connected devices), by NEIAM (OIDC in the system browser, with PKCE), or by
email (a sign-in link, or a password). Emailed sign-in links open the app
when it is installed. The API, the security decisions and the deploy notes
are in docs/app-login.md.
Clustering
In prod the replicas join one Erlang cluster, as the sibling apps do, so
PubSub and Presence span pods (a shared trip’s viewers see each other
whichever pod they’re on). libcluster’s Kubernetes strategy lists the pods
labelled name=cartosnap (the ServiceAccount and Role in app.yml allow
it); rel/env.sh.eex names each node cartosnap_app@<POD_IP> and pins
distribution to port 9100. Every replica needs the same cookie, from the
elixir-args Secret:
kubectl -n cartosnap patch secret elixir-args --type merge \
-p "{\"stringData\":{\"release_cookie\":\"$(openssl rand -hex 32)\"}}"
The tile server only serves pages whose Referer it allowlists
(deployment/argo-01-bos/osm-tiles/app.yml, valid_referers), and only has
North America; the map says so for photos outside it.
Before committing
mix precommit