The Water Tracker is a full-stack web application designed to help users monitor and achieve their daily hydration goals. It features secure user authentication and a real-time dashboard for logging water intake and managing personal hydration targets.
The project follows a decoupled, two-part architecture:
- Frontend (Client): A Next.js application responsible for the user interface, routing, and making API calls.
- Backend (Server): An Express.js API responsible for user authentication, database management (MongoDB), and handling all water log data.
- Secure Authentication: User registration and login protected by JWT (JSON Web Tokens).
- Protected Routes: Dashboard is inaccessible to unauthorized users via a client-side AuthGuard.
- Daily Tracking: Users can log water intake (in ml), updating total progress in real-time.
- Goal Management: Users can view and update their personal daily hydration goal.
- Real-time Dashboard: Displays total intake, daily goal, and a historical log of today's entries.
You must run the backend and frontend simultaneously in two separate terminal windows.
- Node.js (v18+) and npm
- MongoDB instance (local or cloud-hosted via MongoDB Atlas)
- Navigate to the server directory:
cd water-tracker-server - Install dependencies:
npm install
- Configure environment variables:
Create a.envfile in the root of thewater-tracker-serverdirectory:PORT=5000 MONGODB_URI=mongodb+srv://<user>:<password>@<cluster-name>/watertracker JWT_SECRET=YOUR_SECURE_RANDOM_STRING CLIENT_URL=http://localhost:3000 - Start the server:
The server will run at http://localhost:5000.
npm run dev
- Navigate to the client directory:
cd water-tracker-client - Install dependencies:
npm install
- Configure API URL:
Create a.env.localfile in the root ofwater-tracker-client:NEXT_PUBLIC_API_URL=http://localhost:5000/api - Start the frontend:
The client will run at http://localhost:3000.
npm run dev
| Category | Technology | Purpose |
|---|---|---|
| Frontend | Next.js (App Router) | React framework for server-side rendering and routing |
| Styling | Tailwind CSS & Shadcn/ui | Utility-first CSS framework and UI components |
| State/Data Fetching | axios | HTTP client for interacting with the Express API |
| Backend | Express.js | Lightweight Node.js framework for API creation |
| Database | MongoDB & Mongoose | NoSQL database & object modeling |
| Security | JSON Web Tokens (JWT) | Stateless, secure authentication for API requests |
The application is split into two deployable services: the Next.js frontend and the Express.js backend.
- Update server configuration:
Inwater-tracker-server/src/server.ts:const CLIENT_URL = process.env.CLIENT_URL || 'http://localhost:3000';