feat: scaffold newsfeed — user-controlled news feed
Some checks failed
deploy / build (push) Failing after 7s
deploy / deploy-api (push) Has been skipped
deploy / deploy-web (push) Has been skipped

A self-hosted feed where the user owns the ranking: per-source and signed
per-interest weights, decayed by recency, via a transparent deterministic
scorer. Content is sourced algorithmically (worker RSS/Atom polling) and
agentically (per-user API tokens POSTing candidates to the ingest endpoint).
Single-user today, multi-user by construction (every row keyed on user_id).

Rust cargo workspace + Vite/React/SWC/TS SPA:
- newsfeed-entities: DTOs (ts-rs bindings -> web/src/api/bindings)
- newsfeed-core: ranking, auth primitives, ingest, data-access ports
- newsfeed-data: SQLite adapters (sqlx, runtime queries)
- newsfeed-api: axum REST/JSON daemon
- newsfeed-worker: RSS polling + rescoring loop
- web: responsive, mobile-first SPA (React Query, generated types)

Deploy (Gitea Actions, build static musl + SPA, rsync as gitea_ci):
api+worker -> slartibartfast, SPA -> oolon (nginx serves + proxies /v1).

Deliberate deviations from house conventions (documented in CLAUDE.md/readme):
- SQLite instead of Postgres; api+worker co-locate sharing one DB file.
- Runtime sqlx queries instead of query! macros (SQLite dynamic typing;
  keeps CI database-free).

Verified end-to-end: auth, token ingest, interest-weighted ranking, signals,
pagination (curl + browser); cargo fmt/clippy -D/test and pnpm build/lint pass.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016fKZzDpvjiJ9eYbPGgJvUP
This commit is contained in:
2026-07-08 11:36:57 +03:00
commit 5ce52fff4d
104 changed files with 10963 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
# newsfeed-api configuration (production). Rendered to /etc/newsfeed/config.toml.
#
# This file contains no secrets — newsfeed uses SQLite (no DB password), and session
# cookies / API tokens are random values hashed at rest (no signing key). It is therefore
# committed as concrete values, not {{PLACEHOLDER}} templates. Env (NEWSFEED_*) still
# overrides any value at runtime.
# Bind the mesh-routable address so the oolon proxy can reach it. firewalld
# (newsfeed-api service) bounds who may connect; TLS terminates at oolon.
bind = "0.0.0.0:8081"
database_path = "/var/lib/newsfeed/newsfeed.db"
session_ttl_days = 30
max_db_connections = 5
# Same-origin in production (oolon serves the SPA and proxies the API), so no CORS.
cors_origins = []
# Cookies are only sent over HTTPS (the browser talks to oolon over TLS).
cookie_secure = true

View File

@@ -0,0 +1,16 @@
# newsfeed-worker configuration (production). Rendered to /etc/newsfeed/worker.toml.
# No secrets (see config.toml.tmpl).
database_path = "/var/lib/newsfeed/newsfeed.db"
max_db_connections = 2
# Poll cadence.
tick_secs = 60
# Don't re-poll the same RSS source more often than this.
source_min_interval_secs = 900
# Sources polled per cycle, and items rescored per user per cycle.
batch = 20
rescore_limit = 500
http_timeout_secs = 20
user_agent = "newsfeed-worker (+https://git.lair.cafe/grenade/newsfeed)"

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<service>
<short>newsfeed-api</short>
<description>newsfeed REST/JSON API. Reached over the WireGuard mesh by the oolon edge
proxy, which terminates TLS and reverse-proxies to this port.</description>
<port protocol="tcp" port="8081"/>
</service>

View File

@@ -0,0 +1,53 @@
# Mesh-only vhost for newsfeed, fronted by the oolon edge proxy (kosherinata site).
# Cert: internal `lair` CA, minted by infra-setup.sh and renewed by step@newsfeed.timer
# (see architecture internal-tls.md). Serves the static SPA and reverse-proxies the API
# to the newsfeed-api daemon on slartibartfast over the WireGuard mesh.
#
# Enable with a relative symlink into sites-enabled (reverse-proxies.md §4):
# ln -sf ../sites-available/newsfeed.internal.conf /etc/nginx/sites-enabled/
upstream newsfeed_api {
server slartibartfast.kosherinata.internal:8081;
keepalive 16;
}
server {
listen 443 ssl;
listen [::]:443 ssl;
http2 on;
server_name newsfeed.internal;
ssl_certificate /etc/nginx/tls/cert/newsfeed.internal.pem;
ssl_certificate_key /etc/nginx/tls/key/newsfeed.internal.pem;
ssl_protocols TLSv1.3;
ssl_trusted_certificate /etc/pki/ca-trust/source/anchors/root-internal.pem;
root /var/www/newsfeed;
index index.html;
# API + health probe → newsfeed-api on slartibartfast.
location /v1/ {
proxy_pass http://newsfeed_api;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# For future WebSocket streaming endpoints, add the standard Upgrade/Connection
# map here (define `$connection_upgrade` once in http context).
}
location = /health {
proxy_pass http://newsfeed_api;
}
# Static SPA with client-side routing fallback.
location / {
try_files $uri $uri/ /index.html;
}
# Long-cache the fingerprinted asset bundle.
location /assets/ {
expires 1y;
add_header Cache-Control "public, immutable";
try_files $uri =404;
}
}

View File

@@ -0,0 +1,45 @@
# Public (WAN) vhost for newsfeed, fronted by the oolon edge proxy.
#
# Provision the Let's Encrypt cert for rob.fyi (architecture external-tls.md — certbot,
# Cloudflare DNS-01, ECDSA) BEFORE enabling this vhost: `nginx -t` fails on a missing
# ssl_certificate, so only symlink this into sites-enabled once the cert exists
# (reverse-proxies.md §4).
#
# Mesh clients cannot use this name (the public-name hairpin gotcha, reverse-proxies.md
# §2) — they use newsfeed.internal instead. Both vhosts share the /var/www/newsfeed
# webroot and the newsfeed_api upstream defined in newsfeed.internal.conf.
server {
listen 443 ssl;
listen [::]:443 ssl;
http2 on;
server_name rob.fyi;
ssl_certificate /etc/letsencrypt/live/rob.fyi/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/rob.fyi/privkey.pem;
# Classical curves for WAN clients that don't speak post-quantum yet (generic.md §11).
ssl_protocols TLSv1.2 TLSv1.3;
root /var/www/newsfeed;
index index.html;
location /v1/ {
proxy_pass http://newsfeed_api;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location = /health {
proxy_pass http://newsfeed_api;
}
location / {
try_files $uri $uri/ /index.html;
}
location /assets/ {
expires 1y;
add_header Cache-Control "public, immutable";
try_files $uri =404;
}
}

View File

@@ -0,0 +1,38 @@
[Unit]
Description=newsfeed REST/JSON API
Documentation=https://git.lair.cafe/grenade/newsfeed
After=network-online.target
Wants=network-online.target
[Service]
# Type=exec (not notify): axum does not sd_notify READY=1, so notify would block until
# TimeoutStartSec. exec treats the unit as started once the binary execs successfully.
Type=exec
User=newsfeed
Group=newsfeed
ExecStart=/usr/local/bin/newsfeed-api --config /etc/newsfeed/config.toml
Restart=on-failure
RestartSec=2
# Hardening (architecture generic.md §8). Relax individually only if a feature needs it.
NoNewPrivileges=true
ProtectSystem=strict
ProtectHome=true
PrivateTmp=true
PrivateDevices=true
ProtectKernelTunables=true
ProtectKernelModules=true
ProtectControlGroups=true
RestrictRealtime=true
RestrictSUIDSGID=true
LockPersonality=true
MemoryDenyWriteExecute=true
SystemCallArchitectures=native
# The SQLite database and WAL live here; shared read/write with newsfeed-worker.
ReadWritePaths=/var/lib/newsfeed
RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6
[Install]
WantedBy=multi-user.target

View File

@@ -0,0 +1,36 @@
[Unit]
Description=newsfeed content-sourcing worker (RSS/Atom polling + rescoring)
Documentation=https://git.lair.cafe/grenade/newsfeed
After=network-online.target newsfeed-api.service
Wants=network-online.target
[Service]
Type=exec
User=newsfeed
Group=newsfeed
ExecStart=/usr/local/bin/newsfeed-worker --config /etc/newsfeed/worker.toml
Restart=on-failure
RestartSec=5
# Hardening (architecture generic.md §8).
NoNewPrivileges=true
ProtectSystem=strict
ProtectHome=true
PrivateTmp=true
PrivateDevices=true
ProtectKernelTunables=true
ProtectKernelModules=true
ProtectControlGroups=true
RestrictRealtime=true
RestrictSUIDSGID=true
LockPersonality=true
MemoryDenyWriteExecute=true
SystemCallArchitectures=native
# Same database file as the api (co-located: SQLite is single-host).
ReadWritePaths=/var/lib/newsfeed
RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6
[Install]
WantedBy=multi-user.target

View File

@@ -0,0 +1,2 @@
#Type Name ID GECOS Home directory Shell
u newsfeed - "newsfeed service account" /var/lib/newsfeed /usr/sbin/nologin