Building from Source
Compile Alita Robot from source code.
Build Alita Robot from source for development, customization, or when pre-built binaries are not available for your platform.
Prerequisites
| Tool | Minimum Version | Purpose |
|---|---|---|
| Go | 1.26+ | Compilation |
| Git | 2.0+ | Clone repository |
| Make | Any | Build automation |
| golangci-lint | Latest | Code quality checks |
Install Go
Install golangci-lint
brew install golangci-lintcurl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bingo install github.com/golangci/golangci-lint/cmd/golangci-lint@latestClone the Repository
git clone https://github.com/divkix/Alita_Robot.git
cd Alita_Robot
Build Commands
Development Build
Run the bot directly from source:
# Using Make
make run
# Or using Go directly
go run main.go
Production Build
Install GoReleaser
go install github.com/goreleaser/goreleaser/v2@latestBuild release binaries
make buildThis creates binaries in the dist/ directory for all supported platforms.
Manual Build
Build for your current platform:
go build -o alita_robot .
Cross-compile for other platforms:
# 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 .
Makefile Targets
| Target | Command | Description |
|---|---|---|
run |
make run |
Run the bot from source |
build |
make build |
Build release binaries with GoReleaser |
lint |
make lint |
Run golangci-lint for code quality |
tidy |
make tidy |
Clean and download go.mod dependencies |
vendor |
make vendor |
Vendor dependencies |
test |
make test |
Run test suite (SQLite + miniredis; -tags testtools -race -coverprofile=coverage.out) |
psql-migrate |
make psql-migrate |
Apply database migrations |
psql-status |
make psql-status |
Check migration status |
psql-reset |
make psql-reset |
Reset database (DANGEROUS) |
validate-db |
make validate-db |
Validate database for orphaned data |
backup-db |
make backup-db |
Backup database before migrations |
check-translations |
make check-translations |
Detect missing translation keys |
check-duplicates |
make check-duplicates |
Check for duplicate code |
check-docs |
make check-docs |
Check documentation integrity |
inventory |
make inventory |
Show project structure inventory |
generate-docs |
make generate-docs |
Generate documentation site content |
docs-dev |
make docs-dev |
Start the docs dev server |
Code Quality
Run Linter
make lint
This runs golangci-lint with the project’s configuration. Fix any issues before committing.
Check Dependencies
make tidy
This:
- Removes unused dependencies
- Downloads missing dependencies
- Updates
go.sumchecksums
Project Structure
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
├── .dockerignore # Docker ignore rules
├── debug.docker-compose.yml # Debug compose configuration
├── alita/ # Main application code
│ ├── config/ # Configuration loading
│ ├── db/ # Database models and operations
│ ├── modules/ # Bot command handlers
│ ├── utils/ # Utility functions (incl. httpserver for health/metrics/webhook)
│ ├── i18n/ # Internationalization
├── migrations/ # SQL migration files
├── locales/ # Translation files
└── docs/ # Documentation
Development Mode
For development, run with debug logging:
DEBUG=true make run
Or set in your .env file:
DEBUG=true
GoReleaser Configuration
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
mod_timestamp: "{{ .CommitTimestamp }}"
Build Output
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
Dependencies
Key dependencies from go.mod:
| Package | Purpose |
|---|---|
gotgbot/v2 |
Telegram Bot API client |
gorm.io/gorm |
ORM for database operations |
redis/go-redis/v9 |
Redis client |
sirupsen/logrus |
Structured logging |
prometheus/client_golang |
Metrics |
Testing
# Run linter (recommended before commits)
make lint
# Run test suite
make test
# Test manually with a test bot
DEBUG=true make run
Hot Reload (Development)
# 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"]
Contributing
- Fork the repository
- Create a feature branch
- Make changes
- Run
make lintand fix any issues - Submit a pull request
See Contributing Guide for more details.
Troubleshooting
Go version too old
go: go.mod requires go >= 1.26
Update Go to version 1.26 or higher.
golangci-lint not found
# Install golangci-lint
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
# Add to PATH
export PATH=$PATH:$(go env GOPATH)/bin
Module download errors
# Clear module cache
go clean -modcache
# Download dependencies
make tidy
Build fails with CGO errors
CGO_ENABLED=1 go build -o alita_robot .