A full-stack habit tracking application built with Spring Boot (backend) and React + TypeScript (frontend).
- ✅ Create, edit, and delete habits
- ✅ Track habits with different frequencies (daily, weekly, monthly)
- ✅ Calendar view with checkboxes for habit tracking
- ✅ Statistics and progress tracking
- ✅ Modern, responsive UI
- ✅ RESTful API backend
- Java 21 with Spring Boot 3.x
- PostgreSQL database
- Spring Data JPA for data persistence
- Maven for dependency management
- React 18 with TypeScript
- Vite for fast development and building
- CSS for styling (no external UI libraries)
- Java 21 (JDK)
- Node.js 18+ and npm
- PostgreSQL 12+ (or Docker)
git clone https://github.com/enderorman/habit-tracker.git
cd habit-trackerdocker run --name habit-db -d -p 5432:5432 \
-e POSTGRES_USER=your_username \
-e POSTGRES_PASSWORD=your_password \
-e POSTGRES_DB=habit_tracker \
postgres:16- Install PostgreSQL on your system
- Create a database named
habit_tracker - Update database credentials in
src/main/resources/application.propertiesif needed
# From the project root
./mvnw spring-boot:runThe backend will start on http://localhost:8080
API Endpoints:
GET /api/habits- List all habitsPOST /api/habits- Create a new habitDELETE /api/habits/{id}- Delete a habitPOST /api/habits/{id}/mark- Mark habit as completedPOST /api/habits/{id}/unmark- Unmark habitGET /api/habits/{id}/logs- Get habit logsGET /api/stats- Get statistics
# From the project root
cd frontend
npm ci
npm run devThe frontend will start on http://localhost:5173
Open your browser and navigate to http://localhost:5173
The backend uses Spring Boot with the following structure:
src/main/java/com/tracker/habittracker/
├── controller/ # REST API endpoints
├── service/ # Business logic
├── repository/ # Data access layer
├── model/ # Entity classes
└── dto/ # Data transfer objects
Key files:
HabitController.java- REST API endpointsHabitService.java- Business logic for habitsHabitLogService.java- Business logic for habit trackingHabit.java- Main entity modelFrequency.java- Enum for habit frequencies
The frontend uses React with TypeScript:
frontend/src/
├── App.tsx # Main application component
├── App.css # Global styles
└── lib/
└── api.ts # API client functions
Key features:
- Tabbed interface (Habits, Calendar, Stats)
- Optimistic UI updates
- Responsive design
- Calendar view with habit tracking
Habits Table:
id(Primary Key)name(VARCHAR)description(TEXT)frequency(ENUM: DAILY, WEEKLY, MONTHLY)created_at(TIMESTAMP)
Habit Logs Table:
id(Primary Key)habit_id(Foreign Key)completed_date(DATE)created_at(TIMESTAMP)
Edit src/main/resources/application.properties:
# Database
spring.datasource.url=jdbc:postgresql://localhost:5432/habit_tracker
spring.datasource.username=your_username
spring.datasource.password=your_password
# JPA
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=false
# CORS (for frontend)
app.cors.allowed-origins=http://localhost:5173The frontend automatically proxies API requests to the backend during development. For production, set the VITE_API_BASE environment variable.
./mvnw testcd frontend
npm test./mvnw clean packageThe JAR file will be created in target/habittracker-0.0.1-SNAPSHOT.jar
cd frontend
npm run buildThe built files will be in frontend/dist/
-
Render (Free):
- Connect your GitHub repository
- Set build command:
./mvnw clean package - Set start command:
java -jar target/habittracker-0.0.1-SNAPSHOT.jar - Add environment variables for database and CORS
-
Local with Cloudflare Tunnel:
# Install cloudflared brew install cloudflare/cloudflare/cloudflared # Start tunnel cloudflared tunnel --url http://localhost:8080
- Netlify (Free):
- Connect your GitHub repository
- Set build directory:
frontend - Set publish directory:
frontend/dist - Add environment variable:
VITE_API_BASE=https://your-backend-url
-
Database Connection Error:
- Ensure PostgreSQL is running
- Check database credentials in
application.properties - Verify database
habit_trackerexists
-
Frontend Can't Connect to Backend:
- Ensure backend is running on port 8080
- Check CORS configuration
- Verify Vite proxy settings in
frontend/vite.config.ts
-
Port Already in Use:
- Change backend port:
./mvnw spring-boot:run -Dspring-boot.run.jvmArguments="-Dserver.port=8081" - Change frontend port:
npm run dev -- --port 3000
- Change backend port:
- Backend logs: Check terminal where
./mvnw spring-boot:runis running - Frontend logs: Check browser DevTools Console
- Database logs: Check PostgreSQL logs or Docker container logs
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is open source and available under the MIT License.
If you encounter any issues or have questions, please open an issue on GitHub.