Version: 0.7.1 Updated: 2026-02-08
This directory contains comprehensive documentation for the glcmd project, a LibreView glucose monitoring toolkit consisting of a daemon (glcore) and a CLI client (glcli).
HTTP API reference documentation:
- Complete endpoint specifications
- Request/response formats
- Query parameters and validation
- Error handling
- Pagination and filtering
- Example curl commands
- Complete usage script
Read this if you want to:
- Integrate with the glcmd API programmatically
- Query glucose data via HTTP
- Monitor daemon health and metrics
- Build custom dashboards or integrations
Complete architectural overview covering:
- Layered architecture design (domain, persistence, repository, service, daemon)
- Design patterns (Repository, Service, Unit of Work, Retry)
- Database schema and migrations
- Testing strategy and coverage
- Performance considerations
Read this if you want to:
- Understand the codebase structure
- Learn about the design decisions
- Contribute to the project
- Extend functionality with new features
Environment variable configuration reference:
- Database configuration (SQLite)
- Application settings
- Logging configuration
- Configuration examples for different environments
- Security best practices
- Troubleshooting guide
Read this if you want to:
- Configure glcmd for your environment
- Deploy glcmd in production
- Troubleshoot connection or performance issues
- Set up containerized deployment
-
Clone and build:
git clone <repository> cd glcmd make
-
Create data directory:
mkdir -p data
-
Set environment variables:
export GLCMD_EMAIL=your-email@example.com export GLCMD_PASSWORD=your-password export GLCMD_DB_PATH=./data/glcmd.db export GLCMD_LOG_LEVEL=info
-
Run daemon:
./bin/glcore
-
Query data with CLI (in another terminal):
./bin/glcli ./bin/glcli stats --period 7d ./bin/glcli sensor
# Run all tests
make test
# Run tests with coverage
make test-coverage
# Run tests with race detector
make test-raceSee ENV_VARS.md for production configuration examples including:
- Systemd service configuration
- Docker Compose setup
- Security best practices
cmd/glcore (daemon entry point)
↓
internal/daemon (API polling)
↓
internal/api (unified HTTP server on port 8080)
↓
internal/service (business logic)
↓
internal/repository (data access)
↓
internal/persistence (database)
↓
internal/domain (models)
cmd/glcli (CLI entry point, Cobra)
↓
internal/cli (HTTP client + formatters)
Key Features:
- Two binaries:
glcore(daemon) andglcli(CLI client) - Unified HTTP API server on port 8080 with 9 endpoints
- CLI with Cobra subcommands, shell completion, and JSON output
- SQLite with WAL mode for concurrent reads
- Structured logging with configurable format and level
- ACID transactions via Unit of Work
- Automatic retry with exponential backoff
- Context-based timeout enforcement
- Comprehensive test coverage
Data access abstraction that hides GORM implementation details. All repositories support transaction context propagation.
Business logic and transaction orchestration. Services use Unit of Work for multi-step atomic operations.
Transaction management pattern using context propagation. Ensures ACID properties for complex operations.
Exponential backoff for transient database errors (locks, timeouts). Configurable via environment variables.
- Single-file database at
./data/glcmd.db - WAL mode for better concurrency
- Auto-migrations via GORM
- Suitable for single-instance deployments
When contributing to glcmd:
- Understand the architecture: Read ARCHITECTURE.md first
- Follow patterns: Use existing patterns (Repository, Service, UoW)
- Write tests: Focus on critical paths and business logic
- Update documentation: Keep docs in sync with code changes
New Domain Model:
- Add to
internal/domain/with GORM tags - Create repository interface in
internal/repository/interfaces.go - Implement repository in
internal/repository/ - Add to auto-migration in
cmd/glcore/main.go - Write tests for critical paths
New Service:
- Define interface in
internal/service/interfaces.go - Implement service with constructor injection
- Wire up in
cmd/glcore/main.go - Write tests with mocks for repositories
New Repository Method:
- Add to interface in
internal/repository/interfaces.go - Implement in concrete repository
- Support transaction context via
txOrDefault() - Write integration test with in-memory SQLite
Database locked errors:
- Ensure
DB_MAX_OPEN_CONNS=1for SQLite - Check retry configuration
- See ENV_VARS.md troubleshooting section
Build failures:
- SQLite driver requires CGO:
CGO_ENABLED=1 - Install GCC on Linux:
apt-get install build-essential - Install Xcode Command Line Tools on macOS
Connection errors:
- Verify database path directory exists
- Check file permissions
- GORM Documentation: https://gorm.io/docs/
- SQLite WAL Mode: https://www.sqlite.org/wal.html
- Go Context: https://go.dev/blog/context
- Testing in Go: https://go.dev/doc/tutorial/add-a-test
See main repository LICENSE file.