Public
Remixed
Pill tracking with nfc
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.

🎯 Generic Habit Tracker

A flexible, polymorphic habit tracking application that allows users to create custom habits with contextual data capture. Track anythingβ€”water intake, workouts, meditation, readingβ€”with rich metadata tailored to each habit.

Features

πŸ“‹ Generic Habit Management

  • Create unlimited custom habits with names, descriptions, icons, and colors
  • Define custom JSON schemas for contextual data (e.g., water amounts, exercise types)
  • Log events with optional polymorphic context matching your habit's schema
  • Delete and manage habits and events
  • View statistics: today's count, weekly stats, average per day

πŸ“Š Event Logging with Context

  • Manual logging with optional structured data based on habit schema
  • Polymorphic storage: Context is stored as flexible JSON in the database
  • Schema validation: Events are validated against your habit's defined schema
  • Event history: View all logged events with their metadata

🏷️ NFC Tag Integration

  • Create NFC tags linked to specific habits
  • Customizable context templates for each tag (coming soon)
  • Public tap URLs that log events without authentication
  • Instant logging: Tap a physical NFC tag to instantly log an event
  • Manage tags: Create, view, and delete NFC tags from the dashboard

🎨 User-Friendly Interface

  • Dark theme with gradient backgrounds
  • Responsive design works on mobile and desktop
  • Tab navigation for Habits, Events, and NFC Tags
  • Real-time updates with instant feedback

Database Schema

Core Tables

habits
β”œβ”€β”€ id (UUID)
β”œβ”€β”€ userId (FK)
β”œβ”€β”€ name (string)
β”œβ”€β”€ description (string)
β”œβ”€β”€ icon (emoji)
β”œβ”€β”€ color (hex)
β”œβ”€β”€ createdAt, updatedAt

habit_schemas
β”œβ”€β”€ id (UUID)
β”œβ”€β”€ habitId (FK)
β”œβ”€β”€ schema (JSON) – defines context fields
β”œβ”€β”€ createdAt, updatedAt

habit_events
β”œβ”€β”€ id (UUID)
β”œβ”€β”€ habitId (FK)
β”œβ”€β”€ userId (FK)
β”œβ”€β”€ timestamp
β”œβ”€β”€ context (JSON) – polymorphic data matching schema
β”œβ”€β”€ source (string: "manual", "nfc")
β”œβ”€β”€ createdAt

nfc_tags
β”œβ”€β”€ id (UUID)
β”œβ”€β”€ userId (FK)
β”œβ”€β”€ habitId (FK)
β”œβ”€β”€ token (unique)
β”œβ”€β”€ name (string)
β”œβ”€β”€ contextTemplate (JSON) – optional
β”œβ”€β”€ createdAt, updatedAt

API Endpoints

Habits

  • POST /api/habits – Create a new habit with optional JSON schema
  • GET /api/habits – Get all user's habits
  • GET /api/habits/:id – Get habit details with today's events
  • GET /api/habits/:id/history?days=7 – Get event history

Events

  • POST /api/habits/:id/log – Log an event with optional context
  • DELETE /api/habits/:habitId/events/:eventId – Delete an event

NFC Tags

  • POST /api/nfc/tag – Create NFC tag
  • GET /api/nfc/tags – Get user's NFC tags
  • DELETE /api/nfc/tag/:id – Delete NFC tag
  • GET /api/nfc/tap/:token – Public endpoint for NFC tap (logs event)

Creating a Habit with Context Schema

Example: Water Intake Habit

{ "amount": { "type": "number", "required": true, "placeholder": "ml" }, "source": { "type": "string", "required": false, "placeholder": "bottle/tap/filter" } }

Example: Workout Habit

{ "exerciseType": { "type": "string", "required": true, "placeholder": "push-ups, running, yoga" }, "sets": { "type": "number", "required": false }, "reps": { "type": "number", "required": false }, "duration": { "type": "number", "required": false, "placeholder": "minutes" } }

NFC Tag Setup

  1. Create a tag: Go to the NFC Tags tab, select a habit, click "Create NFC Tag"
  2. Get the tap URL: A URL is displayed (e.g., https://your-app.val.run/api/nfc/tap/token123)
  3. Write to NFC tag: Use an NFC writing app (Android NFC Tools, iPhone Shortcuts) to write this URL
  4. Tap to log: Tapping the physical tag opens the URL and logs an event

Authentication

Magic link authentication via email. No passwords required.

Frontend Stack

  • React 18 with TypeScript
  • Tailwind CSS for styling
  • Better Auth with magic link plugin
  • Deno runtime (Val Town)

Backend Stack

  • Hono web framework
  • SQLite database (project-scoped)
  • Better Auth for authentication
  • Deno runtime (Val Town)

Getting Started

  1. Sign in with your email
  2. Create a habit with optional context schema
  3. Log events manually or via NFC tags
  4. View statistics and manage your habits

Future Enhancements

  • Habit streaks and achievements
  • Advanced filtering and search
  • Data export (CSV, JSON)
  • Habit templates
  • Analytics dashboard
  • Reminders and notifications
  • Social sharing
  • Habit recommendations

Built with ❀️ on Val Town