A comprehensive, production-ready template for building modern desktop applications with Electron, React, TypeScript, and Vite. Features a complete development setup with UI components and includes a system monitoring example to demonstrate real-world usage.
- ⚡ Modern Stack: Electron + React + TypeScript + Vite for fast development
- 🎨 UI: Beautiful, professional interface with shadcn/ui components
- 🌗 Dark/Light Mode: Built-in theme switching with smooth transitions
- 🔒 Security First: Follows Electron security best practices out of the box
- 🎯 Type Safety: Full TypeScript coverage with proper IPC typing
- 🛠️ Developer Experience: Hot reload, error handling, and debugging tools
- 📦 Build Ready: Configured for cross-platform builds with Electron Forge
- 🎭 Component Library: Complete shadcn/ui integration with 15+ components
- 🔌 IPC Architecture: Clean, organized Inter-Process Communication setup
- 📱 Responsive Design: Mobile-first approach with Tailwind CSS
The template includes a System Monitoring Dashboard as a practical example:
- 🖥️ Real-time CPU and memory usage tracking
- 📊 Platform-specific system statistics (optimized for macOS)
- 🌐 Network status and process information
- ⚡ Live updates every 2 seconds
- Node.js (v16.4.0 or higher)
- npm (comes with Node.js)
Clone the repository and install dependencies:
# Clone this template repository
git clone <repository-url>
```bash
# Navigate to the project directory
cd electron-react-typescript-template
# Install dependencies
npm install
To start the application in development mode:
npm start
This will:
- Start the development server
- Open your Electron app in a new window
- Enable hot-reloading for quick development
- Display the example system monitoring dashboard
To build the application for your current operating system:
npm run make
The packaged application will be available in the out/make
directory.
This project includes scripts to build for specific platforms:
# Build for macOS
npm run make:mac
# Build for Windows
npm run make:win
# Build for Linux
npm run make:linux
# Build for all platforms (macOS, Windows, and Linux)
npm run make:all
- Building macOS apps: Can only be done on macOS due to code signing requirements
- Building Windows apps on macOS/Linux: Requires Wine and Mono for certain functionality
- Building Linux apps on macOS/Windows: Generally works without extra requirements
- Native dependencies: May require platform-specific compilation
For serious cross-platform builds, consider using CI/CD services like GitHub Actions or CircleCI with runners for each platform.
This template provides a well-organized architecture that separates Electron's main process from the renderer process (UI), making it easy to extend for any desktop application:
├── src/
│ ├── index.ts # Application entry point
│ ├── main/ # Electron main process code
│ │ ├── main.ts # Main process implementation
│ │ ├── preload.ts # Preload script for secure IPC
│ │ └── ipc/ # IPC handlers module
│ │ ├── index.ts # Exports from IPC module
│ │ └── handlers.ts # System monitoring IPC handlers
│ ├── renderer/ # React UI code
│ │ ├── App.tsx # Main React component with system dashboard
│ │ ├── renderer.tsx # React entry point
│ │ ├── index.css # shadcn/ui styling with CSS variables
│ │ ├── components/ # shadcn/ui component library
│ │ │ └── ui/ # Reusable UI components
│ │ │ ├── button.tsx # Button component
│ │ │ ├── card.tsx # Card component
│ │ │ ├── badge.tsx # Badge component
│ │ │ ├── progress.tsx # Progress bar component
│ │ │ ├── switch.tsx # Toggle switch component
│ │ │ ├── tooltip.tsx # Tooltip component
│ │ │ └── ... # Additional UI components
│ │ └── lib/
│ │ └── utils.ts # Utility functions (cn, etc.)
│ └── shared/ # Shared code between processes
│ └── electron.d.ts # TypeScript definitions for IPC APIs
├── components.json # shadcn/ui configuration
├── index.html # HTML template
├── package.json # Project dependencies and scripts
├── tailwind.config.js # Tailwind CSS configuration
├── postcss.config.js # PostCSS configuration
├── tsconfig.json # TypeScript configuration with path mapping
├── forge.config.ts # Electron Forge configuration
├── vite.main.config.ts # Vite config for main process
├── vite.preload.config.ts # Vite config for preload script
└── vite.renderer.config.ts # Vite config for renderer process
The template uses a secure, scalable architecture with clear separation between processes:
-
Main Process (
src/main/
):- Handles application lifecycle, windows, and OS integration
- Contains all Node.js and Electron API access
-
IPC Module (
src/main/ipc/
):- Centralized Inter-Process Communication handlers
- Organized, modular approach for different feature sets
- Example: System monitoring APIs with platform-specific optimizations
- Easy to extend with new functionality
-
Preload Script (
src/main/preload.ts
):- Creates a secure bridge between main and renderer processes
- Exposes a limited API through contextBridge
- Prevents direct access to Node.js APIs from the renderer
-
Renderer Process (
src/renderer/
):- Modern React application
- Complete shadcn/ui component integration
- Dark/light mode with smooth transitions
- Example: Real-time dashboard implementation
- Easy to replace with your own UI components
-
UI Components (
src/components/ui/
):- Complete shadcn/ui component library integration
- Reusable, accessible, and styled components
- Consistent design system with CSS variables
- Tailwind CSS for utility-first styling
-
Shared Code (
src/shared/
):- TypeScript interfaces and type definitions
- Shared utilities and constants
- Ensures type safety across all processes
- Example: System monitoring data interfaces
The template includes a system monitoring example in:
src/main/ipc/handlers.ts
- Replace with your own IPC handlerssrc/renderer/App.tsx
- Replace with your main UI componentsrc/shared/electron.d.ts
- Update with your own type definitions
The template follows a simple 4-step pattern for adding any feature:
// src/shared/electron.d.ts
export interface YourDataType {
id: string;
name: string;
// ... your fields
}
// Extend the API interface
declare global {
interface Window {
electronAPI: {
// ... existing methods
yourNewFeature: (data: YourDataType) => Promise<YourDataType>;
};
}
}
// src/main/ipc/handlers.ts
export function registerIpcHandlers(): void {
// ... existing handlers
ipcMain.handle('your-new-feature', async (_, data: YourDataType) => {
// Your backend logic here:
// - File operations
// - Database queries
// - API calls
// - System integration
return processedData;
});
}
// src/main/preload.ts
contextBridge.exposeInMainWorld('electronAPI', {
// ... existing methods
yourNewFeature: data => ipcRenderer.invoke('your-new-feature', data),
});
// src/renderer/App.tsx
function YourComponent() {
const [data, setData] = useState(null);
const handleAction = async () => {
try {
const result = await window.electronAPI.yourNewFeature(inputData);
setData(result);
} catch (error) {
console.error('Feature failed:', error);
}
};
return (
<Card>
<CardHeader>
<CardTitle>Your Feature</CardTitle>
</CardHeader>
<CardContent>
<Button onClick={handleAction}>Execute Feature</Button>
{data && <div>Result: {JSON.stringify(data)}</div>}
</CardContent>
</Card>
);
}
File Operations:
- Backend: Use Node.js
fs
module,dialog
for file selection - Frontend: File upload/download UI with progress indicators
Settings Management:
- Backend: JSON file storage in
app.getPath('userData')
- Frontend: Settings panels with form controls
Database Integration:
- Backend: SQLite, PostgreSQL, or any database driver
- Frontend: CRUD operations with loading states
External APIs:
- Backend:
fetch()
oraxios
for HTTP requests - Frontend: Data fetching hooks with error handling
System Integration:
- Backend: OS notifications, shell commands, file system watching
- Frontend: Status indicators and system information displays
Real-time Updates:
- Backend: Event emitters to send updates to frontend
- Frontend: Event listeners for live data updates
- Start with types - Define your data structure first
- Build backend logic - Implement the core functionality
- Expose safely - Only expose what the frontend needs
- Create UI components - Build user interface with error handling
- Test thoroughly - Use developer tools and console for debugging
This pattern scales from simple features (showing a notification) to complex ones (real-time file synchronization) while maintaining security and type safety.
The template includes a complete component library:
- Replace the header with your own branding
- Modify the color scheme in
tailwind.config.js
- Add new shadcn/ui components as needed
- Customize the dark/light mode implementation
This template is perfect for building:
- System utilities (monitoring, file management, backup tools)
- Development tools (IDEs, database clients, API testing)
- Productivity apps (note-taking, task management, time tracking)
- Creative tools (image editors, music players, video tools)
- Business applications (CRM, inventory, analytics dashboards)
- Electron - Cross-platform desktop app framework
- React - Modern UI library with hooks and components
- TypeScript - Type-safe JavaScript for better DX
- Vite - Lightning-fast build tool and dev server
- Electron Forge - Complete toolchain for packaging
- shadcn/ui - High-quality, accessible component library
- Tailwind CSS - Utility-first CSS framework
- Radix UI - Unstyled, accessible UI primitives
Common Development Issues:
Template Setup Issues:
App Won't Start:
- Ensure Node.js v16.4.0 or higher is installed
- Run
npm install
to install all dependencies - Check for port conflicts if running in development mode
Components Not Styling Correctly:
- Ensure Tailwind CSS is properly configured
- Check that
postcss.config.js
is present - Verify
src/renderer/index.css
contains shadcn/ui variables
TypeScript Errors:
- Run
npm run type-check
to verify types - Ensure all dependencies are up to date
- Check
tsconfig.json
path mappings are correct
Build Failures:
- Clear
node_modules
and runnpm install
- Check Electron Forge configuration in
forge.config.ts
- Verify all Vite configurations are properly set up
Adding New Components:
- Use
npx shadcn-ui@latest add <component>
to add new UI components - Import components using the
@/
alias configured intsconfig.json
- Follow the existing patterns in
src/renderer/App.tsx
This application follows Electron's security best practices:
-
Content Security Policy (CSP):
- Implemented via meta tag in index.html
- Restricts script and style sources to prevent XSS attacks
- Follows the principle of least privilege
-
Context Isolation:
- Enabled in BrowserWindow configuration
- Prevents malicious scripts from accessing Electron/Node.js APIs
- Creates a separate JavaScript context for preload script
-
Secure IPC Communication:
- Uses contextBridge to expose only specific APIs
- Centralized IPC handlers in dedicated module
- Restricts renderer's access to main process
-
Web Security:
- Enabled by default in BrowserWindow configuration
- Enforces same-origin policy
- Prevents loading and execution of remote code
-
Node Integration Disabled:
- Prevents direct access to Node.js APIs from renderer
- Reduces potential attack surface
For more information on Electron security best practices, visit the Electron Security documentation.
-
Update package.json:
{ "name": "your-app-name", "productName": "Your App Name", "description": "Your app description" }
-
Update the window title in
src/renderer/App.tsx
:<h1 className='ml-4 text-sm font-medium'>Your App Name</h1>
-
Update the app icon (add your icon files to the project and update
forge.config.ts
)
- Backend Logic: Add new IPC handlers in
src/main/ipc/handlers.ts
- API Exposure: Update the preload script in
src/main/preload.ts
- Type Safety: Add interfaces in
src/shared/electron.d.ts
- UI Components: Build your interface in
src/renderer/App.tsx
The template uses a carefully crafted design system:
- Colors: Modify
tailwind.config.js
andsrc/renderer/index.css
- Components: All shadcn/ui components can be customized
- Themes: Dark/light mode variables are in CSS custom properties
- Layout: Spacing and typography are easily adjustable
This template is designed to be a solid foundation for any Electron desktop application. Contributions are welcome!
- Additional example implementations (file manager, text editor, etc.)
- More UI component examples and patterns
- Enhanced build and deployment configurations
- Additional platform-specific optimizations
- Performance monitoring and debugging tools
Start building your desktop application today! This template provides everything you need to create professional, secure, and performant Electron apps with modern web technologies.