A full-stack web application for tracking daily habits and building positive routines. Built with Express.js, MongoDB, and React.
- Features
- Tech Stack
- Project Structure
- Prerequisites
- Installation
- Configuration
- Running the Application
- API Documentation
- Frontend Setup
- User Authentication: Secure registration and login with JWT tokens
- Habit Management: Create, read, update, and delete habits
- Habit Logging: Track habit completion with timestamps
- User Dashboard: View all habits and their completion status
- Protected Routes: Secure endpoints with JWT middleware
- Runtime: Node.js
- Framework: Express.js
- Database: MongoDB
- Authentication: JWT (JSON Web Tokens)
- Password Hashing: bcrypt
- Framework: React 18
- Build Tool: Vite
- Styling: Tailwind CSS
- UI Components: Chakra UI
- State Management: React hooks
HabitTracker/
βββ backend/
β βββ config/ # Configuration files
β βββ controllers/ # Request handlers
β βββ middlewares/ # Express middlewares
β βββ models/ # MongoDB schemas
β βββ repositories/ # Data access layer
β βββ routes/ # API routes
β βββ services/ # Business logic
β βββ utils/ # Utility functions
β βββ server.js # Main server file
β βββ package.json
β βββ .env # Environment variables
β
βββ frontend/
β βββ habbit-tracker/
β βββ src/
β β βββ pages/ # Page components
β β βββ components/ # Reusable components
β β βββ lib/ # Utility functions
β β βββ assets/ # Static assets
β β βββ App.jsx
β β βββ main.jsx
β βββ package.json
β βββ vite.config.js
β βββ tailwind.config.js
β βββ tsconfig.json
β
βββ README.md
- Node.js (v14 or higher)
- npm or yarn
- MongoDB (running locally or via cloud)
- Navigate to the backend directory:
cd backend- Install dependencies:
npm install- Install dotenv (if not already installed):
npm install dotenv- Navigate to the frontend directory:
cd frontend/habbit-tracker- Install dependencies:
npm installCreate a .env file in the backend/ directory with the following variables:
# MongoDB Connection
MONGODB_URI=mongodb://127.0.0.1:27017/test2
# JWT Secret Key
JWT_SECRET=your_secret_key_here
# Server Port
PORT=3000Important: Replace your_secret_key_here with a strong, random secret key for production.
The frontend is configured to connect to the backend at http://localhost:3000. Update the API base URL in the frontend components if your backend runs on a different port.
cd backend
# Development mode with auto-reload
npm run dev
# Production mode
npm startThe backend server will run on http://localhost:3000
cd frontend/habbit-tracker
npm run devThe frontend will run on http://localhost:5173
POST /auth/register
Content-Type: application/json
{
"username": "john_doe",
"email": "john@example.com",
"password": "secure_password"
}
POST /auth/login
Content-Type: application/json
{
"email": "john@example.com",
"password": "secure_password"
}
Response:
{
"token": "jwt_token",
"user": { ... }
}
All habit endpoints require authentication via JWT token in the Authorization header:
Authorization: Bearer <jwt_token>
POST /api/habits
{
"title": "Morning Exercise",
"description": "30 minutes of running"
}
GET /api/habits
GET /api/habits/:habitId
PUT /api/habits/:habitId
{
"title": "Morning Yoga",
"description": "1 hour yoga session"
}
DELETE /api/habits/:habitId
POST /api/habits/:habitId/log
{
"date": "2024-02-11"
}
- Navbar: Navigation component
- HabitCard: Display individual habit cards
- HabitForm: Form for creating/editing habits
- TypeText: Text animation component
- TargetCursor: Custom cursor component
- And more UI components in
ui/folder
- username
- password (hashed)
- createdAt
- userId (reference to User)
- title
- description
- createdAt
- updatedAt
- habitId (reference to Habit)
- userId (reference to User)
- date
- completed
- createdAt
- Password hashing with bcrypt
- JWT token-based authentication
- Protected routes with middleware
- Environment variables for sensitive data
- CORS configuration
Last Updated: February 2024