Enterprise-Grade Energy Management Platform with Real-Time Monitoring & Role-Based Access Control
π Live Demo | π Documentation | π οΈ Getting Started
- π― Problem Statement
- π‘ Solution
- ποΈ Architecture
- π₯ Role-Based System
- β¨ Features
- π οΈ Technology Stack
- π Getting Started
- π Database Schema
- π§ͺ Testing
- π Deployment
- π Performance
- π Security
- π€ Contributing
- π License
Current Industry Problems:
- Fragmented Systems: Multiple disconnected energy monitoring tools
- Data Silos: Energy data scattered across different platforms
- Limited Access Control: No role-based permissions for energy data
- Poor Real-Time Insights: Delayed or incomplete energy analytics
- High Operational Costs: Manual monitoring and inefficient resource allocation
- Compliance Issues: Difficulty tracking energy consumption for regulatory compliance
- Scalability Issues: Systems that don't grow with organizational needs
- 30% higher energy costs due to poor monitoring
- 45% of organizations lack real-time energy insights
- 60% struggle with energy data accessibility
- 25% compliance issues due to inadequate tracking
UrjaFlow is a modern, scalable Energy Management Platform that provides:
- Real-time Energy Monitoring: Live tracking of generation, consumption, and storage
- Role-Based Access Control: Granular permissions for different user types
- Advanced Analytics: AI-powered insights and predictive analytics
- Multi-Organization Support: Manage multiple energy systems from one platform
- Professional Logging: Custom colored terminal logging for better debugging
- Enterprise-Grade Testing: Comprehensive CI/CD with real data validation
- π₯ Real Data Integration: No mock data - actual energy readings and analytics
- π₯ Multi-Role Architecture: SUPER_ADMIN, ORG_ADMIN, MANAGER, VIEWER roles
- π¨ Professional UI/UX: Modern, responsive design with real-time updates
- π Enterprise Security: JWT authentication, role-based permissions
- π Advanced Analytics: Time-based analytics, performance metrics
- π Production Ready: Complete CI/CD pipeline with automated testing
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β Frontend β β Backend API β β Database β
β (Next.js) βββββΊβ (Next.js) βββββΊβ (PostgreSQL) β
β β β β β β
β β’ React 18 β β β’ REST APIs β β β’ Energy Data β
β β’ TypeScript β β β’ Auth (NextAuth)β β β’ User Mgmt β
β β’ Tailwind CSS β β β’ Prisma ORM β β β’ Device Mgmt β
β β’ Real-time UI β β β’ Custom Logger β β β’ Analytics β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β β β
βββββββββββββββββββββββββΌββββββββββββββββββββββββ
β
βββββββββββββββββββ
β External β
β Services β
β β
β β’ Stripe API β
β β’ Email Service β
β β’ IoT Devices β
βββββββββββββββββββ
src/
βββ app/ # Next.js App Router
β βββ (dashboard)/ # Dashboard routes
β βββ admin/ # Admin panel
β βββ analytics/ # Analytics pages
β βββ api/ # API routes
β βββ auth/ # Authentication
βββ components/ # Reusable components
β βββ ui/ # UI components
β βββ forms/ # Form components
β βββ charts/ # Chart components
βββ lib/ # Utilities
β βββ auth.ts # Authentication
β βββ prisma.ts # Database client
β βββ logger.ts # Custom logger
β βββ utils.ts # Helper functions
βββ hooks/ # Custom React hooks
βββ types/ # TypeScript definitions
βββ tests/ # Test files
Full System Access
- β Manage all organizations
- β System-wide analytics
- β User management across orgs
- β Billing and subscription management
- β Platform configuration
- β Advanced reporting
Organization Management
- β Manage own organization
- β Organization analytics
- β Manage organization users
- β Device management
- β Billing for organization
- β Support ticket management
Operations Management
- β View analytics & reports
- β Device monitoring
- β Performance metrics
- β Support ticket creation
- β User management
- β Billing access
Read-Only Access
- β View dashboard
- β View analytics
- β View reports
- β Any management functions
- β Configuration access
- β Support tickets
| Feature | SUPER_ADMIN | ORG_ADMIN | MANAGER | VIEWER |
|---|---|---|---|---|
| Dashboard | β | β | β | β |
| Analytics | β | β | β | β |
| Reports | β | β | β | β |
| Organizations | β | β | β | β |
| Billing | β | β | β | β |
| Support | β | β | β | β |
| Admin Panel | β | β | β | β |
- Live Generation Tracking: Solar, wind, and other renewable sources
- Consumption Analytics: Real-time energy usage patterns
- Battery Management: Storage levels and efficiency metrics
- Device Status: Connected IoT devices monitoring
- Performance Metrics: Efficiency and output analysis
- Organization Management: Create and manage multiple organizations
- User Assignment: Assign users to specific organizations
- Data Isolation: Secure data separation between organizations
- Custom Branding: Organization-specific configurations
- JWT Authentication: Secure token-based authentication
- Role-Based Access: Granular permission system
- Session Management: Secure session handling
- API Security: Protected API endpoints
- Data Encryption: Sensitive data protection
- Time-Based Analytics: Hourly, daily, weekly, monthly views
- Energy Trends: Consumption and generation patterns
- Performance Reports: Efficiency and cost analysis
- Custom Reports: Tailored reporting for different roles
- Export Capabilities: Data export in multiple formats
- Subscription Plans: Basic, Professional, Enterprise tiers
- Usage-Based Billing: Pay-per-use energy tracking
- Invoice Management: Automated billing and invoicing
- Payment Processing: Stripe integration
- Billing History: Complete transaction records
- Modern Design: Clean, intuitive interface
- Responsive Layout: Works on all devices
- Real-Time Updates: Live data refresh
- Dark/Light Mode: Theme customization
- Accessibility: WCAG compliant design
- Color-Coded Logs: Different colors for log levels
- Timestamp Tracking: Precise timing information
- Performance Metrics: Request/response timing
- Error Tracking: Detailed error reporting
- Debug Information: Comprehensive debugging data
- Real Data Testing: Tests with actual database data
- Role-Based Testing: All user roles tested
- E2E Testing: Complete user journey testing
- Performance Testing: Load and stress testing
- Security Testing: Vulnerability scanning
- Automated Testing: Multi-stage testing pipeline
- Database Integration: Real database testing
- Security Scanning: Automated vulnerability checks
- Performance Monitoring: Lighthouse integration
- Multi-Environment: Dev, staging, production deployments
- Next.js 14.2.35 - React framework with App Router
- React 18 - UI library with hooks and concurrent features
- TypeScript 4.9+ - Type-safe JavaScript
- Tailwind CSS - Utility-first CSS framework
- Lucide React - Modern icon library
- Recharts - Chart library for analytics
- React Hook Form - Form management
- Zustand - State management
- Next.js API Routes - Serverless API endpoints
- NextAuth.js - Authentication solution
- Prisma ORM - Database ORM and migrations
- PostgreSQL - Primary database
- JWT - Token-based authentication
- bcrypt - Password hashing
- Stripe API - Payment processing
- Node.js 20+ - JavaScript runtime
- ESLint - Code linting
- Prettier - Code formatting
- Jest - Unit testing framework
- Playwright - E2E testing
- Docker - Containerization
- GitHub Actions - CI/CD pipeline
- Vercel - Deployment platform
- Custom Logger - Professional logging system
- Lighthouse CI - Performance monitoring
- Sentry - Error tracking (optional)
- Google Analytics - User analytics (optional)
- Node.js 20.0.0 or higher
- PostgreSQL 13 or higher
- npm or yarn package manager
- Git for version control
- Clone the repository
git clone https://github.com/your-org/urjaflow.git
cd urjaflow- Install dependencies
npm install- Set up environment variables
cp .env.example .env
# Edit .env with your configuration- Set up database
# Create PostgreSQL database
createdb urjaflow
# Run migrations
npm run prisma:migrate
# Generate Prisma client
npm run prisma:generate
# Seed database with real data
npm run prisma:seed- Start development server
npm run dev- Access the application
- Frontend: http://localhost:3000
- API: http://localhost:3000/api
- Database Studio:
npm run prisma:studio
# Database
DATABASE_URL="postgresql://username:password@localhost:5432/urjaflow"
# NextAuth
NEXTAUTH_URL="http://localhost:3000"
NEXTAUTH_SECRET="your-secret-key"
# Stripe (for payments)
STRIPE_SECRET_KEY="sk_test_..."
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY="pk_test_..."
# Email (optional)
SMTP_HOST="smtp.gmail.com"
SMTP_PORT=587
SMTP_USER="your-email@gmail.com"
SMTP_PASS="your-app-password"
# Features
ENABLE_REALTIME=true
ENABLE_STRIPE=true
ENABLE_EMAIL=trueAfter running npm run prisma:seed, you can use these credentials:
| Role | Password | Access | |
|---|---|---|---|
| SUPER_ADMIN | admin@urjaflow.com | password123 | Full system access |
| ORG_ADMIN | org.admin@techsolutions.com | password123 | Organization management |
| MANAGER | manager@techsolutions.com | password123 | Analytics & reports |
| VIEWER | demo@urjaflow.com | password123 | Read-only access |
organizations {
id: UUID (Primary Key)
name: String
slug: String (Unique)
description: Text
address: JSON
phone: String
email: String
website: String
logo: String
settings: JSON
createdAt: DateTime
updatedAt: DateTime
}users {
id: UUID (Primary Key)
email: String (Unique)
name: String
role: Enum (SUPER_ADMIN, ORG_ADMIN, MANAGER, VIEWER)
password: String (Hashed)
organizationId: UUID (Foreign Key)
phone: String
company: String
address: JSON
isActive: Boolean
lastLoginAt: DateTime
createdAt: DateTime
updatedAt: DateTime
}devices {
id: UUID (Primary Key)
name: String
type: Enum (SOLAR_PANEL, BATTERY, INVERTER, METER)
model: String
serialNumber: String (Unique)
organizationId: UUID (Foreign Key)
location: JSON
specifications: JSON
status: Enum (ACTIVE, INACTIVE, MAINTENANCE)
installedAt: DateTime
createdAt: DateTime
updatedAt: DateTime
}device_readings {
id: UUID (Primary Key)
deviceId: UUID (Foreign Key)
timestamp: DateTime
generationKW: Float
consumptionKW: Float
batteryPercent: Float
voltage: Float
current: Float
temperature: Float
efficiency: Float
metadata: JSON
}Organizations (1) ββ (N) Users
Organizations (1) ββ (N) Devices
Devices (1) ββ (N) Device Readings
Users (1) ββ (N) Support Tickets
Organizations (1) ββ (N) Subscriptions
tests/
βββ e2e/ # End-to-end tests
β βββ auth-helper.ts # Authentication helpers
β βββ dashboard.spec.ts # Dashboard tests
β βββ analytics.spec.ts # Analytics tests
β βββ auth.spec.ts # Authentication tests
βββ unit/ # Unit tests
βββ integration/ # Integration tests
# Run all tests
npm run test:real-data
# Run role-based tests
npm run test:roles
# Run specific feature tests
npm run test:dashboard
npm run test:analytics
# Run E2E tests
npm run test:e2e
# Run unit tests
npm test# Run complete CI pipeline locally
npm run ci:local
# Run Docker-based CI
npm run ci:docker- Authentication: All 4 user roles tested
- Authorization: Route protection and permissions
- Real Data: Tests with actual database data
- UI Components: Component-level testing
- API Endpoints: All API routes tested
- Database Operations: CRUD operations verified
- Performance: Load and stress testing
- Security: Vulnerability scanning
# Install Vercel CLI
npm i -g vercel
# Deploy to production
vercel --prod
# Set environment variables
vercel env add DATABASE_URL
vercel env add NEXTAUTH_SECRET
vercel env add STRIPE_SECRET_KEY# Build production image
docker build -t urjaflow:latest .
# Run with Docker Compose
docker-compose -f docker-compose.prod.yml up -d# Build application
npm run build
# Start production server
npm start
# Use PM2 for process management
pm2 start ecosystem.config.jsNODE_ENV=production
DATABASE_URL=postgresql://user:pass@host:5432/urjaflow_prod
NEXTAUTH_URL=https://your-domain.com
NEXTAUTH_SECRET=production-secret-key
STRIPE_SECRET_KEY=sk_live_...# Create production database
createdb urjaflow_prod
# Run migrations
npm run prisma:migrate
# Seed production data (optional)
npm run prisma:seed- API Health:
/api/healthendpoint - Database Health: Connection monitoring
- Performance Metrics: Response time tracking
- Error Tracking: Comprehensive error logging
- Database Backups: Daily automated backups
- Code Backups: Git version control
- Configuration Backups: Environment variables
- Asset Backups: User uploads and media
- Code Splitting: Automatic route-based splitting
- Image Optimization: Next.js Image component
- Static Generation: Pre-built pages where possible
- Caching: Browser and CDN caching
- Bundle Optimization: Tree shaking and minification
- Database Indexing: Optimized queries
- Connection Pooling: Efficient database connections
- API Caching: Response caching for static data
- Lazy Loading: On-demand data loading
- Compression: Gzip compression
- Lighthouse Score: 95+ across all categories
- First Contentful Paint: < 1.5 seconds
- Time to Interactive: < 3 seconds
- Database Query Time: < 100ms average
- API Response Time: < 200ms average
- Custom Logger: Professional logging system
- Performance Metrics: Request timing
- Error Tracking: Comprehensive error reporting
- Health Checks: Application health monitoring
- Sentry: Error tracking and performance
- Google Analytics: User behavior analytics
- New Relic: Application performance monitoring
- Datadog: Infrastructure monitoring
- JWT Tokens: Secure token-based authentication
- Role-Based Access: Granular permission system
- Session Management: Secure session handling
- Password Security: bcrypt hashing with salt
- Multi-Factor Auth: Optional 2FA support
- Encryption: Data encryption at rest and in transit
- Input Validation: Comprehensive input sanitization
- SQL Injection Prevention: Parameterized queries
- XSS Protection: Content Security Policy
- CSRF Protection: Token-based CSRF protection
- Rate Limiting: API request throttling
- CORS Configuration: Proper cross-origin settings
- API Key Management: Secure API key handling
- Endpoint Protection: Role-based API access
- Audit Logging: Complete access logging
- Code Reviews: Security-focused code reviews
- Dependency Scanning: Automated vulnerability scanning
- Secret Management: Environment variable protection
- Secure Coding: OWASP guidelines compliance
- Regular Updates: Dependency security updates
- Access Control: Principle of least privilege
- Network Security: Firewall and network segmentation
- Backup Security: Encrypted backup storage
- Incident Response: Security incident procedures
- Compliance: GDPR and data protection compliance
- Fork the repository
- Create feature branch:
git checkout -b feature/amazing-feature - Make changes with proper testing
- Run tests:
npm run ci:local - Commit changes:
git commit -m 'Add amazing feature' - Push to branch:
git push origin feature/amazing-feature - Open Pull Request
- Use strict TypeScript configuration
- Provide proper type definitions
- Use interfaces for object shapes
- Avoid
anytype when possible - Use proper error handling
- Follow ESLint configuration
- Use Prettier for formatting
- Write descriptive variable names
- Add comments for complex logic
- Use consistent naming conventions
- Write tests for new features
- Maintain test coverage above 80%
- Test all user roles and permissions
- Include real data testing
- Add performance tests for critical paths
- Description: Clear description of changes
- Testing: All tests must pass
- Documentation: Update relevant documentation
- Performance: No performance regression
- Security: No security vulnerabilities
- Code Review: At least one review required
- Automated Checks: CI/CD pipeline must pass
- Security Review: Security team approval for sensitive changes
- Performance Review: Performance team approval for impactful changes
- Documentation Review: Documentation team approval for user-facing changes
This project is licensed under the MIT License - see the LICENSE file for details.
- β Commercial use allowed
- β Modification allowed
- β Distribution allowed
- β Private use allowed
- β Liability and warranty disclaimed
If you use this project, please include attribution:
Powered by UrjaFlow - Energy as a Service Platform
https://github.com/your-org/urjaflow
- Development Team: Full-stack development and architecture
- Design Team: UI/UX design and user experience
- Testing Team: Quality assurance and testing
- DevOps Team: Infrastructure and deployment
- Next.js: React framework and serverless functions
- Prisma: Database ORM and migrations
- Tailwind CSS: Utility-first CSS framework
- NextAuth.js: Authentication solution
- Playwright: End-to-end testing framework
- GitHub Community: Issue reporting and feature requests
- Discord Community: Real-time discussions and support
- Stack Overflow: Technical questions and answers
- Blog Contributors: Tutorials and best practices
- Documentation: Complete documentation
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Community: Discord Server
- Email: business@urjaflow.com
- Website: https://urjaflow.com
- Sales: sales@urjaflow.com
- Support: support@urjaflow.com
- Twitter: @urjaflow
- LinkedIn: UrjaFlow Company
- YouTube: UrjaFlow Channel
π UrjaFlow - Empowering Sustainable Energy Management
β Star this repo β’ π Report issues β’ π Deploy your own
Made with β€οΈ by the UrjaFlow Team