flora is a fast and secure runtime that lets you write discord bots for your servers, with a rich TypeScript SDK, without worrying about running infrastructure. [mirror]
1# Flora Runtime
2
3The core Rust application powering Flora's Discord bot engine with a multi-threaded V8 JavaScript runtime.
4
5## Architecture
6
7A single-process application that bridges Discord events to isolated JavaScript runtimes:
8
9- **Discord client integration** (Serenity) receives gateway events and serializes them for JavaScript
10- **Multi-threaded worker pool** manages per-guild V8 isolates for isolation and performance
11- **Deno Core extensions** expose Discord operations (messages, interactions, KV storage) to JavaScript code
12- **HTTP API layer** (Axum + utoipa) provides REST endpoints with OpenAPI documentation
13- **Authentication** supports Discord OAuth session management and long-lived API tokens for CLI auth
14- **Persistence** spans PostgreSQL (deployments, tokens), Redis (sessions, cache), and Sled (embedded KV stores)
15
16## Key Components
17
18- `runtime.rs` — Worker pool architecture managing isolates and event dispatch
19- `discord_handler.rs` — Event serialization and routing to JavaScript handlers
20- `ops/` — Deno Core extensions exposing Discord operations (messages, interactions, KV, TLS)
21- `handlers/` — REST API endpoints grouped by feature (auth, deployments, KV, metrics, logs)
22- `bundler.rs` — Custom TypeScript bundler using oxc with source map generation
23- `auth.rs` — Discord OAuth flows, HMAC-signed sessions, token refresh via Redis
24- `deployments.rs` — Guild script storage in Postgres with Redis caching
25- `kv.rs` — Per-guild key-value store service backed by Sled
26- `tokens.rs` — API token management for CLI authentication (SHA256-hashed)
27- `metrics.rs` — Prometheus-style metrics for isolate health and dispatch latency
28- `log_sink.rs` — Circular log buffer with SSE streaming support