A modern, production-ready template for Grenache microservices projects with all the essential tools and configurations you need to get started with distributed microservices quickly! π―
Based on the Bitfinex Grenache tutorial.
This template comes pre-configured with:
- π₯ Bun Runtime: Ultra-fast JavaScript runtime and package manager
- π Grenache Microservices: Distributed microservice architecture with DHT-based service discovery
- π§Ή Biome: Fast linter and formatter (Prettier + ESLint replacement)
- π¦ Monorepo Structure: Bun workspace with Moonrepo for task management
- π WebSocket Communication: Server-client communication via Grenache WebSocket transport
- π¨ Git Integration: Pre-configured with Biome VCS integration
- πͺ Git Hooks: Lefthook for automated quality checks
- π GitHub Templates: CODE_OF_CONDUCT.md, SECURITY.md, and LICENSE included
- β‘ Proto Tool Manager: Automated tool management with moonrepo proto
- proto - A multi-language version manager that will manage all required tools
- Alternatively, you can install tools separately:
- Use this template by clicking the "Use this template" button on GitHub
- Clone your new repository:
git clone https://github.com/yourusername/your-project-name.git cd your-project-name - Install tools and dependencies:
# Install all required tools (bun, biome, moon) using proto proto install # Install project dependencies bun install
Important: You must start the components in this specific order:
-
Start Grape DHT nodes (required for service discovery):
# Terminal 1: Start first grape node cd apps/grape bun run dev:grape1 # Terminal 2: Start second grape node cd apps/grape bun run dev:grape2
-
Start the server (after grape nodes are running):
# Terminal 3: Start the microservice server cd apps/server bun run dev
-
Start the client (after server is running):
# Terminal 4: Start the client cd apps/client bun run dev
| Script | Description |
|---|---|
bun run prepare |
Install Lefthook Git hooks |
| Script | Description |
|---|---|
bun run dev:grape1 |
Start first grape DHT node (port 20001) |
bun run dev:grape2 |
Start second grape DHT node (port 20002) |
| Script | Description |
|---|---|
bun run dev |
Start development server with file watching |
bun run lint |
Run Biome linter for server |
bun run format |
Format server code with Biome |
bun run test |
Run server tests |
| Script | Description |
|---|---|
bun run dev |
Start development client |
bun run lint |
Run Biome linter for client |
bun run format |
Format client code with Biome |
bun run test |
Run client tests |
This template uses Biome for both linting and formatting:
# Check for linting issues
bun run lint
# Auto-fix linting issues and format code
bun run formatThis template includes Lefthook for automated Git hooks and Commitlint for enforcing Conventional Commits:
Git hooks will automatically run on:
- Pre-commit: Format code, run linter, and type-check
- Commit-msg: Validate commit message format
- Pre-push: Final lint and type checks
All commit messages must follow the Conventional Commits specification:
# β
Valid commit messages
git commit -m "feat: add user authentication"
git commit -m "fix: resolve memory leak in data processing"
git commit -m "docs: update API documentation"
git commit -m "refactor: simplify error handling logic"
# β Invalid commit messages
git commit -m "add feature" # Missing type
git commit -m "Fix bug" # Wrong case
git commit -m "feat!: breaking change" # Use BREAKING CHANGE footer insteadAvailable commit types:
feat- New featuresfix- Bug fixesdocs- Documentation changesstyle- Code style changes (formatting, etc.)refactor- Code refactoringperf- Performance improvementstest- Adding or updating testsbuild- Build system changesci- CI configuration changeschore- Other changes (maintenance, etc.)revert- Reverting previous commits
# Install hooks (automatically runs after `bun install`)
bun run prepare
# Skip hooks for a single commit (use sparingly)
git commit -m "feat: add feature" --no-verify
# Temporarily disable hooks
lefthook uninstall
# Re-enable hooks
lefthook installβββ apps/ # Monorepo applications
β βββ grape/ # Grape DHT nodes for service discovery
β β βββ package.json # Grape app dependencies and scripts
β β βββ index.js # Grape DHT node implementation
β βββ server/ # Grenache microservice server
β β βββ package.json # Server dependencies and scripts
β β βββ index.js # Server implementation
β βββ client/ # Grenache microservice client
β βββ package.json # Client dependencies and scripts
β βββ index.js # Client implementation
βββ libs/ # Shared libraries
β βββ biome/ # Shared Biome configuration
βββ .moon/ # Moonrepo configuration
βββ package.json # Root workspace configuration
βββ lefthook.yml # Git hooks configuration
βββ README.md # You are here! π
The biome.json includes:
- All recommended rules enabled
- Tab indentation (configurable)
- Git integration
- Import organization
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Run the linter and formatter:
bun run format - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
To customize this template for your project:
- Update package.json files with your project details in root and each app
- Modify the microservices in
apps/server/index.jsandapps/client/index.jsto fit your needs - Adjust Biome configs in
libs/biome/as needed - Configure Grape DHT ports in
apps/grape/package.jsonfor your network setup - Update this README with your project-specific information
Please see SECURITY.md for our security policy and how to report security vulnerabilities.
This project is licensed under the Apache Licenseβsee the LICENSE file for details.
- Bun for the amazing runtime
- Biome for fast linting and formatting
- Grenache for the microservices framework
- Bitfinex for creating and maintaining Grenache
- Moonrepo for excellent monorepo tooling
Happy coding! π If you find this template useful, please give it a βοΈ