A robust Go-based API for tracking alcohol consumption and calculating Blood Alcohol Content (BAC) with high precision.
- JWT-based authentication system
- Secure email/password registration and login
- Password hashing with bcrypt
- Protected routes via middleware
- Token refresh mechanism
- Session management
- Comprehensive database of pre-defined drinks
- Standardized measurements for accuracy
- Each drink includes:
- Name and type
- Precise size measurements (ml/oz)
- ABV (Alcohol By Volume) percentage
- Standard drink equivalent
- Real-time and historical drink logging
- Accurate timestamp tracking
- User-specific drink history
- Detailed consumption patterns
- Quick-log favorite drinks
- Widmark formula implementation
- Personalized calculations based on:
- Body weight
- Biological sex
- Consumption timeline
- Drink specifications
- Real-time BAC monitoring
- Customizable time series data
- Status indicators:
- 🟢 Sober (0.00-0.02%)
- 🟡 Minimal (0.02-0.05%)
- 🟠 Light (0.05-0.08%)
- 🔴 Over Limit (>0.08%)
- Detailed statistics:
- Peak BAC levels
- Time until sober
- Legal limit warnings
- Consumption patterns
- Go 1.23 or higher
- SQLite 3
- Task (task runner)
- Bruno (API testing)
- Ollama (for natural language processing)
- Swag (for generating Swagger documentation)
- Air (for hot reloading)
- Clone the repository:
git clone https://github.com/axelbellec/sober.git
cd sober
- Install dependencies:
go mod download
- Set up environment:
cp .env.example .env
# Edit .env with your configurations
- Initialize database:
task db:migrate
- Generate Swagger documentation:
task docs
- Install and setup Ollama:
# Install Ollama from https://ollama.ai
# Start Ollama server
ollama serve
# Pull the required model
ollama pull nomic-embed-text
- Run the application:
task run
The API is documented using Swagger/OpenAPI. You can access the interactive documentation at:
http://localhost:8080/swagger
The project includes comprehensive API tests using Bruno.
- 🔧 Local (
localhost:8080
) - 🧪 Test (
test.api.go-sober.com
) 🚧 - 🌐 Production (
api.go-sober.com
) 🚧
# Install Bruno CLI
npm install -g @usebruno/cli
# Run tests
task test:bruno
├── main.go # API entrypoint
├── internal/ # Private application code
│ ├── auth/ # Authentication logic
│ ├── drinks/ # Drink management
│ ├── analytics/ # BAC calculations
│ └── models/ # Domain models
└── platform/ # Platform-specific code
- Framework: net/http
- Database: SQLite
- Authentication: JWT
- Password Security: Bcrypt
- Testing: Go testing + Bruno
- Task Runner: Taskfile
# Start development server
task run
# Run production binary
task run:prod
# Run tests
task test
# Run tests with coverage
task test:coverage
# Run Bruno tests
task test:bruno
# Build development binary
task build
# Build production binary
task build:prod
# Database operations
task db:migrate
task db:rollback
# Docker operations
task docker:build
task docker:run
run
: Starts the development server usinggo run
run:prod
: Runs the compiled production binarybuild
: Builds the binary for developmentbuild:prod
: Creates an optimized production binary inbin/go-sober
test
: Runs all Go tests with verbose outputtest:coverage
: Executes tests and generates coverage reportstest:bruno
: Runs API tests using Bruno (includes database migration)db:migrate
: Applies all pending database migrationsdb:rollback
: Rolls back the most recent database migrationdocker:build
: Builds the Docker imagedocker:run
: Runs the Docker container with environment variables
- Follow Go standard guidelines
- Use
gofmt
for formatting - Run
golangci-lint
before commits
# Run all tests
task test
# Run with coverage
task test:coverage
# Build optimized binary
task build:prod
# Run production build
./bin/go-sober
# Build container
docker build -t sober .
# Run container
docker run -p 8080:8080 sober