apps/habbits/README.md 2.2 K raw
1
# habbits
2
3
A minimal, single-admin habit tracker. Define custom habits (each with a typed
4
value) and log records against them over time. The whole app is behind a
5
session login — there are no public pages.
6
7
## Concepts
8
9
- **Habit** — something you track. Has a `name`, a `value_type`
10
  (`int` | `float` | `bool` | `string`), and optional `unit` and `description`.
11
- **Record** — a single data point for a habit: a `value` (validated against the
12
  habit's type) and a `recorded_at` timestamp. The timestamp auto-fills to the
13
  current time on entry but can be edited/backdated in the UI.
14
15
## Routes
16
17
Web (all require a session except the login flow):
18
19
| Method | Path | Description |
20
| ------ | ---- | ----------- |
21
| GET  | `/login` / `/logout`            | Session login / logout |
22
| GET  | `/`                             | Dashboard: create habit, add record, recent activity |
23
| POST | `/habits`                       | Create a habit |
24
| GET  | `/habits/{short_id}`            | Habit detail: edit habit + its records |
25
| POST | `/habits/{short_id}`            | Update a habit |
26
| POST | `/habits/{short_id}/delete`     | Delete a habit (cascades its records) |
27
| POST | `/records`                      | Create a record |
28
| POST | `/records/{short_id}`           | Update a record |
29
| POST | `/records/{short_id}/delete`    | Delete a record |
30
31
Read-only JSON API (requires `X-API-Key` header; disabled when `HABBITS_API_KEY`
32
is empty):
33
34
| Method | Path | Description |
35
| ------ | ---- | ----------- |
36
| GET | `/api/habits`            | All habits |
37
| GET | `/api/records?limit=100` | Recent records (max 500) |
38
39
## Configuration
40
41
Copy the values below into `apps/habbits/.env` (create the file locally; it is
42
git-ignored):
43
44
```
45
HABBITS_PASSWORD=changeme        # admin password (plaintext or bcrypt hash); empty disables login
46
HABBITS_API_KEY=                 # optional; enables the read-only JSON API when set
47
HABBITS_DB_PATH=habbits.sqlite   # SQLite file path
48
HOST=0.0.0.0
49
PORT=3000
50
BASE_URL=http://localhost:3000
51
COOKIE_SECURE=false              # set true behind HTTPS
52
```
53
54
## Development
55
56
```
57
cd apps/habbits
58
go mod tidy
59
go run .          # serves on $HOST:$PORT
60
```
61
62
Or with Docker (built from repo root):
63
64
```
65
docker build -t habbits -f apps/habbits/Dockerfile .
66
```