Configuration Reference

System configuration is stored as a single JSON blob in Cloudflare KV under the key config:system. It is cached for 5 minutes. On a cache miss, defaults are used. Admins update config from the /admin/settings panel.

All configuration keys

KeyDefaultTypeDescription
site_nameEast Grinstead Athletics ClubstringClub name — used in email templates
site_urlhttps://egac.pages.devURLBase URL for all links in emails
email_fromno-reply@updates.eastgrinsteadac.co.ukemailResend sender address (must be verified)
venue_nameEast Grinstead Leisure CentrestringVenue name in booking confirmations
venue_addressKing Street, East Grinstead, RH19 3DJstringVenue address in emails
weeks_ahead_booking8integer 1–16Weeks of dates shown in booking invite
capacity_per_slot2integer 1–10Default per-session capacity (age group overrides this)
academy_max_age10integer 5–16Upper age bound for academy routing
admin_email(empty)email or emptyBCC address for admin notifications

How configuration is read

// Read full config (cached for 5 minutes)
const config = await getConfig(env);

// Read a single value
const weeksAhead = parseInt(config.weeks_ahead_booking, 10);

// Typed helpers
const weeksAhead = getWeeksAhead(config);           // → number
const capacity   = getCapacityPerSlot(config);       // → number
const maxAge     = getAcademyMaxAge(config);          // → number

All KV values are stored as strings. The typed helper functions in src/lib/config.ts handle parsing with safe fallbacks.

Validation rules

The validateConfigUpdate() function enforces these rules before saving:

KeyRule
capacity_per_slotInteger between 1 and 10
weeks_ahead_bookingInteger between 1 and 16
academy_max_ageInteger between 5 and 16
email_fromValid email format
site_urlValid URL (parseable by new URL())

Validation errors are returned as an array of strings. The admin settings page displays them inline.

Cache behaviour

const CONFIG_CACHE_KEY = 'config:system';
const CONFIG_TTL_SECONDS = 300; // 5 minutes

// Read: KV → merge with defaults → return
// Write: merge with current → PUT to KV with TTL
// Clear: DELETE from KV (next read uses defaults until repopulated)

After saving, clearConfigCache() deletes the KV entry so the next request immediately picks up the new values rather than waiting for the TTL to expire.

Updating programmatically

import { setSystemConfig } from './src/lib/config';

await setSystemConfig({
  weeks_ahead_booking: '12',
  venue_name: 'New Venue Name',
}, env);

Precedence

Configuration values follow this precedence order (highest to lowest):

  1. KV cache (admin-set values)
  2. CONFIG_DEFAULTS in src/lib/config.ts

There is no file-based config — all runtime behaviour is controlled through KV. wrangler.toml only contains non-secret environment variables (APP_ENV, EMAIL_FROM).

info
The KV free tier allows 1,000 write operations per day. Since config writes only happen when an admin explicitly saves settings, this limit is never a concern in practice.