Skip to content

feat: add core application stack — hardware, scheduling, API, and UI#118

Closed
ng wants to merge 5 commits intodevfrom
feat/frontend-ui
Closed

feat: add core application stack — hardware, scheduling, API, and UI#118
ng wants to merge 5 commits intodevfrom
feat/frontend-ui

Conversation

@ng
Copy link
Copy Markdown
Contributor

@ng ng commented Feb 24, 2026

Summary

Foundational implementation of the SleepyPod core stack, built on top of the existing project scaffolding.

  • DB: Migrates from Prisma to Drizzle ORM with better-sqlite3; adds 11-table SQLite schema covering device config, schedules, biometrics, and runtime state
  • Hardware: Type-safe hardware abstraction layer over the dac.sock Unix socket — sequential command queue, response parser, Pod 3/4/5 support, temperature conversion utilities
  • API: Full tRPC router suite — device control, settings, schedule CRUD, biometrics queries; all inputs validated with Zod
  • Scheduler: node-schedule-backed job manager for temperature, power, alarm, prime, and reboot jobs; timezone-aware, database-driven, auto-reloads on config changes
  • UI: Next.js pages for pod control (/control), settings (/settings), and schedule management (/schedules); mobile-responsive navigation; tRPC-integrated with 5s auto-refresh

Test plan

  • pnpm tsc passes with no errors
  • pnpm lint passes
  • pnpm db:migrate runs without errors on a fresh DB
  • /control page renders and reflects live hardware status when pod is connected
  • /settings page saves timezone and side name changes correctly
  • /schedules page lists and deletes schedules correctly
  • Scheduler loads jobs on startup and logs upcoming invocations
  • POWER_ON / POWER_OFF / TEMPERATURE / ALARM jobs execute against hardware

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • New Features
    • Pod Control interface: real-time temperature adjustment, power management, and priming controls
    • Schedules page: create and manage temperature, power, and alarm schedules by day
    • Settings page: configure timezone, temperature unit, and daily device operations
    • Home dashboard with navigation cards for quick access to key features
    • Health analytics for biometric data tracking and summaries

ng added 5 commits February 22, 2026 22:22
- Remove Prisma dependencies and generated files
- Add Drizzle ORM with better-sqlite3
- Create comprehensive schema with 11 tables:
  * Device settings & configuration
  * Side settings & tap gestures
  * Temperature/power/alarm schedules
  * Device state (runtime)
  * Biometrics (sleep, vitals, movement)
  * System health monitoring
- Configure SQLite with WAL mode for concurrency
- Add migration runner with auto-seeding
- Update package.json scripts for Drizzle workflow
- Create type-safe hardware client for pod communication
- Implement Unix socket communication with dac.sock
- Add sequential command queue to prevent race conditions
- Build message stream parser with delimiter support
- Create response parser for device status and gestures
- Support all hardware commands:
  * Temperature control (per side)
  * Alarm management (vibration, patterns)
  * Power control
  * Priming sequences
  * Device status polling
- Add proper error handling with custom error types
- Support Pod 3/4/5 version detection
- Temperature conversion utilities (°F ↔ level)
- Full TypeScript type safety throughout
- Device router: real-time pod control
  * Get device status from hardware
  * Set temperature per side
  * Power on/off control
  * Alarm management (set, clear)
  * Pod priming
  * Auto-sync with database

- Settings router: configuration management
  * Device settings (timezone, temp unit, daily reboot/priming)
  * Side settings (names, away mode)
  * Tap gesture configuration (CRUD)

- Schedules router: automation management
  * Temperature schedules (CRUD per day/side)
  * Power schedules (on/off times)
  * Alarm schedules (vibration, patterns, duration)
  * Query by day and side

- Biometrics router: health data queries
  * Sleep records with date filtering
  * Vitals data (heart rate, HRV, breathing)
  * Movement tracking
  * Vitals summary statistics

All routers feature:
- Full Zod validation
- Type-safe database operations
- Proper error handling
- Hardware client lifecycle management
- Core scheduler with timezone support
  * Cron-based scheduling via node-schedule
  * Event-driven architecture
  * Graceful shutdown handling
  * Job lifecycle management (schedule, execute, cancel)

- Job manager for pod automation
  * Temperature schedules (per side/day)
  * Power schedules (on/off automation)
  * Alarm schedules (wake-up automation)
  * Daily priming sequences
  * Daily system reboots
  * Auto-reload on database changes
  * Timezone-aware execution

- Type-safe job handling
  * Job types enum (temperature, power, alarm, etc.)
  * Execution results tracking
  * Metadata support per job
  * Event emitter for monitoring

- Database integration
  * Loads schedules from Drizzle DB
  * Respects enabled/disabled flags
  * Supports dynamic schedule updates

- Hardware integration
  * Uses hardware client for execution
  * Proper connection lifecycle
  * Error handling and retry logic

All jobs execute in pod's configured timezone with
proper error handling and logging.
- Pod Control page (/control)
  * Real-time temperature control per side
  * Power on/off controls
  * Temperature adjustment (+/-1°, +/-5°)
  * Device status display (water level, priming, version)
  * Auto-refresh every 5 seconds
  * tRPC integration

- Settings page (/settings)
  * Device settings (timezone, temp unit, daily reboot/priming)
  * Side configuration (names, away mode)
  * Instant updates via tRPC mutations

- Schedules page (/schedules)
  * View temperature schedules per side
  * View alarm schedules
  * Delete schedules
  * Side selector toggle

- Home page (/)
  * Navigation cards to all sections
  * Clean dashboard layout

- Components:
  * TemperatureControl: reusable temp control widget
  * Navigation: responsive nav with mobile bottom bar
  * Uses lucide-react icons

- Layout:
  * Global navigation header
  * Mobile-responsive bottom navigation
  * Consistent container layout

All pages use tRPC for type-safe API calls with
optimistic updates and automatic refetching.
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Feb 24, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9158835 and ad3cf21.

⛔ Files ignored due to path filters (9)
  • generated/prisma/browser.ts is excluded by !**/generated/**
  • generated/prisma/client.ts is excluded by !**/generated/**
  • generated/prisma/commonInputTypes.ts is excluded by !**/generated/**
  • generated/prisma/enums.ts is excluded by !**/generated/**
  • generated/prisma/internal/class.ts is excluded by !**/generated/**
  • generated/prisma/internal/prismaNamespace.ts is excluded by !**/generated/**
  • generated/prisma/internal/prismaNamespaceBrowser.ts is excluded by !**/generated/**
  • generated/prisma/models.ts is excluded by !**/generated/**
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (36)
  • .claude/commands/pr-describe.md
  • app/[lang]/control/page.tsx
  • app/[lang]/page.tsx
  • app/[lang]/schedules/page.tsx
  • app/[lang]/settings/page.tsx
  • drizzle.config.ts
  • package.json
  • prisma.config.ts
  • prisma/schema.prisma
  • src/components/Navigation/Navigation.tsx
  • src/components/SideSelector/SideSelector.tsx
  • src/components/TemperatureControl/TemperatureControl.tsx
  • src/db/index.ts
  • src/db/migrate.ts
  • src/db/migrations/0000_plain_silverclaw.sql
  • src/db/migrations/meta/0000_snapshot.json
  • src/db/migrations/meta/_journal.json
  • src/db/schema.ts
  • src/hardware/client.ts
  • src/hardware/index.ts
  • src/hardware/messageStream.ts
  • src/hardware/responseParser.ts
  • src/hardware/sequentialQueue.ts
  • src/hardware/socketClient.ts
  • src/hardware/types.ts
  • src/lib/prisma.ts
  • src/lib/tempUtils.ts
  • src/scheduler/index.ts
  • src/scheduler/jobManager.ts
  • src/scheduler/scheduler.ts
  • src/scheduler/types.ts
  • src/server/routers/app.ts
  • src/server/routers/biometrics.ts
  • src/server/routers/device.ts
  • src/server/routers/schedules.ts
  • src/server/routers/settings.ts

📝 Walkthrough

Walkthrough

Implements a complete smart pod control application with Drizzle ORM backend, hardware abstraction layer, job scheduling system, tRPC API routers, and React UI pages. Replaces Prisma with Drizzle, adds device communication protocols, automated scheduling, and frontend interfaces for temperature control, settings, and schedule management.

Changes

Cohort / File(s) Summary
Database Migration (Prisma → Drizzle)
drizzle.config.ts, src/db/index.ts, src/db/migrate.ts, src/db/schema.ts, src/db/migrations/*, prisma.config.ts, prisma/schema.prisma, src/lib/prisma.ts
Replaces Prisma ORM with Drizzle ORM using better-sqlite3. Adds comprehensive schema with device settings, side settings, device state, schedules (temperature/power/alarm), biometrics (vitals/movement/sleep), system health, and tap gesture tables. Includes migration files, graceful shutdown handlers, and default data seeding.
Hardware Abstraction Layer
src/hardware/client.ts, src/hardware/types.ts, src/hardware/socketClient.ts, src/hardware/messageStream.ts, src/hardware/responseParser.ts, src/hardware/sequentialQueue.ts, src/hardware/index.ts
Adds complete hardware communication layer for pod control. Includes socket-based client with reconnection logic, message streaming with timeout handling, CBOR response parsing, sequential command queuing to prevent race conditions, and comprehensive type definitions for hardware commands, device status, alarms, gestures, and error handling.
Scheduler System
src/scheduler/scheduler.ts, src/scheduler/jobManager.ts, src/scheduler/types.ts, src/scheduler/index.ts
Implements timezone-aware job scheduling using node-schedule. Scheduler manages cron-based jobs with event emission; JobManager loads schedules from database and orchestrates hardware operations (temperature, power, alarms, priming, reboots). Supports reload/timezone updates and graceful shutdown.
tRPC API Routers
src/server/routers/device.ts, src/server/routers/settings.ts, src/server/routers/schedules.ts, src/server/routers/biometrics.ts, src/server/routers/app.ts
Exposes tRPC procedures for device control (status, temperature, power, alarms, priming), device/side settings management with timezone/unit configuration, CRUD operations for three schedule types (temperature/power/alarm) with day-based querying, and biometrics data retrieval (sleep records, vitals, movement) with date filtering and aggregation.
Frontend Pages & Components
app/[lang]/control/page.tsx, app/[lang]/page.tsx, app/[lang]/schedules/page.tsx, app/[lang]/settings/page.tsx, src/components/Navigation/Navigation.tsx, src/components/SideSelector/SideSelector.tsx, src/components/TemperatureControl/TemperatureControl.tsx
Adds responsive React pages with real-time device control UI (two-panel temperature/power/priming), home page with navigation cards, schedules management with temperature/power/alarm CRUD, and settings for device/side configuration. Includes responsive navigation bar and sidebar components with active link highlighting.
Utility Modules & Config
src/lib/tempUtils.ts, .claude/commands/pr-describe.md, package.json
Adds temperature conversion and formatting utilities (Fahrenheit/Celsius, Eight Sleep scale mapping, trend detection). Updates package.json: removes Prisma dependencies, adds Drizzle ORM, node-schedule, and supporting libraries (binary-split, cbor-x); updates dev scripts for database operations. Includes PR documentation guide.

Sequence Diagram(s)

sequenceDiagram
    participant UI as React UI
    participant tRPC as tRPC Router
    participant HW as Hardware Client
    participant DB as Drizzle Database
    participant Socket as Pod Socket

    UI->>tRPC: device.setTemperature(side, temp)
    tRPC->>HW: createHardwareClient().connect()
    HW->>Socket: Connect to Unix socket
    Socket-->>HW: Connected
    HW->>Socket: Send SET_LEVEL command
    Socket-->>HW: Response OK
    tRPC->>DB: Update deviceState (targetTemp, isPowered)
    DB-->>tRPC: Success
    tRPC-->>UI: Temperature set
    HW->>Socket: Disconnect

    UI->>tRPC: schedules.createTemperatureSchedule(...)
    tRPC->>DB: Insert into temperatureSchedules
    DB-->>tRPC: Record inserted
    tRPC-->>UI: Schedule created
    Note over DB: Scheduler loads schedule on startup/reload
Loading
sequenceDiagram
    participant Scheduler as Scheduler
    participant JobMgr as JobManager
    participant DB as Drizzle DB
    participant HW as Hardware Client
    participant Device as Pod Device

    Scheduler->>JobMgr: loadSchedules()
    JobMgr->>DB: Query temperatureSchedules (side, dayOfWeek)
    DB-->>JobMgr: Schedule records
    JobMgr->>Scheduler: scheduleJob(id, cron, handler)
    Scheduler->>Scheduler: Setup cron job with node-schedule
    
    Note over Scheduler: Cron time reached
    Scheduler->>Scheduler: executeJob(id, handler)
    Scheduler->>JobMgr: handler() execution
    JobMgr->>HW: createHardwareClient()
    HW->>Device: setTemperature(side, temp)
    Device-->>HW: Success
    JobMgr-->>Scheduler: JobExecutionResult { success }
    Scheduler->>Scheduler: Emit jobExecuted event
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related issues

Possibly related PRs

Poem

🐰 Whiskers twitch with pod control glee,
Drizzle flowing where Prisma used to be,
Schedules hop and temperatures align,
Socket chatter keeps the device so fine,
A rabbit's dream: hardware, API, and UI shine!

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/frontend-ui

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@ng ng closed this Feb 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant