Files
gerbeur/mod.ts
khannurien 7960d74c55 v4: weekly digests and monthly recaps go out by email, every email is written once as Markdown in the app's one catalog, and a review of the last two commits removes what they stated twice — users get a weekly digest (what happened to them, what the people and playlists they follow posted, the week's top dumps, the community) and a monthly recap (the month's top dumps and the community), both on by default, in their own style and scheme. digest-service sends what is due every quarter of an hour from digest_schedule (migration 0020), which holds each user's rolling 7- or 30-day period; existing users' first periods are spread over the coming week or month, a digest more than a period late covers the last full one, an empty one isn't sent, and an address like admin@localhost is skipped. Each digest carries a one-click unsubscribe (List-Unsubscribe and List-Unsubscribe-Post, POST /api/users/unsubscribe) and a link to the new /unsubscribe page, which asks before turning that cadence off, since mail scanners open every link; the token (lib/jwt) names the user and the cadence and never expires. The welcome email now says the digests are on. The emails' words moved out of a hand-written api/mail/strings.ts into the Lingui catalogs the interface uses: lingui extracts api/mail/ too, the catalogs moved to a top-level locales/ that both halves read, compile emits ES modules the server imports (api/mail/i18n.ts), messages take ICU plurals, and the labels the settings tab, the unsubscribe page and the emails share are one message each (their French had already drifted apart). Each template writes its email once as Markdown, which is the plain-text part, and EmailKit.render draws its blocks in the style (a lone link is a button, a list item starting with an image a thumbnail row, a numbered list a ranking, --- the footer), so no string is declared for an HTML and a text version; user text is escaped for Markdown, which the welcome body didn't do for usernames, whose _ read as emphasis. paint() set colors before a border-top shorthand that reset them, so every divider was black. The review also gave one home to what was written twice: the locale list (shared/locale.ts, read by lingui.config, the client, the server and its catalog loader), the base style and default scheme (shared/theme.ts), an email's look (lookOf, which digest-service, welcome and reset share), whether email is on (EMAIL_ENABLED, read by email-service and index.html), a setting's column and its default in the digests' SQL (SETTINGS_COLUMNS, DEFAULT_SETTINGS), the unsubscribe token (made once, not parsed back from a URL), AuthProvider's compare-and-store, ThemeProvider's twin style and scheme code (useThemeChoice), the test JWT encoder, and duplicate digest messages. The email palettes stay a flattened copy of the themes' tokens, now under a test that caught Times' secondary and link colors drifting. The Dockerfile copies api/mail and locales so the build extracts the emails' messages and the server finds its catalogs, and deno.json maps @lingui/core for the runtime image. 236 backend tests (new: digest building, sending, catch-up, scheduling and unsubscribing; the Markdown renderer; French from the catalog; palettes against themes; the stagger migration; unsubscribe tokens) and 661 frontend tests (new: the unsubscribe page) pass, and tsc, eslint, doc:lint, deno check, deno lint and deno fmt are clean.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-04 22:14:46 +00:00

69 lines
3.5 KiB
TypeScript

/**
* Documents gerbeur, a small invite-only social platform for sharing links and
* files. The repository holds three parts: the backend in `api/`, the
* frontend in `src/`, and in `shared/` whatever crosses the wire between them.
* [Every module](./all_symbols.html) is listed by path, so the list groups
* them by part and layer.
*
* ## Backend, in `api/`
*
* An Oak server over SQLite answers the API and the WebSocket, and serves the
* built frontend. `api/main.ts` builds the application and listens. A request
* goes to a route, which parses it, calls services and answers. The services
* hold the logic and every SQL query, read rows through the model, and reach
* other sites only through `remote/`. Each folder holds one kind of module,
* and each file is named after its domain.
*
* - `routes/` holds the HTTP API. Each router's page lists its endpoints, with
* their method and path, who may call them, and what they do.
* - `middleware/` holds what runs around the routes, which is auth, errors and
* the Open Graph tags.
* - `services/` holds the logic and every SQL query, one module per domain.
* - `model/` holds each table's row type, guard and mappers.
* - `validators/` holds the guards of the request bodies.
* - `remote/` is the only place that fetches from other sites, and its
* `providers/` build the previews of each kind of site.
* - `mail/` renders each email, one template per email on a shared layout
* that takes every site style, and `services/email-service.ts` sends them.
* - `lib/` holds the helpers that belong to no layer.
* - `db/` opens, creates and migrates the database, and cleans it up at
* startup. `db/migrations/` are applied in order, each once.
* - `config.ts` reads the settings from the environment, and `scripts/` holds
* the icon generator.
*
* ## Shared, in `shared/`
*
* The types and constants both halves use sit here, one module per domain.
* They are the API envelope, each domain's types and request bodies, the
* socket protocol, the validation limits and the role permissions. `shared/`
* imports nothing from either half. The server sends `Date`s, and the client
* reads the same types through `Wire<T>`, where every `Date` is an ISO string.
*
* Beside it, `locales/` holds one Lingui catalogue per language for the whole
* app: the interface's messages, and the emails' that `api/mail/i18n.ts`
* loads compiled.
*
* ## Frontend, in `src/`
*
* The React app is built with Vite and translated with Lingui. `main.tsx`
* mounts it, `App.tsx` holds the providers and the route table, and `i18n.ts`
* sets the language. A page reads the API and the socket through contexts and
* hooks, and draws with components, while utils hold what isn't React at all.
*
* - `pages/` holds one component per route, each naming its route, and the two
* guards that keep routes to signed-in or signed-out visitors.
* - `config/` holds the settings read at startup.
* - `contexts/` holds, for each domain, a `FooContext` with its state and the
* `FooProvider` that fills it.
* - `hooks/` holds every hook, and `components/` only components.
* - `utils/` holds every module that isn't React.
*
* Every layer but `pages/` and `config/` is split into the same domains (auth,
* category, chat, comment, dump, editor, feed, form, layout, player, playlist,
* profile, social, theme, ws, and shared for what belongs to no one domain), so
* the chat lives in `components/chat/`, `contexts/chat/`, `hooks/chat/` and
* `utils/chat/`.
*
* @module
*/