How Lion City Scholar Is Built: Our Technical Architecture
Every piece of Lion City Scholar runs on Cloudflare's global edge network — no traditional servers, no containers, no cloud VMs. When a student in Singapore opens the app, their request is handled at a data centre nearby, making every interaction fast.
Here is a bird's-eye view of how it all fits together.
The Core Idea
Lion City Scholar helps students learn from their mistakes. A student photographs a wrong answer, our AI analyses what went wrong, explains the correct approach, and generates similar practice questions — all tailored to the Singapore curriculum.
To make this work reliably and affordably, we built the entire platform on Cloudflare's developer platform.
System Architecture
A request flows through several layers:
- User device — students access the platform via browser or PWA on any phone
- Cloudflare edge — DNS, SSL, DDoS protection, and Turnstile bot verification happen automatically
- Worker — our Hono v4 application routes requests by hostname to the main app or blog
- Storage — D1 for relational data, R2 for images, KV for sessions and rate limiting
- AI providers — multiple providers with automatic failover for mistake analysis
Our Cloudflare Stack
Cloudflare Workers is the compute layer. Our application code runs in lightweight V8 isolates across 300+ global locations. There are no cold starts — responses begin in milliseconds. We use Hono, a fast TypeScript web framework designed for edge runtimes, to handle routing and middleware. Cloudflare D1 is our database. It is serverless SQLite at the edge — fast reads, zero configuration, and automatic replication. We store user accounts, student profiles, mistake records, exam results, and blog posts here. Cloudflare R2 handles image storage. Students upload photos of their work (worksheets, exam papers, handwritten answers). R2 is S3-compatible with zero egress fees, so serving images back to students costs nothing extra. Cloudflare KV powers our sessions and rate limiting. JWT authentication tokens, login rate limits, and API throttling all run through KV's fast key-value lookups with automatic expiry. Cloudflare Turnstile protects our login and signup forms from bots — without annoying CAPTCHAs.Two Sites, One Worker
We run two websites from a single Worker:
- lioncityscholar.ai — the main learning application
- blog.lioncityscholar.ai — this blog, server-side rendered
The Worker inspects the incoming hostname and routes to the right application. Blog pages are rendered as full HTML at the edge with caching, so they load instantly while still being dynamic.
AI-Powered Analysis
The heart of the platform is AI analysis. When a student uploads a mistake, the AI:
- Reads the image and identifies the question
- Pinpoints what the student got wrong and why
- Provides a clear, step-by-step solution
- Generates similar practice questions for reinforcement
We support multiple AI providers — including Google Gemini, Anthropic Claude, OpenAI, and others — through a unified interface. If one provider goes down, the system automatically fails over to a backup. Switching providers requires only a configuration change, not a code change.
Every user has daily usage limits to keep costs predictable and prevent abuse.
Authentication
Students and parents can sign in three ways:
- Email and password — with secure password hashing
- Google sign-in — the most popular choice
- GitHub sign-in — for the tech-savvy
All methods produce the same session token, so the experience is consistent regardless of how you log in.
Security
Security is built into every layer:
- Content Security Policy restricts what scripts, styles, and connections the browser allows
- HSTS enforces HTTPS everywhere, including subdomains
- Rate limiting on all sensitive endpoints prevents brute-force attacks
- Input validation with strict size limits on all user-submitted data
- Escape-first rendering in the blog prevents cross-site scripting by design
Deployment
Deploying the entire platform is a single command. Cloudflare handles global distribution, SSL certificates, DDoS protection, and automatic scaling. There are no servers to patch, no load balancers to configure, and no infrastructure to maintain.
Why This Stack
For an education platform serving Singapore students, this architecture offers three key benefits:
Speed — everything runs at the edge, close to users. No round trips to distant servers. Simplicity — one codebase, one deployment command, one platform. Less infrastructure means more time building features. Cost efficiency — Cloudflare's generous free tiers and serverless pricing mean infrastructure costs stay low as we grow.We believe the best technology is invisible to the user. Students should focus on learning, not loading spinners. This architecture makes that possible.