mirror of
https://github.com/bitbaum/botsmann.git
synced 2026-12-03 20:57:07 +01:00
The product was renamed on 2026-09-14: bitbaum/loki, loki.orangecat.ch, LOKI_* env keys, loki-* units. This repo referenced the old name in 15 files changed, 29 insertions(+), 29 deletions(-). Email addresses at the old sending domain stay until the new domain is verified in Resend. Claude-Session: https://claude.ai/code/session_016YJVAanfj8keVSXyZnTemh Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
3.1 KiB
3.1 KiB
SSOT: Single Source of Truth (Botsmann)
Created: 2026-01-23
Last modified: 2026-08-14
Last modified summary: CSP must allow https://loki.orangecat.ch on script-src and connect-src, and the widget token must be present at next build.
This document is the authoritative SSOT map for where things live and how to use them. Follow this to avoid duplication and drift.
API Responses & Validation
- Source:
lib/api/responses.ts(exported vialib/api/index.ts) - Use:
import { jsonSuccess, jsonError, jsonValidationError, HTTP_STATUS } from '@/lib/api' - Zod helpers:
validateBody,formatZodErrors,hasValidationError,handleErrorinlib/api/responses.ts - Why: Ensures consistent payloads, status codes, and error handling across all routes.
Auth Helpers (Server)
- Source:
lib/api-utils.ts - Use:
import { verifyUser, requireAuth } from '@/lib/api-utils' - Notes:
HTTP_STATUScomes fromlib/api(responses) to keep SSOT for status codes.
Domain Constants
- Source:
lib/constants.ts - Includes:
DOMAIN_ERRORS,API_CONFIG,SYSTEM_PROMPTS, validation constants, model providers. - Use domain errors/messages from here; do not hardcode in routes or components.
Supabase Client
- Client (browser):
createClientComponentClientvialib/auth.tsx - Server (service role):
getServiceClient()inlib/supabase.ts(server-only) - Check configured:
isSupabaseConfigured()inlib/supabase.ts
Bot Configurations
- Source:
data/bots.ts - Use: Import to render navigation, content sections, and metadata for each bot.
Types
- Source:
types/ - Rule: Prefer interfaces for objects,
typefor unions/intersections.
Shared UI Components
- Source:
components/shared/*(e.g.,BotPageTemplate,BotSection) - Rule: Reuse for consistent IA/UX; keep components presentational; move logic to hooks.
Hooks
- Source:
lib/hooks/* - Rule: Encapsulate stateful or effectful logic; keep pure utilities in
lib/.
Environment Variables
- SSOT:
.env.local(not committed) built from.env.example - Never commit: any
.env*files..gitignorealready ignores them. - Rotate immediately if a secret leaks (Supabase service role, anon key, Groq, AWS, etc.).
LOKI_FEEDBACK_TOKEN: public widget token. Must be present atnext build(self-host CD pulls box.env). Runtime-only.envafter deploy does not emit the script — Next tree-shakes an empty token. Production layout also has a public-token fallback so the FAB still ships if the env var is missing at build.- CSP (
next.config.js):script-srcandconnect-srcmust allowhttps://loki.orangecat.chor the browser blockswidget.jsand boot/submit.
Testing
- Unit/integration:
vitest,@testing-library/*→tests/__tests__/ - E2E:
playwright→pnpm run test:e2e
Import Order (SSOT)
- React/Next
- Third-party libs
- Local components
- Local utilities (
lib/*) - Types (
types/*) - Styles
Commit Discipline
- Conventional commits:
type(scope): description - Pre-commit: husky runs
pnpm exec lint-staged(ESLint + Prettier on staged files)