An open API service indexing awesome lists of open source software.

https://github.com/codesign-cloud/cdc-electron-starterkit

"Hello world" Electron app starter kit. Latest versions, inter-process communication, base, React, Jest, Playwright
https://github.com/codesign-cloud/cdc-electron-starterkit

Last synced: about 2 months ago
JSON representation

"Hello world" Electron app starter kit. Latest versions, inter-process communication, base, React, Jest, Playwright

Awesome Lists containing this project

README

          

# CDC Electron Starterkit

A modern, secure, and feature-rich Electron + React starter template with best practices built-in.

## ๐Ÿš€ Features

- **Modern Stack**: Electron 37+ with React 19
- **Security First**: Context isolation, disabled node integration, CSP headers
- **Development Experience**: Hot reload, dev tools, source maps
- **Build System**: Webpack 5 with Babel transpilation
- **Testing**: Jest setup with example tests
- **Cross-Platform**: Windows, macOS, and Linux support
- **Modern UI**: Beautiful gradient design with responsive layout

##### Screenshot
![Screenshot](assets/screenshot.png "Screenshot")

## ๐Ÿ“ฆ What's Included

- โœ… Secure IPC communication between main and renderer processes
- โœ… Modern React with hooks and error boundaries
- โœ… Webpack configuration for development and production
- โœ… Hot reload during development
- โœ… Professional application menu
- โœ… CSS modules support
- โœ… Jest testing framework
- โœ… Cross-platform build configuration
- โœ… Security best practices implemented

## ๐Ÿ›  Installation

```bash
# Clone the repository
git clone https://github.com/codesign-cloud/cdc-electron-starterkit.git
cd cdc-electron-starterkit

# Install dependencies
npm install
```

## ๐Ÿš€ Development

**Important**: You need to build the React app first before running Electron!

### Quick Start (Recommended)
```bash
# This automatically builds the React app AND starts Electron with hot reload
npm start
```

### Manual Process (if needed)
```bash
# Step 1: Build the React app first
npm run build:renderer:dev

# Step 2: Then start Electron
npm run start:electron
```

### Other Development Commands
```bash
# Build renderer for development (with source maps) - REQUIRED before first run
npm run build:renderer:dev

# Build renderer for production (optimized)
npm run build:renderer

# Clean build artifacts
npm run clean
```

**Note**: The `npm start` command runs both webpack (to build React) and Electron simultaneously with hot reload, so you don't need to build separately when using it.

## ๐Ÿงช Testing

```bash
# Run tests once
npm test

# Run tests in watch mode
npm run test:watch
```

## ๐Ÿ“ฆ Building for Production

```bash
# Build the app for all platforms
npm run build

# Build and publish (requires proper GitHub setup)
npm run release
```

## ๐Ÿ— Project Structure

```
cdc-electron-starterkit/
โ”œโ”€โ”€ src/
โ”‚ โ”œโ”€โ”€ __tests__/ # Test files
โ”‚ โ”œโ”€โ”€ main.js # Electron main process
โ”‚ โ”œโ”€โ”€ preload.js # Secure bridge script
โ”‚ โ”œโ”€โ”€ renderer.jsx # React application
โ”‚ โ”œโ”€โ”€ index.html # HTML template
โ”‚ โ””โ”€โ”€ style.css # Application styles
โ”œโ”€โ”€ dist/ # Built files (auto-generated)
โ”œโ”€โ”€ docs/ # Documentation
โ”œโ”€โ”€ package.json # Dependencies and scripts
โ”œโ”€โ”€ webpack.config.js # Webpack configuration
โ”œโ”€โ”€ babel.config.js # Babel configuration
โ””โ”€โ”€ jest.config.js # Jest configuration
```

### File Structure for Development:

```
src/
โ”œโ”€โ”€ renderer.jsx โ† Main React app (edit here!)
โ”œโ”€โ”€ style.css โ† Styling (edit here!)
โ”œโ”€โ”€ index.html โ† HTML template
โ”œโ”€โ”€ main.js โ† Electron main process
โ””โ”€โ”€ preload.js โ† Security bridge
```

## ๐Ÿ”’ Security Features

This starterkit implements Electron security best practices:

- **Context Isolation**: Enabled to prevent renderer access to Node.js APIs
- **Node Integration**: Disabled in renderer process
- **Preload Script**: Secure bridge for IPC communication
- **Content Security Policy**: Configured for development and production
- **Sandboxing**: Ready to be enabled for additional security
- **Menu Security**: Prevents unauthorized window creation

## ๐ŸŽจ Customization

### Styling
- Modify `src/style.css` for global styles
- The app uses a modern gradient design that's fully customizable
- Responsive design works on all screen sizes

### Adding Features
- Add new IPC handlers in `src/main.js`
- Expose them securely through `src/preload.js`
- Use them in your React components via `window.electronAPI`

### Build Configuration
- Modify `package.json` build section for app metadata
- Update `webpack.config.js` for build customizations
- Configure `babel.config.js` for JavaScript transpilation

## ๐Ÿ“‹ Scripts Reference

| Script | Description |
|--------|-------------|
| `npm start` | Start development with hot reload |
| `npm run dev` | Alias for start |
| `npm test` | Run tests once |
| `npm run test:watch` | Run tests in watch mode |
| `npm run build:renderer` | Build renderer for production |
| `npm run build:renderer:dev` | Build renderer for development |
| `npm run build` | Build app for all platforms |
| `npm run release` | Build and publish app |
| `npm run clean` | Clean build artifacts |

## ๐Ÿ› Troubleshooting

### Common Issues

1. **App won't start**: Make sure you've run `npm install` and `npm run build:renderer`
2. **Hot reload not working**: Check that both webpack and electron processes are running
3. **Build fails**: Ensure all dependencies are installed and up to date

### Development Tips

- Use `Ctrl+Shift+I` (or `Cmd+Option+I` on Mac) to open DevTools
- Check the console for any JavaScript errors
- Use the Network tab to debug resource loading issues

## ๐Ÿค Contributing

1. Fork the repository
2. Create a feature branch
3. Make your changes
4. Add tests if applicable
5. Submit a pull request

## ๐Ÿ“„ License

This project is licensed under the CC0-1.0 License - see the LICENSE file for details.

## ๐Ÿ™ Acknowledgments

- Built with [Electron](https://electronjs.org/)
- UI powered by [React](https://reactjs.org/)
- Bundled with [Webpack](https://webpack.js.org/)
- Tested with [Jest](https://jestjs.io/)

---

**Happy coding! ๐ŸŽ‰**