The API service is the core backend for GhostNote, running as a Cloudflare Worker. It is responsible for database interactions, authentication, message encryption, and business logic.
- Serves RESTful endpoints for the Web Frontend (authentication, dashboard stats, links).
- Handles public submissions and validates access passwords.
- Interacts with Cloudflare D1 (SQLite) via Drizzle ORM.
- Secures stored messages using AES-GCM encryption at rest via the Web Crypto API.
- Communicates directly with the
telegram-botservice via Cloudflare Service Bindings to push notifications.
- Hono Framework: Lightweight routing.
- Drizzle ORM: Type-safe database queries.
- Service Bindings: Secure, private network communication to the Telegram bot worker (
c.env.BOT.fetch). - Encryption at Rest: Messages are encrypted seamlessly on insert and decrypted on retrieval.
src/db/: Drizzle schema and migrations.src/middleware/: Authentication checks (JWT, Internal Service Secret).src/routes/: Hono route handlers (links.ts,dashboard.ts,user.ts,internal.ts).src/utils/: Shared utilities (encryption.ts,password.ts,slug.ts,telegram.ts).drizzle/: Generated SQL migrations.
Local variables are defined in .dev.vars. Production secrets must be set using Wrangler.
JWT_SECRET: Secret used to sign session cookies for the web dashboard.INTERNAL_SERVICE_SECRET: Pre-shared key to authenticate requests coming from thetelegram-botservice.MESSAGE_ENCRYPTION_KEY: 256-bit secure key used for AES-GCM message encryption.FRONTEND_URL: (Optional) Base URL for formatting generated links.
# Install dependencies
npm install
# Run the development server
npm run dev
# Generate new Drizzle migrations (after editing schema.ts)
npm run db:generateDeploy the worker to Cloudflare:
npm run deploy