Skip to content

Read the commits #42

Merged
weroperking merged 3 commits intoweroperking:mainfrom
Helal-maker:main
Mar 28, 2026
Merged

Read the commits #42
weroperking merged 3 commits intoweroperking:mainfrom
Helal-maker:main

Conversation

@Helal-maker
Copy link
Copy Markdown
Contributor

@Helal-maker Helal-maker commented Mar 28, 2026

Summary by CodeRabbit

Release Notes

  • New Features

    • Raw SQL execution with built-in security protections
    • Full-text search and vector similarity search capabilities
    • Optimistic mutation updates for improved UI responsiveness
    • Query diagnostics and optimization analyzer with performance recommendations
    • Data export/import functionality with automated backup scheduling
    • Real-time dashboard monitoring for active queries and connections
    • CLI tool for migrating projects from Convex
    • Enhanced IaC dashboard with schema, functions, jobs, and real-time monitoring pages
  • Documentation

    • Comprehensive guides for new search, query optimization, and data portability features
    • Storage, scheduler, and module pattern documentation added

- Add 6 new dashboard pages for IaC features:
  - IaC Schema Viewer: View tables, columns, indexes
  - IaC Functions Dashboard: List queries, mutations, actions
  - Scheduled Jobs: Manage cron jobs from bbf/cron.ts
  - Realtime Connections: Monitor WebSocket connections
  - SQL Query Runner: Execute raw SELECT queries
- Add IaC routes in server package
- Add test suite for IaC API routes (10 tests)
- Simplify README.md and CODEBASE_MAP.md
- Add IaC documentation (docs/iac/)

BREAKING CHANGE: Dashboard routes moved under /projects/:id/iac/
…template

- Made bb init use BetterBase template as default (instead of requiring --iac flag)
- Renamed BBF folder to BetterBase across the entire codebase
- Updated all references from bbf/ to betterbase/ in CLI, server, core, client packages
- Updated test files to use BetterBase naming
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 28, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3e503860-2c9f-490c-b38d-e7044056f6b1

📥 Commits

Reviewing files that changed from the base of the PR and between 4a42191 and 3a62daa.

⛔ Files ignored due to path filters (1)
  • bun.lock is excluded by !**/*.lock
📒 Files selected for processing (93)
  • BetterBase_IaC_Phase2_Spec.md
  • BetterBase_IaC_Phase3_Spec.md
  • CODEBASE_MAP.md
  • README.md
  • apps/dashboard/src/pages/projects/ProjectIaCFunctionsPage.tsx
  • apps/dashboard/src/pages/projects/ProjectIaCJobsPage.tsx
  • apps/dashboard/src/pages/projects/ProjectIaCQueryPage.tsx
  • apps/dashboard/src/pages/projects/ProjectIaCRealtimePage.tsx
  • apps/dashboard/src/pages/projects/ProjectIaCSchemaPage.tsx
  • apps/dashboard/src/pages/projects/ProjectTabs.tsx
  • apps/dashboard/src/routes.tsx
  • biome.json
  • docs/COMPARISON.md
  • docs/iac/01-introduction.md
  • docs/iac/02-schema.md
  • docs/iac/03-functions.md
  • docs/iac/04-client-hooks.md
  • docs/iac/05-storage.md
  • docs/iac/06-scheduler.md
  • docs/iac/07-modules.md
  • docs/iac/08-optimistic-updates.md
  • docs/iac/09-raw-sql.md
  • docs/iac/10-full-text-search.md
  • docs/iac/11-vector-search.md
  • docs/iac/12-query-optimization.md
  • docs/iac/13-data-portability.md
  • docs/iac/14-migration-from-convex.md
  • packages/cli/src/commands/dev.ts
  • packages/cli/src/commands/dev/error-formatter.ts
  • packages/cli/src/commands/dev/process-manager.ts
  • packages/cli/src/commands/dev/query-log.ts
  • packages/cli/src/commands/dev/watcher.ts
  • packages/cli/src/commands/iac/analyze.ts
  • packages/cli/src/commands/iac/export.ts
  • packages/cli/src/commands/iac/generate.ts
  • packages/cli/src/commands/iac/import.ts
  • packages/cli/src/commands/iac/sync.ts
  • packages/cli/src/commands/init.ts
  • packages/cli/src/commands/migrate/from-convex.ts
  • packages/cli/src/index.ts
  • packages/cli/src/utils/context-generator.ts
  • packages/cli/test/dev.test.ts
  • packages/cli/test/iac-commands.test.ts
  • packages/client/package.json
  • packages/client/src/build.ts
  • packages/client/src/iac/embeddings.ts
  • packages/client/src/iac/hooks.ts
  • packages/client/src/iac/index.ts
  • packages/client/src/iac/paginated-query.ts
  • packages/client/src/iac/provider.tsx
  • packages/client/src/iac/vanilla.ts
  • packages/client/src/index.ts
  • packages/client/test/iac.test.ts
  • packages/client/tsconfig.json
  • packages/core/src/iac/cron.ts
  • packages/core/src/iac/db-context.ts
  • packages/core/src/iac/errors.ts
  • packages/core/src/iac/function-registry.ts
  • packages/core/src/iac/functions.ts
  • packages/core/src/iac/generators/api-typegen.ts
  • packages/core/src/iac/generators/drizzle-schema-gen.ts
  • packages/core/src/iac/index.ts
  • packages/core/src/iac/realtime/invalidation-manager.ts
  • packages/core/src/iac/realtime/subscription-tracker.ts
  • packages/core/src/iac/realtime/table-dep-inferrer.ts
  • packages/core/src/iac/schema-serializer.ts
  • packages/core/src/iac/storage/storage-ctx.ts
  • packages/core/src/iac/validators.ts
  • packages/core/src/index.ts
  • packages/server/migrations/011_iac_storage.sql
  • packages/server/migrations/012_iac_scheduler.sql
  • packages/server/package.json
  • packages/server/src/index.ts
  • packages/server/src/lib/env.ts
  • packages/server/src/routes/admin/project-scoped/iac.ts
  • packages/server/src/routes/admin/project-scoped/index.ts
  • packages/server/src/routes/admin/project-scoped/realtime.ts
  • packages/server/src/routes/bbf/index.ts
  • packages/server/src/routes/betterbase/index.ts
  • packages/server/src/routes/betterbase/ws.ts
  • packages/server/test/iac-routes.test.ts
  • templates/base/MIGRATION_GUIDE.md
  • templates/iac/betterbase.config.ts
  • templates/iac/betterbase/actions/.gitkeep
  • templates/iac/betterbase/cron.ts
  • templates/iac/betterbase/mutations/todos.ts
  • templates/iac/betterbase/queries/todos.ts
  • templates/iac/betterbase/schema.ts
  • templates/iac/package.json
  • templates/iac/src/index.ts
  • templates/iac/src/modules/.gitkeep
  • templates/iac/src/modules/README.md
  • templates/iac/tsconfig.json

📝 Walkthrough

Walkthrough

A comprehensive PR implementing BetterBase Phase 3 IaC specification with 30 ordered tasks: adds optimistic mutations, raw SQL/analyze APIs, PostgreSQL full-text search and pgvector similarity, query diagnostics, data portability tooling, improved error handling, Convex migration CLI, dev-mode query logging, and extensive IaC documentation for schema definition, functions, client hooks, storage, scheduler, modules, realtime, and optimization guidance.

Changes

Cohort / File(s) Summary
Phase 3 Specification
BetterBase_IaC_Phase3_Spec.md
Comprehensive 30-task specification document defining optimistic mutations, raw SQL execution, full-text search, similarity search, query diagnostics, data portability, and developer-experience improvements.
Documentation & Guides
docs/COMPARISON.md, docs/iac/01-introduction.md through docs/iac/14-migration-from-convex.md, CODEBASE_MAP.md, README.md
14 new IaC documentation pages covering introduction, schema, functions, client hooks, storage, scheduler, modules, optimistic updates, raw SQL, full-text search, vector search, query optimization, data portability, and Convex migration; updated CODEBASE_MAP and README with IaC-first guidance.
Dashboard Pages
apps/dashboard/src/pages/projects/ProjectIaCSchemaPage.tsx, ProjectIaCFunctionsPage.tsx, ProjectIaCJobsPage.tsx, ProjectIaCQueryPage.tsx, ProjectIaCRealtimePage.tsx, ProjectTabs.tsx, apps/dashboard/src/routes.tsx
Five new React dashboard pages for viewing IaC schema, functions, scheduled jobs, realtime events, and executing SQL queries; added IaC tab routing and lazy loading.
Core IaC Database Context
packages/core/src/iac/db-context.ts
Extended DatabaseReader and DatabaseWriter with execute() for raw SQL, analyze() for query planning, search() for full-text search, and similarity() for vector similarity; added SQL sanitization and schema prefixing.
Core IaC Validators & Errors
packages/core/src/iac/validators.ts, packages/core/src/iac/errors.ts
Added fullText() and vector(dimensions) validators; introduced structured error system with IaCError, ValidationError, DatabaseError, AuthError, NotFoundError, and formatError.
Core IaC Functions & Schema
packages/core/src/iac/functions.ts, packages/core/src/iac/cron.ts, packages/core/src/iac/function-registry.ts, packages/core/src/iac/index.ts
Added optimistic mutation support via _optimistic function; updated function discovery to use functionsDir parameter; expanded public exports for error classes and realtime modules.
Core IaC Generators
packages/core/src/iac/generators/api-typegen.ts, packages/core/src/iac/generators/drizzle-schema-gen.ts, packages/core/src/iac/schema-serializer.ts
Updated schema/API generation to reference betterbase/ directory instead of bbf/; applied tab-based formatting throughout.
Core Realtime Infrastructure
packages/core/src/iac/realtime/subscription-tracker.ts, packages/core/src/iac/realtime/invalidation-manager.ts, packages/core/src/iac/realtime/table-dep-inferrer.ts
New modules for tracking WebSocket subscriptions, batching invalidation messages, and inferring table dependencies from query handlers.
Core Storage Context
packages/core/src/iac/storage/storage-ctx.ts
New storage layer integrating S3 presigning, metadata persistence, and public URL generation for file uploads/downloads.
CLI Dev Infrastructure
packages/cli/src/commands/dev.ts, packages/cli/src/commands/dev/process-manager.ts, packages/cli/src/commands/dev/watcher.ts, packages/cli/src/commands/dev/error-formatter.ts, packages/cli/src/commands/dev/query-log.ts
Refactored dev command to use modular ProcessManager, DevWatcher, query logging, and error formatting; added schema/function change detection and per-event restart behavior.
CLI IaC Commands
packages/cli/src/commands/iac/sync.ts, packages/cli/src/commands/iac/generate.ts, packages/cli/src/commands/iac/analyze.ts, packages/cli/src/commands/iac/export.ts, packages/cli/src/commands/iac/import.ts
New CLI commands for schema diffing/syncing, function generation, query complexity analysis, data export, and data import with dry-run support.
CLI Init & Migration
packages/cli/src/commands/init.ts, packages/cli/src/commands/migrate/from-convex.ts
Extended init to support IaC template scaffolding; added Convex-to-BetterBase migration tool with regex-based schema/function conversion.
CLI Core
packages/cli/src/index.ts, packages/cli/src/utils/context-generator.ts
Added IaC command group; extended context generator to discover IaC functions and populate prompt for AI assistance.
CLI Tests
packages/cli/test/dev.test.ts, packages/cli/test/iac-commands.test.ts
Updated dev tests; added comprehensive test suite for IaC commands including unit and integration tests.
Client IaC Hooks
packages/client/src/iac/hooks.ts, packages/client/src/iac/provider.tsx, packages/client/src/iac/paginated-query.ts
New React hooks (useQuery, useMutation, useAction, usePaginatedQuery) with WebSocket subscription, optimistic updates, and automatic query invalidation.
Client IaC Utilities
packages/client/src/iac/vanilla.ts, packages/client/src/iac/embeddings.ts, packages/client/src/iac/index.ts
Non-React vanilla client with RPC/subscription support; embedding generation helpers for OpenAI/Cohere; barrel exports for all IaC client APIs.
Client Build & Config
packages/client/src/build.ts, packages/client/package.json, packages/client/tsconfig.json, packages/client/test/iac.test.ts
Added IaC submodule build step; added React dependencies; enabled JSX transformation; added IaC export map and integration tests.
Server IaC Routes
packages/server/src/routes/betterbase/index.ts, packages/server/src/routes/betterbase/ws.ts, packages/server/src/routes/admin/project-scoped/iac.ts
New betterbase router with function execution (queries/mutations/actions), storage presigning, and admin schema/function/job/realtime endpoints; WebSocket handler with client/subscription management.
Server Legacy Routes
packages/server/src/routes/bbf/index.ts
Removed legacy /bbf route handler in favor of new /betterbase endpoint.
Server Infrastructure
packages/server/src/index.ts, packages/server/src/lib/env.ts
Updated route registration from bbfRouter to betterbaseRouter; added STORAGE_PUBLIC_BASE environment variable.
Database Migrations
packages/server/migrations/011_iac_storage.sql, packages/server/migrations/012_iac_scheduler.sql
New SQL migrations for IaC storage table provisioning and scheduled job persistence.
Server Dependencies & Tests
packages/server/package.json, packages/server/test/iac-routes.test.ts
Added S3 presigner dependency; added comprehensive test suite for IaC routes with mocked database layer.
IaC Templates
templates/iac/betterbase.config.ts, templates/iac/betterbase/{schema,queries,mutations,cron}.ts, templates/iac/src/index.ts, templates/iac/src/modules/README.md, templates/iac/package.json, templates/iac/tsconfig.json, templates/base/MIGRATION_GUIDE.md
New IaC project template with example schema, queries, mutations, cron jobs, Hono entrypoint, module pattern documentation, and migration guide from legacy template.
Project Configuration
biome.json
Disabled useExhaustiveDependencies linting rule.

Sequence Diagrams

sequenceDiagram
    participant Client
    participant Server as Server<br/>(Function Handler)
    participant Database as Database<br/>(PostgreSQL)
    participant WSBroadcaster as WebSocket<br/>(Invalidation)

    Client->>Client: Call mutation<br/>(with optimistic data)
    Client->>Server: POST /betterbase/mutations/*<br/>{args}
    activate Server
    Server->>Database: BEGIN TRANSACTION
    Server->>Database: INSERT/UPDATE/DELETE
    Database->>Server: Success
    Server->>Database: COMMIT
    Server->>WSBroadcaster: Emit invalidate<br/>(table changes)
    Server->>Client: {result: ...}
    deactivate Server
    
    Client->>Client: Replace optimistic<br/>with real result
    WSBroadcaster->>Client: {type: invalidate,<br/>tables: [...]}
    Client->>Client: Refetch subscribed<br/>queries
Loading
sequenceDiagram
    participant Client
    participant Server as Server<br/>(Schema Analyzer)
    participant Database as Database<br/>(EXPLAIN ANALYZE)

    Client->>Server: POST /betterbase/queries/*<br/>{sql, params}
    activate Server
    Server->>Server: Sanitize SQL<br/>(SELECT only)
    Server->>Database: EXECUTE query
    Database->>Server: {rows, columns}
    Server->>Client: {columns, rows, row_count}
    deactivate Server
    
    Client->>Server: ctx.db.analyze(query)
    activate Server
    Server->>Database: EXPLAIN ANALYZE
    Database->>Server: Plan + cost info
    Server->>Server: Parse plan,<br/>extract cost/indexes
    Server->>Client: {plan, estimatedCost,<br/>suggestedIndexes, isSlow}
    deactivate Server
Loading
sequenceDiagram
    participant Client
    participant WSServer as WebSocket<br/>Server
    participant SubTracker as Subscription<br/>Tracker
    participant InvalidMgr as Invalidation<br/>Manager

    Client->>WSServer: Connect<br/>(/betterbase/ws)
    activate WSServer
    WSServer->>Client: {type: connected,<br/>clientId}
    deactivate WSServer
    
    Client->>WSServer: {type: subscribe,<br/>path, args}
    activate WSServer
    WSServer->>SubTracker: Register subscription
    WSServer->>Client: {type: subscribed}
    deactivate WSServer
    
    Note over InvalidMgr: Table mutation occurs
    InvalidMgr->>SubTracker: Get subscriptions<br/>for affected tables
    SubTracker->>InvalidMgr: [{clientId, path, args}]
    InvalidMgr->>WSServer: Push invalidate msg
    WSServer->>Client: {type: invalidate,<br/>tables, functionPath}
    Client->>Client: Refetch query
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Suggested labels

feature, iac, database, realtime, client-sdk, cli, dashboard, phase-3


🐰 Hops through schema fields and vector dreams,
Full-text search flows in data streams,
Optimistic mutations race to grace,
WebSockets ping from place to place,
From Convex burrows, migration's way,
Betterbase IaC saves the day! 🎉

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

@weroperking weroperking merged commit 8e7c3ea into weroperking:main Mar 28, 2026
1 of 4 checks passed
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

export default {
port,
fetch: app.fetch,
};

P1 Badge Expose websocket config from server entrypoint

The server entrypoint exports only { port, fetch }, so Bun never receives a websocket handler or upgrade hook for /betterbase/ws (implemented separately in routes/betterbase/ws.ts). This leaves realtime subscriptions unreachable in runtime even though clients always attempt to connect to that websocket endpoint.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +183 to +184
mutateAsync(args).catch(() => {}); // fire-and-forget variant
return mutateAsync(args);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Call mutateAsync only once per mutate invocation

mutate currently invokes mutateAsync(args) twice (once fire-and-forget and once returned), so every mutation sends two HTTP requests and can apply side effects twice. This is especially harmful for non-idempotent writes (e.g., inserts/payments) and will also duplicate optimistic state transitions.

Useful? React with 👍 / 👎.

Comment on lines +20 to +23
headers: {
"Content-Type": "application/json",
...(token ? { Authorization: `Bearer ${token}` } : {}),
},
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Send project slug header in IaC HTTP calls

The client request helper does not include X-Project-Slug, but the server resolves schema from that header (packages/server/src/routes/betterbase/index.ts, projectSlug = c.req.header("X-Project-Slug") ?? "default"). As a result, multi-project apps will execute all function calls against project_default instead of the configured project, causing cross-project reads/writes.

Useful? React with 👍 / 👎.

Comment on lines +200 to +204
"DROP",
"TRUNCATE",
"DELETE",
"INSERT",
"UPDATE",
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Allow write statements in writer SQL sanitizer

The shared sanitizer still marks DELETE, INSERT, and UPDATE as forbidden, but DatabaseWriter.execute() advertises write support and calls this sanitizer. In practice, writer raw SQL writes always throw before execution, breaking documented mutation-side ctx.db.execute(...) workflows.

Useful? React with 👍 / 👎.

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.

2 participants