This backend service processes and analyzes historical weather data using a scalable, high-performance infrastructure. Built with Node.js, Express.js, MongoDB , Redis and BullMQ, it supports real-time data streaming and has been optimized for large dataset processing, robust access control, and responsive data visualization.
- High-Performance Data Processing: Handles large weather datasets, specifically OpenWeather Historical Weather Data in CSV format, for real-time analytics and visualization.
- WebSocket Integration: Enables real-time data streaming for live updates and responsive data visualization.
- Redis Caching: Utilizes Redis to optimize data retrieval times and manage request load efficiently.
- Role-Based Access Control (RBAC): Secures data access by supporting roles like
admin
,manager
, anduser
with JSON Web Token (JWT) based authentication. - Robust Logging: Detailed logs have been added to the code to facilitate monitoring and debugging, enhancing the observability of the service.
- Dockerized Deployment: Simplifies containerized deployment to AWS EC2 using Docker and an automated CI/CD pipeline.
- Backend: Node.js, Express.js, MongoDB, TypeScript
- Authentication: JWT (JSON Web Token)
- Caching: Redis
- Queue Processing: Bull.js for managing large data processing tasks efficiently
- WebSocket Integration: Socket.IO for real-time data streaming
- Deployment: Docker, GitHub Actions, AWS EC2
- Node.js v18+
- Express
- MongoDB
- Docker
- AWS EC2 (for deployment)
- Redis ( deployed on an AWS EC2 instance)
-
Clone the Repository:
git clone https://github.com/suryathink/mapup cd <repository-directory> cd server # Move into the backend code folder
-
Install Dependencies:
npm install
-
Configure Environment Variables:
Create a
.env
file with the following environment variables:MONGO_URL=<your-mongo-db-url> JWT_SECRET=<your-jwt-secret> REDIS_HOST_URL=<your-redis-host-url> REDIS_PORT=<your-redis-port> REDIS_PASSWORD=<your-redis-password>
-
Run the Application:
npm run dev
Build the Docker image locally:
docker build -t suryathink/map:latest -f server/Dockerfile .
The project utilizes GitHub Actions for CI/CD:
- Build and Push Docker Image: On every push to the
main
branch, the code is checked out, dependencies installed, and the Docker image built and pushed to Docker Hub. - Deploy to AWS EC2: The deployment job securely connects to the EC2 instance, pulls the latest Docker image, stops any running containers, and starts a new container with updated environment variables.
This service processes weather data received in CSV format, specifically OpenWeather Historical Weather Data. The CSV file is parsed, and data is processed for real-time use through WebSocket connections or stored for later retrieval via API endpoints.
- Queue Setup: Uses Bull.js to manage file processing tasks efficiently and ensure scalability for large datasets.
- CSV Parsing and Processing: Reads CSV files, processes weather records, and stores them in MongoDB, enabling fast querying and retrieval.
Socket.IO is used to stream data in real-time, allowing clients to receive updates without polling the server.
The backend service exposes the following RESTful API routes for user management, weather data processing, and real-time data streaming:
Method | Endpoint | Middleware | Roles Allowed | Description |
---|---|---|---|---|
POST | /upload |
apiLimiterMiddleware , verifyToken |
user , admin , manager |
Uploads a CSV file containing weather data. The file is processed and stored in the database. |
POST | /signup |
authLimiterMiddleware |
Public | Allows new users to sign up and create an account. |
POST | /login |
authLimiterMiddleware |
Public | Authenticates a user and provides a JWT for secure access. |
GET | / |
apiLimiterMiddleware , verifyToken |
admin , user , manager |
Fetches all stored weather data. Returns a paginated response of weather records. |
GET | /hello |
apiLimiterMiddleware |
Public | Returns a basic greeting to confirm the server is running and accessible. |
PUT | /:id |
apiLimiterMiddleware , verifyToken |
admin |
Updates a specific weather data record by ID. |
DELETE | /:id |
apiLimiterMiddleware , verifyToken |
admin |
Deletes a specific weather data record by ID. |
- File Upload (
/upload
): Protected route allowing users withuser
,admin
, ormanager
roles to upload a weather dataset in CSV format. The data is processed and added to the database for further analysis and retrieval. - User Signup (
/signup
): Public route for new users to create accounts. TheauthLimiterMiddleware
rate-limits requests to mitigate brute-force attacks. - User Login (
/login
): Public route for logging in and generating a JWT, allowing users to access protected resources. - Fetch All Weather Data (
/
): Protected route for authorized users to retrieve paginated weather records stored in the database. - Greeting Route (
/hello
): A simple endpoint that returns a basic greeting, useful for testing the server's availability. - Update Weather Data (
/:id
): Admin-only route for updating weather records by ID. This allows admins to modify existing data in the database. - Delete Weather Data (
/:id
): Admin-only route for deleting a specific weather data record by ID.
Sample data you can try uploading weather_data.csv