Package Exports
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (gaya-code) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
๐ฑ GayaCode
Analyze the environmental impact of your Node.js code with beautiful dashboards and actionable insights
GayaCode is a powerful CLI tool that measures and visualizes the environmental impact of your Node.js applications. Get detailed insights into energy consumption, COโ emissions, and receive actionable recommendations to make your code more sustainable.
โจ Features
- ๐ Energy Consumption Analysis - Track real-time energy usage
- ๐ COโ Emission Calculations - See your carbon footprint
- ๐ Beautiful Interactive Dashboards - Stunning visualizations with animations
- ๐ Live Carbon Flow Visualization - Real-time particle effects
- ๏ฟฝ Virtual Forest Impact - See how many trees you'd need
- โก Power Consumption Radar - Multi-dimensional performance analysis
- ๐ฏ Eco Score Rating - Get graded on environmental impact (A+ to F)
- ๐ Scaling Projections - See impact at different scales
- ๐ Real-World Equivalents - Compare to everyday activities
- ๐๏ธ SOLID Architecture - Clean, modular, and extensible code
๐ Installation
Global Installation (Recommended)
npm install -g gayacode
Local Installation
npm install gayacode
npx gayacode <script>
๐ Usage
Basic Usage
# Analyze a script and open dashboard
gayacode your-script.js
# Analyze without opening browser
gayacode your-script.js --no-open
# Custom output directory
gayacode your-script.js -o ./my-reports
# Custom emission factor
gayacode your-script.js --emission-factor 500
Advanced Options
gayacode --help
Usage: gayacode [options] <script>
๐ฑ Analyze the environmental impact of your Node.js code
Arguments:
script Path to the Node.js script to analyze
Options:
-V, --version output the version number
-o, --output <path> Output directory for the dashboard (default: "./gayacode-report")
--no-open Skip opening the dashboard in browser
--emission-factor <factor> COโ emission factor (g/kWh) (default: "400")
--timeout <ms> Maximum execution time (ms) (default: "60000")
-h, --help display help for command
๐ Dashboard Features
Performance Timeline
- Real-time CPU and memory usage graphs
- Interactive Chart.js visualizations
- Detailed execution metrics
Carbon Flow Visualization
- Animated particle system
- Real-time COโ flow representation
- Dynamic color coding based on emission rates
Virtual Forest Impact
- Growing tree animations
- Calculate trees needed to offset emissions
- Beautiful forest visualization with seasonal effects
Power Consumption Radar
- Multi-dimensional performance analysis
- CPU efficiency, memory usage, execution speed
- Interactive radar charts
Real-World Impact
- Energy equivalents (smartphone charges, LED hours, etc.)
- Carbon equivalents (tree years, car km, flight km)
- Scaling projections (1K, 1M, 1B executions)
๐๏ธ Architecture
GayaCode follows SOLID principles with a clean, modular architecture:
src/
โโโ core/interfaces/ # Core interfaces and types
โโโ monitoring/ # Process monitoring strategies
โโโ calculations/ # Environmental calculation strategies
โโโ utils/ # Utility functions and formatters
โโโ dashboard/
โ โโโ components/ # Modular dashboard components
โ โโโ templates/ # HTML template engine
โ โโโ DashboardGenerator.js
โโโ analyzer/ # Main environmental analyzer
โโโ cli/ # Command-line interface
Key Components
- Strategy Pattern: Pluggable monitoring and calculation strategies
- Component-Based: Modular dashboard components
- Dependency Injection: Clean separation of concerns
- Template Engine: Flexible HTML generation
- Interface Segregation: Well-defined contracts
๐ฏ Eco Score Rating
GayaCode provides a comprehensive eco score (0-100) with letter grades:
- A+ (90-100): Excellent - Minimal environmental impact
- A (80-89): Very Good - Low environmental impact
- B (70-79): Good - Moderate environmental impact
- C (60-69): Fair - Room for improvement
- D (50-59): Poor - Significant environmental impact
- F (0-49): Very Poor - High environmental impact
๐ Environmental Metrics
Energy Consumption
- Real-time power usage calculation
- CPU and memory power coefficients
- High-precision timing measurements
COโ Emissions
- Configurable emission factors
- Grid-based carbon intensity
- Regional emission calculations
Real-World Equivalents
- Smartphone battery charges
- LED light hours
- Laptop usage time
- Tree absorption years
- Car driving distance
- Flight emissions
๐ Example Output
๐ฑ GayaCode - Environmental Impact Analyzer v2.0
โ
Analysis complete
๐ Quick Results:
โก Energy: 0.59 ยตWh
๐ COโ: 0.0002 g
โฑ๏ธ Time: 1242 ms
๐ฅ๏ธ Peak CPU: 160.0%
๐พ Peak Memory: 156.7 MB
๐ฏ Eco Score: 61/100 (B)
๐ Report saved to: ./gayacode-report/index.html
๏ฟฝ๏ธ Programmatic Usage
You can also use GayaCode programmatically in your Node.js applications:
import { EnvironmentalAnalyzer } from 'gayacode'
const analyzer = new EnvironmentalAnalyzer({
emissionFactor: 400,
maxExecutionTime: 60000
})
const result = await analyzer.analyzeScript('./my-script.js')
console.log(`Eco Score: ${result.ecoScore.overall}/100`)
console.log(`COโ Emissions: ${result.metrics.co2Grams}g`)
๐ค Contributing
We welcome contributions! Please see our Contributing Guide for details.
Development Setup
git clone https://github.com/shalevo13/GayaCode.git
cd GayaCode
npm install
npm run dev test-script.js
๏ฟฝ License
MIT ยฉ GayaCode Contributors
๏ฟฝ Acknowledgments
- Built with โค๏ธ for a more sustainable future
- Inspired by the need for environmentally conscious software development
- Uses pidusage for process monitoring
- Visualizations powered by Chart.js
Made with ๐ฑ by developers who care about the planet
- Local execution (no cloud resources)
- Efficient monitoring algorithms
- Optimized frontend bundle size
- Sustainable development practices
Made with ๐ฑ for sustainable software development