Skip to content
ghwmelite-dotcomPublic

About

πŸ§ͺ Africa's virtual science laboratory β€” 29 interactive simulations across chemistry, biology, physics, pharmacy & medicine, with an AI lab assistant. SvelteKit PWA on Cloudflare (D1, KV, R2, Workers AI).

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Repository files navigation

AfriLab β€” Africa's Virtual Science Laboratory Platform

SvelteKit Svelte 5 Cloudflare Pages TypeScript Tailwind CSS MIT License

Hands-on science education for African universities β€” no physical lab required.
29 interactive experiments across 5 disciplines, an AI lab assistant, and real analytics,
served from the Cloudflare edge to any device, even on flaky connections.


Table of Contents


Overview

Laboratory access is one of the biggest bottlenecks in African science education: equipment is scarce, consumables are expensive, and a single broken centrifuge can sideline an entire cohort. AfriLab closes that gap with a fully simulated laboratory platform where students perform real experimental procedure β€” titrating, pipetting, wiring circuits, reading ECGs β€” in the browser, with measurement recording, AI-guided hints, and instructor oversight built in.

The whole platform is a single SvelteKit application deployed to Cloudflare Pages, backed by D1 (SQLite at the edge), KV sessions, R2 asset storage, and Workers AI for tutoring. It ships as an installable PWA with offline support, so learning doesn't stop when the connection does.


Key Features

Simulations Β Β  AI assistant Β Β  Analytics Β Β  Collaboration Β Β  Offline PWA Β Β  Institutions

  • 29 interactive simulations, 5 disciplines β€” Chemistry, Biology, Physics, Pharmacy, and Medical labs with step-guided procedures, 3D equipment (Three.js), safety banners, timers, and data recorders.
  • AI lab assistant β€” a context-aware tutor powered by Cloudflare Workers AI (@cf/meta/llama-3.1-70b-instruct) that knows your discipline, experiment, current step, and recent measurements β€” and gives progressive hints instead of answers.
  • Progress & analytics β€” measurement recording, lab reports, certificates, a student dashboard with history and progress tracking, a leaderboard, and an instructor analytics view.
  • Collaboration β€” presence indicators and a collaboration panel so students can work together in the lab.
  • Offline-first PWA β€” installable, with a service worker, offline page, and connection indicator.
  • Multi-institution by design β€” institution registry, role-based access (student / instructor / admin), enrollments, assignments, and Google OAuth sign-in alongside email/password auth.

Experiment Catalogue

Every experiment below has a working simulation engine in src/lib/simulations/ and a lab route under src/routes/labs/.

Discipline Experiments
Chemistry Acid–Base Titration Β· UV-Vis Spectroscopy Β· Calorimetry Β· Chromatography Β· Electrochemistry Β· Organic Synthesis
Biology Microscopy Β· DNA Extraction Β· Cell Division Β· Enzyme Kinetics Β· Genetics Β· Photosynthesis Β· Ecosystem
Physics Ohm's Law Β· Optics Β· Pendulum Β· Projectile Motion Β· Thermodynamics Β· Wave Motion
Pharmacy Compounding Β· Dosage Calculations Β· Drug Interactions Β· Pharmacokinetics Β· Quality Control
Medical Auscultation Β· Blood Analysis Β· ECG Reading Β· Patient Assessment Β· Vital Signs

Architecture

AfriLab architecture

AfriLab runs entirely on Cloudflare's edge network β€” there is no separate backend to deploy:

Layer Technology Role
Frontend & SSR SvelteKit 2 + Svelte 5 on Cloudflare Pages Server-rendered UI, lab routes, dashboards
API SvelteKit server routes (/api/*) AI chat & hints, analytics, demo lifecycle, seeding
Database Cloudflare D1 (SQLite) Users, institutions, experiments, sessions, measurements, assessments
Sessions & cache Cloudflare KV Low-latency session storage
Object storage Cloudflare R2 3D models, videos, and lab assets
AI Cloudflare Workers AI Llama 3.1 70B lab assistant and adaptive hints
Auth Custom sessions + Google OAuth 2.0 Email/password and institutional Google sign-in
3D rendering Three.js Interactive lab equipment (beakers, burettes, flasks)

Tech Stack

Category Choice
Framework SvelteKit 2, Svelte 5, Vite 6
Language TypeScript
Styling Tailwind CSS 3 (+ forms & typography plugins)
Platform Cloudflare Pages via @sveltejs/adapter-cloudflare
Data D1, KV, R2
AI Workers AI (@cf/meta/llama-3.1-70b-instruct)
3D Three.js
Unit tests Vitest + Testing Library
E2E tests Playwright

Getting Started

Prerequisites

  • Node.js 18+
  • A Cloudflare account with the Wrangler CLI (npm install -g wrangler)

Setup

# 1. Clone
git clone https://github.com/ghwmelite-dotcom/AfriLab.git
cd AfriLab

# 2. Install dependencies
npm install

# 3. Create the Cloudflare resources
wrangler d1 create afrilab-db
wrangler kv:namespace create SESSIONS
wrangler r2 bucket create afrilab-assets

# 4. Copy the generated IDs into wrangler.toml

# 5. Apply the database schema and seed data
npm run db:migrate          # local D1
npm run db:migrate:prod     # production D1

# 6. Run the dev server
npm run dev

To run with real Cloudflare bindings locally:

npm run build
npm run preview:wrangler

For Google sign-in, set GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET as secrets and configure GOOGLE_REDIRECT_URI (see the comments in wrangler.toml). Without them, email/password auth still works.

Deploy

npm run deploy    # builds and deploys to Cloudflare Pages

Project Structure

afrilab/
β”œβ”€β”€ migrations/                  # D1 schema + seed migrations (0001–0005)
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ lib/
β”‚   β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”‚   β”œβ”€β”€ ai/              # Chat assistant & hint button
β”‚   β”‚   β”‚   β”œβ”€β”€ analytics/       # Dashboard & page tracking
β”‚   β”‚   β”‚   β”œβ”€β”€ collaboration/   # Presence & collaboration panel
β”‚   β”‚   β”‚   β”œβ”€β”€ lab/             # Lab canvas, 3D equipment, data recorder, certificates
β”‚   β”‚   β”‚   β”œβ”€β”€ layout/          # Header, sidebar, footer
β”‚   β”‚   β”‚   β”œβ”€β”€ onboarding/      # First-run experience
β”‚   β”‚   β”‚   β”œβ”€β”€ pwa/             # Install prompt & offline indicator
β”‚   β”‚   β”‚   └── ui/              # Shared UI primitives
β”‚   β”‚   β”œβ”€β”€ server/              # auth, OAuth, db, AI prompt builders & hints
β”‚   β”‚   β”œβ”€β”€ simulations/         # 29 experiment engines, one file each
β”‚   β”‚   β”‚   β”œβ”€β”€ biology/  chemistry/  medical/  pharmacy/  physics/
β”‚   β”‚   β”œβ”€β”€ stores/              # Svelte stores (lab, AI, user, theme, notifications…)
β”‚   β”‚   β”œβ”€β”€ types/               # Shared TypeScript definitions
β”‚   β”‚   └── utils/               # Helpers (incl. Three.js utilities)
β”‚   β”œβ”€β”€ routes/
β”‚   β”‚   β”œβ”€β”€ api/                 # ai/chat, ai/hint, analytics, demo-login, demo-cleanup, seed
β”‚   β”‚   β”œβ”€β”€ auth/                # login, register, logout, Google OAuth flow
β”‚   β”‚   β”œβ”€β”€ dashboard/           # student home, labs, progress, history, leaderboard, profile
β”‚   β”‚   β”œβ”€β”€ instructor/          # students, assignments, analytics
β”‚   β”‚   β”œβ”€β”€ labs/                # 29 lab pages across 5 disciplines
β”‚   β”‚   β”œβ”€β”€ admin/               # admin & seeding
β”‚   β”‚   └── offline/             # offline fallback page
β”‚   β”œβ”€β”€ hooks.server.ts          # session resolution
β”‚   └── service-worker.ts        # PWA offline support
β”œβ”€β”€ e2e/                         # Playwright end-to-end suites
β”œβ”€β”€ static/                      # favicon, web manifest, service worker assets
β”œβ”€β”€ docs/                        # documentation & assets (incl. this README's artwork)
└── wrangler.toml                # Cloudflare bindings & configuration

Testing

npm run test:run       # unit tests (Vitest, single run)
npm run test:coverage  # unit tests with coverage
npm run test:e2e       # Playwright end-to-end tests
npm run test:e2e:ui    # Playwright interactive UI mode

Roadmap

  • Expand the experiment catalogue (organic synthesis pathways, more medical scenarios)
  • Richer instructor tooling: rubric-based grading and cohort comparisons
  • Real-time multiplayer lab benches
  • Localized content for more African languages
  • LMS integration (LTI) for universities

Contributing

Contributions are welcome β€” from new simulations to accessibility fixes.

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/my-experiment
  3. Make your changes (TypeScript, follow the existing code style, add tests for new behavior)
  4. Run npm run test:run and npm run build
  5. Open a pull request

Please report bugs and request experiments via GitHub Issues.


License

Distributed under the MIT License. See LICENSE for details.


Built for African education.
Powered by SvelteKit and the Cloudflare edge.

About

πŸ§ͺ Africa's virtual science laboratory β€” 29 interactive simulations across chemistry, biology, physics, pharmacy & medicine, with an AI lab assistant. SvelteKit PWA on Cloudflare (D1, KV, R2, Workers AI).

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages