A full-stack web application designed to help users build and maintain positive habits. It features a secure REST API backend built with Node.js/Express and a modern React frontend.
- User Authentication: Secure registration and login with email/password.
- JWT Session Management: Uses
httpOnlycookies with access and refresh tokens for secure, persistent user sessions. - Social Login: Frontend is configured for Google Sign-In via Firebase.
- Habit Management: Users can create and view their personal habits.
- Daily Check-ins: Functionality to mark habits as completed for the day.
- Protected API: Backend routes are protected to ensure users can only access their own data.
- Backend: Node.js, Express, MongoDB, Mongoose, JSON Web Token (JWT), bcryptjs, cookie-parser
- Frontend: React (Vite), Firebase Authentication
SHT/
├── backend/ # Node.js & Express REST API
│ ├── src/
│ │ ├── config/
│ │ ├── controllers/
│ │ ├── middlewares/
│ │ ├── models/
│ │ └── routes/
│ └── ...
├── frontend/ # React Client Application
│ ├── src/
│ └── ...
└── README.md
Follow these instructions to get a copy of the project up and running on your local machine for development and testing purposes.
- Node.js (v18.x or higher)
- npm or yarn
- A running MongoDB instance (local or cloud-based like MongoDB Atlas)
- Navigate to the backend directory:
cd backend - Install dependencies:
npm install
- Create a
.envfile in thebackenddirectory and add the following environment variables:PORT=5000 MONGO_URI=your_mongodb_connection_string CLIENT_URL=http://localhost:5173 ACCESS_TOKEN_SECRET=your_strong_access_token_secret REFRESH_TOKEN_SECRET=your_strong_refresh_token_secret
- Start the server:
The backend server will be running on
npm start
http://localhost:5000.
-
Navigate to the frontend directory:
cd ../frontend -
Install dependencies:
npm install
-
Update Firebase Config in
src/firebaseConfig.jswith your own Firebase project credentials. -
Start the development server:
npm run dev
The frontend application will be available at
http://localhost:5173.
All habit-related routes are protected and require a valid JWT access token.
| Method | Endpoint | Description |
|---|---|---|
POST |
/api/auth/register |
Register a new user. |
POST |
/api/auth/login |
Log in a user and return tokens. |
POST |
/api/auth/refresh |
Refresh an expired access token. |
GET |
/api/auth/me |
Get the currently authenticated user. |
GET |
/api/habits |
Get all habits for the logged-in user. |
POST |
/api/habits |
Create a new habit for the user. |
POST |
/api/habits/:id/checkin |
Mark a habit as completed for the day. |
- Full CRUD for Habits: Implement
UpdateandDeletefunctionality. - Input Validation: Add robust server-side validation for all API inputs using a library like
Joiorexpress-validator. - Testing: Write a comprehensive suite of unit and integration tests for the backend using Jest and Supertest.
- Data Visualization: Add charts or calendars to visualize habit streaks and progress.