Skip to content

Architecture Overview ​

Go Bananas! is built as an edge-deployed, multi-tenant MCP server on Cloudflare's global network.

High-Level Architecture ​

Multi-provider routing flow

MCP clients, the REST API, and the Web Console all hit the same Cloudflare Edge Worker, which routes through the model registry to whichever provider the tenant chose for that request.

Key Design Principles ​

1. Edge-First Architecture ​

Deployed to 300+ Cloudflare data centers worldwide:

  • Sub-10ms routing to nearest edge
  • Automatic scaling with no cold starts
  • Global data via Durable Objects

2. Multi-Tenant Isolation ​

Complete data separation between tenants:

  • Database: All rows filtered by tenant_id
  • Storage: R2 keys prefixed with {tenant_id}/
  • API Keys: Multiple keys per tenant

3. Stateful Sessions ​

Durable Objects maintain conversation context:

  • Session tracking: last_image_id for conversational editing
  • Request-scoped: Context lives for request duration
  • Persistent state: Session data saved to D1

4. Hybrid Storage ​

Optimized for different data types:

  • R2: Binary image data (cost-effective, CDN-backed)
  • D1: Metadata, relationships, search indexes
  • KV: Fast lookups for config and keys

Component Overview ​

Component Diagram

Worker entry point, MCP Agent, services layer, and storage

ComponentTechnologyPurpose
Entry PointCloudflare WorkerRequest routing, auth
MCP AgentDurable ObjectStateful MCP handling
DatabaseD1 (SQLite)Metadata, relationships
Object StorageR2Image files
CacheKVAPI keys, config
AI BackendGemini API + OpenAI APIImage generation (per-tenant model registry)

Request Lifecycle ​

Every request follows this path:

  1. Ingress → Worker receives HTTP request
  2. Authentication → OAuth bearer token or API key validated
  3. Routing → Request forwarded to Durable Object
  4. Execution → MCP tool processes request
  5. Storage → Results saved to R2/D1
  6. Response → Results returned to client

Documentation Structure ​

Explore each architectural component:

SectionCoverage
System OverviewComplete system diagram
Request FlowRequest processing sequence
Multi-TenancyTenant isolation patterns
Data FlowHow data moves through the system
Storage ArchitectureR2, D1, and KV patterns
Session ManagementStateful conversation handling
Character SystemCharacter reference architecture
SecurityEncryption and access control

Technology Stack ​

Runtime ​

  • Cloudflare Workers - V8 isolate runtime
  • Durable Objects - Stateful edge compute
  • TypeScript - Type-safe development

Storage ​

  • D1 - Serverless SQLite database
  • R2 - S3-compatible object storage
  • KV - Key-value store

Frontend ​

  • React 18 - UI framework
  • Vite - Build tool
  • TailwindCSS - Styling

External ​

  • Gemini API (Flash Lite, Flash, Pro) - Image generation
  • OpenAI API (GPT Image 2, GPT Image 2.5 Flare and Sunburst) - Alternative image provider, tenant-selectable
  • MCP Protocol - AI integration standard

Performance Characteristics ​

MetricTargetTypical
Auth latency<5ms2-3ms
D1 query<10ms3-5ms
R2 read<50ms20-30ms
Provider call (Flash)<10s3-5s
Provider call (Pro / OpenAI)<30s8-25s
E2E generation<15s5-8s

Scaling Model ​

Deployment Model

Deployed to 300+ edge locations worldwide

  • Workers: Unlimited parallel execution
  • Durable Objects: One per session ID
  • D1: Shared with concurrent access
  • R2: Unlimited parallel reads/writes

Next Steps ​

Released under the MIT License.