- Create docs/ with 7 focused files: architecture, api, scoring, agent, deployment, freeswitch, development - Rewrite README.md as concise overview with links to docs/ - Remove AGENTS.md (content merged into docs/ and README)
3.6 KiB
3.6 KiB
Development
Requirements
- Go 1.26+
- Node.js 22+
- NATS Server (auto-downloaded via
make nats)
Build
git clone git@git.totmin.ru:en2zmax/pulse-lets-go.git
cd pulse-lets-go
make build
Makefile Commands
| Command | Description |
|---|---|
make build |
Full build (Go + SvelteKit) |
make dev |
Go backend + SvelteKit dev server (hot-reload) |
make test |
Go tests with coverage |
make test-race |
Tests with race detector |
make lint |
go vet ./... |
make fmt |
go fmt ./... |
make build-agent |
Build pulse-lets-go-agent |
make build-siptest |
Build SIP tester |
make emulate-* |
Metrics emulation (normal, overload, chaos, stale, ...) |
make siptest-* |
SIP testing (uas, uac, full) |
make nats |
Start local NATS server |
Running Locally
# Terminal 1: NATS
make nats
# Terminal 2: balancer
./bin/pulse-lets-go
# Terminal 3: metrics emulator (3 healthy nodes)
make emulate-normal
Code Style
Before committing:
make fmt
make lint
make test
Project Structure
pulse-lets-go/
├── cmd/
│ ├── pulse-lets-go/ # Main entry point
│ ├── pulse-lets-go-agent/ # Metrics collector (FS / Asterisk)
│ ├── emulator/ # Metrics emulator for testing
│ └── siptest/ # SIP tester for e2e checks
├── internal/
│ ├── api/ # HTTP handlers (auth, nodes, trunks, users, monitoring, ws, route)
│ ├── config/ # JSON config manager (atomic save, thread-safe)
│ ├── engine/ # Scoring engine + router (sync.RWMutex, best-node cache)
│ ├── esl/ # FreeSWITCH ESL client (raw TCP)
│ ├── ami/ # Asterisk AMI client (raw TCP)
│ ├── log/ # ASCII metrics logger with rotation
│ ├── models/ # Data types (NodeMetric, NodeState, Trunk, User, ...)
│ └── nats/ # NATS subscriber
├── contrib/ # route.lua, agent configs
├── deploy/ # systemd unit
├── web/ # SvelteKit frontend
└── data/ # Runtime JSON files (gitignored)
Adding a New Endpoint
- Define model in
internal/models/types.go - Implement handler in
internal/api/<name>.go - Register route in
internal/api/router.gowith required middleware (auth, admin) - Add tests in
internal/engine/engine_test.goif scoring is affected
Commit Messages
Conventional Commits format:
feat: add support for custom scoring weights
fix: handle nil ESL client in route handler
docs: add API reference table to README
refactor: extract scoring logic into separate method
test: add lethal condition tests for stale nodes
chore: update Go dependencies
Implementation Order
cmd/pulse-lets-go/main.go+ Go module + пустая структураinternal/internal/models/— все типы данныхinternal/config/— чтение/запись JSON, атомарное сохранениеinternal/nats/— подписка, in-memory storeinternal/engine/— scorer + routerinternal/api/— все хендлерыinternal/log/— ASCII-логгер + ring buffer- Web-фронт (SvelteKit)
- Makefile + systemd unit
- Тесты + graceful shutdown
PR Process
- Branch from
main, namedfeature/,fix/, ordocs/ - One PR — one logical change
- All tests pass (
make test) - Code passes
make lint - If API changes — update docs