Technical Architecture Document · March 2026

Software Architecture Analysis

AI Story Companion Ecosystem — Hybrid Edge-Cloud Architecture across 5 modular SKUs with magnetic pogo-pin connector interface. v4 updates: Physical Input Architecture (GPIO interrupt format, all controls BACK face + USB-C), Projection Mapping Software Pipeline with 6-step Calibration Engine, and Education Content System integration.

1. Architectural Overview

The AI Story Companion platform uses a hybrid edge-cloud architecture. The AI Audio Cube runs lightweight local inference, audio processing, physical input handling, and camera-based projection mapping on-device (edge), while complex AI tasks — story generation, illustration, music, projection scenes, education content — are offloaded to cloud services. All controls (4 buttons, privacy slide, USB-C) are on the BACK face (parent-facing) of the Cube.

1.1 Physical Input Architecture — GPIO Interrupt Format

All physical controls are mounted on the BACK face of the AI Audio Cube. A single button_handler.py daemon manages all GPIO interrupts in an async event loop. Events are published to an internal message bus consumed by the Audio Pipeline, Camera Service, and Privacy Monitor.

ControlGPIO (BCM)TriggerHandlerEvent Published
Power Button (BACK face)GPIO 17Falling edge, pull-up; debounce 50 msbutton_handler.pybutton_event{id:"power", type:"press"|"long_press"} → power manager
Volume Up (BACK face)GPIO 27Falling edge, pull-up; debounce 50 ms; auto-repeat 150 ms on holdbutton_handler.pybutton_event{id:"vol_up", type:"press"|"auto_repeat"} → audio pipeline
Volume Down (BACK face)GPIO 22Falling edge, pull-up; double-press = mutebutton_handler.pybutton_event{id:"vol_dn", type:"press"|"auto_repeat"|"double"} → audio pipeline
Camera Capture (BACK face)GPIO 5Falling edge, pull-up; disabled if privacy slide CLOSEDbutton_handler.py → camera_svc.pybutton_event{id:"cam", type:"press"} → camera_capture task
🔒 Privacy Slide (BACK face)GPIO 6Both edges, pull-up; CLOSED = GPIO LOWprivacy_monitor.pyslide_event{state:"open"|"closed"} → suspends camera pipeline <100 ms; logged to audit
⚡ USB-C Charge State (BACK face)I²C bus 1, addr 0x6BPMIC polled 1 Hz (TI BQ25895); INT pin GPIO 4pmic_monitor.pycharge_event{status:"charging"|"full"|"disconnected", pct:N} → LED ring + cloud heartbeat
USB-C charging note: The USB-C 3.1 Gen 1 port (5V/3A, 15W) is the primary standalone charging path. The Docking Station provides the same charging via pogo-pin connector — both paths are handled by the BQ25895 PMIC. The pmic_monitor.py service tracks charge state and adjusts LED ring breathing animation to reflect it.

1.2 Module Communication Architecture

All 5 SKUs share a common magnetic pogo-pin connector interface. The connector carries a defined set of signals that enable power delivery, high-speed video, module identification, and synchronisation.

SignalProtocolSpecPurpose
PowerDC Rail12V / 3A (36W max)Powers projection modules via Cube/Dock pass-through
VideoHDMI 2.04K@30fps / 1080p@60fpsCarries projection content from Cube Projection Compositor
Module BusI2C 400kHz7-bit addressingModule Manager ↔ module: config, status, dim command (brightness control)
Frame SyncGPIO5V logic, <1ms jitterSynchronises frames across 4-Sides Module projectors
Module ID1-WireDS2401 64-bit ROMUnique module identification; auto-detected in <3s on attach
GroundShared GND planePower + signal return
Connector Note: The magnetic pogo-pin connector spec was frozen at Phase 1 Month 3. All 5 SKUs share identical female/male connector geometry. The Docking Station passes all signals through to mains power and USB-C PD. Hot-swap is supported — Module Manager re-initialises within 3 seconds of any physical connection change. The I2C dim command is the mechanism used by the person-safety system (1-Proj) to auto-dim the projector within 200ms.

1.3 Projection Mapping Software Pipeline — Calibration Engine

The Calibration Engine is an on-device Python service that runs a 6-step projection mapping pipeline for each attached projection module. It executes automatically on boot and on any module hot-plug event. Projection begins in fallback (uncorrected) mode and transitions to calibrated mode once the pipeline completes (<15 s per module).

StepProcessAlgorithm / APIInputOutputTime Budget
1Module DetectionI2C 1-Wire ID ROM read (DS2401); Module Manager triggers calibration eventHot-plug or boot eventModule type enum (Dome / 1-Proj / 4-Sides)<500 ms
2Camera Initialisationlibcamera CameraManager.get() + configure(); CSI-2 stream startModule type → camera model (OV5647)Active camera handle; raw frame pipeline open<1 s
3Structured-Light ScanProject known binary pattern (or checkerboard) via HDMI → capture with module camera; OpenCV findChessboardCorners()Camera frames + projected pattern2D feature point correspondences<5 s
4Distortion ComputationDome: cv2.calibrateCamera() fisheye model (Brown–Conrady); 1-Proj/4-Sides: cv2.findHomography() perspective modelFeature point correspondencesCamera matrix K; distortion coefficients D; homography matrix H<3 s
5LUT / Warp Map GenerationDome: cv2.initUndistortRectifyMap(); 1-Proj/4-Sides: cv2.warpPerspective() precomputed map; stored to RAM + flashCalibration parameters (K, D, H)Per-pixel warp LUT (float32 map)<2 s
6Compositor UpdatePass warp LUT to OpenGL ES shader via uniform texture; Projection Compositor switches from fallback to calibrated render modeWarp LUTCalibrated projection active — geometry-corrected output<500 ms
Total calibration time: <15 s per module. Re-calibration triggers automatically if: (a) module is hot-plugged; (b) camera detects >5% geometry change during active projection (room moved, object obstructing wall); (c) parent manually requests recalibration via app. Calibration parameters cached to eMMC flash — reused on subsequent boots without full scan if room geometry is stable.

1.4 Module-Aware Projection Renderer

The Projection Compositor (on-device, Custom OpenGL ES) selects a render configuration based on the module set reported by Module Manager. All warp maps from the Calibration Engine are applied as GPU texture lookups.

Module AttachedRender ConfigWarp TypeResolutionNotes
Dome ProjectorFisheye equirectangular warpUndistort LUT (Brown–Conrady)1080p@60fps≥95% dome ceiling coverage; obstacle mask applied
1 Projector ModulePerspective warp (wall plane)Homography H720p@60fpsAuto-dims on person detection <200ms; re-brightens on clear
4 Sides Module4× independent surfaces, frame sync <1msPer-face homography ×44× 720p@60fpsHDMI 1→4 distribution IC; edge blending at seams; active fan cooling
No module / Cube onlyNull renderer (audio-only mode)LED ring animations only; Calibration Engine idle

1.5 AI Processing Pipeline (10 Stages)

#StageComponentLocationTechnology
1Voice InputWake word + VADEdge (device)TensorFlow Lite / Porcupine
2Speech-to-TextASR EngineEdge + Cloud fallbackWhisper.cpp (local small) / Google STT ($0.024/min)
3Safety Check (input)Content FilterCloudLLM guard / custom classifier + education tier validator
4Story Orchestrator + LLMNarrative Manager & Story GeneratorCloudLangChain + LangGraph + Claude 3 Sonnet / GPT-4o + module context + education tier context
5Memory RetrievalVector StoreCloudPinecone / pgvector + education progress store
6Music EngineAdaptive AudioHybridMusicGen / curated S3 library; tier-appropriate mood mapping
7Illustration EngineScene ImagesCloudDALL-E 3 / Stable Diffusion XL; education scene assets from Course CDN
8Text-to-SpeechVoice SynthesisCloud + Edge cacheElevenLabs Pro v2 ($0.12/1K chars) / local Piper TTS; rate-limited by age tier
9Projection RendererModule-aware compositor + Calibration Engine warpEdge (device)Custom OpenGL ES + Calibration Engine LUT per module; person safety via 1-Proj camera
10OutputAudio + Projection + LED + Physical ControlsEdge (device)PulseAudio + HDMI over pogo-pin + LED ring + GPIO BACK face button feedback

2. System Components

2.1 Device Software (Embedded / Edge)

The AI Audio Cube runs a custom Linux-based OS (Buildroot or Yocto). v4 adds the Calibration Engine for projection mapping and splits the Camera layer into a Camera Service (libcamera, capture) and CV Pipeline (OpenCV + TFLite, projection mapping + person detection).

LayerComponentNotes
OSLinux (Yocto/Buildroot)Lightweight, minimal attack surface
RuntimePython 3.11 + asyncioMain application runtime
AudioPulseAudio / ALSAMicrophone array + speaker management
Wake WordPorcupine SDK (on-device)Always-on low power mode
Local ASRWhisper.cpp (tiny/base model)Offline fallback STT
Local TTSPiper / Coqui TTSCache common phrases offline
Physical Input Handlerbutton_handler.py + privacy_monitor.py + pmic_monitor.pyGPIO interrupt daemon: 4 buttons + privacy slide (all BACK face); USB-C charge state via I²C; publishes typed events to internal bus
Module ManagerCustom I2C daemon + 1-Wire readerAuto-detect module via 1-Wire ID in <3s; manage hot-swap; expose module context to cloud; triggers Calibration Engine on detect
Calibration Enginecalibration_engine.py (Python + OpenCV)6-step projection mapping pipeline per module: detect → camera init → structured-light scan → distortion compute → LUT generate → compositor update; runs <15s non-blocking
Camera Servicecamera_svc.py (libcamera + V4L2)Manages all 7 cameras: Sony IMX477 (Cube, FRONT face) + 6× OV5647 (Dome, 1-Proj, 4-Sides); routes frames to Calibration Engine or CV Pipeline; disabled by privacy slide GPIO signal
CV Pipelinecv_pipeline.py (TFLite MobileNet + OpenCV)Person detection on 1-Proj (<200ms auto-dim via I2C dim cmd); fisheye correction (Dome, passes LUT to Calibration Engine); 4-surface keystone + edge blend (4-Sides)
Projection CompositorCustom OpenGL ES rendererSelects render config per module set; applies Calibration Engine warp LUT as GPU texture; drives HDMI over pogo-pin
ConnectivityNetworkManager + BlueZWi-Fi 6 + BLE 5.3 management
OTAMender / SWUpdateSecure firmware update for Cube + all attached modules in single session
SecurityTPM 2.0 + LUKS encryptionSecure boot + storage encryption

2.2 Cloud Backend Microservices

The cloud backend is a set of microservices on Kubernetes. v4 adds the Education Content Service for Adventure Course pack management and progress tracking.

ServiceResponsibilityTech Stack
API GatewayAuth, rate limiting, routingKong / AWS API Gateway
Auth ServiceJWT, OAuth2, device registration, parental consentPython/FastAPI + Keycloak
Story OrchestratorNarrative state machine, LLM calls, module context ingestion, education tier context injectionPython/FastAPI + LangChain + LangGraph
Memory ServiceChild profile, story history, education progress, vector searchPostgreSQL + pgvector / Pinecone
Content SafetyAI output moderation, age filter (input + output), education accuracy classifierPython + custom LLM classifier
Projection Scene ServiceModule-aware scene selection; narrative context → projection content; returns config per module set in <500msPython/FastAPI + Redis cache
Education Content ServiceAdventure Course pack catalogue, curriculum metadata, progress tracking API, tier management, course pack CDN deliveryPython/FastAPI + S3 + CloudFront CDN
Music ServiceDynamic music selection and generation; tier-appropriate mood mappingPython + MusicGen / S3 library
Illustration ServiceScene image generation; education scene assets served from Course CDNPython + DALL-E 3 / SD API
TTS ServiceVoice synthesis, caching; age-tier rate control (Seedlings ≤120 WPM)Python + ElevenLabs Pro v2 / Azure TTS
OTA ServiceFirmware update orchestration for all 5 SKUsGo + Mender API
Parent App APIProfile mgmt, module status, education tier control, sleep reports, subscription mgmtPython/FastAPI
Analytics ServiceUsage tracking, module attach analytics, education progress analytics, sleep reportsPython + ClickHouse
Notification ServicePush notifications, email summaries, new course alertsPython + FCM / SendGrid

2.3 Mobile Application (Parent App)

Cross-platform mobile app (iOS + Android) built with React Native + Expo. Communicates with the Cube over BLE (setup/config/module status) and with cloud backend over REST/HTTPS. v4 additions: Education tier selector (Seedlings / Explorers / Adventurers), Adventure Course marketplace and download management, learning progress dashboard (per subject, per tier), and curriculum alignment view (EYFS/KS/Common Core). Core features retained: live module detection, per-module projection controls, child profile management, content filters, bedtime schedules, sleep summaries.

3. Data Architecture

The platform handles sensitive data about children, requiring careful data architecture with privacy by design. Module connection events and education progress are logged for analytics but never associated with raw child behavioural data. All CV frames are on-device only.

Data TypeStorageRetentionCompliance
Child profiles, age tiers & preferencesPostgreSQL (encrypted)Account lifetimeGDPR/COPPA
Story history & memorypgvector + PostgreSQL12 months rollingGDPR
Education progress (per subject / tier)PostgreSQL + Redis cacheAccount lifetime; exportableGDPR/COPPA
Adventure Course packs (content assets)S3 + CloudFront CDN + local eMMC (device)Indefinite (versioned)Internal + license terms
Voice recordingsProcessed in-flight, NOT storedReal-time onlyCOPPA compliant
Module connection eventsClickHouse (anonymised, device ID only)24 monthsGDPR Art. 89
Projection scene selectionsRedis (short-lived cache) + ClickHouse aggregateReal-time / 30 days aggregateGDPR
Sleep motion dataTime-series DB (InfluxDB)30 days + aggregatedGDPR
Camera captures (Cube IMX477)Processed in-flight → character injection; NOT stored rawThumbnail S3 30 days with consentGDPR/COPPA
CV frames (module cameras)On-device NPU processing only; NOT transmittedReal-time onlyCOPPA compliant
Privacy slide state eventsClickHouse (anonymised, device ID + timestamp)90 daysGDPR Art. 89
Button event logs (debug)CloudWatch Logs7 days (debug tier)Internal
Firmware binaries (all 5 SKUs)S3 + CDN (versioned per SKU)All versions retainedInternal
Auth tokensRedis (short TTL)15 min access / 7d refreshOWASP

4. Security Architecture

Given the child-facing nature of the product, security is a first-class concern at every layer. The module connector interface is isolated by design — I2C commands are validated and sandboxed; no module can issue arbitrary firmware commands.

Device Security

Secure boot (TPM 2.0), encrypted storage (LUKS), signed firmware updates (per-SKU), no debug ports in production, certificate pinning for cloud comms. Module I2C commands validated by Module Manager whitelist.

API Security

mTLS for device-to-cloud, JWT with short expiry, rate limiting per device/account, OWASP Top 10 hardening. Module context passed as signed device attestation token.

AI Content Safety

Multi-layer: system prompt guardrails → LLM content classifier → education accuracy validator → age-appropriate filter (per tier) → parent override. Projection scene content and Adventure Course content screened independently.

Privacy

No voice recording storage (COPPA), GDPR data subject rights API, parental consent flows, right-to-erasure implemented. Module analytics anonymised. Education progress data exportable and deletable on request.

Network Security

All traffic TLS 1.3+, VPC isolation for services, WAF on API Gateway, DDoS protection via Cloudflare.

Module Connector Security

1-Wire ID read-only; I2C commands restricted to approved command set; no module can escalate to OS level; module firmware signed and verified before execution.

🔒 Privacy Slide & Camera Security

Mechanical privacy slide (BACK face) physically blocks Cube lens — GPIO 6 LOW simultaneously suspends camera pipeline <100ms, no software override possible. CV frames from module cameras processed on-device NPU only — never transmitted. Raw camera data never stored. Privacy slide state changes logged (device ID only, no child association). Camera LED reflects slide state in real time.

Education Content Security

Adventure Course packs are signed and verified before installation; curriculum content screened by dedicated education safety classifier (factual accuracy + age appropriateness + curriculum alignment); parental controls enforced server-side — no client-side bypass possible.

5. Scalability & Reliability

99.9%
API Uptime SLA
<800ms
Story Response Latency (p95)
100K+
Active Devices Supported
<500ms
Projection Scene Service Response
<15s
Calibration Engine — full pipeline per module
<200ms
Person Detection → Projector Auto-Dim (1-Proj Safety)
<3s
Module Auto-Detection + Calibration Trigger
<100ms
Privacy Slide → Camera Pipeline Suspend
7
Cameras — 1 Cube + 1 Dome + 1 1-Proj + 4 × 4-Sides
Auto-scaling microservices on Kubernetes (EKS/GKE), multi-region active-passive failover, CDN-delivered media assets (illustrations, audio, Adventure Course packs). Projection Scene Service and Education Content Service scale independently. Cloud outages degrade gracefully — Cube falls back to pre-cached stories and local audio without projection; local Adventure Course packs remain fully functional offline. Monitoring via Prometheus + Grafana + PagerDuty.