This file contains instructions for agentic coding agents working on the TelDrive codebase.
The project uses task (taskfile.yml) for build automation and standard Go toolchain.
- Build Server:
task server(builds binary tobin/teldrive) - Build UI:
task ui(downloads frontend assets) - Full Build:
task(runsuithenserver) - Install Dependencies:
task deps(runsgo mod download && go mod tidy) - Generate Code:
task gen(runsgo generate ./...)
- Run All Tests:
go test ./... - Run Specific Package:
go test ./internal/config/... - Run Specific Test:
go test -v ./internal/config -run TestConfigLoader - Run with Race Detector:
go test -race ./...
- Run Linter:
task lint(runsgolangci-lint run) - Format Code:
go fmt ./...
- Go Standard: Strictly follow
gofmtand standard Go idioms. - Imports: Group imports into standard library, 3rd party, and local packages.
- Line Length: Aim for readable line lengths (soft limit ~120 chars), but prioritize readability.
cmd/: Entry points for the application commands (server, check, etc.).internal/: Private application code.config/: Configuration loading (Koanf based).database/: Database interactions (GORM).tgc/: Telegram client wrappers.
pkg/: Library code that might be imported by other projects.services/: Core business logic and API handlers.models/: GORM database models.
- Interfaces: Named with
-ersuffix (e.g.,Reader,Writer) where appropriate. - Structs: PascalCase.
- Variables: camelCase.
- Constants: PascalCase or SCREAMING_SNAKE_CASE.
- Package Names: Short, lowercase, single word (e.g.,
config,auth).
- Wrapping: Use
%wto wrap errors to preserve context. - Check Errors: Never swallow errors. Handle them or return them.
- Panic: Avoid panic except during initialization/startup where recovery is impossible.
- Logging: Use
zaplogger vialogging.FromContext(ctx).- Levels: Use
Debugfor trace info,Infofor general ops,Errorfor failures. - Fields: Use structured logging (e.g.,
zap.String("key", "value")).
- Levels: Use
- Library: Uses
knadh/koanf/v2. - Loading: Loads from Defaults -> Config File -> Env Vars -> Flags.
- Validation: Uses
go-playground/validator. Ensure struct tagsvalidate:"..."are present. - Mapping: Use explicit mapping in
populatemethod ininternal/config/config.go(avoid reflection where possible).
- Library: GORM with PostgreSQL.
- Migrations: Use SQL migrations in
internal/database/migrationsor GORM auto-migration if configured. - Context: Always pass
ctxto database calls.
- Library:
gotd/td. - Session: Managed via
internal/tgcand database. - Concurrency: Be mindful of Telegram rate limits. Use
tgc.NewMiddlewarewith rate limiters.
- Location:
ui/directory. - Assets: Embeds frontend in binary via
embedpackage or serves fromui/dist.
- Dependencies: Ensure
taskis installed. - Generate: Run
task genif modifying API definitions or generated code. - Test: Write unit tests for new logic, especially in
internal/packages. - Lint: Run linter before committing.