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

https://github.com/enum314/nemesis

Nemesis is a modern Discord bot template designed to streamline bot development with best practices, advanced infrastructure, and seamless deployment. Built with Node.js 22, Discord.js, and PNPM 10, it includes Docker, CI/CD workflows, and Pterodactyl integration for easy hosting.
https://github.com/enum314/nemesis

best-practices bot-template cicd discord-bot discordjs docker nodejs pnpm pterodactyl-egg scalable-infrastructure

Last synced: 9 months ago
JSON representation

Nemesis is a modern Discord bot template designed to streamline bot development with best practices, advanced infrastructure, and seamless deployment. Built with Node.js 22, Discord.js, and PNPM 10, it includes Docker, CI/CD workflows, and Pterodactyl integration for easy hosting.

Awesome Lists containing this project

README

          

# Nemesis

A modern Discord bot template designed to jumpstart your bot development with best practices and ready-to-use infrastructure. While primarily focused on Discord bots, Nemesis can also serve as a foundation for any Node.js application.

## ๐Ÿš€ About This Template

This is a template repository that provides a solid foundation for building modern Discord bots and Node.js applications. It's designed to be forked or used as a starting point for new projects, saving you hours of initial setup and configuration.

The template offers:

- **Discord.js integration** with advanced sharding and bot framework
- **Ready-to-use infrastructure** with Docker, CI/CD workflows, and deployment scripts
- **Modern tech stack** with Node.js 22 and PNPM 10
- **Development best practices** baked in from the start
- **Production-ready configuration** for immediate deployment
- **Pterodactyl integration** for easy hosting on game server panels

## ๐Ÿ“‹ Prerequisites

- [Node.js](https://nodejs.org/) v22 or later
- [PNPM](https://pnpm.io/) v10 or later
- [Docker](https://www.docker.com/) and [Docker Compose](https://docs.docker.com/compose/) (optional, for containerized development)
- [Git](https://git-scm.com/)

## ๐Ÿ› ๏ธ Getting Started

### Using This Template

```bash
# Clone the template (or use GitHub's "Use this template" button)
git clone https://github.com/enum314/nemesis.git my-new-project
cd my-new-project

# Customize for your project
# - Update package.json with your project details
# - Modify .env.example for your environment variables
# - Customize the Dockerfile if needed
# - Update this README!

# Install dependencies
pnpm install

# Start development server
pnpm dev
```

### Local Development

```bash
# Start development environment
pnpm dev

# OR with Docker
docker-compose up app-dev
```

### Production Environment

```bash
# Start production environment with Docker
docker-compose up app-prod
```

## ๐Ÿšข Deployment Options

### 1. Server Deployment with Script

This template includes a deployment script that pulls directly from GitHub:

```bash
# First-time deployment
./deploy.sh --first-run --path /opt/nemesis

# Update existing deployment
./deploy.sh --update --path /opt/nemesis

# Specify a different GitHub repository
./deploy.sh --first-run --github-user username --repository repo-name --path /opt/nemesis

# For private repositories, include a personal access token
./deploy.sh --first-run --github-user username --repository repo-name --token YOUR_TOKEN --path /opt/nemesis
```

The deployment script supports various options:

```bash
Usage: deploy.sh [OPTIONS]
Options:
--github-user USER GitHub username (default: enum314)
--repository REPO Repository name (default: nemesis)
--token TOKEN GitHub personal access token for private repos
--branch NAME Branch to deploy (default: main)
--path PATH Installation path (default: /opt/nemesis)
--first-run Perform first-time setup
--force-rebuild Force rebuild of Docker containers
--show-logs Show Docker logs after deployment
--update Update existing deployment
--help Show this help message
```

### 2. Pterodactyl Panel Deployment

The template includes Pterodactyl egg files for deployment on Pterodactyl game server panels:

- `egg-nemesis.json` - JSON format egg for Pterodactyl
- `egg-nemesis.yml` - YAML format egg for Pterodactyl

#### How to Use the Pterodactyl Egg:

1. **Import to Pterodactyl Panel**:

- Log in to your Pterodactyl admin panel
- Go to Nests > Import Egg
- Upload the `egg-nemesis.json` file

2. **Create a New Server**:

- In the Pterodactyl admin panel, create a new server
- Select the Nemesis egg from the list
- Configure server settings including port allocations and resources

3. **Configurable Options**:

- **Auto Update**: Automatically pull changes on startup
- **Node Environment**: Choose between production, development, staging, or test
- **Additional Packages**: Install extra Node.js packages if needed
- **Wipe Directory**: Option to clean installation directory
- **Startup Command**: Customize how the application starts
- **GitHub Repository Settings**:
- **GitHub Username**: Username of the repository owner
- **GitHub Repository**: Name of the repository to clone
- **GitHub Branch**: Branch to use (default: main)
- **GitHub Personal Access Token**: For private repositories (optional)

4. **After Installation**:
- The server will automatically install your project from the specified GitHub repository
- It will configure the correct port in .env
- The server will build and start automatically

The deployment script handles:

- Environment setup
- Pulling latest changes from GitHub
- Building and starting Docker containers
- Intelligent rebuilding (only when needed)
- Status checking and error reporting

## ๐Ÿ—๏ธ Template Structure

```
nemesis/
โ”œโ”€โ”€ .github/workflows/ # GitHub Actions CI/CD configurations
โ”œโ”€โ”€ src/ # Application source code
โ”œโ”€โ”€ .dockerignore # Files to exclude from Docker build
โ”œโ”€โ”€ .env.example # Example environment variables
โ”œโ”€โ”€ Dockerfile # Docker configuration
โ”œโ”€โ”€ docker-compose.yml # Docker Compose configuration
โ”œโ”€โ”€ deploy.sh # Deployment script
โ”œโ”€โ”€ egg-nemesis.json # Pterodactyl egg (JSON format)
โ”œโ”€โ”€ egg-nemesis.yml # Pterodactyl egg (YAML format)
โ”œโ”€โ”€ package.json # Project metadata and scripts
โ”œโ”€โ”€ pnpm-lock.yaml # Lock file for dependencies
โ””โ”€โ”€ tsconfig.json # TypeScript configuration
```

## ๐Ÿณ Docker

This project includes a multi-stage Dockerfile and Docker Compose configuration:

### Development

```bash
docker-compose up app-dev
```

- Hot reload enabled
- Source code mounted as a volume
- Running on port 3001
- Development dependencies included

### Production

```bash
docker-compose up app-prod
```

- Optimized build with minimal dependencies
- Running on port 3001
- Production-ready configuration

### Building Images Manually

```bash
# Build development image
docker build --target development -t nemesis-dev .

# Build production image
docker build --target production -t nemesis-prod .
```

## ๐Ÿ“ Available Scripts

- `pnpm dev` - Start development server
- `pnpm build` - Build for production
- `pnpm start` - Start production server
- `pnpm test` - Run tests and build
- `pnpm lint` - Check for code style issues
- `pnpm v:patch` - Version bump patch (0.0.x)
- `pnpm v:minor` - Version bump minor (0.x.0)
- `pnpm v:major` - Version bump major (x.0.0)

## ๐Ÿค– Discord Bot Sharding

This template includes support for Discord.js sharding, which helps distribute your bot's load across multiple processes when it grows to serve more guilds.

### What is Sharding?

Discord requires sharding for bots in 2,500+ guilds. Sharding splits your bot into multiple processes, each handling a portion of the guilds, which:

- Reduces memory usage and CPU load per process
- Improves performance by distributing workload
- Is required by Discord for larger bots

### Using Sharding

Sharding can be enabled/disabled through:

**Environment Variables**:

- `ENABLE_SHARDING`: Set to "true" to enable sharding
- `TOTAL_SHARDS`: Number of shards to spawn, or "auto" to let Discord.js decide

You can enable sharding by setting these environment variables before starting your bot:

```bash
# Enable sharding with environment variables
ENABLE_SHARDING=true node .

# Or with a specific number of shards
ENABLE_SHARDING=true TOTAL_SHARDS=2 node .
```

This approach gives you more flexibility since it doesn't rely on predefined scripts. Instead, you can control sharding directly through environment variables when starting the bot. This keeps things simpler and gives you more control over the configuration.

Let me know if you'd prefer a different approach to enabling/disabling sharding in your bot!

## ๐Ÿšข CI/CD

The template includes GitHub workflows for:

- **PR Staging**: Runs tests, lint checks, and builds on pull requests
- **Staging**: Runs tests and lint checks when merging to main

## ๐Ÿ›ก๏ธ Environment Variables

Copy `.env.example` to `.env` and adjust the variables as needed:

```bash
cp .env.example .env
```

Required environment variables:

- `PORT`: Application port (default: 3001)
- Other variables as specified in `.env.example`

## ๐Ÿงช Testing

```bash
# Run tests
pnpm test

# Run linting
pnpm lint
```

## ๐Ÿ“„ License

This template is licensed under the MIT License - see the LICENSE file for details.

## ๐Ÿ‘ฅ Customizing This Template

1. Replace this README with information specific to your project
2. Update package.json with your project details
3. Customize the Docker setup if needed
4. Update environment variables in .env.example
5. Add your application code to the src directory