No description
  • Java 64.2%
  • HTML 35.8%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Lars Richter 089b0b4eef Refactor logHabit to take the date from the caller
This makes testing easier and enables logging of habits for other days than today
2025-03-31 15:40:43 +02:00
database Save and show streak 2025-03-12 17:23:28 +01:00
gradle/wrapper Initial Commit 2025-03-05 09:57:34 +01:00
src Refactor logHabit to take the date from the caller 2025-03-31 15:40:43 +02:00
.gitattributes Initial Commit 2025-03-05 09:57:34 +01:00
.gitignore Ignore deploy scripts 2025-03-18 17:27:41 +01:00
build.gradle Add flyway for automatic db migrations 2025-03-17 12:26:36 +01:00
gradlew Initial Commit 2025-03-05 09:57:34 +01:00
gradlew.bat Initial Commit 2025-03-05 09:57:34 +01:00
README.md Added direct deploy info to README 2025-03-18 09:31:28 +01:00
settings.gradle Initial Commit 2025-03-05 09:57:34 +01:00

Habit Tracker

A simple Spring Boot application for tracking daily habits and rewarding consistency.

Overview

The Habit Tracker helps users build and maintain positive habits by tracking daily activities and providing rewards for consistency. The application allows users to create habits, log their completion, and redeem rewards.

Features

  • Create and manage habits with descriptions
  • Log completion of daily habits
  • View habit history and streaks
  • Redeem rewards for consistent habit completion
  • Simple and intuitive user interface

Tech Stack

  • Java 23
  • Spring Boot
  • PostgreSQL database
  • Gradle build system
  • REST API architecture

Setup & Installation

Prerequisites

  • Java 23 JDK/JRE
  • PostgreSQL database
  • Gradle 8.x+

Database Setup

  1. Create a PostgreSQL database
  2. Run the schema creation script:
    psql -U postgres -d yourdb -f database/schema.sql
    
  3. (Optional) Load sample data:
    psql -U postgres -d yourdb -f database/sample-data.sql
    

Running Locally

./gradlew bootRun

Deployment Options

Deploy existing service

  1. Build the JAR:

    ./gradlew bootJar
    
  2. Stop the service (via ssh)

    ssh user@server
    sudo systemctl stop habittracker.service
    
  3. SCP jar to server

    scp build/libs/habittracker-0.0.1-SNAPSHOT.jar user@server:/path/to/app
    
  4. Start the service (via ssh)

     ssh user@server
     sudo systemctl start habittracker.service
    

As a Systemd Service

  1. Build the JAR:

    ./gradlew bootJar
    
  2. Create a systemd service file:

    [Unit]
    Description=Habit Tracker Service
    After=network.target
    
    [Service]
    User=youruser
    WorkingDirectory=/path/to/app
    ExecStart=/path/to/java -jar habittracker-0.0.1-SNAPSHOT.jar --server.address=0.0.0.0
    SuccessExitStatus=143
    Restart=on-failure
    RestartSec=5
    
    [Install]
    WantedBy=multi-user.target
    
  3. Enable and start the service:

    sudo systemctl enable habittracker
    sudo systemctl start habittracker
    

API Endpoints

  • GET /api/habits - List all habits
  • POST /api/habits - Create a new habit
  • GET /api/habits/{id} - Get a specific habit
  • PUT /api/habits/{id} - Update a habit
  • POST /api/habits/{id}/log - Log completion of a habit
  • GET /api/rewards - List all rewards
  • POST /api/rewards/redeem - Redeem a reward

Configuration

Configure the application via application.properties:

server.port=8084
server.address=0.0.0.0
spring.datasource.url=jdbc:postgresql://localhost:5432/yourdb
spring.datasource.username=postgres
spring.datasource.password=yourpassword