ChargeHive is a peer-to-peer EV charging platform that connects electric vehicle owners with homeowners who have charging stations. This backend API provides REST endpoints for user authentication, provider management, session booking, payment processing, and blockchain integration using Flow blockchain.
ChargeHive solves the problem of limited EV charging infrastructure by enabling homeowners to rent out their private chargers. The platform includes:
- User and provider authentication with Supabase
- Service management for charging stations
- Session booking and scheduling
- Payment processing
- Flow blockchain integration for transparent charging data and rewards
- CHToken reward system for providers
- Node.js 18.x or higher
- npm or yarn
- Supabase account
- Flow blockchain testnet account (optional for full functionality)
- Clone the repository
git clone https://github.com/Charge-Hive/Chargehive-backend.git
cd Chargehive-backend- Install dependencies
npm install- Set up environment variables
Create a
.envfile in the root directory:
# Supabase Configuration
SUPABASE_URL=your_supabase_url
SUPABASE_ANON_KEY=your_supabase_anon_key
SUPABASE_SERVICE_KEY=your_supabase_service_key
# JWT Configuration
JWT_SECRET=your_jwt_secret
# Flow Blockchain Configuration
FLOW_PRIVATE_KEY=your_flow_private_key
FLOW_SERVICE_ACCOUNT_ADDRESS=your_flow_account_address
ADAPTER_ID=your_adapter_id
# Application Configuration
PORT=3000
NODE_ENV=development
LOG_LEVEL=debug- Run the application
# Development mode with hot reload
npm run start:dev
# Production mode
npm run build
npm run start:prodThe API will be available at http://localhost:3000/api
API documentation (Swagger) will be available at http://localhost:3000/api/docs
# Run all tests
npm test
# Run tests in watch mode
npm run test:watch
# Run tests with coverage
npm run test:covChargehive-backend/
├── src/
│ ├── auth/ # Authentication module (JWT, password hashing)
│ │ ├── auth.service.ts
│ │ ├── auth.service.spec.ts
│ │ └── auth.module.ts
│ ├── common/ # Shared utilities
│ │ ├── dto/ # Error response DTOs
│ │ ├── filters/ # Global exception filters
│ │ │ ├── http-exception.filter.ts
│ │ │ └── validation-exception.filter.ts
│ │ ├── interceptors/ # Request logging interceptor
│ │ │ └── logging.interceptor.ts
│ │ └── logger/ # Winston logger service
│ │ ├── logger.service.ts
│ │ └── logger.module.ts
│ ├── flow/ # Flow blockchain integration
│ │ └── flow.service.ts
│ ├── health/ # Health check endpoint
│ │ ├── health.controller.ts
│ │ └── health.module.ts
│ ├── payments/ # Payment processing
│ │ ├── payments.service.ts
│ │ └── payments.controller.ts
│ ├── provider/ # Provider management
│ │ ├── provider.service.ts
│ │ └── provider.controller.ts
│ ├── services/ # Charging service management
│ │ ├── services.service.ts
│ │ └── services.controller.ts
│ ├── sessions/ # Booking sessions
│ │ ├── sessions.service.ts
│ │ ├── sessions.service.spec.ts
│ │ └── sessions.controller.ts
│ ├── supabase/ # Supabase client configuration
│ │ └── supabase.service.ts
│ ├── user/ # User management
│ │ ├── user.service.ts
│ │ └── user.controller.ts
│ ├── wallet/ # Blockchain wallet management
│ │ ├── wallet.service.ts
│ │ └── wallet.controller.ts
│ ├── app.module.ts # Root application module
│ └── main.ts # Application entry point
├── logs/ # Application logs (daily rotation)
│ ├── application-YYYY-MM-DD.log
│ └── error-YYYY-MM-DD.log
├── .github/
│ └── workflows/
│ └── ci-cd.yml # GitHub Actions CI/CD pipeline
├── jest.config.js # Jest testing configuration
├── Procfile # Heroku deployment configuration
├── package.json
└── tsconfig.json
The project uses GitHub Actions for automated testing and deployment. The pipeline is defined in .github/workflows/ci-cd.yml.
- Install Dependencies:
npm ci - Linting:
npm run lint(non-blocking) - Testing:
npm test- All unit tests must pass - Build:
npm run build- TypeScript compilation - Coverage Upload: Test coverage reports uploaded as artifacts
- Deploy to Heroku: Automated deployment using
akhileshns/heroku-deploy - Health Check: Verifies deployment at
/api/healthendpoint - Auto Rollback: Automatically rolls back if health check fails
- Unit Tests: Testing individual services and controllers in isolation
- Auth service: Password hashing, JWT generation/verification
- Sessions service: Booking validation, availability checks
- Health controller: Endpoint response validation
- Test Coverage: Configured to generate coverage reports
- CI Integration: Tests run automatically on every code push
The Procfile defines the production start command:
web: npm run start:prod
Required Heroku Secrets (configured in GitHub repository secrets):
HEROKU_API_KEY: Your Heroku API keyHEROKU_APP_NAME: Your Heroku application nameHEROKU_EMAIL: Your Heroku account email
Health Check Endpoint: /api/health
- Returns:
{ status: "ok", timestamp: "...", uptime: 123.45 } - Used by CI/CD pipeline to verify successful deployment
- Global Exception Filters: Catch all errors and return user-friendly messages
- Error Codes: Standardized error codes (4xx for client errors, 5xx for server errors)
- Daily Log Rotation: Logs stored in
logs/directory with daily rotationapplication-YYYY-MM-DD.log: All logs (info, warn, error)error-YYYY-MM-DD.log: Error logs only
- Sensitive Data Protection: Passwords, tokens, and private keys are redacted from logs
- Request Logging: All HTTP requests logged with method, URL, response time, and status code
Once the application is running, visit:
- Swagger UI:
http://localhost:3000/api/docs - Health Check:
http://localhost:3000/api/health
- Framework: NestJS
- Language: TypeScript
- Database: Supabase (PostgreSQL)
- Authentication: Supabase Auth + JWT
- Blockchain: Flow blockchain
- Testing: Jest
- Logging: Winston with daily rotation
- CI/CD: GitHub Actions + Heroku
- Documentation: Swagger/OpenAPI