feat: implement live sync infrastructure with pub/sub support and centralized configuration#58
Merged
adiagarwalrock merged 5 commits intomasterfrom Apr 6, 2026
Merged
feat: implement live sync infrastructure with pub/sub support and centralized configuration#58adiagarwalrock merged 5 commits intomasterfrom
adiagarwalrock merged 5 commits intomasterfrom
Conversation
…tralized configuration
There was a problem hiding this comment.
Pull request overview
This PR adds a live-sync (SSE “socket” + polling fallback) infrastructure backed by a new pub/sub layer, centralizes sync configuration via environment variables, and updates related caching/DB/UX plumbing to support near-realtime collaboration.
Changes:
- Introduces server-side pub/sub + SSE endpoints for live sync events, plus client hooks to consume them with polling fallback.
- Adds snapshot helpers + ETag support for doc GET endpoints and publishes list/doc sync events on create/update/delete.
- Refactors settings mutations to a single
updateSettings, adds a chart UI component for Settings, and updates DB URL/provider utilities + docs/tooling.
Reviewed changes
Copilot reviewed 50 out of 51 changed files in this pull request and generated 15 comments.
Show a summary per file
| File | Description |
|---|---|
| src/lib/useLiveSync.ts | Adds SSE-driven doc sync with ETag-based refresh + polling fallback. |
| src/lib/useListSync.ts | Adds SSE-driven list sync option alongside polling. |
| src/lib/types.ts | Simplifies store API to updateSettings; removes live sync settings fields. |
| src/lib/store.ts | Implements updateSettings; removes per-setting setters and live-sync defaults. |
| src/lib/pubsub.ts | Adds pub/sub backends (redis/file/memory) for sync event fanout. |
| src/lib/prisma.ts | Uses shared DB URL resolver + sqlite path parsing. |
| src/lib/notes-data.ts | Updates searchVector filtering for Postgres full-text search. |
| src/lib/logger.ts | Introduces pino-based logger and structured API error logging. |
| src/lib/live-sync-config.ts | Centralizes live-sync transport + polling interval via env vars. |
| src/lib/database-url.ts | Wraps scripts/database-url for shared URL/path resolution. |
| src/lib/data.ts | Updates diagram searchVector filtering for Postgres full-text search. |
| src/lib/cache.ts | Adds doc snapshot helpers for diagrams/notes. |
| src/lib/ai/config.ts | Centralizes AI model + Gemini API version defaults. |
| src/components/ui/chart.tsx | Adds reusable Recharts wrapper components (ChartContainer/Tooltip/etc.). |
| src/components/notes/NoteWorkspace.tsx | Adds draft publish + SSE live updates; wires x-client-id into writes. |
| src/components/notes/NotesContext.tsx | Switches notes list sync to LIVE_SYNC_CONFIG + SSE topics. |
| src/components/DiagramGrid.tsx | Switches diagrams list sync to LIVE_SYNC_CONFIG + SSE topics; settings updates. |
| src/components/DiagramEditor.tsx | Adds draft publish + SSE live updates; wires x-client-id into writes. |
| src/components/DashboardHeader.tsx | Migrates to updateSettings for AI settings hydration. |
| src/app/settings/page.tsx | Migrates to updateSettings, adds activity chart, shows sync transport status. |
| src/app/api/sync/stream/route.ts | Adds SSE stream endpoint subscribing to pub/sub topics. |
| src/app/api/sync/publish/route.ts | Adds CSRF-protected publish endpoint with optional draft de-dupe via snapshots. |
| src/app/api/settings/sync-status/route.ts | Exposes pub/sub backend status for UI/ops visibility. |
| src/app/api/settings/db-status/route.ts | Uses shared DB URL resolver for DB status reporting. |
| src/app/api/settings/ai-key/route.ts | Uses centralized AI model defaults from src/lib/ai/config.ts. |
| src/app/api/notes/route.ts | Publishes list sync events on note create; refactors caching flow. |
| src/app/api/notes/[id]/route.ts | Adds snapshot + ETag support; publishes doc/list sync events on update/delete. |
| src/app/api/diagrams/route.ts | Publishes list sync events on diagram create. |
| src/app/api/diagrams/[id]/route.ts | Adds snapshot + ETag support; publishes doc/list sync events on update/delete. |
| src/app/api/ai/assist/route.ts | Uses centralized AI config; supports configurable Gemini API version. |
| scripts/prepare-prisma-schema.js | Adds template substitution for previewFeatures + index behavior by provider. |
| scripts/database-url.js | Adds robust DB URL + writable sqlite path resolution. |
| scripts/bootstrap.js | Uses shared DB URL resolver + sqlite path parsing; refactors bootstrap flow. |
| scripts/backfill-tag-counts.js | Uses shared DB URL resolver + sqlite path parsing. |
| public/sw.js | Disables service worker caching to avoid interfering with SSE/live sync. |
| prisma/schema.template.prisma | Adds @@PREVIEW_FEATURES@@ token for provider-specific generation. |
| prisma/schema.prisma | Defaults to Postgres + enables fullTextSearchPostgres preview feature. |
| prisma/prisma.config.ts | Uses shared DB URL resolver for prisma config datasource URL. |
| prisma.config.ts | Uses shared DB URL resolver for prisma config datasource URL. |
| plan/code-map.md | Adds mandatory code map and intent/ownership routing. |
| package.json | Updates deps (Next, Mermaid, Prisma) and adds pino/recharts; removes next-pwa. |
| docs/settings.md | Updates Gemini default model + documents GEMINI_API_VERSION. |
| docs/CONTAINER_STARTUP.md | Updates Gemini default model + documents GEMINI_API_VERSION. |
| docs/AI.md | Updates AI provider docs (Gemini model reference). |
| docker-compose.yml | Adds live sync env vars, AI key, explicit UID/GID, networks/volumes, healthcheck. |
| AGENTS.md | Adds mandatory code-map workflow instructions. |
| .github/workflows/lint.yml | Adds CI lint + prettier check workflow. |
| .env.example | Documents live-sync env vars (transport + poll interval). |
| .dockerignore | Expands ignored files/dirs for cleaner Docker builds. |
| .codex/environments/environment.toml | Adds autogenerated environment setup metadata. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…stent indentation
…nce query sanitization in data retrieval
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces several important improvements across the codebase, focusing on enhanced documentation, environment and deployment configuration, database provider flexibility, and dependency updates. The most significant changes include the introduction of a required code map for code navigation and ownership, updates to the Prisma database configuration for better provider handling, improvements to the Docker and environment setup, and documentation updates for AI model support.
Documentation and Workflow Improvements
plan/code-map.mdfile, establishing a code map workflow that requires developers to update the map with every structural or ownership change. This ensures accurate file routing and reduces unnecessary searching.AGENTS.mdto enforce the code map workflow and clarified the structure and update requirements forplan/code-map.md. [1] [2] [3]Database and Prisma Configuration
prisma/schema.prismato set the provider to PostgreSQL by default and enabled thefullTextSearchPostgrespreview feature, while removing redundant search vector indexes. [1] [2] [3]prisma/schema.template.prismato allow dynamic preview features via template substitution.Deployment and Environment Configuration
docker-compose.ymlby setting explicit user IDs, adding AI and live sync environment variables, defining custom networks and volumes, and updating health checks for reliability. [1] [2] [3].codex/environments/environment.tomlfor environment setup automation..env.examplewith live sync transport and polling interval options for better configuration clarity..dockerignoreto exclude additional configuration, documentation, and data directories, ensuring cleaner Docker builds. [1] [2]AI Model and Documentation Updates
gemini-3.1-pro-previewand added support for theGEMINI_API_VERSIONenvironment variable, with corresponding changes in user-facing docs. [1] [2] [3] [4]Tooling and Dependency Updates
mermaid,next,prisma, and addedpino,pino-pretty, andrechartsfor enhanced logging and charting. [1] [2]These changes collectively improve project maintainability, developer onboarding, deployment flexibility, and documentation accuracy.