david 10d45fc34e Add COUNTER type with auto-increment and IsNegative field
COUNTER type:
- Only accepts integer values (rejects decimals)
- Auto-increment behavior: each mark adds to existing value
- Supports decrement via negative values (e.g., -2)
- Enforces minimum value of 0 (never negative)
- Default increment is 1 if no value provided

VALUE type:
- Accepts decimal values
- Replaces value (no auto-increment)

IsNegative field:
- New boolean field on Habit entity
- Persisted in database (is_negative column)
- Available in all DTOs and HTTP responses
- Marks habits as "negative" (e.g., candy consumption)

Examples:
- COUNTER: 5 + (-2) = 3, 2 + (-3) = 0, 0 + (-1) = 0
- VALUE: 5000 → 12000 = 12000 (replacement)
2025-11-27 08:58:39 +01:00
2025-11-26 18:38:26 +01:00
2025-11-25 10:09:42 +01:00
2025-11-26 20:37:52 +01:00

Apocapoc

Self-hosted habit tracking service with a clean, hexagonal architecture.

Features

  • Multiple habit types: Boolean (check), Counter, Value
  • Flexible scheduling: Daily, Weekly, Monthly with specific days
  • Carry-over support: Choose if incomplete habits persist or expire
  • Full history tracking: Complete audit trail of all interactions
  • Statistics: Track streaks, completion rates, and progress
  • Self-hosted first: Easy deployment with SQLite
  • Security: JWT authentication, rate limiting on auth endpoints
  • API Documentation: Interactive Swagger UI

Quick Start

  1. Create a docker-compose.yml file:
services:
  api:
    image: ghcr.io/davidfolch/apocapoc-api:latest
    ports:
      - "8080:8080"
    environment:
      - DB_PATH=/data/apocapoc.db
      - JWT_SECRET=YOUR_SECRET_HERE
      - JWT_EXPIRY=24h
      - REFRESH_TOKEN_EXPIRY=168h
      - CORS_ORIGINS=http://localhost:3000
      - DEFAULT_TIMEZONE=UTC
    volumes:
      - habit-data:/data
    restart: unless-stopped

volumes:
  habit-data:
  1. Important: Replace YOUR_SECRET_HERE with a secure random string for JWT_SECRET

  2. Start the service:

docker-compose up -d

The API will be available at http://localhost:8080

Configuration options:

  • JWT_SECRET: Required. Use a long random string
  • JWT_EXPIRY: Token expiration (e.g., 24h, 48h)
  • REFRESH_TOKEN_EXPIRY: Refresh token expiration (e.g., 168h = 7 days)
  • CORS_ORIGINS: Comma-separated list of allowed origins
  • DEFAULT_TIMEZONE: Timezone for date calculations (e.g., UTC, Europe/Madrid)

Using the binary

  1. Download the latest release
  2. Copy .env.example to .env and configure
  3. Run: ./apocapoc-api

The API will be available at http://localhost:8080

Development

Prerequisites

  • Go 1.23+
  • SQLite
  • Docker (optional)
cp docker-compose.example.yml docker-compose.yml
docker-compose up --build

The API will be available at http://localhost:8080

Running locally with Go

cp .env.example .env
go run cmd/api/main.go

API Documentation

Once running, visit http://localhost:8080/api/v1/docs for interactive Swagger documentation.

Architecture

This project follows hexagonal (ports & adapters) architecture:

  • domain/: Core business logic and entities
  • application/: Use cases (commands & queries)
  • infrastructure/: External adapters (database, HTTP, etc.)
  • shared/: Common utilities and errors

License

MIT

S
Description
No description provided
Readme MIT 764 KiB
Languages
Go 99.5%
HTML 0.4%