- Go 100%
| cmd | ||
| docs | ||
| internal | ||
| migrations | ||
| .golangci.yml | ||
| config.example.yaml | ||
| go.mod | ||
| go.sum | ||
| README.md | ||
Still Alive Bot
A Telegram bot that periodically polls users at a configurable interval. If a user does not respond, the bot sends alert messages to the user's pre-registered trusted contacts (relatives).
Project Structure
cmd/
api/ — API server entrypoint
migrator/ — Database migration tool
internal/
app/ — Application bootstrap
config/ — Configuration parsing and validation
domain/ — Domain entities, repository interfaces, and errors
repository — Repository implementations (SQLite)
migrations/ — SQL migration files (up/down)
docs/ — Documentation and diagrams
Configuration
Configuration is loaded from a YAML file (default: config.yaml). See
config.example.yaml for all available options.
The bot token can be provided either in the config file (bot.token) or via the
bot_token environment variable.
Migrations
Run up migrations:
go run ./cmd/migrator -config config.yaml
Run down migrations:
go run ./cmd/migrator -config config.yaml -down
Running
go run ./cmd/api -config config.yaml
Database Schema
See docs/db_schema.png for the ER diagram.
Storage Conventions
active— stored asINTEGERwithCHECK(active IN (0, 1));0= inactive,1= active.poll_interval— stored asTEXTrepresenting a Gotime.Durationstring (e.g."5m","1h30m").last_seen,next_poll— stored asTEXTin RFC 3339 / ISO 8601 format (Gotime.Timedefault).
Testing
go test ./internal/repository/ -v
Repository tests use an in-memory SQLite database (:memory:) created once per
top-level test function via setupTestDB.
Each sub-test runs inside a transaction that is rolled back in t.Cleanup,
ensuring full isolation between test cases without the overhead of recreating
the database schema for every test.
Repository implementations depend on the DBTX
interface (satisfied by both *sql.DB and *sql.Tx), which enables this
transaction-based isolation pattern.