Skip to content

🌱 A minimalist habit tracking API built with NestJS and MongoDB, featuring JWT authentication, streak tracking, and comprehensive statistics. Clean, modern, and developer-friendly.

License

Notifications You must be signed in to change notification settings

fberrez/minihabits

Repository files navigation

minihabits

A minimalist habit tracking app built with NestJS (backend) and React + Vite (frontend) in an Turborepo monorepo, designed to help users build and maintain daily habits with a clean, intuitive interface.

Architecture

This is an Turborepo monorepo containing:

  • Backend (apps/backend/) - NestJS API with MongoDB, JWT authentication, and SWC for fast compilation
  • Frontend (apps/frontend/) - React + Vite SPA with TypeScript and Tailwind CSS

Features

Backend

  • πŸ” JWT authentication with refresh tokens
  • πŸ“Š Habit tracking and statistics
  • πŸ“§ Email notifications (Resend)
  • πŸ—„οΈ MongoDB with Mongoose
  • πŸ›‘οΈ Input validation and security
  • πŸ“ OpenAPI documentation
  • ⚑ Fast compilation with SWC (10x faster than tsc)
  • πŸ”„ Hot reload development with source maps

Frontend

  • πŸŒ“ Dark/Light mode support
  • πŸ“± Responsive, modern UI with Tailwind CSS
  • πŸ“Š Interactive habit tracking with heatmaps
  • πŸ”₯ Streak counting and statistics
  • πŸ“ˆ Visual charts and progress tracking
  • 🎡 Audio feedback for habit completion
  • ⚑ Fast development with Vite

Getting Started

Prerequisites

  • Node.js (v20 or later)
  • pnpm
  • MongoDB (local or remote)

Installation

  1. Clone the repository:
git clone https://github.com/fberrez/minihabits.git
cd minihabits
  1. Install dependencies:
pnpm install
  1. Create a .env file in both apps/backend/ and apps/frontend directories using .env.example

Development

Start both applications:

# Start backend and frontend with hot reload
pnpm run dev

Project Structure

minihabits/
β”œβ”€β”€ apps/
β”‚   β”œβ”€β”€ backend/           # NestJS API (SWC compilation)
β”‚   β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”‚   β”œβ”€β”€ auth/      # Authentication module
β”‚   β”‚   β”‚   β”œβ”€β”€ habits/    # Habits management
β”‚   β”‚   β”‚   β”œβ”€β”€ stats/     # Statistics & analytics
β”‚   β”‚   β”‚   β”œβ”€β”€ users/     # User management
β”‚   β”‚   β”‚   └── ...
β”‚   β”‚   β”œβ”€β”€ .swcrc         # SWC compiler configuration
β”‚   β”‚   └── Dockerfile
β”‚   └── frontend/          # React + Vite SPA
β”‚       β”œβ”€β”€ src/
β”‚       β”‚   β”œβ”€β”€ components/
β”‚       β”‚   β”œβ”€β”€ pages/
β”‚       β”‚   β”œβ”€β”€ api/       # Generated OpenAPI client
β”‚       β”‚   └── ...
β”‚       └── Dockerfile
β”œβ”€β”€ bruno/                 # API testing collection
└── docker-compose.yml    # Development containers

Backend Build System

The backend uses SWC instead of the traditional TypeScript compiler or Nest CLI for significantly faster builds:

Key Features

  • ⚑ 10x faster compilation than TypeScript compiler
  • πŸ—ΊοΈ Source maps enabled - errors point to TypeScript files
  • πŸ”„ Hot reload with nodemon + concurrently
  • πŸ”§ Path mapping support for absolute imports
  • πŸ“¦ Turborepo integration with build caching
  • 🎯 No Nest CLI dependency - streamlined toolchain

Build Configuration

  • Compiler: SWC with custom configuration (.swcrc)
  • Path mapping: Supports absolute imports (src/*)
  • Source maps: Enabled for proper error reporting
  • Hot reload: Automatic rebuild and restart on file changes
  • Type checking: Runs separately via TypeScript compiler

Development Workflow

  1. File change detected β†’ SWC rebuilds instantly
  2. Build complete β†’ nodemon restarts Node.js process
  3. Error occurs β†’ Stack trace shows TypeScript file locations
  4. Repeat β†’ Fast iteration cycle

Production Deployment

Infrastructure

  • Hosting: VPS - OVH
  • Containerization: Docker (multi-stage builds)
  • Backend Compilation: SWC for fast production builds
  • Reverse Proxy: Traefik
  • SSL: Let's Encrypt via Traefik
  • Monorepo: Turborepo for build optimization and caching

Docker Usage

# Development with Docker Compose
docker-compose up -d

# Build production images
docker build -f apps/backend/Dockerfile -t minihabits-backend .
docker build -f apps/frontend/Dockerfile -t minihabits-frontend .

Technologies

Backend

  • Framework: NestJS with TypeScript
  • Compiler: SWC (replacing tsc and Nest CLI)
  • Database: MongoDB with Mongoose ODM
  • Authentication: JWT with refresh tokens
  • Validation: class-validator, class-transformer
  • Email: Resend API
  • Documentation: OpenAPI/Swagger
  • Testing: Jest
  • Development: Hot reload with nodemon + concurrently

Frontend

  • Framework: React 18 with TypeScript
  • Build Tool: Vite
  • Styling: Tailwind CSS
  • UI Components: Custom components with Radix UI
  • Charts: Recharts
  • HTTP Client: Generated from OpenAPI spec
  • State Management: React Query (TanStack Query)

DevOps & Tools

  • Monorepo: Turborepo
  • Package Manager: pnpm
  • Containerization: Docker
  • API Testing: Bruno
  • Code Quality: ESLint, Prettier
  • CI/CD: GitHub Actions

Development Notes

SWC vs Traditional NestJS Build

This project uses SWC instead of the traditional Nest CLI or TypeScript compiler:

Feature Nest CLI SWC
Build Speed ~3-5s ~0.1s
Hot Reload Built-in Custom setup
Source Maps βœ… βœ…
Dependencies @nestjs/cli @swc/cli
Configuration nest-cli.json .swcrc

License

This project is licensed under the GNU License - see the LICENSE file for details.

About

🌱 A minimalist habit tracking API built with NestJS and MongoDB, featuring JWT authentication, streak tracking, and comprehensive statistics. Clean, modern, and developer-friendly.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors 2

  •  
  •  

Languages