Here is the English version of your documentation:
A modern desktop application template based on Electron + Vite + Drizzle ORM + Better-SQLite3.
- Drizzle ORM – A modern and lightweight ORM solution
- Vue 3 for the UI layer (can be replaced as needed)
- Electron v34.0.0 + Node.js v20.18.0
- Better-SQLite3 – A performant, synchronous SQLite library
📦 Project Root
├── assets # Static assets (including packaged app icons)
├── electron # Electron-related code
│ ├── main # Main process code
│ │ ├── auto-update # electron-updater related code
│ │ ├── db # Database logic
│ │ ├── router # Routes providing DB access interfaces
│ │ ├── utils.ts # Utility functions
│ │ ├── dbServicesInit.ts # Database initialization logic
│ │ ├── index.ts # Entry file of the main process
│ ├── preload # Preload scripts
├── migrations # Database migration files
├── public # Vue public assets
├── src # Vue source code
├── drizzle.config.ts # Drizzle ORM migration config
├── electron-builder.json # Electron build config
├── vite.config.ts # Vite build config
-
Node.js version
v20.18.0
-
Visual Studio 2022 (Install the Desktop development with C++ workload)
-
Python 3.7
-
Configure environment variables
npm config edit
Add the following:
ELECTRON_MIRROR=https://registry.npmmirror.com/-/binary/electron/ home=https://npmmirror.com msvs_version=2022 python=python registry=https://registry.npmmirror.com/
-
Install
node-gyp
globallynpm install -g node-gyp
npm install # Install dependencies
npm rebuild # Rebuild native dependencies
npx electron-rebuild -f -w better-sqlite3 # Rebuild native modules for Electron (e.g., better-sqlite3)
npm run syncSchema # Sync local development database schema
npm run dev # Start development (run syncSchema first)
npm run build # Build the app (will generate migration files first)
-
To sync schema changes to your local database, run:
npm run syncSchema This command quickly syncs schema fields without generating migration files. Migration files are automatically generated during the build.
npm run syncSchema-old # (Deprecated and slower) This runs: 1. `npm rebuild` – Rebuild better-sqlite3 for the local Node.js version 2. `npx drizzle-kit push` – Push schema to local database 3. `npx electron-rebuild -f -w better-sqlite3` – Rebuild for Electron compatibility
-
Run the build command to generate migration files using the development database structure:
npm run build
The development (.env.db) and production (.db) database files are separate to avoid issues with migration failures when installing the production app over an already-updated local dev DB. If using the same file, delete or back up the existing local file before installing the production app.
webPreferences
disables Node.js in renderer and enables context isolation (sandbox is not enabled). Native modules and IPC must be exposed through preload scripts.- Preload files are compiled as
.mjs
using ES module syntax, withimport
used for dependencies.
Migrations differ between development and production environments:
- Migration files are automatically generated during build
- Make sure
drizzle.config.ts
points to the correct local database path
-
After schema changes, run:
npm run syncSchema
This:
- Syncs the schema with the local development database
- The
migrations
directory stores all migration files - Do not delete this directory to avoid potential data loss
✅ Database communication example ✅ App auto-updater with electron-updater ✅ Add logger ⬜ Multi-window example ⬜ Bytecode encryption
🎉 Enjoy coding with Electron + Vite + Drizzle ORM! 🚀