Skip to content

annanyaa03/CHARGENET

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

182 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

 β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ•—  β–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ•—   β–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—
β–ˆβ–ˆβ•”β•β•β•β•β•β–ˆβ–ˆβ•‘  β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•”β•β•β•β•β• β–ˆβ–ˆβ•”β•β•β•β•β•β–ˆβ–ˆβ–ˆβ–ˆβ•—  β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β•β•β•β•šβ•β•β–ˆβ–ˆβ•”β•β•β•
β–ˆβ–ˆβ•‘     β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘  β–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—  β–ˆβ–ˆβ•”β–ˆβ–ˆβ•— β–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—     β–ˆβ–ˆβ•‘   
β–ˆβ–ˆβ•‘     β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘   β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β•  β–ˆβ–ˆβ•‘β•šβ–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β•     β–ˆβ–ˆβ•‘   
β•šβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘  β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘  β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘  β–ˆβ–ˆβ•‘β•šβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘ β•šβ–ˆβ–ˆβ–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—   β–ˆβ–ˆβ•‘   
 β•šβ•β•β•β•β•β•β•šβ•β•  β•šβ•β•β•šβ•β•  β•šβ•β•β•šβ•β•  β•šβ•β• β•šβ•β•β•β•β•β•β•šβ•β•β•β•β•β•β•β•šβ•β•  β•šβ•β•β•β•β•šβ•β•β•β•β•β•β•   β•šβ•β•   

India's EV Charging Station Network

Find. Book. Charge.


React Vite Node.js Express Tailwind CSS Supabase Socket.io License


Overview

ChargeNet is a full-stack web application that connects EV drivers with a network of 80+ charging stations across India. The platform provides real-time charger availability, slot booking, weather and AQI data at each station, community reviews, and AI-powered station tagging β€” all accessible through a clean, map-first interface.

The backend is built with a production-grade Express.js architecture: modular MVC structure, Zod schema validation, Pino structured logging, per-route rate limiting, Helmet security headers, and Supabase JWT authentication.


🎭 CHARGENET AI Character Generator

A high-performance AI Character Generator integrated into the ChargeNet ecosystem.

Deploy with Vercel

Features

  • Stable Diffusion v1.5: State-of-the-art character generation.
  • CPU Optimized: 20s inference on Vercel CPU using optimized diffusers pipeline.
  • Supabase Integration: Automatically saves generated images to Supabase Storage.
  • Premium Gradio UI: Responsive design with sharing capabilities.

Environment Variables

To enable cloud storage, add the following to your Vercel deployment or .env:

  • SUPABASE_URL: Your Supabase project URL.
  • SUPABASE_KEY: Your Supabase service role or anon key.

Quick Deploy

vercel --prod


Table of Contents


Features

Feature Description
Station Discovery Browse 80+ stations on an interactive Leaflet map
Real-time Availability Live charger status per station
Slot Booking Book and cancel EV charging sessions
Weather and AQI On-site environmental data via Open-Meteo
Reviews and Ratings Community-sourced station feedback
AI Tagging Anthropic Claude-powered station tag generation
Shareable URLs Public slug-based station pages
Payments Razorpay integration

Architecture

                          CLIENT (React + Vite)
                                   |
                          HTTP / REST (JSON)
                                   |
            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
            β”‚              EXPRESS API SERVER              β”‚
            β”‚                                             β”‚
            β”‚  requestLogger β†’ helmet β†’ cors β†’ bodyParser β”‚
            β”‚          β†’ rateLimit β†’ requireAuth          β”‚
            β”‚                                             β”‚
            β”‚   /api/v1/stations   β†’  stationRoutes       β”‚
            β”‚   /api/v1/chargers   β†’  chargerRoutes       β”‚
            β”‚   /api/v1/bookings   β†’  bookingRoutes       β”‚
            β”‚   /api/v1/reviews    β†’  reviewRoutes        β”‚
            β”‚                                             β”‚
            β”‚        notFoundHandler β†’ errorHandler       β”‚
            β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                           |
              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
              |                         |
       β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”
       β”‚  SUPABASE   β”‚         β”‚  EXTERNAL APIs  β”‚
       β”‚ PostgreSQL  β”‚         β”‚                 β”‚
       β”‚    + Auth   β”‚         β”‚  Open-Meteo     β”‚
       β”‚    + RLS    β”‚         β”‚  Anthropic AI   β”‚
       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β”‚  Razorpay       β”‚
                               β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Tech Stack

Backend

Technology Version Purpose
Node.js >= 18 Runtime
Express.js 4.x HTTP framework
Supabase JS 2.x Database client and JWT verification
Zod 3.x Request schema validation
Pino Latest Structured JSON logging
Helmet Latest HTTP security headers
express-rate-limit Latest Per-route rate limiting
Vitest Latest Unit and integration testing

Frontend

Technology Version Purpose
React 18.2 UI framework
Vite 5.x Build tool and dev server
Tailwind CSS 3.4 Utility-first styling
React Router v6 Client-side routing
Zustand 4.4 Global state management
TanStack Query 5.x Server state and caching
React Leaflet 4.2 Interactive maps
Framer Motion 11.x Animations
React Hook Form 7.x Form handling

External APIs

API Purpose Cost
Open-Meteo Weather and AQI data Free
OpenStreetMap / Leaflet Map tiles Free
Nominatim Geocoding Free
Anthropic Claude AI station tagging Usage-based
Razorpay Payment processing Transaction fee

Project Structure

chargenet/
β”œβ”€β”€ .github/
β”‚   └── workflows/
β”‚       └── ci.yml                  # GitHub Actions CI pipeline
β”‚
β”œβ”€β”€ server/                         # Express API server
β”‚   β”œβ”€β”€ controllers/
β”‚   β”‚   β”œβ”€β”€ bookingsController.js
β”‚   β”‚   β”œβ”€β”€ chargersController.js
β”‚   β”‚   β”œβ”€β”€ reviewsController.js
β”‚   β”‚   └── stationsController.js
β”‚   β”œβ”€β”€ lib/
β”‚   β”‚   β”œβ”€β”€ logger.js               # Pino logger instance
β”‚   β”‚   β”œβ”€β”€ response.js             # Standardised response helpers
β”‚   β”‚   └── supabase.js             # Supabase client (service role)
β”‚   β”œβ”€β”€ middleware/
β”‚   β”‚   β”œβ”€β”€ asyncHandler.js         # Async error wrapper
β”‚   β”‚   β”œβ”€β”€ auth.js                 # Supabase JWT verification
β”‚   β”‚   β”œβ”€β”€ errorHandler.js         # Global error and 404 handler
β”‚   β”‚   β”œβ”€β”€ logger.js               # pino-http request logger
β”‚   β”‚   β”œβ”€β”€ rateLimit.js            # Per-route rate limiters
β”‚   β”‚   β”œβ”€β”€ security.js             # Helmet and CORS configuration
β”‚   β”‚   └── validate.js             # Zod schema validator middleware
β”‚   β”œβ”€β”€ routes/
β”‚   β”‚   β”œβ”€β”€ bookings.js
β”‚   β”‚   β”œβ”€β”€ chargers.js
β”‚   β”‚   β”œβ”€β”€ reviews.js
β”‚   β”‚   └── stations.js
β”‚   β”œβ”€β”€ schemas/
β”‚   β”‚   β”œβ”€β”€ auth.schema.js
β”‚   β”‚   β”œβ”€β”€ booking.schema.js
β”‚   β”‚   β”œβ”€β”€ review.schema.js
β”‚   β”‚   └── station.schema.js
β”‚   β”œβ”€β”€ services/
β”‚   β”‚   β”œβ”€β”€ ai.js                   # Anthropic Claude integration
β”‚   β”‚   β”œβ”€β”€ booking.service.js
β”‚   β”‚   β”œβ”€β”€ charger.service.js
β”‚   β”‚   β”œβ”€β”€ review.service.js
β”‚   β”‚   β”œβ”€β”€ station.service.js
β”‚   β”‚   └── supabase.js
β”‚   β”œβ”€β”€ tests/                      # Vitest test suite
β”‚   β”œβ”€β”€ index.js                    # Application entry point
β”‚   β”œβ”€β”€ vitest.config.js
β”‚   └── package.json
β”‚
β”œβ”€β”€ sql/
β”‚   β”œβ”€β”€ schema.sql                  # Full database schema
β”‚   β”œβ”€β”€ seed-stations.sql           # Station seed data
β”‚   β”œβ”€β”€ database-design-fix.sql
β”‚   └── public-rls-fix.sql          # Row Level Security policies
β”‚
β”œβ”€β”€ src/                            # React frontend
β”‚   β”œβ”€β”€ components/
β”‚   β”œβ”€β”€ context/
β”‚   β”œβ”€β”€ hooks/
β”‚   β”œβ”€β”€ lib/                        # Supabase client (anon key)
β”‚   β”œβ”€β”€ mock/
β”‚   β”œβ”€β”€ pages/
β”‚   β”œβ”€β”€ routes/
β”‚   β”œβ”€β”€ services/                   # Frontend API service layer
β”‚   β”œβ”€β”€ store/                      # Zustand stores
β”‚   └── utils/
β”‚
β”œβ”€β”€ .env.example
β”œβ”€β”€ SECURITY.md
β”œβ”€β”€ package.json
└── vite.config.js

Database Schema

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  stations   │──────<β”‚   chargers   β”‚       β”‚   bookings   β”‚
│─────────────│       │──────────────│       │──────────────│
β”‚ id          β”‚       β”‚ id           β”‚       β”‚ id           β”‚
β”‚ name        β”‚       β”‚ station_id   β”‚       β”‚ user_id      β”‚
β”‚ slug        β”‚       β”‚ type         β”‚       β”‚ charger_id   β”‚
β”‚ location    β”‚       β”‚ power_kw     β”‚       β”‚ station_id   β”‚
β”‚ latitude    β”‚       β”‚ status       β”‚       β”‚ start_time   β”‚
β”‚ longitude   β”‚       β”‚ connector    β”‚       β”‚ end_time     β”‚
β”‚ address     β”‚       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜       β”‚ status       β”‚
β”‚ amenities   β”‚                              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜
       β”‚                β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
       β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€<β”‚   reviews    β”‚       β”‚   profiles   β”‚
       β”‚                │──────────────│       │──────────────│
       β”‚                β”‚ id           β”‚       β”‚ id           β”‚
       β”‚                β”‚ station_id   β”‚       β”‚ user_id      β”‚
       β”‚                β”‚ user_id      β”‚       β”‚ full_name    β”‚
       β”‚                β”‚ rating       β”‚       β”‚ vehicle_type β”‚
       β”‚                β”‚ comment      β”‚       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
       β”‚                β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
       β”‚
       β”‚         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
       └────────<β”‚ station_tags β”‚>────│     tags     β”‚
                 β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

API Reference

Base URL: http://localhost:3001/api/v1

All write endpoints require an Authorization: Bearer <token> header.
All responses follow the envelope: { success, data | error, timestamp }.


Health

Method Endpoint Auth Description
GET /health Public Server status, uptime, version

Stations

Method Endpoint Auth Description
GET /stations Public List all stations
GET /stations/:id Public Get station by ID
GET /stations/slug/:slug Public Get station by public slug
POST /stations Required Create a station
PUT /stations/:id Required Update a station
DELETE /stations/:id Required Delete a station
GET /stations/:id/chargers Public List chargers at a station
GET /stations/:id/reviews Public List reviews for a station

Chargers

Method Endpoint Auth Description
PATCH /chargers/:id/status Required Update charger availability

Bookings

Method Endpoint Auth Description
GET /bookings Required List current user's bookings
POST /bookings Required Create a booking
PATCH /bookings/:id/cancel Required Cancel a booking

Reviews

Method Endpoint Auth Description
POST /reviews Required Submit a station review

Response Format

// Success
{
  "success": true,
  "data": { ... },
  "timestamp": "2025-01-01T00:00:00.000Z"
}

// Error
{
  "success": false,
  "error": {
    "code": "VALIDATION_ERROR",
    "message": "Validation failed",
    "details": [{ "field": "rating", "message": "Expected number" }]
  },
  "timestamp": "2025-01-01T00:00:00.000Z"
}

Error Codes

Code HTTP Status Cause
VALIDATION_ERROR 400 Zod schema validation failed
UNAUTHORIZED 401 Missing or invalid JWT
FORBIDDEN 403 Authenticated but not permitted
NOT_FOUND 404 Resource does not exist
CONFLICT 409 Duplicate resource (DB constraint)
SERVER_ERROR 500 Unhandled internal error

Getting Started

Prerequisites

  • Node.js >= 18
  • npm >= 9
  • A Supabase project
  • Razorpay test account (optional, for payment flows)

1. Clone and Install

git clone https://github.com/annanyaa03/CHARGENET.git
cd CHARGENET

# Frontend dependencies
npm install

# Server dependencies
cd server && npm install && cd ..

2. Configure Environment

cp .env.example .env
cp server/.env.example server/.env
# Edit both files and populate all required values

3. Apply Database Schema

In your Supabase SQL editor, run the files in this order:

sql/schema.sql
sql/public-rls-fix.sql
sql/seed-stations.sql      # optional: seeds 80+ stations

4. Start Development Servers

# Frontend only   β€” http://localhost:5173
npm run dev

# Backend only    β€” http://localhost:3001
npm run dev:server

# Both together
npm run dev:all

Environment Variables

Frontend (/.env) β€” compiled into browser bundle, publicly visible

Variable Description
VITE_SUPABASE_URL Supabase project URL
VITE_SUPABASE_ANON_KEY Supabase anonymous (publishable) key
VITE_API_URL Express API base URL
VITE_RAZORPAY_KEY_ID Razorpay publishable key

Server (/server/.env) β€” server-side only, never exposed to client

Variable Description
PORT Server port (default: 3001)
NODE_ENV development or production
FRONTEND_URL Allowed CORS origin in production
SUPABASE_URL Supabase project URL
SUPABASE_PUBLISHABLE_KEY Supabase anonymous key
SUPABASE_SECRET_KEY Supabase service role key β€” privileged
SUPABASE_JWT_SECRET JWT secret for token verification
RAZORPAY_KEY_ID Razorpay key ID
RAZORPAY_KEY_SECRET Razorpay secret key β€” server only
SMTP_HOST SMTP server hostname
SMTP_PORT SMTP port (typically 587)
SMTP_USER SMTP authentication username
SMTP_PASS SMTP authentication password
SMTP_FROM Sender address for transactional email

VITE_ prefixed variables are bundled into the client and visible to all users.
Never assign privileged credentials β€” service role keys, payment secrets, SMTP passwords β€” to VITE_ variables.


Development Scripts

Script Description
npm run dev Start Vite frontend dev server
npm run dev:server Start Express API with nodemon
npm run dev:all Start frontend and backend concurrently
npm run build Production build of the frontend
npm run preview Preview production build locally
npm run lint Run ESLint across all JS and JSX files
cd server && npm test Run Vitest test suite

Security

The backend implements a layered security model across every request.

HTTP Headers β€” Helmet enforces Content Security Policy, HSTS with a one-year max-age and preload, X-Frame-Options deny, X-Content-Type-Options nosniff, and Referrer-Policy strict-origin-when-cross-origin.

CORS β€” Strict origin whitelist. Requests from unlisted origins are rejected at the middleware level. Access-Control-Allow-Credentials is enabled for authenticated flows.

Authentication β€” All non-GET routes require a valid Supabase JWT as Authorization: Bearer <token>. Tokens are verified server-side via the Supabase service role client and the authenticated user is attached to req.user for all downstream handlers.

Rate Limiting β€” Four independent limiters protect distinct surfaces:

Limiter Window Limit
General API 15 minutes 100 requests
Authentication 15 minutes 10 requests
Bookings 1 hour 20 requests
Reviews 1 hour 5 requests

Validation β€” All incoming request bodies are validated against Zod schemas before reaching controllers. Invalid payloads return structured 400 responses with per-field error details.

Database β€” Row Level Security policies are applied at the Supabase layer, ensuring users can only access their own data regardless of API-level checks.

To report a vulnerability, see SECURITY.md.


Contributing

  1. Fork the repository.
  2. Create a feature branch: git checkout -b feature/your-feature-name
  3. Write tests for any new behaviour.
  4. Ensure all tests pass: cd server && npm test
  5. Commit using Conventional Commits.
  6. Open a pull request against main with a clear description of changes.

License

MIT License. See LICENSE for details.


Built with React, Express, and Supabase.

About

ChargeNet is a full-stack web application that connects EV drivers with a network of 80+ charging stations across India. The platform provides real-time charger availability, slot booking, weather and AQI data at each station, community reviews, and AI-powered station tagging.

Resources

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors