Setup
This guide helps you set up a complete development environment for contributing to BarStrad-Bot.
Prerequisites
Ensure you have the following tools installed:
Required Tools
- Node.js (v18 or higher) - Download
- npm (comes with Node.js) or yarn
- Git - Download
- Docker - Download
- VS Code (recommended) - Download
Recommended VS Code Extensions
- TypeScript and JavaScript Language Features (built-in)
- ESLint - Code linting
- Prettier - Code formatting
- Docker - Docker container management
- GitLens - Enhanced Git capabilities
Initial Setup
1. Fork and Clone Repository
# Fork the repository on GitHub, then clone your fork
git clone https://github.com/YOUR_USERNAME/BarStrad-Bot.git
cd BarStrad-Bot
# Add upstream remote for staying in sync
git remote add upstream https://github.com/The-Running-Dev/BarStrad-Bot.git
2. Install Dependencies
# Install Node.js dependencies
npm install
# Or if you prefer yarn
yarn install
3. Environment Configuration
Create a .env
file in the root directory:
# Discord Bot Configuration
DiscordBotToken=your_development_bot_token_here
DiscordWebhookUrl=your_development_webhook_url_here
# Environment Settings
NODE_ENV=development
DEBUG=true
Important: Never commit your .env
file. It's already in .gitignore
.
4. Discord Development Bot Setup
For development, create a separate Discord bot:
- Go to Discord Developer Portal
- Create a new application (e.g., "BarStrad-Bot-Dev")
- Create a bot and copy the token
- Create a test Discord server for development
- Invite your development bot to the test server
Development Workflow
Starting Development Server
# Start with hot reload
npm run dev
# Or with yarn
yarn dev
This uses ts-node
to run TypeScript directly with automatic restarts on file changes.
Code Structure Understanding
src/
├── Bot.ts # Main bot class - handles Discord events
├── index.ts # Application entry point
├── Menu.ts # Menu management logic
├── data/ # Menu data files (JSON)
│ ├── menu-items.bg.json # Bulgarian menu
│ └── menu-items.en.json # English menu
├── models/ # TypeScript interfaces
│ ├── menu-item.model.ts # Menu item structure
│ ├── menu-category.model.ts # Category structure
│ └── menu-data.model.ts # Overall menu structure
├── services/ # Business logic services
│ └── discord-notification.service.ts # Webhook notifications
└── environments/ # Environment configuration
└── environment.ts # Environment settings
Development Commands
Command | Purpose |
---|---|
npm run dev | Start development server with hot reload |
npm run build | Build TypeScript to JavaScript |
npm run start | Start production build |
npm test | Run tests (when available) |
Code Style and Standards
TypeScript Configuration
The project uses strict TypeScript configuration:
{
"compilerOptions": {
"target": "es2020",
"module": "CommonJS",
"outDir": "./artifacts",
"rootDir": "./src",
"strict": true
}
}
Coding Standards
- TypeScript: Use strict typing, avoid
any
- Naming: Use PascalCase for classes, camelCase for variables
- Imports: Use explicit import/export statements
- Error Handling: Always handle errors gracefully
- Comments: Document complex logic and public APIs
Example Code Style
// Good - Explicit types and error handling
export class Menu {
private data: MenuData;
private currentLanguage: string;
constructor() {
this.currentLanguage = 'bg';
this.data = this.loadMenu(this.currentLanguage);
}
private loadMenu(language: string): MenuData {
try {
const fileContent = fs.readFileSync(`data/menu-items.${language}.json`, "utf-8");
return { categories: JSON.parse(fileContent) };
} catch (error) {
console.error(`Error loading menu: ${error}`);
return { categories: [] };
}
}
}
Testing Your Changes
Manual Testing
-
Start Development Bot
npm run dev
-
Test Basic Commands in your Discord test server:
!menu
!menu-en
!order 1 Test User -
Verify Console Output for errors or warnings
Menu Changes Testing
When modifying menu files:
-
Validate JSON Syntax:
node -e "console.log(JSON.parse(require('fs').readFileSync('src/data/menu-items.bg.json', 'utf8')))"
-
Test Both Languages:
!menu # Test Bulgarian menu
!menu-en # Test English menu -
Test Order Numbers:
!order 1 Test
!order [last_item_number] Test
Docker Testing
Test your changes in a containerized environment:
# Build production version
npm run build
# Build Docker image
docker build -t barstrad-bot-dev .
# Run container with your environment
docker run --env-file .env barstrad-bot-dev
CI/CD Workflow Testing
Test your changes against the actual CI/CD workflows before pushing:
# Test CI workflow locally (validates your code)
.\scripts\ci-workflow.ps1
This validates your changes using the same environment as the CI/CD pipeline. For detailed instructions, see Local Testing with Act.
Making Changes
Feature Development Process
-
Create Feature Branch
git checkout -b feature/your-feature-name
-
Make Your Changes
- Follow existing code patterns
- Add appropriate error handling
- Update documentation if needed
-
Test Thoroughly
- Test all affected commands
- Verify no regressions
- Test edge cases
-
Commit Changes
git add .
git commit -m "Add feature: your feature description" -
Push and Create PR
git push origin feature/your-feature-name
Common Development Tasks
Adding New Commands
- Update Bot.ts - Add new command handler in
messageCreate
event - Add Logic - Create appropriate service methods
- Update Documentation - Add command to documentation
- Test Thoroughly - Verify command works as expected
Modifying Menu System
- Update Models - Modify TypeScript interfaces if needed
- Update Menu.ts - Modify menu loading/display logic
- Update Menu Files - Modify JSON menu data
- Test Both Languages - Ensure consistency
Adding New Services
- Create Service File - Add new file in
src/services/
- Define Interface - Create TypeScript interfaces
- Integrate Service - Connect to main Bot class
- Add Error Handling - Handle service failures gracefully
Debugging
Console Debugging
The bot provides detailed console logging:
console.log(`✅ Logged in as ${this.client.user?.tag}`);
console.error("❌ No Bot Token Found in .env File!");
VS Code Debugging
Create .vscode/launch.json
:
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug BarStrad-Bot",
"type": "node",
"request": "launch",
"program": "${workspaceFolder}/src/index.ts",
"outFiles": ["${workspaceFolder}/artifacts/**/*.js"],
"runtimeArgs": ["-r", "ts-node/register"],
"env": {
"NODE_ENV": "development"
}
}
]
}
Common Debug Scenarios
- Bot Not Connecting: Check Discord token and internet connection
- Commands Not Working: Verify bot permissions and command syntax
- Menu Not Loading: Check JSON syntax and file paths
- Webhooks Failing: Verify webhook URL and permissions
Contributing Guidelines
Before Submitting a PR
-
Code Review Checklist:
- Code follows project style guidelines
- All new code has appropriate error handling
- Changes are tested manually
- Documentation is updated if needed
- No console errors or warnings
-
PR Description Should Include:
- Clear description of changes
- Steps to test the changes
- Screenshots if UI-related
- Related issue references
Code Review Process
- Automated Checks: CI workflow runs automatically
- Manual Review: Maintainers review code and functionality
- Testing: Changes tested in development environment
- Merge: Approved changes merged to main branch
- Deployment: Release workflow deploys to production
Staying in Sync
Syncing with Upstream
# Fetch upstream changes
git fetch upstream
# Switch to main branch
git checkout main
# Merge upstream changes
git merge upstream/main
# Push to your fork
git push origin main
Resolving Conflicts
# If conflicts occur during merge
git status # See conflicted files
# Edit files to resolve conflicts
git add . # Stage resolved files
git commit # Complete merge
Development Resources
Documentation
- Discord.js Guide - Discord bot development
- TypeScript Handbook - TypeScript language guide
- Node.js Documentation - Node.js API reference
Tools
- JSON Validator - Validate menu JSON files
- Discord Developer Portal - Manage Discord apps
- GitHub CLI - Command-line GitHub operations
Ready to contribute? Check out our open issues or suggest new features!