HydroForecast is a full-stack water tank monitoring and forecasting project that combines a Node.js dashboard with a Python prediction service. The application lets users register tanks, record water-level logs, review tank history, and open a prediction view that combines groundwater estimation, rainfall forecast data, and future tank-level forecasting.
The repository currently contains two connected applications:
- A Node.js + Express + MongoDB + EJS web app for authentication, tank management, and log management.
- A FastAPI + Prophet + geospatial analysis service that generates prediction data for a selected tank.
The codebase already implements these user-facing flows:
- User sign-up and login with JWT-based authentication.
- Cookie-based session handling for the browser dashboard.
- Tank registration with name, capacity, location, current level, unit, and alert threshold.
- Dashboard listing for all tanks owned by the logged-in user.
- Manual tank log creation.
- Sensor-style automatic tank log creation through a dedicated API route that converts a measured distance into estimated stored volume.
- Viewing historical tank logs for each tank.
- Tank deletion.
- Prediction page for each tank that shows:
- groundwater level estimate based on the tank location,
- rainfall forecast from Open-Meteo,
- future tank-level predictions from Prophet.
- Framework: Express
- Database: MongoDB via Mongoose
- Templating: EJS
- Auth: JWT in HTTP-only cookies, with header fallback for API clients
- UI: Server-rendered pages with vanilla JavaScript
- Framework: FastAPI
- Database access: PyMongo
- Forecasting: Prophet
- Geocoding: geopy with Nominatim
- Spatial lookup: KDTree over a groundwater CSV dataset
- Weather source: Open-Meteo daily precipitation forecast
- The browser talks to the Node.js app.
- The dashboard exposes a prediction link for a selected tank.
- The Node.js route
/prediction/:tankIdcalls the Python FastAPI endpoint athttp://127.0.0.1:8000/prediction. - The Python service reads tank data and logs from MongoDB, performs enrichment and forecasting, and returns prediction data.
- The Node.js app renders the prediction page using EJS and Chart.js.
HydroForecast/
├── package.json
├── backend/
│ ├── server.js
│ ├── config/
│ ├── controllers/
│ ├── middleware/
│ ├── models/
│ ├── public/
│ ├── routes/
│ ├── utils/
│ └── views/
└── AI/
├── application.py
├── requirements.txt
├── setup.py
├── test.py
├── notebooks/
└── src/
├── components/
├── pipeline/
├── exception.py
├── logger.py
└── utils.py
nameemailpassword(hashed before save)locationcreatedAt
usernamecapacitycurrentLevellocationunit(liters,gallons,cubic_meters)alertThresholdstatus(active,inactive,maintenance)createdAtlastUpdated- virtual field:
percentageFilled
tankuser(optional in the schema)currentLevelrainfallusagetimestampnoteslogType
/login: login page for existing users./signup: account creation page./dashboard: authenticated dashboard for tank management./prediction/:tankId: analytics page for one tank, including predicted tank levels and rainfall forecast charts.
POST /api/auth/signupPOST /api/auth/loginPOST /api/auth/logoutGET /api/auth/me
POST /api/tanksGET /api/tanksGET /api/tanks/:idPUT /api/tanks/:idDELETE /api/tanks/:id
POST /api/tanklogsGET /api/tanklogs/:tankIdDELETE /api/tanklogs/:tankId/clearDELETE /api/tanklogs/:logIdPOST /api/tanklogs/auto
GET /prediction/:tankIdrenders the prediction page through the Node.js app.POST http://127.0.0.1:8000/predictionis the Python service endpoint used by the web app.
- Node.js 18 or newer
- Python 3.10 or 3.11 recommended
- MongoDB instance
The repository has a root package.json, so install JavaScript dependencies from the project root.
npm installFrom the AI directory:
cd AI
python -m venv .venv
source .venv/Scripts/activate
pip install -r requirements.txt
pip install scipy prophetNotes:
scipyandprophetare imported by the code but are not listed inAI/requirements.txt, so they need to be installed separately unless you update the dependency file.- If you are using PowerShell instead of Git Bash, activate the virtual environment with
.venv\Scripts\Activate.ps1.
The code expects environment variables for both the backend and the AI service.
Create a .env file in the project root if you run the backend with node backend/server.js:
MONGO_URI=mongodb://127.0.0.1:27017/hydroforecast
JWT_SECRET=replace_with_a_secure_secret
PORT=5000
NODE_ENV=developmentCreate an AI/.env file if you run the FastAPI service from inside the AI folder:
MONGO_URI=mongodb://127.0.0.1:27017/hydroforecast
WEATHER_API_KEY=optional_currently_unusedNotes:
WEATHER_API_KEYis loaded in the Python service but is not currently used by the implemented weather call.- Both services must point to the same MongoDB database.
The prediction service expects this CSV file to exist:
AI/src/components/artifacts/underground.csv
The CSV must include at least these columns:
LATITUDELONGITUDEWL(mbgl)
Without this file, the groundwater lookup path will fail.
From the AI directory:
uvicorn application:app --reload --host 127.0.0.1 --port 8000From the project root:
node backend/server.jsFor development with reload:
npx nodemon backend/server.jsThe dashboard will be available at:
http://localhost:5000
- Start MongoDB.
- Start the FastAPI service on port 8000.
- Start the Express app on port 5000.
- Open
http://localhost:5000. - Sign up or log in.
- Create a tank with a valid location.
- Add a few manual logs.
- Open the prediction page for that tank.
Important: the prediction logic requires enough historical log data for Prophet to work well. The implementation currently raises an error when fewer than 5 values are available.
When the prediction endpoint is called, the Python service performs these steps:
- Look up the selected tank in MongoDB.
- Read the tank location.
- Geocode that location using Nominatim.
- Load the groundwater CSV and find the nearest groundwater record using KDTree.
- Fetch rainfall forecast data from Open-Meteo.
- Read historical tank logs from MongoDB.
- Forecast future tank levels using Prophet.
- Return structured prediction data to the Express app for rendering.
The route POST /api/tanklogs/auto is designed for a sensor-style input flow. It expects a currentLevel value that is treated as a distance from the top of a fixed-height tank, then converts that distance into water volume using:
- fixed tank height of
3 distanceFromTop = currentLevel / 100- computed stored volume based on tank capacity
This is useful to understand before integrating real hardware, because the field name currentLevel in that route is not a direct stored water volume.
This README is intentionally honest about the current state of the repository.
The weather monitoring service is intended to periodically create rainfall-based logs, but the HTTP request used to fetch forecast data is commented out while the code still references response. As written, that path cannot work reliably.
The repository references AI/src/components/artifacts/underground.csv, but that file is not present in the current codebase snapshot.
AI/src/utils.pyis empty.AI/src/pipeline/dataIngestionPipeline.pyis empty.AI/src/pipeline/dataTransformationPipeline.pyis empty.AI/src/pipeline/predictionPipeline.pyis empty.
The log routes do not use the authentication middleware, so any client with access to the API can currently create, read, or delete logs if they know the identifiers.
The Python code imports packages that are not fully represented in AI/requirements.txt, and the JavaScript root package.json does not currently define start scripts.
The Prophet-based prediction path requires at least 5 log entries. Tanks with very little historical data will not produce a forecast.
- The backend uses root-level JavaScript dependencies from
package.json. - The backend serves EJS pages directly and also exposes JSON APIs.
- The prediction page uses Chart.js loaded from a CDN.
- The AI service talks directly to MongoDB rather than through the Node.js API.
AI/test.pyis a manual exploratory script, not a full automated test suite.
If you plan to continue this project, the most valuable next fixes are:
- Restore or rewrite the backend weather-monitoring request path.
- Add the missing groundwater dataset or document how to obtain it.
- Protect tank-log routes with authentication and ownership checks.
- Add proper start scripts to
package.json. - Add automated tests for both the API and the prediction service.
- Move hardcoded URLs and CORS origin values into environment variables.
HydroForecast is best understood as a working prototype for smart tank monitoring and hydro-aware forecasting. The main dashboard flow is implemented, the prediction experience is integrated end-to-end, and the codebase is structured clearly enough for extension, but a few critical runtime and security gaps still need attention before the project is production-ready.