Skip to content

Building from Source

Build Alita Robot from source for development, customization, or when pre-built binaries are not available for your platform.

ToolMinimum VersionPurpose
Go1.25+Compilation
Git2.0+Clone repository
MakeAnyBuild automation
golangci-lintLatestCode quality checks
Terminal window
# macOS
brew install go
# Ubuntu/Debian
sudo snap install go --classic
# Or download from https://go.dev/dl/
Terminal window
# macOS
brew install golangci-lint
# Linux/macOS via script
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin
# Go install
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
Terminal window
git clone https://github.com/divkix/Alita_Robot.git
cd Alita_Robot

Run the bot directly from source:

Terminal window
# Using Make
make run
# Or using Go directly
go run main.go

Build optimized release binaries using GoReleaser:

Terminal window
# Install GoReleaser
go install github.com/goreleaser/goreleaser@latest
# Build
make build

This creates binaries in the dist/ directory for all supported platforms.

Build for your current platform:

Terminal window
go build -o alita_robot .

Build with optimizations:

Terminal window
go build -ldflags="-s -w" -o alita_robot .

Cross-compile for other platforms:

Terminal window
# Linux amd64
GOOS=linux GOARCH=amd64 go build -o alita_robot_linux_amd64 .
# macOS arm64
GOOS=darwin GOARCH=arm64 go build -o alita_robot_darwin_arm64 .
# Windows amd64
GOOS=windows GOARCH=amd64 go build -o alita_robot_windows_amd64.exe .
TargetCommandDescription
runmake runRun the bot from source
buildmake buildBuild release binaries with GoReleaser
lintmake lintRun golangci-lint for code quality
tidymake tidyClean and download go.mod dependencies
vendormake vendorVendor dependencies
psql-migratemake psql-migrateApply database migrations
psql-statusmake psql-statusCheck migration status
psql-resetmake psql-resetReset database (DANGEROUS)
Terminal window
make lint

This runs golangci-lint with the project’s configuration. Fix any issues before committing.

Terminal window
make tidy

This:

  • Removes unused dependencies
  • Downloads missing dependencies
  • Updates go.sum checksums
Alita_Robot/
├── main.go # Entry point
├── go.mod # Go module definition
├── go.sum # Dependency checksums
├── Makefile # Build automation
├── .goreleaser.yaml # GoReleaser configuration
├── sample.env # Example environment file
├── docker-compose.yml # Docker Compose configuration
├── alita/ # Main application code
│ ├── config/ # Configuration loading
│ ├── db/ # Database models and operations
│ ├── modules/ # Bot command handlers
│ ├── utils/ # Utility functions
│ ├── i18n/ # Internationalization
│ └── health/ # Health check handlers
├── migrations/ # SQL migration files
├── locales/ # Translation files
└── docs/ # Documentation

For development, run with debug logging:

Terminal window
DEBUG=true make run

Or set in your .env file:

Terminal window
DEBUG=true

Debug mode:

  • Increases log verbosity
  • Disables performance monitoring
  • Shows detailed error stack traces

The .goreleaser.yaml defines the build process:

version: 2
project_name: alita_robot
builds:
- binary: alita_robot
env:
- CGO_ENABLED=0
goos:
- darwin
- linux
- windows
goarch:
- amd64
- arm64
flags:
- -trimpath
ldflags:
- -s -w -X main.version={{.Version}} -X main.commit={{.Commit}}

After running make build, binaries are created in:

dist/
├── alita_robot_linux_amd64/
│ └── alita_robot
├── alita_robot_linux_arm64/
│ └── alita_robot
├── alita_robot_darwin_amd64/
│ └── alita_robot
├── alita_robot_darwin_arm64/
│ └── alita_robot
├── alita_robot_windows_amd64/
│ └── alita_robot.exe
└── checksums.txt

Key dependencies from go.mod:

PackagePurpose
gotgbot/v2Telegram Bot API client
gorm.io/gormORM for database operations
go-redis/v9Redis client
sirupsen/logrusStructured logging
spf13/viperConfiguration management
sentry-goError tracking
prometheus/client_golangMetrics

While the project primarily uses golangci-lint for quality checks:

Terminal window
# Run linter (recommended before commits)
make lint
# Test manually with a test bot
DEBUG=true make run

Use air for automatic reloading during development:

Terminal window
# Install air
go install github.com/air-verse/air@latest
# Create .air.toml
air init
# Run with hot reload
air

Example .air.toml:

root = "."
tmp_dir = "tmp"
[build]
cmd = "go build -o ./tmp/alita_robot ."
bin = "tmp/alita_robot"
include_ext = ["go"]
exclude_dir = ["tmp", "vendor", "docs"]
  1. Fork the repository
  2. Create a feature branch
  3. Make changes
  4. Run make lint and fix any issues
  5. Submit a pull request

See Contributing Guide for more details.

go: go.mod requires go >= 1.25

Update Go to version 1.25 or higher.

Terminal window
# Install golangci-lint
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
# Add to PATH
export PATH=$PATH:$(go env GOPATH)/bin
Terminal window
# Clear module cache
go clean -modcache
# Download dependencies
make tidy

The bot is built with CGO_ENABLED=0 for static binaries. If you need CGO:

Terminal window
CGO_ENABLED=1 go build -o alita_robot .

Note: CGO requires C compiler and platform-specific libraries.