2.6 KiB
2.6 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.
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