How electric-sql/pglite works
Project type and purpose
• This is a multi‐package monorepo hosting an open‐source library/tool: a WASM-compiled build of PostgreSQL (PGlite) plus a TypeScript client and related extension packages (React, Vue, web-REPL, sync engine, CLI tools, protocol layer).
• Its primary use case is embedding a single-user Postgres instance in browser/Node/Deno/Bun applications, with optional persistence (IndexedDB or file system) and wrappers for various frameworks.
File structure
• Top‐level “packages/” folder holds independent npm packages:
• packages/pglite – core WASM+TS client and FS abstraction
• packages/pg-protocol – low-level message parser/serializer for Postgres wire protocol
• packages/pglite-react / pglite-vue – React/Vue hook providers
• packages/pglite-repl – web component UI for SQL REPL
• packages/pglite-sync – synchronization engine for multi-tab or client-server syncing
• packages/pglite-tools – CLI scripts (bundle-WASM, pg_dump integration)
• packages/benchmark – performance test harness
• “docs/” and “examples/” directories provide documentation site and runnable sample apps.
• Build/config files: Dockerfiles (implied), pnpm-workspace.yaml, GitHub Actions workflow, tsconfig/tup.config/vitest.config in each package.
README for additional insights
• Describes two-stage build: (1) Docker/Emscripten → Postgres WASM module → copied to packages/pglite/release; (2) pnpm builds TypeScript packages in dependency order.
• Runtime environments: browser IndexedDB, Node FS, Bun, Deno.
• Extensions support via “packages/pglite/src/contrib” and FS plugins under “src/fs/”.
Elements
• Clear labels: “Docker/Emscripten”, “WASM Module”, “TS Bundler”, “pnpm Workspace”, “Core Client”, “Protocol Layer”, “React Hooks”, “Vue Hooks”, “REPL WebComponent”, “Sync Engine”, “FS Abstraction”, “IndexedDB”, “Node FS”
• Runtime hosts (rounded rectangles)