This document is designed to give AI coding assistants and autonomous agents the complete technical context, architecture schema, and structural conventions of Aetheris v3.0. Read this file fully before creating new features or modifying the core gameplay loop.
Aetheris is an idle/clicker MMO hybrid built on a serverless stack meant to function at scale on Cloudflare's free tier. The architecture specifically avoids long-running processes (like Node.js servers) in favor of Edge computing.
packages/web/- React/Phaser frontend.src/App.tsx- Main shell, handles tab navigation (forge,upgrades,market,leaderboard,achievements,profile).src/useGameState.ts- God-hook managing the synchronization between local clicks and the remote backend polling mechanism. Keep complex game math here.src/PhaserGame.tsx- The graphical interface. Communicates with React viaReact.MutableRefObjectand imperative handles.src/Market.tsx&src/PriceChart.tsx- Complex UI for the order book and native canvas candlestick charts.src/PasskeyAuth.tsx- WebAuthn registration and verification flows.
packages/backend/- Cloudflare Worker running Hono.src/index.ts- All API routes. Keeps business logic entirely inside Cloudflare Workers.schema.sql- Base DB schema.migration_*.sql- Sequential migrations for updating the D1 database.
packages/contracts/- Hardhat workspace for Solidity. (Currently mostly scaffolding, active logic resides in backend).
- Package Manager: Bun (
bun install,bun run dev). - Database: Cloudflare D1 (SQLite semantics). No foreign key constraints enabled by default.
ALTER TABLEis limited. - Build/Lint: Strict ESLint flat config + Prettier. Run
bun run fixprior to any PR. - State Management: React local state synced periodically with D1 backend. Immediate visual feedback is prioritized over strict real-time validation to handle edge latency elegantly.
When adding new features, note the following tables:
mainframe_state: Singleton table (id=1). Tracksintegrity,max_integrity, andlast_regen_atfor boss HP.users: Storeshash_balance,data_balance,cred_balanceand stats.market_orders&trades: Used by the order matching engine.passkey_credentials: Maps public keys touser_ids for WebAuthn.
Warning: D1 writes are asynchronously batched under the hood, but reads are highly distributed. The Hono code executes matching engines serially, which works at this scale but must avoid complex distributed locks.
- Backend Extensions: Add new Hono routes in
packages/backend/src/index.ts. Remember to interact withc.env.DBsecurely using bound statements (?1, ?2). - Frontend Extensions: Expose backend endpoints via functions in
packages/web/src/useGameState.tsor directly within the new UI component if isolated (likeMarket.tsx). - UI Components: Build inside
packages/web/src/. Rely onTailwind CSS. Green/Black matrix aesthetics are preferred.
The frontend and backend both run on Cloudflare. The backend worker exposes api.aetheris-backend.workers.dev (or similarly named domains), and the frontend connects via VITE_API_URL fallback constants.