react-github-timeline
Version:
3D visualization of GitHub repository evolution over time using React Three Fiber
342 lines (261 loc) ⢠11.7 kB
Markdown
# Repo Timeline Visualizer
[](https://github.com/rjwalters/github-timeline/actions/workflows/test.yml)
[](https://codecov.io/gh/rjwalters/github-timeline)
A 3D visualization tool for exploring Git repository evolution over time. Watch your codebase grow, change, and evolve with an interactive force-directed graph showing files and directories as connected nodes in 3D space.
š **[Live Demo](https://rjwalters.github.io/github-timeline/)**
## Quick Start
### Using as an npm Package
Install the package in your React application:
```bash
npm install react-github-timeline
# or
pnpm add react-github-timeline
```
Then import and use the component:
```tsx
import { RepoTimeline } from 'react-github-timeline';
function App() {
return (
<div style={{ width: '100vw', height: '100vh' }}>
<RepoTimeline repoPath="facebook/react" />
</div>
);
}
```
### Avoiding Rate Limits (Recommended)
GitHub's API has a rate limit of **60 requests/hour** for unauthenticated requests. For better performance, pass a GitHub personal access token:
```tsx
<RepoTimeline
repoPath="facebook/react"
githubToken="ghp_your_token_here" // 5,000 requests/hour
/>
```
**How to get a token:**
1. Go to GitHub ā Settings ā Developer settings ā [Personal access tokens](https://github.com/settings/tokens)
2. Generate new token (classic)
3. No scopes needed for public repositories
4. Copy the token and pass it to the component
ā ļø **Important:** Never commit tokens to your repository. Use environment variables:
```tsx
<RepoTimeline
repoPath="facebook/react"
githubToken={import.meta.env.VITE_GITHUB_TOKEN}
/>
```
š **[Full embedding guide](EMBEDDING.md)** - Installation, props, TypeScript, and advanced usage
### Development Setup
For local development or to contribute to this project:
1. Clone the repository
2. Install dependencies: `pnpm install`
3. Start dev server: `pnpm dev`
4. Open browser to `http://localhost:5173`
See the **[Contributing](#contributing)** section below for more details.
## Deployment
This project automatically deploys to GitHub Pages via GitHub Actions. To enable:
1. Go to repository **Settings** ā **Pages**
2. Under **Build and deployment**, set **Source** to **GitHub Actions**
3. Push to main branch to trigger deployment
The site will be available at `https://[username].github.io/github-timeline/`
## Features
- **3D Force-Directed Graph**: Files and directories are visualized as nodes connected by springs, creating an organic, physics-based layout
- **Time Travel**: Scrub through your repository's commit history to see how the structure evolved
- **Real GitHub Integration**: Analyze any public GitHub repository by entering `owner/repo`
- **Cloudflare Worker Caching**: Fast loading with globally cached PR data, avoiding GitHub rate limits
- **Interactive Playback**: Multiple speeds (1x to 1800x), forward/backward playback, and smooth transitions
- **Incremental Loading**: Watch the visualization build progressively as data loads
- **Interactive Controls**: Pan, zoom, and rotate the 3D view with your mouse
- **File Size Visualization**: Node sizes reflect file sizes (logarithmic scale)
- **Real-time Physics**: Watch the graph settle into its natural layout with spring physics
- **Smart Caching**: localStorage caching for instant subsequent loads
## Technology Stack
### Frontend
- **Vite**: Fast build tool and dev server
- **React**: UI framework
- **TypeScript**: Type-safe development
- **Three.js**: 3D rendering engine
- **React Three Fiber**: React renderer for Three.js
- **React Three Drei**: Useful helpers for R3F
- **Tailwind CSS**: Utility-first styling
- **Vitest**: Fast unit testing with coverage
- **Biome**: Fast linter and formatter
- **pnpm**: Efficient package manager
### Backend (Optional)
- **Cloudflare Workers**: Edge computing for API caching
- **Cloudflare D1**: SQLite database for PR data storage
- **GitHub API**: Source of repository data
## Development Commands
### Installation
```bash
pnpm install
```
### Development
```bash
pnpm dev # Start demo app dev server
```
Open your browser to `http://localhost:5173`
### Build
```bash
pnpm build # Build library for npm
pnpm build:demo # Build demo app for GitHub Pages
```
### Test
```bash
pnpm test # Run tests in watch mode
pnpm test:coverage # Run tests with coverage report
pnpm test:ui # Run tests with interactive UI
```
Coverage thresholds are set at 50% for statements, branches, functions, and lines.
### Lint
```bash
pnpm lint # Check code quality
pnpm lint:fix # Auto-fix issues
pnpm format # Format code with Biome
```
### Bundle Size
```bash
pnpm size # Check bundle sizes against limits
pnpm size:why # Analyze what's included in bundles
```
Current bundle sizes:
- ESM: ~14 KB gzipped (limit: 18 KB)
- UMD: ~14 KB gzipped (limit: 15 KB)
### Preview
```bash
pnpm preview # Preview demo build
```
## Project Structure
```
repo-timeline/
āāā src/
ā āāā lib/ # NPM package exports
ā ā āāā index.ts # Main library entry point
ā ā āāā types.ts # Public API types
ā āāā demo/ # Demo app (GitHub Pages)
ā ā āāā App.tsx # Demo app root
ā ā āāā main.tsx # Demo app entry point
ā ā āāā RepoInput.tsx # Repository input form
ā ā āāā RepoWrapper.tsx # Demo app wrapper
ā āāā components/
ā ā āāā FileNode3D.tsx # Individual file/directory node
ā ā āāā FileEdge3D.tsx # Connection between nodes
ā ā āāā RepoGraph3D.tsx # Main 3D graph component
ā ā āāā TimelineScrubber.tsx # Commit timeline controls
ā ā āāā RepoTimeline.tsx # Main container component
ā ā āāā GitHubAuthButton.tsx # GitHub authentication
ā ā āāā RateLimitDisplay.tsx # Rate limit indicator
ā ā āāā TestScene.tsx # Test visualization scene
ā āāā services/
ā ā āāā gitService.ts # Main Git service orchestration
ā ā āāā githubApiService.ts # GitHub API integration
ā ā āāā storageService.ts # LocalStorage caching
ā āāā utils/
ā ā āāā forceSimulation.ts # Physics simulation for graph layout
ā ā āāā fileTreeBuilder.ts # Build file trees from PR data
ā ā āāā fileStateTracker.ts # Track file state across PRs
ā āāā data/
ā ā āāā demoCommits.ts # Demo data for fallback
ā āāā config.ts # Application configuration
ā āāā types.ts # TypeScript type definitions
ā āāā index.css # Global styles
āāā dist/ # NPM package build output
ā āāā index.js # ESM bundle
ā āāā index.umd.js # UMD bundle
ā āāā index.d.ts # TypeScript declarations
ā āāā style.css # Bundled styles
āāā demo-dist/ # Demo app build output (GitHub Pages)
āāā worker/ # Cloudflare Worker (optional)
ā āāā src/
ā ā āāā index.ts # Worker API endpoints
ā āāā migrations/ # D1 database migrations
ā āāā wrangler.toml # Worker configuration
ā āāā package.json
āāā index.html
āāā package.json
āāā vite.config.ts # Library build config
āāā vite.demo.config.ts # Demo build config
āāā tailwind.config.js
```
## How It Works
### Force-Directed Graph Layout
The visualization uses a custom force-directed graph algorithm with three types of forces:
1. **Spring Forces**: Connected nodes (parent/child relationships) attract each other
2. **Repulsion Forces**: All nodes repel each other to prevent overlap
3. **Centering Force**: Gentle pull toward the origin to keep the graph centered
### Data Flow
1. **User enters repository** (`owner/repo`)
2. **Metadata fetch**: Quick metadata endpoint loads PR list and time range
3. **Data source selection**:
- **Cloudflare Worker** (preferred): Fetches cached PR data from global D1 database
- **localStorage cache**: Loads previously fetched data instantly
- **GitHub API** (fallback): Direct API calls with rate limiting
4. **Incremental loading**: PRs processed one-by-one, visualization updates in real-time
5. **File state tracking**: Each PR's file changes are applied cumulatively
6. **Tree building**: File paths converted to hierarchical node/edge structure
7. **Force simulation**: Physics calculates optimal 3D positions for nodes
8. **Three.js rendering**: 3D scene rendered with React Three Fiber
9. **Time travel**: Scrubber controls let you navigate through commits
### Node Visualization
- **Blue octahedrons (diamonds)**: Directories (fixed size)
- **Green spheres**: Files (size scales logarithmically with file size)
- **White tubes**: Parent-child relationships in file tree
- **Virtual root**: "/" node connects all root-level files
- **Transitions**: Smooth animations show size changes, additions, deletions
## Customization
### Adjust Physics
Edit `src/utils/forceSimulation.ts`:
```typescript
new ForceSimulation(nodesCopy, edges, {
strength: 0.05, // Spring strength
distance: 30, // Target distance between connected nodes
iterations: 300, // Simulation steps
});
```
### Change Colors
Edit colors in `src/components/FileNode3D.tsx` and `src/components/FileEdge3D.tsx`
### Camera Settings
Edit initial camera position in `src/components/RepoGraph3D.tsx`:
```typescript
camera={{ position: [0, 0, 200], fov: 75 }}
```
## Optional: Cloudflare Worker Setup
For better performance and to avoid GitHub rate limits, you can deploy the included Cloudflare Worker:
1. See **[WORKER_DEPLOYMENT.md](WORKER_DEPLOYMENT.md)** for detailed setup instructions
2. Worker provides:
- Global caching of PR data across all users
- Background updates to keep cache fresh
- 5,000+ requests/hour (vs 60 unauthenticated GitHub API)
- <100ms response times for cached repos
- Free tier covers most usage
**Quick Setup:**
```bash
cd worker
npm install
npx wrangler d1 create repo_timeline
npm run db:migrate
npx wrangler secret put GITHUB_TOKENS
npm run deploy
```
Update `src/config.ts` with your worker URL, and you're done!
## Future Enhancements
- ā
~~Real Git integration~~ (Completed - GitHub API + Worker)
- ā
~~Animation transitions between commits~~ (Completed)
- File content diffing
- Dependency graph visualization (import/export relationships)
- Author-based coloring
- Commit message search
- Export visualizations as video/GIF
- Multiple repository comparison
- Custom layout algorithms (hierarchical, circular, etc.)
- Performance optimizations for very large repos (>10k PRs)
- Branch visualization
- Interactive file diff viewer
## Publishing
Ready to publish? See **[PUBLISHING_CHECKLIST.md](PUBLISHING_CHECKLIST.md)** for the complete guide including:
- Testing the package locally with `npm pack`
- Publishing to npm registry
- Post-publish verification
- Creating GitHub releases
## License
MIT
## Contributing
Contributions welcome! Please open an issue or PR.