A Full Stack (MERN) web application for monitoring and controlling home appliances to conserve Energy and Water. Built with modern technologies and real-time database integration.
- Overview
- Features
- Tech Stack
- Project Structure
- Installation
- Environment Variables
- Quick Start
- API Documentation
- Database Schema
- Screenshots
Energy Core is a comprehensive smart home dashboard that enables users to:
- Monitor real-time energy (kW) and water (L/min) consumption
- Control connected appliances remotely (ON/OFF, Eco Mode)
- Track historical usage patterns with interactive charts
- Set conservation goals and receive visual feedback
- Predict monthly electricity bills based on current usage
- Simulate water leak scenarios for emergency preparedness
The system uses real database integration - all charts, device states, and settings are persisted in MongoDB, making it a production-ready full-stack application.
- Create: Add new energy or water devices
- Read: View all connected appliances with real-time status
- Update: Toggle devices ON/OFF, enable Eco Mode
- Delete: Remove devices from the system
- Energy Charts: 7-day historical energy usage (kWh) from database
- Water Charts: 7-day historical water consumption (Liters) from database
- Conservation Monitor: Visual indicators (Red/Green) when usage exceeds limits
- Bill Predictor: Calculate estimated monthly costs based on current load
- Persistent Limits: Energy and Water conservation goals saved to database
- Instant UI: Sliders update immediately while dragging
- Auto-Save: Settings persist on page refresh
- Leak Detection Simulation: Visual alert system for abnormal water flow
- Real-Time Monitoring: Track water usage patterns
- JWT Authentication: Secure token-based user sessions
- Password Hashing: bcryptjs with salt rounds
- Protected Routes: All device/energy/settings endpoints require authentication
- React 19.2.0 - UI framework with Hooks
- Vite 7.2.4 - Build tool and dev server
- Tailwind CSS 3.4.18 - Utility-first styling
- Recharts 3.5.1 - Data visualization library
- React Router DOM 7.10.1 - Client-side routing
- Axios 1.13.2 - HTTP client with interceptors
- Lucide React 0.561.0 - Icon library
- Node.js - JavaScript runtime
- Express 4.21.1 - Web framework
- MongoDB - NoSQL database (MongoDB Atlas or Local)
- Mongoose 8.8.0 - ODM for MongoDB
- JWT (jsonwebtoken 9.0.2) - Authentication tokens
- bcryptjs 2.4.3 - Password hashing
- CORS - Cross-origin resource sharing
- Morgan - HTTP request logger
Energy-Core/
├── client/
│ └── client/
│ ├── src/
│ │ ├── api/ # API client configuration
│ │ ├── components/ # Reusable React components
│ │ ├── context/ # Auth context provider
│ │ ├── layouts/ # Page layouts
│ │ └── pages/ # Main page components
│ ├── package.json
│ └── .env # Frontend environment variables
│
├── server/
│ └── src/
│ ├── config/ # Database configuration
│ ├── controllers/ # Business logic
│ ├── middleware/ # Auth middleware
│ ├── models/ # Mongoose schemas
│ ├── routes/ # API route definitions
│ ├── seed/ # Database seeding scripts
│ ├── utils/ # Helper functions
│ ├── app.js # Express app setup
│ └── server.js # Server entry point
│ ├── package.json
│ └── .env # Backend environment variables
│
└── README.md
- Node.js (v16 or higher)
- npm (v8 or higher)
- MongoDB (MongoDB Atlas account or local MongoDB installation)
git clone <repository-url>
cd Energy-Corecd server
npm installcd ../client/client
npm installCreate a .env file in the server/ directory:
PORT=5000
MONGO_URI=mongodb+srv://username:password@cluster.mongodb.net/smart_energy_mvp?retryWrites=true&w=majority
JWT_SECRET=your_super_secret_jwt_key_change_this
NODE_ENV=developmentRequired Variables:
PORT- Server port (default: 5000)MONGO_URI- MongoDB connection string (Atlas or local)JWT_SECRET- Secret key for JWT token signingNODE_ENV- Environment mode (development/production)
Create a .env file in the client/client/ directory:
VITE_API_BASE_URL=http://localhost:5000/apiRequired Variables:
VITE_API_BASE_URL- Backend API base URL
cd server
npm run dev # Development mode with nodemon
# OR
npm start # Production modeThe server will start on http://localhost:5000
cd client/client
npm run devThe frontend will start on http://localhost:5173 (or another port if 5173 is busy)
To populate the database with sample devices and historical data:
cd server
# Seed default devices (5 devices)
npm run seed:devices
# Seed 7 days of historical data
npm run seed:history- Open
http://localhost:5173in your browser - Register a new account or Login with existing credentials
- Navigate to the Dashboard to start monitoring
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
POST |
/api/auth/register |
Register new user | ❌ |
POST |
/api/auth/login |
Login user | ❌ |
GET |
/api/auth/me |
Get current user | ✅ |
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
GET |
/api/devices |
Get all user devices | ✅ |
GET |
/api/devices/:id |
Get device by ID | ✅ |
POST |
/api/devices |
Create new device | ✅ |
DELETE |
/api/devices/:id |
Delete device | ✅ |
PATCH |
/api/devices/:id/toggle |
Toggle device ON/OFF | ✅ |
PATCH |
/api/devices/:id/eco |
Toggle Eco Mode | ✅ |
POST |
/api/devices/seed |
Seed default devices | ✅ |
GET |
/api/devices/history/water |
Get water usage history | ✅ |
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
GET |
/api/energy/history?range=daily |
Get energy history (daily/weekly) | ✅ |
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
GET |
/api/settings |
Get user settings | ✅ |
PATCH |
/api/settings |
Update user settings | ✅ |
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
GET |
/api/dashboard/summary |
Get dashboard summary | ✅ |
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
GET |
/api/health |
Server health check | ❌ |
{
name: String (required),
email: String (required, unique),
passwordHash: String (required),
role: String (enum: ['user', 'admin'])
}{
userId: ObjectId (ref: User),
name: String (required),
type: String (enum: ['energy', 'water']),
consumption: Number (kW for energy, L/min for water),
isOn: Boolean,
isEco: Boolean,
category: String (enum: ['HVAC', 'LIGHTING', 'WATER_HEATER', 'OTHER']),
location: String,
currentPowerKw: Number (calculated),
timestamps: true
}{
userId: ObjectId (ref: User),
deviceId: ObjectId (ref: Device),
timestamp: Date,
powerKw: Number,
energyKwh: Number,
day: String ("YYYY-MM-DD"),
week: String ("YYYY-Wxx")
}{
userId: ObjectId (ref: User),
deviceId: ObjectId (ref: Device),
timestamp: Date,
flowRateLpm: Number,
totalLiters: Number,
day: String ("YYYY-MM-DD"),
week: String ("YYYY-Wxx")
}{
userId: ObjectId (ref: User, unique),
energyLimit: Number (default: 15, min: 5, max: 50),
waterLimit: Number (default: 100, min: 50, max: 200)
}The application is fully responsive and optimized for mobile devices. The viewport meta tag is configured in client/client/index.html:
<meta name="viewport" content="width=device-width, initial-scale=1.0" />- Red/Green Logic: Charts automatically color-code bars based on conservation limits
- Real-Time Updates: Charts refresh when devices are toggled
- Dual Resource View: Toggle between Energy (kWh) and Water (Liters) views
- Real-Time Calculation: Uses current device load (kW) × 24 hours × 30 days × rate
- Localized Currency: Default set to Indian Rupee (₹) with configurable rate
- Instant Updates: Recalculates when devices are toggled or rate is changed
- iOS-Style Toggles: Modern switch UI for device control
- Eco Mode: Reduce consumption by 20% when enabled
- Real-Time Status: Shows current consumption rate (kW or L/min)
npm run dev # Start development server (nodemon)
npm start # Start production server
npm run seed:devices # Seed default devices
npm run seed:history # Seed 7 days of historical data
npm run clear:history # Clear all history logsnpm run dev # Start development server (Vite)
npm run build # Build for production
npm run preview # Preview production build
npm run lint # Run ESLintThis usually means the backend server encountered an error. Check the following:
-
Missing
.envfile:- Create a
.envfile in theserver/directory - Add required variables:
MONGO_URI,JWT_SECRET,PORT - See Environment Variables section above
- Create a
-
MongoDB Connection:
- Ensure MongoDB is running (local) or Atlas connection string is correct
- Check server console for MongoDB connection errors
-
JWT Secret Missing:
- If
JWT_SECRETis not set, authentication will fail - Generate a secure key:
node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"
- If
-
Check Server Logs:
- Look at the server console output for detailed error messages
- The improved error handling now logs full error stacks
- Local MongoDB: Ensure MongoDB service is running (
mongod) - MongoDB Atlas: Verify connection string in
.envand network access settings - Check
server/src/config/db.jsfor detailed error messages
- Backend (5000): Change
PORTinserver/.envor kill the process using port 5000 - Frontend (5173): Vite will automatically use the next available port
- Ensure backend CORS is enabled (already configured in
server/src/app.js) - Verify
VITE_API_BASE_URLmatches your backend URL
- Check server console for error messages
- Verify
.envfile exists and has all required variables - Ensure MongoDB is connected and accessible
- Check that user is authenticated (JWT token is valid)
This project is created for educational purposes (University Final Project).
- Development Team - Energy Core Project
- Built with modern MERN stack best practices
- UI inspired by production SaaS dashboards
- Charts powered by Recharts library
Version: 1.0.0
Last Updated: December 2025