Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

9 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Habit Tracker

A personal habit tracking backend built with Rust, featuring AI-powered coaching, sleep tracking, daily memory prompts, and journaling.

Stack

Layer Tech
Runtime Rust + Tokio
Web framework Axum
Database PostgreSQL (Neon)
ORM SeaORM
Cache Redis (Upstash)
Storage Filebase (S3-compatible)
AI Google Gemini API
Deploy Fly.io

Features

  • Habit tracking — create good habits and bad habits to reduce, with daily check-ins, streak tracking, and history
  • Sleep tracking — answer 1-5 questions, AI derives a sleep score from your answers
  • Core memories — AI asks a daily question, you answer in your own words
  • Journaling — free-form daily entries with AI-assisted summarization
  • AI coach — conversational AI with configurable persona (friendly / formal / custom) that knows your habit and sleep context
  • Passive summaries — weekly and monthly AI-generated reviews of your progress

Project Structure

src/
├── main.rs               # Entrypoint
├── app.rs                # Shared AppState
├── config.rs             # Environment config
├── ai/
│   ├── client.rs         # Gemini API wrapper (streaming + non-streaming)
│   ├── context.rs        # Build user context for AI injection
│   ├── persona.rs        # System prompt builder per persona
│   └── summarizer.rs     # Weekly / monthly passive summaries
├── api/
│   ├── error.rs          # Unified error response
│   ├── router.rs         # Axum route definitions
│   ├── handlers/         # HTTP handlers per domain
│   └── middleware/
│       └── auth.rs       # JWT middleware
├── domain/
│   ├── habit/            # Habit + log + streak logic
│   ├── sleep/            # Sleep questions + scoring
│   ├── memory/           # Daily memory prompts
│   ├── journal/          # Journal entries
│   └── user/             # User management
├── infra/
│   ├── db.rs             # Neon PostgreSQL pool
│   ├── redis.rs          # Upstash Redis client
│   └── storage.rs        # Filebase S3 client
└── jobs/
    ├── notification.rs   # Habit reminder jobs
    ├── summary.rs        # Scheduled summary jobs
    └── question.rs       # Daily memory question jobs

Getting Started

Prerequisites

Setup

1. Clone and install dependencies

git clone <your-repo>
cd habit-tracker

2. Configure environment

cp .env.example .env
# Fill in your credentials — see .env.example for all required variables

Generate a JWT secret:

openssl rand -hex 32

3. Run migrations

cargo install sea-orm-cli
sea-orm-cli migrate up

4. Start the server

# Standard
cargo run

# With hot reload
cargo install cargo-watch
cargo watch -x run

Server runs at http://localhost:8080.

API Overview

All endpoints (except auth) require Authorization: Bearer <token>.

Domain Base path
Auth /api/auth
Habits /api/habits
Sleep /api/sleep
Core memories /api/memories
Journal /api/journal
AI coach /api/ai

Full API documentation coming soon.

Design Decisions

Idempotent habit logging — calling the log endpoint multiple times on the same day always returns the same entry. Response includes already_logged: true so the client handles it gracefully.

Soft delete — habits are never hard deleted. History stays intact for AI context and streak calculations.

AI context injection — every AI request pulls the user's recent habit data, sleep scores, and persona config before calling Gemini. The AI always has context without the user needing to repeat themselves.

Streaming AI responses — the chat endpoint uses Server-Sent Events (SSE) so responses stream token by token instead of waiting for the full generation.

Repository pattern — all database access goes through repository interfaces. Business logic in services never touches the database directly, making it testable and swappable.

Deployment

brew install flyctl
fly auth login
fly launch
fly secrets set DATABASE_URL="..." REDIS_URL="..." AI_API_KEY="..." JWT_SECRET="..."
fly deploy

Environment Variables

See .env.example for the full list of required and optional variables.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages