- PLpgSQL 50.6%
- TypeScript 23.9%
- Svelte 18.1%
- JavaScript 4.1%
- HTML 3.1%
- Other 0.1%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| .netlify | ||
| android | ||
| app | ||
| import | ||
| presentazione | ||
| supabase | ||
| .env.example | ||
| .gitignore | ||
| CLAUDE.md | ||
| DEPLOY.md | ||
| LICENSE | ||
| netlify.toml | ||
| README.md | ||
| SPEC.md | ||
| TODO.md | ||
Bacheca Cilento
Live at https://bachecacilento.org.
A community-run events map for the Cilento: what is on it is what the people
who use it add, moderated by volunteer admins. A public website and installable mobile
web app that lists upcoming events on a map and as a list, filterable by date,
distance and tags. The full build specification is in SPEC.md.
Licence
Copyright © 2026 Mahé Perrette. All the code in this repository, its
history included, is free software under the GNU Affero General Public
License, version 3 or (at your option) any later version: see
LICENSE. Anyone may use, modify and run it, commercially too;
whoever runs a modified version as a website must offer its source to
that site's users under the same licence.
How it was made
The site was designed by Mahé Perrette and written entirely with Claude (Anthropic's AI assistant), in Claude Code: the design choices, the reviews and the decisions are his; the code and the documentation were written by Claude under his direction. The early commits show Claude as co-author.
Layout
| Path | Contents |
|---|---|
app/ |
SvelteKit frontend (TypeScript, Tailwind CSS, Leaflet), deployed to Netlify |
supabase/ |
Database migrations, RLS policies, seed data, SQL tests; see supabase/README.md |
import/ |
Local CLI that reads flyers with Claude and writes events; see import/README.md |
netlify.toml |
Netlify build settings, SPA redirect, function and edge-function wiring |
Pages
Every page one visits and then leaves (sign-in, account, settings, forms,
confirmations) is built on app/src/lib/components/AuthShell.svelte: a title
with a cross beside it, and Esc, back to the section one was on
(app/src/lib/leave.ts). The cross is on by default; the sections (Eventi,
Luoghi, Produttori, Annunci) and the members' Piazza are the main pages and
have none. Cards (/e, /l, /a) use CardClose.svelte: the round cross top
right and Esc, back to their section with its search.
Local development
Requires Node 22.
cd app
npm install
cp .env.example .env # optionally add a MapTiler key
npm run dev
Other commands, all run inside app/:
npm run build # production build into app/build
npm run preview # serve the production build locally
npm run check # svelte-check (type checking)
npm run lint # prettier --check
npm run format # prettier --write
To look at a build in the browser before deploying, build with
PWA_OFF=1 npm run build: the service worker then removes itself instead
of keeping the previous copy, so a plain reload shows the new build. The
site's /api functions do not run locally; vite preview with a proxy
to the live site (server.proxy / preview.proxy for /api) lets the
pages call them.
Deployment
A new deployment, or a copy for another region, follows DEPLOY.md step by
step; the sections below explain each piece.
Netlify builds from this repository on every push, with deploy previews on
pull requests. The settings in netlify.toml are: base directory app,
build command npm run build, publish directory build.
Environment variables to set in Netlify (all are safe to expose in the browser). They are inlined into the bundle at build time, so a change needs a rebuild:
| Variable | Purpose |
|---|---|
PUBLIC_SUPABASE_URL |
Supabase project URL |
PUBLIC_SUPABASE_ANON_KEY |
Supabase anon key |
MAPTILER_API_KEY |
MapTiler key (public, domain-restricted), for the background styles on trial |
STADIA_API_KEY |
Stadia Maps key, used by the dev server on localhost only (never in a build) |
PUBLIC_GOOGLE_LOGIN |
1 shows "Continua con Google"; leave unset until the provider is configured |
PUBLIC_VAPID_PUBLIC_KEY |
VAPID public key; enables push notifications on the "Notifiche" page |
Server-side variables, read only by the functions in app/netlify/functions/
and never inlined into the site (mark them secret in Netlify):
| Variable | Purpose |
|---|---|
ANTHROPIC_API_KEY |
Anthropic API key used to read flyers |
ANTHROPIC_MODEL |
Optional, default claude-sonnet-5; claude-haiku-4-5 is faster and cheaper |
ANTHROPIC_EFFORT |
Optional, low (default), medium or high: how long the model deliberates |
RESEND_API_KEY |
Resend key with sending access, for the sign-up notification mail |
ADMIN_NOTIFY_EMAIL |
The admins' address: reading and network failures, WhatsApp report, moderator candidacies (several, comma-separated) |
MODERATORS_EMAIL |
Optional, the moderators' address, e.g. info@bachecacilento.org: new accounts, Piazza requests, requests to manage a card (several, comma-separated; ADMIN_NOTIFY_EMAIL when unset) |
NOTIFY_WEBHOOK_SECRET |
Random string; the Supabase webhook sends it as x-webhook-secret |
VAPID_PRIVATE_KEY |
VAPID private key for push notifications (pair of PUBLIC_VAPID_PUBLIC_KEY) |
VAPID_SUBJECT |
Optional, mailto: address given to the push services (default info@bachecacilento.org) |
The Supabase service-role key must never be set in Netlify or committed. It is only used by the local import script.
Without the two Supabase variables the site still builds and shows the map, with a notice in the list that no backend is configured.
Places: the directory
/luoghi ("Luoghi e associazioni"; "Luoghi" on narrow screens) is a second
map for the fixed side of the territory: associations,
pro loco, producers, artisans, artists, markets, shops, venues, spaces. The
places table mirrors events minus the dates (name, description, location,
address, "when to find them" as free text, link, contact, photo, hashtags,
search vector, status, owner) with the same write guard, RLS and moderation
as events. Kinds are tags in a group with scope = 'place' (Tipo, shown
as filter chips); tag_groups.scope keeps event and place groups apart in
the forms. places_nearby and place_detail are the reads; the map, list,
form and page live under /luoghi, /luoghi/nuovo, /l/<id> and
/l/<id>/modifica. Photos go to the flyers bucket as place-<id>.jpg;
link previews work for /l/<id> too. Unverified places of still-pending
accounts expire with the nightly job. Not yet: a feed for places.
Festivals with a programme
An event or a notice can name who organizes it among the board's cards
(organizer_kind, organizer_id): a place (an association, a pro loco,
an artist) or another event (a festival). The event form's "Chi
organizza" (EntityField, find_linkables()) finds places and live
events as the name is typed and links the one picked; a name not on the
board stays as the free text organizer. Picked while "Dove" is empty,
the organizer's place is offered in one tap ("Si tiene presso …?"), never
filled in silently, since an association often organizes elsewhere. A
notice has the same field as "Per conto di". The event page links the
organizer, a festival's page lists the events it organizes (its
programme), and a place's page lists those it organizes elsewhere besides
those held there (organized_events()). "Fa parte di" (parent_id) is
gone from the forms: the few links there were became organizers
(…_organizers.sql). Only cards organize, not members: a member has no
public page and their handle is not public; someone who organizes often
can have a card of the "Artista" kind. The form reads: title, when, who
organizes, where, description, the rest, and "Riservato" just above the
publish button.
An event can be held at a place of the board (events.place_id). The
event keeps its own place_name, address and location, copied from
the place by a trigger (events_place_copy), so the search, the map, the
feeds and the previews read events as before; a change to the place's
name, address or pin is carried to its linked events
(places_carry_to_events, a system write, so the events' own guard stays
out of it), and deleting the place only unlinks them. location_detail
says where inside or around the place (a room, a floor, the courtyard). In
the form the place is searched by name among the board's places, nearest
first (searchPlaces); while linked, the name, address and map are the
place's, and "Modifica" unlinks them. A place that is not on the board yet
can be created from the form, with a name, a kind and the address and pin
already filled in. A sub-event takes its festival's place. The place's page
lists its upcoming events (place_events).
A lighter programme needs no events of its own: event_programme holds
entries of an event (a time, a title, a few lines, where inside the place,
a picture), written by its editors («Aggiungi al programma» on a one-off
event, «Dettagli di questa data» on a repeating one, ProgrammeList,
RepeatDates). They have no page or pin; their words are part of the
event's search text, and events_nearby returns those of each date's
days, so the list shows them under the event. A repeating event's date
also shows what a feed among its links (else its organizer cards') says of
that day: same day and a title word in common, no AI (feed-match.ts).
Contact on an event
An event or a place can carry a contact email and phone (optional), read
from flyers by the model and taken from ORGANIZER:mailto: and CONTACT
on calendar imports. They are shown on request only: the page offers
"Mostra contatti", and the tap fetches that one card's contact through
contact_details(). The map and list queries, the detail rows (except for
the card's editors, whose form needs them), the feeds and the link previews
carry none, and the two columns are readable by the service role only
(column grants in supabase/migrations/…_contact_reveal.sql; a migration
that adds a column to events or places must grant it to anon and
authenticated). This keeps addresses away from feed and API harvesting
and from crawlers that do not run a browser. The admin setting "Contatti
solo per chi ha effettuato l'accesso" (settings.contacts_require_login)
goes one step further and shows them to signed-in members only. The
author can opt out per card with "Contatti in chiaro" (contact_public):
that card's contacts are then on the page without a tap, in the list rows
and in the feeds, as on a printed flyer.
The tap is against robots, which are not signed in: someone signed in
sees a card's contact at once, with no button (ContactReveal). A
notice's contact is for the signed-in only, whatever the setting and
"Contatti in chiaro" (which then means shown at once to them): notices
are mostly private people, who can be answered by private message.
notice_contact_details(), notice_detail() and notices_nearby() give
it to no visitor, so the notices feed carries none
(…_notice_contacts_members.sql).
Importing an event
The top of the event form, "Importa da una locandina, un post o un link", takes one of:
- an image (a flyer, a photo, a screenshot of a post), chosen, pasted with Ctrl+V anywhere on the page or dropped on it: read at once;
- a post's text: read with "Importa";
- a link: the Netlify Function
read-linkfetches the page for the signed-in member (public hosts only, 8 s, 2 MB of page and 4 MB of image) and returns its preview tags and schema.org Event, which are read like a post's text with the page's image; Facebook and Instagram pages need a sign-in and return nothing, so the form asks for a screenshot; - a calendar (
.icsfile or address,webcal:too): its events are listed and the chosen one fills the form. Addresses go through the functionfetch-ics(browsers cannot read most of them; approved members, public addresses only,safeFetch), 1 MB at most. The parser lives inimport/src/ics.ts, shared with the CLI'sbacheca import-ics, which keeps a whole feed in sync by UID (seeimport/README.md).
From Eventi and the Piazza, a signed-in member can also paste or drop an
image on the page, or use the picture button (the right half of the add
button on Eventi, beside "+ Scheda" in the Piazza): the form opens with the
image imported (app/src/lib/pending-import.ts). Nothing is published
until the member checks the fields and presses "Pubblica". When fields are
already filled, reading asks before replacing them.
"Scegli un'immagine" and the "Locandina" field's own "Leggi" button both use the reader described next.
Icon
One Leaflet map serves the whole visit (app/src/lib/map/live-map.ts).
Each section is its own page, so a map built per page was torn down and
rebuilt at every change of tab: the tiles blinked and everything the
visitor had done to the map was lost. The map, its tiles, its pin layer
and its circle are made once and kept in a container the module owns; a
page borrows the container into its own DOM, fills the layer with its own
pins, and hands it back untouched (the arriving page mounts before the
leaving one is torn down, so the handlers carry their owner).
The map moves only while it is seen: on a phone showing the list it is hidden and has no size, where fitting it zooms all the way in and panning it lands anywhere. A move asked for meanwhile (framing a search, arriving on a card, a pin selected) is kept and made when the map shows; on a wide screen, where the map is always beside the list, nothing changes.
The map moves when the visitor asks it to and never on its own. Results
arriving, a tab changing, a section loading: none of that reframes it, and
the centre and zoom carry from one section to the next
(view.svelte.ts remembers where it was looking), so only the pins
differ. What does move it: a zone or a distance chosen in the filter bar,
a card opened from its own page, and the button at the map's top left that
fits everything again.
Each page starts from default settings and settles its centre and distance
as the settings, the link's filters and the device location arrive, so the
map cannot tell a new search from its centre prop changing. The page says
so instead: it bumps frameToken on PinMap when the visitor picks a zone,
asks for their location, clears it, or lets go of the distance slider. The
one exception is the first page of the visit, where the map follows the
search as it settles, until the first change of tab or the first touch of
the map.
The list is what lies inside the circle. The map also shows, faded and
behind them, the cards in view outside it that match the same filters:
after every move PinMap reports the whole view (onarea: its centre and
the radius of the circle around it), and the page runs the same search
there, up to AROUND_MAX_KM, unless the view lies entirely inside the
circle. The selected card is never faded.
Pins are teardrops with the point on the spot (app/src/lib/map/pin-icon.ts,
a Leaflet divIcon holding an inline SVG), in the card's colour, hollow and
dashed when unverified, larger with a deeper shadow when selected; the
location picker uses the same drawing.
The sections are tabs (SectionChips.svelte): an icon, the name and an
underline in the section's colour under the one on show. They navigate, so
they no longer wear the pill that filters (dates, kinds) or the plain
#parola that comes from the cards; one shape per job. On a phone only the
tab in hand spells its name, the others being their icon alone. At the far
end of the same row sit the actions: a round plus in the colour of the
section (its name is the label and the tooltip) and the chat as its speech
bubble with the unread badge, both spelled out from the sm breakpoint up.
On a phone a list row opens the card, and a small map button at its right
end shows the pin instead. The map then highlights that pin, larger, with
the others faded, and the card it belongs to appears as a strip at the
foot of the screen (MapCardStrip.svelte): picture, title and one line of
detail, a tap opens the card, a cross dismisses it. Leaflet's own controls move above the strip while it is up
(.map-card-open), so the zoom buttons never sit under it. The filter
rows under the sections fold away on a phone, by the handle at the foot of
the bar rather than on their own, and the choice is kept per browser. It is the same idea as the
list beside the map on a desktop, reduced to the one card in hand, and it
never covers the pin. Tapping a pin directly does the same, so the map
leads to the cards without popups. From the md breakpoint up, where the map sits beside the list,
the row still picks the pin and opens its popup as before, with the arrow
opening the card.
On a desktop the arrows walk the site: left and right between the
sections, carrying the zone and the distance as the tabs do, up and down
through the cards in the order the list shows them, and Escape lets the
chosen card go (app/src/lib/keys.ts). They stay out of the way of
anything that has its own use for them: a form being filled in, the map,
which pans with the arrows, the chat, which scrolls, and any text field.
Lists come full or compact: full cards as before, or one line per card
(title, place, distance; no picture, tags or hashtags), for when a section
holds many. The choice is shared by the four sections and kept per browser
(view.svelte.ts again), switched beside the map/list button on phones and
from the list's own header on wider screens.
On narrow screens each section shows either the map or the list, and the
button at the bottom switches; the map is taken out of the flow while the
list shows, since Leaflet's own controls would otherwise sit above it. The choice is shared by the four sections
and kept per browser (app/src/lib/view.svelte.ts), so it survives a move
from Eventi to Luoghi; the list is the default, since on a phone it says
more at a glance. Tapping a card or a hashtag still moves the view for
that action without changing the stored choice. Wide screens show both
and ignore all this.
Light or dark follows the browser, and the sun in the header switches it for
this browser (app/src/lib/theme.svelte.ts writes data-theme on <html>,
which the palette reads; a small script in app.html applies the stored
choice before the first paint, and a right click on the sun goes back to the
browser's setting). The maps swap their tiles on a themechange event.
One drawing, app/src/lib/assets/icon.svg (the four sections, each in its
colour: the calendar of the events, the pin of the places, the leaf of the
producers, the notice board of the annunci, the same marks the tabs wear, bare on the site's cream, no frame),
is the home-screen icon and the
link preview and the source of every raster size in app/static/icons/
(home-screen, maskable, Apple touch); a second, favicon.svg, wears the
leaf alone in green for the sizes where four marks blur into a smudge, and
is the browser tab icon, with static/favicon-32.png and favicon-16.png
(scripts/icons.mjs renders them all). The
link-preview card for pages without their own image is
app/src/lib/assets/og-default.svg, rendered to static/og-default.png
as a 1200×1200 square (chat apps crop wide images to a square thumbnail).
After editing either SVG, run npm run icons in app/ to regenerate them.
Feeds: calendar, GeoJSON and Atom
/api/events.ics, /api/events.json and /api/events.atom (Netlify
Function app/netlify/functions/feed.mts) serve the published events as a
calendar people can subscribe to, as GeoJSON for other websites, and as an
Atom feed for feed readers and feed-to-mail or feed-to-channel services.
The Atom feed has one entry per event with a stable id (the event's URL),
published = created, updated = last edit, categories for tags and
hashtags and the flyer as enclosure, so a reader tells a new card from a
changed one and decides what to notify. All three accept the
home page's search as query parameters (lat, lng, radius, from, to,
days, q), read through the anon key so only published events come out,
allow any origin, and are cached for five minutes. "Esporta" above the event
list links to them with the filters in use; the Info page ("Dati aperti")
documents them for the public, with the CC BY 4.0 licence on the data.
/api/annunci.atom is the same for notices (one entry per notice, "Offro:
…" or "Cerco: …", the kind and the hashtags as categories, the days in
the summary; tipo=offro|cerco, lat, lng, radius, q, and from,
to or days as a day window that only dated notices must overlap), and
/api/bacheca.atom puts events and notices in one feed. The Avvisi page
(the bell in the header, open to everyone) lists the three, whole region,
and every page carries them as <link rel="alternate"> for
autodiscovery.
npm test in app/ covers the query parsing and the formats.
Links on cards
Events, places and notices carry up to five links (links text[],
migration …_links.sql; url stays in step with the first one for the
feeds, the importer and old clients, and a writer sending url alone
gets it as the one link). The form has one input per link with "+ altro
link"; people just paste, and app/src/lib/links.ts reads the platform
from the address: Instagram, Facebook, X, Telegram, WhatsApp, YouTube,
TikTok, or a globe for anything else. "@nome" becomes an Instagram
address and a bare "instagram.com/…" gets its scheme
(normalizeLink). Pages show a round button per link with the platform's
glyph (LinkRow.svelte); list cards show small muted glyphs for the link
kinds and for the presence of an email or a phone (CardGlyphs.svelte,
has_email/has_phone in the nearby rows, never the values). The flyer
reader extracts every printed address into links, handles included.
The GeoJSON feed carries links, the Atom feed one rel="related" link
each.
The link-preview card (og-default.svg) carries the same four marks with
the name under them on two lines.
A card page's map snippet is a link to this site's own map, centred on the
card with it already chosen, in the card's own section (a producer opens
Produttori). The link carries the visitor's last search in that section,
kept for the visit (view.searchFor), plus sel=<id> and
focus=<lat>,<lng>, so opening a card on the map never changes the zone
or the distance. On arrival the section looks the card up around focus
with the visitor's filters; if they leave it out, the filters are cleared
(zone and distance kept). Either way the card's pin shows while it is
selected, even outside the circle. A card posted in the chat opens the
same way on a wide screen (its section's map, the card selected, its
position looked up from the card itself), and as its own page on a phone. "Apri in mappe" beside it opens the spot on Google Maps
rather than starting a route there, since the reader may want to look
around first and directions are one tap away on the other side.
Sharing and link previews
Previews are served by the edge function og.ts, which fetches the app
shell and the card from Supabase at the same time and writes the tags
into the head. The CDN keeps the result for five minutes
(Netlify-CDN-Cache-Control, cache: 'manual', the private-event token in
the cache key via Netlify-Vary: query=k), tagged e-<id>, l-<id> or
a-<id>; the push function purges the tag on every insert or update of
an event or a notice, and on every update of a place (its own webhook,
…_places_preview_purge.sql), so an edit reaches chat apps at once. A
preview made without its card (the database slow, the card hidden) is not
kept (no-store), so a passing failure does not stick to the link. The
flyer's preview copy is referenced without a round trip to check it, since
every flyer has one.
The site has no platform share buttons. "Condividi" on an event page opens the phone's own share sheet (WhatsApp, Telegram, Facebook groups, Instagram, email) with the text and, where the platform accepts it, the flyer attached; on a desktop it copies the link. "Copia testo" copies a ready-to-paste summary. Nothing is loaded from any social network.
A pasted event link shows a preview (title, date and place, flyer) because
the edge function in app/netlify/edge-functions/og.ts splices the event's
Open Graph tags into the page shell for /e/<id> requests, reading the event
through the public anon key. The section pages get a preview too: /luoghi a fixed line, the old /produttori
"Chi produce cosa, su una mappa" with the most used producer hashtags on
its last line (fetchProducerProducts). Other pages use the static tags in
app/src/app.html and the card app/static/og-default.png. An event or
place without a picture of its own gets the small og-thumb.png instead of
the card, so chat apps show a thumbnail next to the text rather than a
full-width banner; the large card is for the home and section pages. Every flyer has
a preview copy (<event>.thumb.jpg, 800 px) uploaded next to it; chat apps
refuse large preview images. npm test in app/ runs the edge function's
unit tests with Node; npm run check:functions type-checks it.
Each upload gets a name of its own (<owner>/<card>-<stamp>.jpg, with the
preview beside it). The path used to be fixed per card, so replacing a
picture kept the same public URL and browsers, the storage CDN and chat
apps went on serving the old bytes for an hour. Names being unique now,
the files are cached for a year and the replaced one is deleted right
after the new path is recorded (prune-flyers sweeps what a member's
account may not delete).
Storage
The flyers bucket (public read, 2 MB limit, JPEG/PNG/WebP) and its
policies are created by the migrations; nothing to configure by hand.
Flyers are resized to 1280 px in the browser and stored as
<user id>/<event id>.jpg.
Reading flyers
/api/read-flyer is a Netlify Function that checks the member's Supabase
session, sends the image and/or text to Claude with the list of existing
tags, and returns the fields (import/src/schema.ts), which prefill the form
for the member to check. The reader also says what the image is
(image_kind): a flyer or a photo becomes the event's picture; from a
screenshot, the poster it shows is cut out (poster_box) or, if none, the
screenshot is left out with "Usala comunque". The same extraction code runs
in the import/ CLI. A read costs about two cents with Sonnet 5; the function
allows 30 reads per member per hour, and the API credit balance caps the
total (a monthly limit can be set in the Anthropic console).
Reading costs the site (the Anthropic key): approved members only, 40
readings a day each, counted in the database (ai_read_take(),
private.ai_reads); a monthly spending limit on the Anthropic account is
the last guard. read-link, which fetches a pasted address and its
image, goes only to the public internet (shared/safe-fetch.ts): every
redirect is checked, and the addresses a name resolves to, again at the
connection (DNS rebinding); an IPv4 address written inside an IPv6 one
(mapped, NAT64, 6to4) is judged as the IPv4 address.
La mia zona
A member can keep a zone (a centre, a name, a distance) in member_prefs
(home_zone, home_lat, home_lng, home_km; readable by the owner only,
rounded to about 1 km); a visitor's stays in the browser and moves into the
account on signing in (app/src/lib/home-zone.svelte.ts). On a new visit
the lists and the map start there unless the link names a zone. It is set
from the zone row of the filter bar ("Ricorda come mia zona") or on the
account page. "Sposta qui la zona" on the map names the zone after its
municipality (Photon reverse, nearestTown()), else its coordinates.
Events of others
Members may add events and places they do not run. Who organizes is in
"Organizzato da" and who added the card in "Inserito sul sito da"; every
card offers the organizers "Organizzi questo evento? Chiedi di gestirlo"
(the ownership request), and its author "Invita chi lo organizza", a ready
message for the share sheet. Before publishing, the form lists possible
duplicates (similar_events(): same day, within 2 km or a similar title).
"Suggerisci una modifica" on a card sends a note to its author and editors
(suggest_change(), a suggestion alert in Posta and by push), once per
card per member a day.
Geocoding
The address and place search (the forms' picker, the zone box of the
sections, the Avvisi page) asks Photon (komoot's public geocoder over
OpenStreetMap data: search-as-you-type, tolerant of typos, knows shops
and farms by name) inside a box of about 50 km around the region, and
falls back to Nominatim, better at exact street addresses, when Photon has
nothing. The picker suggests while typing (Photon only, after a pause);
Enter or "Cerca" runs the full search. A marker set by hand gets its
address from Nominatim's reverse lookup. Both are public services asking
for modest traffic, which is all a small community site sends; if usage
grows, app/src/lib/api/geocode.ts is the one place to switch to a keyed
service such as MapTiler's geocoding.
Supabase Auth settings
In the Supabase dashboard under Authentication:
- URL configuration: set Site URL to the deployed site
(
https://bachecacilento.org) and addhttps://bachecacilento.org/**,http://localhost:5173/**and the Netlify deploy-preview pattern (https://*--<site>.netlify.app/**) to Redirect URLs. Confirmation and magic-link emails send people back to the site root. - Providers → Email: keep Confirm email on. The login page offers Telegram and Google first (one tap each), then the magic link and a password; no social account is required.
- Providers → Google (optional, "Continua con Google"; the button appears
only with
PUBLIC_GOOGLE_LOGIN=1in Netlify, set it after this): in the Google Cloud console create a project under the project's own Google account, configure the OAuth consent screen (external, app name "Bacheca Cilento", homepagehttps://bachecacilento.org, privacy policyhttps://bachecacilento.org/info; only the default email and profile scopes, which need no Google review) and publish it, then create an OAuth client ID of type Web application with the authorised redirect URI shown in Supabase's Google provider page (https://<project-ref>.supabase.co/auth/v1/callback). Paste client ID and secret into Supabase. Nothing from Google is loaded into the page: the sign-in is a redirect through Supabase Auth. A Google address already registered by email joins the existing account (Google confirms the address); the profile name comes from Google'sfull_namefor new accounts (supabase/migrations/…_oauth_names.sql). New Google accounts start pending like any other. - Providers → custom provider Telegram (optional, "Continua con
Telegram"). The site runs the login itself, so Telegram's screen names
bachecacilento.org and the Telegram number (which Supabase does not keep)
links the bot in the same step; Supabase only checks Telegram's token.
In BotFather's mini app (the chat's Open button) → the bot → Login
Widget: note the Client Secret (the Client ID is the bot's number),
add
https://bachecacilento.org/login/telegramto Redirect URIs andhttps://bachecacilento.orgto Trusted origins, signing algorithm RS256. On Netlify setTELEGRAM_CLIENT_SECRET. In Supabase, Authentication → Sign In / Providers → New provider, Auto-discovery (OIDC): identifiercustom:telegram, issuerhttps://oauth.telegram.org, scopesprofile, the Client ID and Secret, email optional; and turn on Allow manual linking (User Signups). The flow:src/lib/telegram-login.tssends the browser to Telegram with a PKCE challenge; back at/login/telegram,netlify/functions/telegram-login.mtsswaps the code for the token, checks it and notes the number (tg_login_note); the page signs in (signInWithIdToken) or links (linkIdentity) with the token, then claims the note (tg_login_claim), which links the bot. A Telegram the bot knows from an account (linked with the bot's code) becomes that account's way in at once and signs into it (tg_login_note); «entra con quell'account» is left as a fallback. A new account is asked whether there is an older one (the name last signed in on the device helps); then it is deleted and Telegram linked to the older. Accounts are never merged: a second one is deleted (its events and places stay, open to whoever takes them,…_telegram_sign_in.sql). - Emails → Templates: paste the Italian templates from
supabase/email-templates/(subject and body per template). - SMTP settings: custom SMTP through Resend, see Email under Administration below. Without it Supabase's built-in sender allows only a few messages an hour and shows "Supabase Auth" as the sender.
- When the confirmation mail bounces. Institutional and corporate mail
servers (a university, a research institute) often refuse mail from a
young sending domain outright, and the person is then stuck with an
account they cannot use. The sign-up form says so under the email field
and again after submitting: use a personal address, or sign in with
Google, which needs no confirmation mail, or write to the admins. An
admin then presses "Conferma email" on the accounts page
(
admin_confirm_email(), migration…_admin_confirm_email.sql;admin_list_accounts()marks unconfirmed addresses). Resend's Emails page shows whether a message was delivered or bounced, and a bounced address is suppressed for later sends. - Sign-up is open (spec §4) and, by default, approval is automatic: whoever
registers is a member and their cards publish at once
(
settings.auto_approve, "Approvazione automatica" on the admin page's settings tab). Untick it to go back to pending accounts, whose cards show as unverified until an admin approves them. The first admin is set once by SQL, seesupabase/README.md.
Administration
Who holds what, and the recurring chores. Nothing here contains a secret; every key lives in the service that needs it and nowhere else.
Services and accounts
| Service | Role | Where it is configured |
|---|---|---|
GitHub perrette/bacheca-cilento |
Source code, private. Every merge to main deploys. |
github.com |
| Netlify | Builds the site, serves it, runs the two functions (read-flyer, feed) and the edge function (og) |
app.netlify.com, site bacheca-cilento |
| Supabase | Postgres database, auth, flyer storage, nightly job | supabase.com, project htenrmokjwmjcbjpekvw |
| Namecheap | Registrar of bachecacilento.org (renews yearly) |
namecheap.com; nameservers point to Netlify DNS |
| Netlify DNS | All DNS records of the domain: site, Resend, ImprovMX | Netlify, Domains |
| Resend | Sends every email from the domain (sign-up confirmations, replies from info@) |
resend.com, domain verified |
| ImprovMX | Receives email for the domain and forwards it | improvmx.com, free plan |
| Anthropic | Reads flyers (the "Leggi la locandina" button and the import CLI) | console.anthropic.com, pay per use |
Keys and where they live
| Key | Lives in | Never in |
|---|---|---|
| Supabase anon key and URL | Netlify environment (not marked secret; it is public by design), app/.env locally |
nowhere else needed |
Supabase service-role key (or a sb_secret_… key) |
.env.local (repository root) on the administrator's machine only |
Netlify, the repository, the browser |
| Anthropic API key | Netlify environment as a secret (ANTHROPIC_API_KEY), .env.local |
the repository, the browser |
| Resend API key | Supabase SMTP settings; Netlify as RESEND_API_KEY (secret) for the sign-up notification; Gmail "Send mail as" for info@ |
the repository, the browser |
| MapTiler key (optional) | Netlify environment |
Sending and receiving are split between two free services:
- Resend sends.
bachecacilento.orgis verified there (DKIM and SPF records in Netlify DNS, on thesendsubdomain). Supabase uses it under Authentication → SMTP Settings: hostsmtp.resend.com, port 465, userresend, password the API key, sendernotifiche@bachecacilento.org, name Bacheca Cilento. The free tier (3 000 a month, 100 a day) is far above what sign-ups need. Delivery problems show in Supabase → Logs → Auth and in Resend's own log. - ImprovMX receives. MX and SPF records for the apex domain are in
Netlify DNS. A catch-all forwards every address on the domain to the
administrator's Gmail, so
info@(the address on the Info page) and anything else arrive there. Should replies tonotifiche@become too many, replacing the catch-all by explicit aliases (info,admin) makes every other address refused. One alias can forward to several people:admin@forwarding to every administrator is the intended way to reach all of them at once. - Replying as
info@is done from Gmail with Send mail as pointed at Resend's SMTP (same host, port, user and key as above), with "reply from the same address the message was sent to" ticked. If Gmail drops that feature, any mail client (Thunderbird, FairEmail) can send through the same SMTP settings. A real mailbox on the domain (Migadu, about 19 € a year) is the step up once several people run the site.
The site's own emails (sign-in links, digests, alerts, admin notices) come
from notifiche@, apart from info@, the address people write to. They
say that replies are not read and link to the Info page's help box; a
reply still arrives through the catch-all (a Gmail filter on
to:notifiche@bachecacilento.org can file those away). The digest carries
List-Unsubscribe headers, answered by the unsubscribe function, so the
mail apps' own button stops it in one click. DMARC is best set to
p=quarantine (the records align), with rua=mailto:info@… for the
weekly reports.
Notifications. The Netlify Function notify-signup sends mail through
Resend when Supabase database webhooks call it: a new account goes to the
moderators (MODERATORS_EMAIL, "Nuovo account da approvare: …"); an
ownership request goes to the card's current owner (to the moderators when
the card has none), an escalated request to the moderators, and the answer
to the person who asked; a Piazza request to the moderators; a moderator
candidacy to the admins (ADMIN_NOTIFY_EMAIL). To set it up
once: pick a random secret (for example openssl rand -hex 24), add
RESEND_API_KEY, ADMIN_NOTIFY_EMAIL and NOTIFY_WEBHOOK_SECRET in Netlify
(secrets) and redeploy; then in Supabase → Database → Webhooks create two
hooks of type HTTP request, method POST, URL
https://bachecacilento.org/api/notify-signup, HTTP header
x-webhook-secret set to the same secret: notify_signup on
public.profiles for Insert, and notify_claims on public.claims for
Insert and Update. Mails carry display names and links; a member's
address is used only as a recipient, never shown.
Ownership of a card. Whoever adds an event or a place owns it (edits,
deletes). Someone else can ask for it from the card's page ("Questa scheda è
tua?"): the request goes to the owner, who accepts or refuses on the page.
A refused request can be sent again or escalated to the admins, as can one
left unanswered for a week; escalated requests are decided on the admin
page ("Richieste") and count in the header badge. An owner can also hand a
card over directly by email. All of this is in
supabase/migrations/…_claims.sql (table claims, functions
respond_claim, escalate_claim, admin_resolve_claim, transfer_item).
An imported event (WhatsApp, calendars: source = 'import') belongs to
nobody in particular: the first approved member who asks ("Prendilo in
gestione", one tap) gets it at once and the admins are told by email;
after that, requests go to the new owner as for any card, and the calendar
import no longer rewrites or removes it (…_import_takeover.sql). An event
not posted on the social accounts (an import, or a box left off) shows its
editors "Pubblica sui social" (SocialPublish), which warns first when a
similar event already went out (social_twins) and then lets it go out
after the usual delay, as if it had been added by hand.
Reports ("Segnala") exist on places as well as events, with the same
auto-hide threshold.
Several editors. The creator of a card (or an admin) can add other
registered accounts by email under "Chi può modificare" on the edit page;
editors edit the card, its tags, its picture and the programme of a
festival, but cannot delete it or add editors, and can leave the list.
Table item_editors and function can_edit() in
supabase/migrations/…_editors_private.sql; every update policy goes
through can_edit().
Private events. "Riservato" in the event form keeps an event off the
map, the list, the feeds and the link previews without its code: only the
link on its page (/e/<id>?k=<token>) opens it. The token is generated on
save and shown only to the event's editors. Unticking the box publishes the
event like any other. Private events still follow the usual status rules
(unverified while the account is pending, hidden by reports).
Piazza (the chat)
Adding a card starts with a row of tabs (NewCardTabs.svelte) above the
form: Eventi, Luoghi, Produttori, Annunci, the one in hand decided by the
add button that was pressed, so a change of mind costs a click rather
than a restart. The Produttore tab settles the kind: the page says
"Nuovo produttore", the tag is set and its chooser disappears, and the
Luogo tab offers every kind but that one, so the two never overlap. A cross at the end of the row
leaves without adding anything, back where one came from. The wording is
"Aggiungi" throughout, on the buttons and the page titles alike. The chat's composer carries the same plus, beside the
send button and in the same accent colour: adding a card is posting, not
a stray action.
Called "Piazza" throughout (it was "Chat"): the village square, the
public place where people meet and where new cards are announced. It
carries the new cards as well as what people write, and a name that sounds
like reading only ("Feed", "Novità") would say nobody may join in;
"Forum" would promise threads and topics it does not have. In the code
it is still the chat (messages, ChatPanel, chat.svelte.ts).
One room for the members. A "Piazza" chip in blue on the right of the
filter bar, next to the add button (ChatChip.svelte, with the unread
badge; an action on the site, not a filter of it), shown to members
only: it opens the chat over the current page without leaving it, as a side panel on the right on screens 1024px and wider
(remembered per browser) and as a full-screen overlay with a close cross
on narrower ones, so the map, filters and lists underneath keep their
state. /piazza is the page for direct links (/chat redirects there), with the section chips at
the top (the only place the chat appears among them). Visitors see
neither the chip nor, on phones, the add button: signing in is how one
gets to do more. ChatPanel.svelte renders the three
variants (page, panel, overlay):
flat text messages up to 1000 characters, links and #hashtags made
clickable, no Markdown. Members and admins read and write; pending
accounts and visitors see nothing (RLS, table messages, chat_messages()
for a page with the authors' names). A trigger sets the author, trims the
text and allows ten messages a minute per account. Authors edit (the message then says
"modificato", edited_at, migration …_chat_edit.sql) and delete their
own messages, admins hide or delete any; reports work as on cards (fourth
target, auto-hide, admin page). Live updates through Supabase Realtime
(the table is in the supabase_realtime publication; the page polls every
fifteen seconds when the channel is down). chat_housekeeping() deletes
messages older than settings.chat_retention_days (90 at most, admin
page) every night at 02:40 UTC via pg_cron. Push: "Anche la piazza" per
device on the Avvisi page, push_chat_targets() with a ten-minute
cooldown per device, the notify_push_messages webhook created by the
migration from the stored secret; the notification says "Piazza · Name"
and the first words, one tag for the room so newer ones replace older
ones. A card published announces itself there, once, under its author's name and
as a preview one taps to open it: the picture, the title, the date and
place, and the opening of the description without its hashtags
(card_summary()) (messages.card_kind, card_id, card_title,
card_meta, card_image, card_text, filled by the announce_card() trigger on
events, notices and, on creation only, places; a card without an author,
an import, says nothing, and the columns are the trigger's alone). The
message then follows its card: the image, uploaded just after the card is
saved, and any later edit reach it (…_chat_card_refresh.sql). Under the
preview, an icon opens the card and another shares its link (the share
sheet on a phone, the link copied on a desktop); map popups end with the
same two icons. Those
announcements never wake a phone through the chat, the Avvisi having
already covered the card, and they do not count towards the ten messages a
minute. The stream reads as a conversation: bubbles on a tinted ground,
several in a row from one person grouped under one name, the time in the
corner of the last, and the actions behind a dot. Migrations
…_chat_card_posts.sql and …_chat_card_text.sql. A member's first visit on a wide screen opens
with the chat beside the list and the map, since it carries every new
card; after that, open or closed is remembered per browser at either
width, so a reload finds it where it was. A narrow window opens closed,
the chat covering the page there. following a card from the overlay closes it, the page being
underneath. The chat icon in the header carries the
count of messages by others since the account last opened the chat
(chat_reads, chat_unread(), chat_mark_read(), migration
…_chat_reads.sql), bumped live and cleared on opening.
Email digest
"Riepilogo via email" on the Avvisi page, one per account (table
email_digests): daily or weekly (Friday), events, notices or both, with
the zone, radius, categories and words of the form. The Netlify scheduled
function digest.mts runs at 05:30 UTC: email_digest_due() lists the
accounts due (with the email from auth.users, secret-guarded),
email_digest_content() gives the cards published since the last digest
(events with their next date, live notices), shared/digest.ts builds
the mail (text and HTML, unsubscribe link with the row's token, never
sent to the browser), Resend sends it, email_digest_mark() restarts the
clock and logs the send in email_log. Nothing is sent when nothing is
new. Sends go in batches with a pause; a 429 from Resend stops the run
and the rest stays due for the next morning. /disiscrivi?t=<token>
removes the subscription without login. The admin settings page shows
mails sent today and this month (Resend free plan: 100 a day, 3000 a
month; the Pro plan lifts the daily cap). Needs RESEND_API_KEY,
NOTIFY_WEBHOOK_SECRET and the Supabase variables, already set;
SITE_URL optionally for the links. Migration …_email_digest.sql.
Private messages
A member answers a notice in private: "Scrivi" on the notice opens a
conversation with its author (conversations, private_messages), one
per notice and per person writing, seen by the two of them only; an admin
reads a message only once it is reported (pm_report(), the reports tab).
Messages go through pm_send() (approved members, not to oneself, twenty
a minute at most) and arrive live in an open conversation (realtime).
A conversation closes when its notice is deleted and is erased a week
after the notice is deleted or has ended (pm_housekeeping(), nightly),
which the page says, so a phone number can be left there. Each message
wakes the other person's devices whose "Messaggi privati" switch is on
(a message alert, push_alert_targets()); no email per message, only a
line in the email digest when it goes anyway (pm_unread_for()). The
envelope in the header counts the conversations to read; /messaggi
lists them, and a notice's author sees on the notice who wrote. Migration
…_private_messages.sql.
The same conversations reach event and place cards: "Scrivi a chi
gestisce la scheda" (pm_start_card(), /messaggi/nuovo?evento=<id> or
?luogo=<id>) opens one per card and per person writing, answered by the
card's managers, its author and its editors (private.card_managers()),
who share the thread, its alerts and whether it is read; each message
shows who wrote it. pm_party() and pm_answers() decide who is in it
(only about the caller, so nobody learns who manages a card). A card's
conversation closes when the card is deleted and goes a week later, or
after 180 days without a message. Migration …_card_conversations.sql.
An administrator can also write to a person about nothing in particular
(pm_start_direct(), /messaggi/nuovo?persona=<id>): from the accounts
list ("Scrivi"), or from a name anywhere on the site, which is a link for
administrators only (PersonLink: a card's "Inserito sul sito da", the
authors in the Piazza). One conversation per administrator and person,
answered from Posta, even by an account still waiting for approval;
members do not start one. Migration …_admin_conversations.sql.
Announcements reach every member at once: an administrator writes one in
the admin page's «Annunci» tab (announcement_post()), and it shows among
the Posta's «Novità» for 30 days with the megaphone, counted on the
envelope until the Posta is opened (member_prefs.announcements_read_at);
no push, no email. A new account finds there, for its first 30 days, a
welcome saying how to follow the Bacheca (my_news() writes it; no alert
row). The sign-up box «Ricevo il riepilogo settimanale via email» starts a
weekly digest on the region at the first sign-in (digest_from_signup(),
once). Unread rows are bold, tinted and dotted; «Segna tutto come letto»
reads every conversation (pm_read_all()). Migration
…_announcements_welcome.sql.
Handles and mentions
Every member has a handle, a code given in order of sign-up (@utente3,
claim_code(), …_member_codes.sql), so words stay for associations and
places; nothing is chosen on the account page. Handles live
in one table, handles (kind: member now, event, place and notice
next), so an @ can point at a person or a card. Members' handles are
visible to the signed-in only. find_members() finds approved members by
handle, by a word of the name, or by an email typed in full, and never
returns the email; it drives the suggestions after an @ in the chat
(MentionSuggest) and the field that adds an editor or hands a card over
(MemberField), where add_editor() and transfer_item() now take an
@handle as well as an email. In a message, a handle that points at
something shows its name, not its code: a member highlighted, a card
linked to its page, the code in the tooltip (resolve_handles()); the
pushes read names too (render_mentions()); a handle gone, or a card the
reader cannot see, stays text.
Cards have handles too, made from the title when the card is created
(claim_handle()), and gone with the card. Words are kept for what lasts:
a place's handle comes from its name and shows on its form, changeable
(HandleField, set_card_handle(), checked free as it is typed); events
and notices get a code in order instead (@evento12, @annuncio7,
claim_code(), …_card_codes.sql), still found after an @ by any word of
their title.
After an @ the chat suggests members and cards together
(find_mentionables()): a handle starting so or any word of a title, and
for each card what tells it from similar ones (an event's next date and
place, a place's address, a notice's Offro/Cerco and address). Only live
cards are offered: events not over, soonest first, published places,
notices not expired. A card mentioned in the chat alerts its creator and
its editors (a mention alert with the card, one per person per message;
the push names the card). Migration …_card_handles.sql.
member_alerts records what concerns one member: a mention in the chat
(messages_mention_alerts), being added among a card's editors, a card
handed over (claims included). Each new row goes through the
notify_push_alerts webhook to notify-push, which asks
push_alert_targets() for the devices and the words. Two switches per
device, both on by default: mentions (even with the chat switch off,
and without the ten-minute wait; such a device is then not woken a second
time for the same message) and assignments. Migration
…_member_handles.sql.
Follows
A member follows a hashtag or a place (follows, one row each, per
account). A hashtag is matched exactly, spellings grouped by stem
(#semivaganti, not the word anywhere in a text); a place covers the
events held there (events.place_id) and those whose description names
it by its @handle. What is followed reaches the member whatever the zone
of their notifications: push_targets() and push_notice_targets() wake
the devices whose zone matches, as before, or whose follows switch is on
(the default) when follows_event() / follows_notice() say so; the
email digest (email_digest_content()) includes followed cards the same
way. A place is followed from its page ("Segui"); a hashtag by the small
bell beside it on a card's page, or beside a hashtag selected in the
filter row (FollowBell), or from the notifications page, which lists
everything followed (FollowsPanel). The bells share one list per visit
(follows.svelte.ts). Following a place also covers the events and
notices it organizes, wherever they are held. Each follow reaches the
member anywhere (the default) or only within the zone of their
notifications (follows.anywhere, switched on the notifications page,
…_follow_scope.sql).
Migration …_follows.sql.
Condiviso da (event_shares, migration …_event_shares.sql): an
organization's card passes on an event it does not organize, as Semi
Vaganti relays what reaches its WhatsApp group. Several cards may share
one event; the card's managers share it ("Condividi come " at the
bottom of the event's page, SharedBy) and unshare it, and the event's
editors may remove a share. It shows as one minor line, "Condiviso da: …",
at the bottom of the event's page only (not in previews, lists, digests or
posts). A shared event counts as the card's own for its followers
(follows_event via card_has_event; a share made more than ten minutes
after the event was added pushes them then, push_share_targets through
the notify_push_shares webhook, and puts it among the new events of
their next digest), on its page (a box of its own, "Eventi condivisi", the next five
and "Mostra tutti", each with who runs it), in its calendar and next events, and on the fediverse: the
card's account boosts it (ap_shares_queue, ap_boostable), even when the
event is not on the site's own accounts, whose page of it is then served
for the boost without @eventi posting it; Telegram, Facebook and
Instagram know nothing of a share. Removing a share takes it out of the
card's outbox (no Undo is sent).
The notifications page (/avvisi) reads top to bottom: what is followed,
then "Zona e parole" (zone, distance, words and notices, shared by the
pushes and the email digest), then four tabs for how it reaches you:
Notifiche (this device, its switches, the other devices), Sul sito (what
shows while browsing: the Piazza's count of new messages and the
envelope's count of private conversations, per account in
member_prefs, both on unless turned off), Email (the digest) and Feed
RSS. The tab is kept in the address (#email, #feeds)
so a link can open it; visitors see the sign-in note and the feeds.
Fediverse and the other networks
Every event that goes out appears on the Bacheca's accounts: Mastodon and the fediverse, Bluesky (through a bridge), the Telegram channel, the Facebook Page and the Instagram account. The site, the map, the calendars and the feeds show events either way.
What goes out is one rule, private.ap_goes(event): published, public
(not "riservato"), the event's box events.share ticked ("Condividi sui
social della Bacheca" in its form, on by default), within
settings.share_radius_km of the region's centre (200 km), and none of its
organizers or its venue, confirmed or waiting, with places.share_events
off (a card's "Condividi i suoi eventi sui social della Bacheca"). The
event form greys the box out and names the card that refuses
(places_refusing_share). When the answer changes (the box, a card's
setting, an organizer or a venue added or removed, the place moved) the
event is queued in ap_queue: withdrawn where it no longer goes, posted
where it now does.
Fediverse (ActivityPub). @eventi@<domain> posts every event that goes
out as an ActivityPub Event; each place card with fediverse on (the
default; "Seguibile da Mastodon e dal fediverso" in its form) is an account
@<handle>@<domain> that boosts the events it organizes or hosts once the
link is confirmed; a card has that account as long as its events are
shared (fediverse follows share_events, one box in its form). Accounts
are keyed by the card's id, so a new handle keeps the followers.
ap-publicanswers WebFinger, NodeInfo, the accounts, their latest posts and the events (JSON for the fediverse, a redirect to the page for a browser; cached five minutes).ap-inboxtakes Follow, Undo and account deletions, checks the HTTP signature, and answers Accept. From an account a member linked (Account → "Il tuo account del fediverso",fedi-link): a Like saves the event in their calendar, and a public or unlisted reply to an event becomes their comment under it (edits and deletions follow). Anything else is dropped.fedi-reply: a member's answer to such a comment goes from@eventito the account in its thread, public or private as chosen.ap-deliver-background(/api/ap-deliver, a background function: up to 15 minutes, 12 used) sends the queue (ap_queue), called every 15 minutes by the database (ap_wake) when something is ready: a new card waits 15 minutes first, and at most 3 new ones go per pass, besides the events out at 11:00, which all go in one pass, in their order. It goes one channel at a time for all the cards of the pass: Telegram, Facebook, the push («Novità in zona»), then the fediverse (Create, Update, Delete to the followers' servers, signed) and the places' Announce (Instagram follows fromig-post). A row taken is not taken again for 20 minutes. A card leaves the queue only once every channel went; a failure keeps it for the next pass (attempts,last_error), up to 10 times, then the administrators get an email.
The site's RSA key is in private.secrets (ap_private_key,
ap_public_key; see DEPLOY.md); keep it, as a new key makes servers refuse
what the site sends until they fetch the accounts again.
A mirror on a Mastodon server (shared/mastodon-mirror.ts):
@bachecacilento@mastodon.uno, an account marked as a bot that follows
@eventi, boosts each new event (MASTODON_MIRROR_URL,
MASTODON_MIRROR_TOKEN), since a server shows its own accounts to
visitors not signed in, and other servers' accounts often not. A withdrawn
event's Delete reaches that server as a follower's, and the boost goes.
Bluesky goes through Bridgy Fed: @eventi follows its account
(ap-follow, see DEPLOY.md), which follows back and republishes as
@eventi.<domain>.ap.brid.gy. The bridge drops Event objects, so its
inbox gets each one as a Note with the same address (forInbox), and
replies and likes from Bluesky come back to the event.
Telegram (shared/telegram.ts): a bot, administrator of the channel,
posts the flyer with a caption (or text with the page's preview) and a
button to the event's page; the post is edited when the event changes and
deleted when it is withdrawn (Telegram refuses after 48 hours). Silent from
22:00 to 8:00. telegram_posts keeps each event's message.
Flyers in a Telegram group (tg-bot, …_telegram_group_flyers.sql):
add the bot to the group, turn its privacy mode off in BotFather (Bot
Settings → Group Privacy) so it sees messages that are not commands, and
have an administrator whose Telegram is linked send /collega in the group
(/scollega undoes it). Then each photo or link posted there is read (40
readings a day per group); the bot says nothing unless it looks like an
event: a new one gets a reply «Sembra un evento: …» with «Pubblica su
Bacheca» and «No» for anyone in the group; one probably on the site
already, «Forse è già in Bacheca» with its link. Pubblica publishes it as
the presser's when their Telegram is linked, else as the import account,
always left open to others (intake_open_for_others); the reply becomes
the event's link. «No», or a day without an answer (tg-notify clears
them), and the reply goes. In the Piazza any member may press «Pubblica»
under a post at once; someone else's post makes an event left open too.
The Piazza mirrored with its Telegram group (tg-bot, tg-piazza,
shared/tg-piazza.ts, …_piazza_telegram_mirror.sql): an administrator
whose Telegram is linked sends /collega piazza in the group (the bot an
admin there, allowed to delete and pin messages; it says which right it
lacks). From then on, nothing earlier: each message in the group is copied
into the Piazza, under the linked account or the Telegram name (the
Telegram number kept: the messages move to the account when that Telegram
is linked), photos stored, other files as a line, answers and forwards
noted; edits follow (edited_message, added to the webhook by tg-notify
when missing). What members write in the Piazza by hand goes to the group
from the bot, «Nome: testo» (the import account's posts do not), within
seconds (webhook tg_piazza_messages → tg-piazza, and tg-notify every
five minutes), and its edits and deletions after it. An event made from a
message gets the link in the group. Telegram does not tell bots about
deletions: the bot sets an empty reaction on the three messages before
each new one, on those of the last two days every hour and of the last
thirty days every week; «not found» removes them from the Piazza.
/cancella in answer to a message, by its author or a group admin, removes
it from both. The bot pins a notice; the Piazza shows a line with the
group's invitation (settings.piazza_telegram_url).
Events sent to the bot (tg-bot, shared/tg-intake.ts): an approved
member links their Telegram account from the Account page
(tg-link makes a code, "/start " in the bot's chat confirms it;
tg_links). Each message they then send the bot (a flyer, a text, a link,
often shared from WhatsApp) is read as one event, with the form's reader
(extract.ts, and shared/link-read.ts for a link). The reply says what
is missing (title, date, time, a place found on the map) or, when
similar_events finds an event that may be the same, asks: add to it
(only its empty fields, links appended, the flyer if it has none), publish
anyway, or leave it (private.tg_offers, two days). Otherwise the event is
published as theirs, like a form's, and goes to the networks after the
usual delay. The flyer is Telegram's biggest size, its preview the size
of about 800 px, uploaded by the import account into its folder (the bot
has no session of the member). Telegram gets its answer at once and the
reading goes on after it (context.waitUntil, within the function's 60
seconds); an update sent again is handled once (private.tg_updates).
Open to approved members (…_intake_members.sql); a pending account is
told to wait for approval. Readings count in the form's daily limit (40,
intake_read_take on private.ai_reads).
Pubblicazione automatica (a card's feed makes events, feed-events,
hourly; …_card_feed_events.sql): on the card's form, when its links hold a
feed (a calendar or news: isFeedLink), its managers can tick "Crea sulla
Bacheca gli eventi del feed" (places.auto_events). A calendar's events are
taken as they are (import/src/ics.ts, placed by GEO, by geocoding the
location, or at the card when none is said); a news feed's items
(shared/feed-items.ts) are read by the reader like a WhatsApp message,
two an hour (a scheduled function has 30 seconds), news older than 45 days
left out; at most 5 new events a day per feed (…_import_daily_cap.sql,
also for the WhatsApp group; the calendar imports take 5 a run). An event
already on the site within 10 km that a small model
confirms is the same is shared by the card ("Condiviso da"); otherwise it
is created as the card owner's, organized by the card (feed_event_create),
not posted on its own (the evening round-up lists it, "Pubblica sui social"
posts it). Each item is noted once in private.imported (source
feed:<card>). The card's managers get an email when something was
published or needs completing. These events have their owner, so the
one-tap takeover of imported events does not apply to them.
Only on the site (…_not_on_socials.sql, …_social_decisions.sql):
the administrators' "Social" tab (SocialTab) lists the upcoming public
events not posted on the social accounts, with why (from the WhatsApp
group, a card's feed, another site's calendar, the box left off, an
organizer's refusal, too far) and who shares them. For the first four,
"Pubblica" sends one out after the usual delay (warning first when a
similar event already went out) and "Solo sul sito" records the decision
(private.social_decisions). The undecided ones count in the header
badge (admin_pending_count). On an event's page, who may publish it sees
a "Solo sul sito" label beside the title (event_on_socials), leading to
"Pubblica sui social" at the bottom.
Shared from another app (Android, the installed site in the share
menu): the manifest's share_target posts what is shared (title, text,
link, an image) to /api/condividi. The service worker takes that POST
(static/push-sw.js) and keeps it in the browser, in the shared cache
under a random token, then opens /new?condiviso=<token>; the event form
takes it once (src/lib/shared-local.ts) and reads it: an image with its
words as a flyer, a lone address as a link (a calendar too), words as a
post. Nothing goes to the server, and nothing is read before the person
is signed in (the form asks for the sign-in first; the copy waits a day).
When nothing usable came, the form says what did and points to the email
address. The address is unchanged, so Android needs no new install.
The condividi function stays for what does not stop at the worker: a
share sent before the worker updated, a share whose image reached the
worker empty (Chrome did so in September 2026; the worker then forwards
the share, as the site received those images whole from 2026-10-09 on),
and the iPhone Shortcut (?link=1). It keeps the share an hour under a
random token (private.shared_inbox, shared_put), logs what arrived
part by part, and opens /new?condiviso=<token>, which the form takes
with shared_take. Anyone may post there without an account, so
shared_put takes at most 30 shares an hour all together, images up to
5 MB and 50 MB of images at once; beyond that the form opens empty.
Events sent by email (mail-in, shared/mail-intake.ts): the same
reading (shared/intake.ts, shared with the bot) for a mail sent to
aggiungi@<domain>, an ImprovMX alias that forwards to a hidden address
(MAIL_IN_ADDRESS) on in.<domain>, a subdomain Resend receives. Resend
calls mail-in (webhook email.received, signed, RESEND_WEBHOOK_SECRET);
the function asks Resend for the mail and its attachments. There is no
length limit, unlike a Telegram caption (1024 characters), so a WhatsApp
message shared to the mail app arrives whole. Only mail from an approved
member's account address is read (within the form's daily limit of
readings), and only when Resend's own checks show it comes from that
address (mailVerified: DMARC pass, or DKIM pass with a signature whose
domain d= is the From domain, its parent or a subdomain, read from the
mail's DKIM-Signature headers; DMARC alone would refuse Gmail, whose policy
is p=none).
Unverified mail from a member's address is not read and gets an answer
saying why (once a day per address: it may reach someone whose address
was used by another); every mail is answered, except
a machine's (bounces, auto-replies, lists, no-reply addresses: RFC 3834)
and one whose sender's domain says it is forged (DMARC fail), of which the
administrators are told. Who cannot publish (no account: how to register
or which address to write from; an account awaiting approval: the form),
only when its mail is verified, and a member whose mail failed, are answered
at most once a day per address
(private.intake_replies), so spam with forged senders cannot make the
site write to strangers again and again. The answer to a member
says what became of the event (published, what is missing, or "forse c'è
già" with the event's link); the question's buttons also
go to the sender's chat with the bot when their Telegram is linked.
Facebook (shared/facebook.ts): the Page posts the flyer with the text,
or the text with the page's preview, through the Graph API with a Page
token; edited and deleted with the event. social_posts keeps the posts.
Instagram (shared/instagram.ts, Instagram API with Instagram Login):
only events with a flyer, which ig-image makes fit Instagram's
proportions (4:5 to 1.91:1) with white bands; Instagram allows no link in
the text (the site is in the bio) and no change once published. The token
lasts 60 days and is renewed weekly into private.instagram_token, used
while Netlify's variable holds the token it came from.
By hand, from the Piazza: an administrator can publish one of their own
messages on Telegram, the Facebook Page and the fediverse (from @eventi,
reaching Bluesky through the bridge, and as a post of the Mastodon
mirror), from the message's menu after a confirmation (piazza-share;
piazza_shares keeps where each went). Only their own: the Piazza is the
members', what goes out becomes public.
When a key stops working, the administrators get an email
(ADMIN_NOTIFY_EMAIL, at most one a day per network, shared/network-alert.ts)
with what to do: when a post is refused for its key, and from
network-watch, which checks the accounts each morning and warns a week
before Facebook's data access lapses (every 90 days, renewed by
generating a token again in the Graph API Explorer).
/api/social-backfill with {"network":"check"} runs the same check now.
Each post shows, besides the event's page, the event's link on that same
network (networkLinks): an Instagram profile as a mention, a Facebook or
Telegram address as it is. The links to other networks stay on the site.
Push notifications
The notification's small icon (Android's status bar) is badge-96.png, a
white silhouette of the board on transparent (src/lib/assets/badge.svg,
drawn by scripts/icons.mjs): the system keeps only the shape, so the
colour icon came out as a grey square. iOS shows the installed app's icon
and delivers pushes only to the site added to the home screen; the
notifications page says so, iPads (which present themselves as Macs)
included.
Members turn on alerts per device on /avvisi (the bell in the header,
shown to everyone: visitors find the feeds there and an invitation to sign
in; also linked from the account page): a zone, a radius, optional categories and words. The
browser's push subscription (endpoint and keys) goes to
push_subscriptions with the zone rounded to about a kilometre; nothing
else leaves the device. When an event becomes visible (inserted as
published and public, or edited into that state), the Netlify function
app/netlify/functions/notify-push.mts asks the database for the devices
to wake (push_targets(): within radius, one of the chosen categories,
matching words, never the author's own devices) and sends the pushes with
web-push; dead devices are dropped (push_forget()). The service worker
shows the notification (app/static/push-sw.js) and opens the event on
tap. Plain edits of an event send nothing.
Notices are opt-in per device (push_subscriptions.notices: none, all,
offer or seek, with their own words in notice_search): a webhook on
public.notices calls the same function, which asks
push_notice_targets() and pushes "Offro: …" or "Cerco: …" with the days
and the place, opening the notice. The migration …_push_notices.sql
creates that webhook trigger itself from the secret in private.secrets
(step 2 below); where the secret is missing it says so and the webhook is
added by hand like the events one.
Setup, once:
- Generate a VAPID key pair:
npx web-push generate-vapid-keys in app/.
In Netlify set PUBLIC_VAPID_PUBLIC_KEY (plain) and VAPID_PRIVATE_KEY
(secret), then redeploy: the "Avvisi" page and its bell appear.
- Give the database the webhook secret so the function can prove itself,
in the SQL editor:
insert into private.secrets (name, value) values ('webhook', '<NOTIFY_WEBHOOK_SECRET>');
Without this row every push is refused silently (the function answers 502
and nobody is woken), and the migrations that build the notices and chat
webhooks skip them. To check the whole chain:
select name from private.secrets; and
select tgname from pg_trigger where tgname like 'notify_push%';
should list webhook and the three triggers notify_push,
notify_push_notices, notify_push_messages. The header the triggers
send must equal NOTIFY_WEBHOOK_SECRET in Netlify and the stored row.
- Add a database webhook
notify_push on public.events for Insert and
Update, POST to https://bachecacilento.org/api/notify-push with the
x-webhook-secret header, like the other two. The one on
public.notices (notify_push_notices) comes with the migration when
the secret is already there.
iPhone and iPad deliver pushes only to the app installed on the home
screen; the page says so. npm test in app/ covers the decision and the
payload; supabase/tests/test_9g_push.sql covers the targeting.
Recurring chores
When
What
A new account appears (mail; badge only with manual approval)
Nothing, with automatic approval; otherwise approve or reject it on the Amministrazione page, pending accounts' events stay "non verificati"
A report arrives
Amministrazione → Segnalazioni: hide the event or place, or dismiss the report
An ownership request is escalated (mail, badge)
Amministrazione → Richieste: hand the card over or reject
A migration is added under supabase/migrations/
supabase db push from the repository root (needs supabase login and supabase link once)
Monthly
npm run prune in import/ to delete flyer files no event refers to
Once, after adopting flyer previews
npm run thumbs in import/
Yearly
Domain renewal at Namecheap; check the Anthropic credit balance
Every night at 02:30 UTC, automatic
nightly_housekeeping() via pg_cron: expired unverified events, old past events, orphaned reports; see supabase/README.md
Every night, automatic
Other pg_cron jobs: the chat's retention (02:40), private messages (02:50), fediverse deliveries left over a week (02:50), old alerts and codes (02:55)
Emergency switch
settings.lockdown, set in Amministrazione → Impostazioni
(«Interruttore di emergenza», one «Salva») or, without signing in, in
Supabase's SQL editor:
update public.settings set lockdown = 3, lockdown_since = now(); -- 0 = normal
Level
Name in Impostazioni
What stops
0
Normale
Nothing
1
Nuovi account sospesi
New accounts: handle_new_user refuses («Registrazioni sospese: riprova più tardi.»); the sign-up page says so
2
Scrivono solo amministratori e facilitatori
1, and every write by a signed-in account that is not an admin or a facilitator, through any table or RPC (trigger lockdown_guard on every table of public and private), flyer uploads, and new push sign-ups (visitors' too). Read markers and view counts go on; so do robots, imports and cron jobs (the Telegram bot and the e-mail intake too)
3
Robot fermi
2, and the robots: private.secret_ok answers false (every RPC behind the webhook secret refuses); the pg_cron jobs that send things out (ap_wake, hearts_send) do nothing; the Netlify functions that run by themselves or receive webhooks stop at their first line and answer 200 (netlify/shared/lockdown.ts, so Telegram and Meta do not send again)
4
Sola lettura
3, and every write through the API (anon, authenticated, service role) but an admin's; the housekeeping cron jobs do nothing
A direct SQL session (SQL editor, psql, migrations) is never refused, nor
are sign-ins of existing accounts. From level 2 the accounts see a bar
(«Scrittura sospesa dagli amministratori.», at 4 «Bacheca in sola
lettura») and no «+»; admins and facilitators see the level's name. Each
change is in the «Registro» (by an admin, or «Un comando SQL»), and
lockdown_since says since when. A table created later gets the guard
with select private.lockdown_guard_attach(); in its migration (the SQL
suite checks that every table has it). Telegram sign-in goes through the
webhook secret, so at 3 and 4 admins sign in by email or Google.
Where to look when something is wrong
- Site not updating: Netlify → Deploys (build log). The installed app picks
up a new version on the next open, sometimes the one after.
- Sign-up mail missing: Supabase → Logs → Auth, then Resend → Logs.
- Import or "Leggi" failing: Netlify → Logs → Functions →
read-flyer
(and read-link for links); the Anthropic console for credit.
- Fediverse, Telegram, Facebook: Netlify → Logs → Functions →
ap-deliver-background (one line per pass, with the cards sent, failed and
left, and the milliseconds per channel); select * from ap_queue; shows what
waits, with its tries and last error and ap-inbox; select * from ap_followers; lists
who follows.
- Link previews wrong: Netlify → Logs → Edge functions →
og;
WhatsApp caches a preview for about a day.
- Feeds empty or erroring:
https://bachecacilento.org/api/events.json
shows the error text; Netlify → Logs → Functions → feed.
- Database: Supabase → Table editor, or SQL editor; RLS keeps the anon key
read-only on published data.
Searching and tags
The home page has date chips (any date, the default: everything from today on; today, weekend, next 7 days, last 7 days, custom), a distance slider and one search box. A repeating event is listed once, at its next occurrence, with a "si ripete" mark. A search
matches every word, as a prefix and stemmed in Italian, against the title,
hashtags, tag names, organizer, place and, unless the visitor unticks "cerca
anche nella descrizione", the description ("famiglia teatro"
finds an event tagged Famiglia whose description mentions "teatrale"). Any
#parola in a description becomes a hashtag: shown as a chip, tappable to
search. Events have no categories: the kinds of events are too many for a
fixed list, so they are described by hashtags alone (Categoria and Prezzo
were turned into hashtags at the end of the descriptions and a price text,
…_event_hashtags.sql). The events filter has a row of the hashtags in
use in the date window (event_hashtags()), as places and notices have;
event pins take the section's colour. Ricorrenza stays, set by the
database. The tag machinery remains for the places' kinds and for any
group an admin adds; tag_groups.filterable shows one as a filter. The places' "Tipo" group is treated
the same way: shown on the cards, not offered as a filter (the producers
have their own chip, and the search box finds a kind by name).
Luoghi (/luoghi, "Luoghi, associazioni e produttori" on wide screens)
holds the producers too, on one map and one list sorted by distance: a
card with a kind of what is made and sold locally (PRODUCER_SLUGS:
Produttore, Artigiano, Bottega, Cooperativa) has the leaf in green, the
others the house in orange (withSectionLook). Two chips keep one side
(filters.side, solo=produttori|luoghi in the link): "Produttori" asks
for any of those kinds and labels the hashtag row "Prodotti"; "Luoghi e
associazioni" leaves out the cards with only those kinds, except while one
organizes or hosts an event in the next 30 days (places_nearby(…, with_events), place_has_upcoming()). The chip "Aperto al pubblico"
keeps the places one can walk into (public_space). The old /produttori
address redirects to /luoghi?solo=produttori and keeps its link preview.
Switching section keeps only the zone and the distance; search, tags and
dates reset.
Annunci: offers and requests
"Annunci" is a third section (/annunci, tab after Luoghi): a card is
"Offro" or "Cerco" (tipo=offro|cerco in the link), with a title, a
description whose #hashtags are the vocabulary of the section (#casa
#affittasi #passaggio #mobili #lavoro, suggested while typing and shown as
a row with counts), a spot on the map (the village is enough), an optional
photo, and contacts on request like the other cards. A notice may carry a
day or a span of days (starts_on, ends_on, region-local dates without a
time: a lift on the 3rd, a room from the 1st to the 15th, firewood until
the end of the month; "Al" alone means until): it shows on the card, the
date chips of the section (Qualsiasi data, Oggi, Questo weekend, Prossimi
7 giorni, Scegli le date; date= in the link as on Eventi, default any)
keep the dated notices that overlap the window and every undated one, and
the notice leaves the map the day after its last day. Otherwise a notice
stays up for 60 days, renewable from its page ("Rinnova", undated notices
only) up to 180 days ahead; a dated one stays until its last day whatever
the expiry. Expired or past notices are deleted by the nightly job a week
later.
Reports work as on places (auto-hide, admin page). Table notices, RPCs
notices_nearby, notice_detail, notice_contact_details,
notice_hashtags in supabase/migrations/…_notices.sql; pages under
app/src/routes/annunci and /a/<id>; link previews "Offro: …" with the
hashtags last.
Hashtags double as a shared vocabulary, which is how producers list what
they have ("#pomodori #olio #carote" in the description) without a stock
system. On the places page, once a kind is selected (say Produttore), a
row lists the hashtags used by every place of that kind in the directory
(capped at the 1000 most recently updated places, so the vocabulary is the
same everywhere), each with the number of those places within the search
radius; words nobody nearby uses are dimmed. A tap adds #word to the
search. Spellings are grouped by Italian stem, so
"pomodori" and "pomodoro" are one chip (hashtag_stem(),
place_hashtags()). In both forms, typing # offers completions from the
hashtags already in use, matched by similarity so "#pomm" proposes
"#pomodori" (hashtag_suggest(), pg_trgm); with nothing typed, the most
used hashtags are offered to copy from.
A tag chip in the filter bar is ticked or not. Cards need any of the ticked
tags, or all of them when the visitor switches "almeno uno" to "tutti"
(all=1 in the link; tags= carries the ticked tags). Only tags some
published card carries get a chip (tag_usage()). The database and the
link also accept excluded tags (not=), kept for feeds and links, without
a control in the bar.
The Info page
The Info page (/info, app/src/routes/info/+page.svelte) has four tabs,
each a Markdown file in app/src/content/:
- Guida (
info.md): the project, who is behind it, contacts, and «In
breve», one line per tab to go further;
- Aggiungere (
info-eventi.md): signing in, the app on the phone,
then events, spreading them, cards and annunci;
- Restare aggiornati (
info-aggiornati.md): social accounts, email,
what an account adds;
- Dati e trasparenza (
info-dati.md): who runs the site, privacy, the
source code.
The pages are written as a layered introduction. Someone who does not
understand a page at first sight does not try, and leaves; someone who
found the simple things easy comes back for more. So each tab starts with
what a newcomer needs to do the simple thing (add an event, follow the
Bacheca), in a few short sentences, and ends with a closed «Per esperti»
fold-out (same name in every tab) for the rest: festivals with a
programme, automatic publishing, calendars and feeds, open data. The
test for the first level: does it help a newcomer use the site and act?
What only explains how the site works (imports, automatic sources, rules)
or serves an advanced action goes in «Per esperti». Leave out
what does not change what the reader does: internal rules, limits and
numbers belong in this README, not on the page. A new feature gets at most
a sentence where a reader needs it, in the newcomer part only if newcomers
use it.
<details>/<summary> are allowed in these pages only
(renderMarkdown(…, folds)); a link to a heading inside a closed fold-out
opens it. Headings get their anchor from their text, and the app links to
some of them (/info#sui-social, #calendario-e-feed, #fediverso,
#dati-aperti, #contatti): keep those texts, or update the links.
Language
The interface is Italian. All strings live in app/src/lib/i18n/it.ts;
en.ts defines the shape and keeps an English version. Dates and times are
always formatted in Italian (locale in app/src/lib/format.ts), whatever
the phone's language. Tag and group names are data, fixed in
Italian: see the seed and the …_italian_tag_names.sql migration.
Build progress
Following the build order in SPEC.md §11:
- 1. Repo skeleton, SvelteKit app, Tailwind, Netlify config, Leaflet map centred on the region
- 2. Supabase migrations, PostGIS, RLS, seed tags,
events_nearby (see supabase/README.md)
- 3. Home page: events on map and list; date and distance filters
- 4. Tag filter controls; URL-synced filters
- 5. Auth pages; profiles trigger; first admin
- 6. Add / edit event form
- 7. Event detail page; reports
- 8. Admin page (
/admin: accounts, reports, tags, settings); sign-up notification mail through Resend
- 9. Nightly housekeeping job (pg_cron, 02:30 UTC) plus
bacheca prune-flyers for orphaned files
- 10. PWA manifest and service worker
- [~] 11. Import:
bacheca add for one flyer or message and bacheca import-ics for a calendar feed (done); WhatsApp export batch with review CSV (not started, on hold)
- 12. Polish: dark mode, empty, loading and error states, Italian interface, README
Beyond the spec, from use: free-text search with hashtags, organizer and
contact fields, price as tags, Italian dates everywhere, Info page, manual
search zone, flyer previews and link previews for chat apps, share and copy
buttons, calendar and GeoJSON feeds, calendar import, festivals with a
programme, the places directory, one icon, custom domain and email setup
(see Administration).
Since then: organizers and venues linked to cards (with confirmation),
Posta (private messages, requests, news), saved alerts with push and email,
the email digest, La mia zona, the fediverse accounts, the import at the top
of the event form, events of others and suggestions.
Open: a publishing API with per-account tokens, a feed for places, reading
replies from the fediverse.