A personal habit tracking backend built with Rust, featuring AI-powered coaching, sleep tracking, daily memory prompts, and journaling.
| 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 |
- 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
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
- Rust 1.81+
- A Neon PostgreSQL database
- An Upstash Redis instance
- A Google AI Studio API key
- A Filebase account (optional for MVP)
1. Clone and install dependencies
git clone <your-repo>
cd habit-tracker2. Configure environment
cp .env.example .env
# Fill in your credentials — see .env.example for all required variablesGenerate a JWT secret:
openssl rand -hex 323. Run migrations
cargo install sea-orm-cli
sea-orm-cli migrate up4. Start the server
# Standard
cargo run
# With hot reload
cargo install cargo-watch
cargo watch -x runServer runs at http://localhost:8080.
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.
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.
brew install flyctl
fly auth login
fly launch
fly secrets set DATABASE_URL="..." REDIS_URL="..." AI_API_KEY="..." JWT_SECRET="..."
fly deploySee .env.example for the full list of required and optional variables.