github_analyzer 0.1.3
github_analyzer: ^0.1.3 copied to clipboard
Analyze GitHub repositories and generate AI context for LLMs with cross-platform support
GitHub Analyzer #
Powerful GitHub Repository Analysis Tool for AI/LLM
A pure Dart package that analyzes GitHub repositories and automatically generates markdown documentation optimized for AI and LLM contexts. Accelerate code reviews, documentation, and project onboarding with AI assistance.
β¨ Key Features #
- π Fast & Efficient - Optimized with isolate-based parallel processing
- π¦ Dual Mode - Supports both local directories and remote GitHub repositories
- π― LLM Optimized - Generates compact context for AI models
- π Incremental Updates - Smart caching for fast re-analysis
- π Cross-Platform - Works on web, desktop, and mobile
- π Private Repositories - Access private repos with GitHub tokens
- π Auto Environment Setup - Automatically loads tokens from .env files
- β‘ Cache Control - Explicitly enable/disable caching
π― Use Cases #
- AI Code Review - Provide full project context to ChatGPT/Claude
- Automated Documentation - Auto-analyze project structure and tech stack
- Onboarding - Quickly share project overview with new team members
- CI/CD Integration - Detect code changes and generate automatic reports
- Project Comparison - Compare structure and complexity of multiple repositories
π¦ Installation #
Add to your pubspec.yaml:
dependencies:
github_analyzer: ^0.1.3
Install:
dart pub get
π Quick Start #
1. Environment Setup (Optional but Recommended) #
Create a .env file in your project root:
GITHUB_TOKEN=your_github_token_here
Why you need a token:
- β Access private repositories
- β Increased API rate limit (60 β 5,000 req/hr)
- β Prevent 403 errors
How to get a token:
- Go to GitHub Settings β Tokens
- Generate fine-grained token (recommended)
- Set Contents: Read-only permission
- Copy to .env file
2. Basic Usage #
import 'package:github_analyzer/github_analyzer.dart';
void main() async {
// Analyze a repository (token auto-loaded from .env)
final result = await analyzeQuick(
'https://github.com/flutter/flutter',
);
print('Files: ${result.statistics.totalFiles}');
print('Lines: ${result.statistics.totalLines}');
print('Language: ${result.metadata.language}');
}
3. Generate Markdown for LLM #
import 'package:github_analyzer/github_analyzer.dart';
void main() async {
// LLM-optimized analysis and markdown generation
final outputPath = await analyzeForLLM(
'https://github.com/your/repo',
outputDir: './analysis',
maxFiles: 200,
);
print('Generated: $outputPath');
}
4. Advanced Usage #
import 'package:github_analyzer/github_analyzer.dart';
void main() async {
// Create analyzer with custom config
final config = await GithubAnalyzerConfig.create(
githubToken: 'your_token', // or auto-load from .env
excludePatterns: ['test/', 'docs/'],
maxFileSize: 1024 * 1024, // 1MB
enableCache: true,
);
final analyzer = await GithubAnalyzer.create(config: config);
// Analyze remote repository (disable cache)
final result = await analyzer.analyzeRemote(
repositoryUrl: 'https://github.com/your/repo',
useCache: false, // always fetch latest data
);
// Generate compact markdown
final outputPath = await ContextGenerator.generate(
result,
outputDir: './output',
config: MarkdownConfig.compact,
);
print('Generated: $outputPath');
// Clean up resources
await analyzer.dispose();
}
βοΈ Configuration Options #
Quick Analysis (Fast) #
final config = await GithubAnalyzerConfig.quick();
- β‘ Fast speed
- π Max 100 files
- π« Cache disabled
- π« Isolate disabled
LLM Optimized (Balanced) #
final config = await GithubAnalyzerConfig.forLLM(maxFiles: 200);
- βοΈ Balanced performance
- π Custom file count
- β Cache enabled
- β Isolate enabled
- π§ͺ Test files excluded
Full Analysis (Comprehensive) #
final config = await GithubAnalyzerConfig.create(
enableCache: true,
enableIsolatePool: true,
maxConcurrentRequests: 10,
);
- π Detailed analysis
- βΎοΈ Unlimited files
- β‘ Maximum concurrency
- πΎ Optimized caching
π Private Repository Access #
Fine-grained Token (Recommended) #
- Create token
- Repository access: Select "Only select repositories"
- Permissions: Contents: Read-only
- Save to .env:
GITHUB_TOKEN=github_pat_xxxxxxxxxxxxx
Classic Token #
- Create token
- Scopes: Check
repo - Save to .env:
GITHUB_TOKEN=ghp_xxxxxxxxxxxxx
Use in Code #
final config = await GithubAnalyzerConfig.create(
githubToken: 'your_token_here',
);
final analyzer = await GithubAnalyzer.create(config: config);
π€ Output Formats #
Compact (LLM Friendly) #
final config = MarkdownConfig.compact;
- Minimal formatting
- No statistics
- Token count optimized
Standard (Balanced) #
final config = MarkdownConfig.standard;
- Includes statistics
- Code blocks
- Directory tree
Detailed (Comprehensive) #
final config = MarkdownConfig.detailed;
- Full statistics
- Language distribution
- Dependency analysis
π Platform Support #
| Platform | Local Analysis | Remote Analysis | Cache | Isolates |
|---|---|---|---|---|
| Desktop | β | β | β | β |
| Mobile | β | β | β | β |
| Web | β | β | β οΈ* | β |
*Web uses browser storage instead of file system
π οΈ Convenience Functions #
// Quick analysis
final result = await analyzeQuick('https://github.com/user/repo');
// LLM-optimized analysis + markdown generation
final outputPath = await analyzeForLLM(
'https://github.com/user/repo',
outputDir: './output',
maxFiles: 100,
);
// Custom config analysis
final result = await analyze(
'https://github.com/user/repo',
config: await GithubAnalyzerConfig.create(),
verbose: true,
useCache: false, // disable cache
);
π Troubleshooting #
403 Forbidden Error #
Cause: Missing or insufficient GitHub token permissions
Solution:
- Check token exists in .env file
- Fine-grained token: Verify repository access settings
- Classic token: Ensure
reposcope is enabled - Test token:
curl -H "Authorization: token YOUR_TOKEN" https://api.github.com/user
404 Not Found Error #
Cause: Repository doesn't exist, is private without token, or wrong branch name
Solution:
- Verify repository URL is correct
- Add GitHub token for private repos
- Check default branch name (main vs master)
Rate Limit Exceeded #
Cause: GitHub API rate limit (60 req/hr without token)
Solution:
- Add GitHub token to .env file
- With token: 5,000 req/hr
π Examples #
Check out more examples in the example/ directory:
demo.dart- Comprehensive demo with performance metrics- Basic usage examples
- Custom configuration examples
π€ Contributing #
Contributions are always welcome! Feel free to submit Pull Requests.
Development Setup #
# Clone repository
git clone https://github.com/cruxhan/github_analyzer.git
# Install dependencies
dart pub get
# Run tests
dart test
π License #
MIT License - See LICENSE file for details.
π Links #
π‘ Usage Tips #
- Large Repositories: Limit file count with
maxFilesparameter - Cache Management: Use
useCache: falseto always fetch latest data - Token Management: Keep tokens safe using .env files
- Performance Optimization: Enable parallel processing with
enableIsolatePool: true - LLM Token Savings: Use
MarkdownConfig.compact
Made with β€οΈ for the Dart & Flutter community