Operating AURELITH
This is the reference for the foundation phase: architecture, environment, tokens, error handling, and a status table that names the module behind each capability.
Overview
AURELITH is a hybrid intelligence operating environment: a Next.js App Router application with a local-first data layer (IndexedDB via Dexie), a cloud inference path over Firebase AI Logic, and a domain layer where every record, error and entitlement is schema-defined.
The product is deliberately honest about capability. Cloud inference without configuration reports CLOUD_MODEL_UNAVAILABLE; local inference without a runtime reports LOCAL_MODEL_NOT_READY. No placeholder answer is ever generated.
Architecture
- apps/web/src/app — App Router routes. Public surfaces are server components; the workspace shell and domain surfaces are client components over IndexedDB.
- src/lib/domain — Zod schemas, the error taxonomy and the entitlement engine. No React, no browser APIs.
- src/lib/inference — the
HybridInferenceClientand its two adapters. UI never calls a provider SDK directly. - src/lib/db — Dexie schema and repositories. Every write is schema-parsed before persistence.
- src/styles — the token layers: primitives, semantic themes, Tailwind aliases.
// Execution mode is a request-time decision, not a claim.
const decision = await hybridInferenceClient.route("hybrid");
if ("error" in decision) {
// Both backends reported unavailable — surface the taxonomy code and reason.
return decision.error; // e.g. MODEL_UNAVAILABLE
}
// decision.source === "local" | "cloud"
const result = await hybridInferenceClient.generate({
prompt,
model: "gemini-3.8-flash",
mode: "hybrid",
});Configuration
Copy the repository's .env.example to apps/web/.env.local. Next.js only reads env files inside the application directory. Empty Firebase values are a supported state: the workspace runs local-first and the header states it.
# apps/web/.env.local — copy from the repository root .env.example
NEXT_PUBLIC_FIREBASE_API_KEY=...
NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=your-project.firebaseapp.com
NEXT_PUBLIC_FIREBASE_PROJECT_ID=your-project
NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET=your-project.appspot.com
NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID=...
NEXT_PUBLIC_FIREBASE_APP_ID=...
# Firebase AI Logic (Gemini)
NEXT_PUBLIC_FIREBASE_AI_MODEL=gemini-3.8-flash
# App Check (optional at boot; required before production traffic)
NEXT_PUBLIC_RECAPTCHA_ENTERPRISE_SITE_KEY=App Check uses reCAPTCHA Enterprise with the site key above. In development, register a debug token in the Firebase console before testing protected endpoints.
Design system
Three layers. Primitives (--palette-*) never appear in components. Semantic tokens (--color-background-*, --color-text-*, --color-action-*, --color-intelligence-*) are rewritten per theme. Tailwind aliases expose them as bg-surface, text-ink, border-line.
Themes: Obsidian Intelligence, Arctic Clarity, Midnight Graphite, Solar Meridian, Deep Aurora, High Contrast. Motion durations are tokens (80 / 140 / 220 / 360 / 520ms) and collapse to 1ms under the reduced-motion preference.
Switch themes in the workspace header or at Settings → Themes. Press ⌘ K for search.
Error taxonomy
Thirty-seven stable codes, each with a title, plain-language explanation, recovery action and retryability. Codes are persisted in execution records and audit events, so they are treated as API surface.
import { AurelithError, toAurelithError } from "@/lib/domain/errors";
try {
await saveExecution(record);
} catch (cause) {
const error = toAurelithError(cause, { context: { operation: "execution.save" } });
// error.code, error.definition.recovery, error.retryable
throw error;
}Security
- Roles resolve to explicit permissions in a data-driven map; the UI never hardcodes a check.
- Cloud requests carry App Check attestation when a site key is configured; the server enforces it only when
AURELITH_ENFORCE_APP_CHECKis on, which production configuration requires. - A local-only policy refuses cloud and hybrid requests in the client router; the server records provenance but does not enforce an egress policy.
- Payments unlock entitlements only when network, amount and verification agree.
- Security headers (nosniff, frame-deny, referrer policy, permissions policy) are set in next.config.ts.
Server-side enforcement (Firestore rules, Cloud Functions authorisation) is not part of this phase; client checks are advisory until it lands.
Billing
Plan definitions, entitlement keys and payment schemas (fiat and on-chain) exist and are validated. No payment provider is connected in this phase: the pricing page says so, and no success state is fabricated.
When connecting a provider, the settlement invariant is: intent.network === tx.network ∧ intent.amountMinor === tx.amountMinor ∧ tx.verification === "verified".
Implementation status
Each row below names the module that implements it. Where a capability is absent, the product reports it as unavailable rather than rendering an empty success.
| Area | State |
|---|---|
| Local generation (with streaming) | Implemented — src/lib/inference/local-adapter.ts via the browser Prompt API |
| Cloud generation | Implemented — src/lib/inference/firebase-adapter.ts over Firebase AI Logic |
| Routing and fallback | Implemented — src/lib/inference/router.ts, fallback.ts |
| Execution record | Implemented — beginInferenceExecution / completeInferenceExecution |
| Knowledge ingestion | Implemented — functions/src/knowledge (parse, chunk, embed) |
| Retrieval | Implemented — lexical BM25 with semantic when embeddings exist; degraded mode reported |
| Agent runs | Implemented — functions/src/modules/agent-runs.ts |
| Workflow runs | Implemented — functions/src/workflows/runtime.ts |
| Server authorization and org administration | Implemented — functions/src/lib/authz.ts, modules/organizations.ts, modules/roles.ts |
| Payment verification and settlement | Implemented — functions/src/payments (EVM, Solana, fiat webhook) |
| Enterprise SSO | Implemented for OIDC — functions/src/sso; SAML is out of scope for v1 |
| REST /api/v1 façade | Not deployed — docs/API_CONTRACTS.md is the target contract; the live wire surface is callables |
| Billing checkout | Card checkout is not connected in this deployment — plan changes and crypto settlement are implemented server-side |
Continue to the workspace .