3.8 KiB
CyberHybridHub Runbook
This is a focused runbook for working safely in the current CyberHybridHub codebase.
1. Architecture Snapshot
- Framework: Fresh 2 with Vite (
main.ts) - Server runtime: Deno
- Persistence: PostgreSQL + Drizzle (
db/schema.ts,db/db.ts) - Supplemental cache layer:
modules/KvCacheStore.ts - Authentication:
/auth/loginstarts OAuth flow/auth/callbackexchanges code, upserts user, stores tokens, sets cookies/auth/validaterefreshes token/session
- Authorization:
services/authMiddleware.ts+services/authRouteConfig.ts
2. Critical Invariants
- Database search path must keep
publicfirst:SET search_path TO public, memory, checkpoints. - OAuth callback must guarantee parent
usersrow exists before writing touser_tokens. - Concurrent session support depends on composite key
(user_id, state_id)inuser_tokens. - Cookie sealing/unsealing must stay compatible with
state_keysrecords.
If these drift, auth failures and FK errors are likely.
3. High-Risk Files
routes/auth/callback.tsroutes/auth/validate.tsservices/stateMiddleware.tsservices/authMiddleware.tsdb/db.tsdb/sqlUserRepository.tsmodules/KvCacheStore.ts
4. Local Setup Checklist
- Copy
.env.exampleto.env. - Set
POSTGRES_OPTIONS. - Set OAuth env vars (
AUTHORITY,CLIENT_ID,CLIENT_SECRET,REDIRECT_URI,TOKEN_URL,REDIRECT_HOME). - Start app:
deno task dev.
5. Verification Commands
Baseline quality:
deno task check
Auth callback regression:
deno task test:auth-callback-db
E2E suite:
deno task e2e
6. Troubleshooting
FK error on token insert
Symptom:
- foreign key violation for
user_tokens_user_id_users_id_fk
Checks:
- Confirm callback still upserts/ensures user before token write.
- Confirm writes target expected schema/tables.
- Confirm
POSTGRES_OPTIONSpoints to the intended database. - Restart server to avoid stale process code paths.
Session appears invalid after login
Checks:
- Verify
xx_state_idandsessioncookies are both present. - Confirm
state_keysrow exists for the same state ID. - Ensure cookie hash/state key validation logic remains unchanged.
Payments in local mode
- If
SANDBOX_MODE=trueorDISABLE_EXTERNAL_APIS=true, payment intent flow stays local and does not call Stripe.
Islands disappear after load (production / Ubuntu server)
Symptom:
- Island components (e.g. WelcomeBar, GuestHome) render briefly then vanish when the app is run from a production build on another machine (e.g. Ubuntu).
Cause:
- Multiple copies of Preact end up in the bundle/cache. Hydration then fails and Preact can tear down the island DOM. Common when the server has a different or stale Deno cache than the machine that built the app.
Checks and fix:
-
On the deployment server (Ubuntu), force a clean dependency install before building:
deno install -r --allow-scripts deno task build deno task start -
Ensure the process working directory is the project root so that
_fresh/server.jsand_fresh/static/are found (e.g. in systemd setWorkingDirectory=to the app directory). -
For reproducible builds across machines, consider re-enabling the lockfile in
deno.json("lock": true) and committingdeno.lock, then using the same lock on the server. -
Do not use
esm.shfor Preact (this project already usesnpm:preact); duplicate Preact from mixed sources is a common cause.
7. Change Discipline
- Keep docs and code aligned when behavior changes.
- Avoid adding temporary root-level feature summary markdown files.
- After auth/session/database changes, always run:
deno task checkdeno task test:auth-callback-db