This document provides comprehensive information about the GitHub integration system implemented in SyntaxLab. The integration allows users to:
- Import any public GitHub repository into the playground
- Export playground code to GitHub repositories
- Sync changes bidirectionally between playground and GitHub
- Create new repositories from playground templates
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ Frontend UI │◄──►│ API Routes │◄──►│ GitHub API │
│ │ │ │ │ │
│ • Repo Browser │ │ • /api/github/ │ │ • Repositories │
│ • Export Modal │ │ • /api/import/ │ │ • Contents │
│ • Sync Status │ │ • /api/export/ │ │ • Commits │
└─────────────────┘ └──────────────────┘ └─────────────────┘
│ │ │
▼ ▼ ▼
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ Database │ │ File System │ │ Git Operations │
│ │ │ │ │ │
│ • Playground │ │ • Temp Storage │ │ • Clone/Push │
│ • TemplateFiles│ │ • File Cache │ │ • Branch Mgmt │
│ • GitHub Sync │ │ • Export Files │ │ • Commits │
└─────────────────┘ └──────────────────┘ └─────────────────┘
- Purpose: Direct communication with GitHub REST API
- Features:
- Repository management (list, get, create)
- File operations (read, create, update)
- Branch management
- Pull request creation
- Search functionality
- Purpose: High-level Git operations using GitHub API
- Features:
- Template to GitHub file conversion
- Repository import/export
- Commit and push operations
- Branch creation and PR management
- RepoSelectorModal: Browse and select GitHub repositories
- GitHubExportModal: Export playground to GitHub
- GitHubSyncStatus: Display sync status and actions
Add these to your .env file:
# GitHub OAuth (already exists, update scope)
AUTH_GITHUB_ID=your_github_client_id
AUTH_GITHUB_SECRET=your_github_client_secret
# Next.js URL for API callbacks
NEXTAUTH_URL=http://localhost:3000
AUTH_SECRET=your_auth_secret-
Go to GitHub Settings → Developer settings → OAuth Apps
-
Create new OAuth App with:
- Authorization callback URL:
http://localhost:3000/api/auth/callback/github - Application name: Your app name
- Homepage URL:
http://localhost:3000
- Authorization callback URL:
-
Note the Client ID and generate Client Secret
The system adds a CUSTOM template type for imported repositories:
enum Templates {
REACT
NEXTJS
EXPRESS
VUE
HONO
ANGULAR
CUSTOM // Added for GitHub imports
}Run npx prisma generate && npx prisma db push to apply changes.
- Scope: Updated to include
repo user:emailpermissions - Provider: GitHub OAuth with repository access
Fetch user's repositories
Response:
{
"success": true,
"data": [
{
"id": 123456,
"name": "my-repo",
"full_name": "username/my-repo",
"description": "Repository description",
"private": false,
"html_url": "https://github.com/username/my-repo",
"default_branch": "main",
"language": "TypeScript",
"stargazers_count": 42,
"owner": {
"login": "username",
"id": 789012
}
}
]
}Search GitHub repositories
Request:
{
"query": "react typescript",
"perPage": 20
}Import a GitHub repository into playground
Request:
{
"owner": "username",
"repo": "repository-name",
"branch": "main"
}Response:
{
"success": true,
"message": "Successfully imported username/repository-name",
"data": {
"folderName": "repository-name",
"items": [
{
"filename": "index",
"fileExtension": "js",
"content": "console.log('Hello World');"
}
]
}
}Create playground from imported repository
Request:
{
"title": "My Imported Project",
"description": "Imported from GitHub",
"templateData": { /* TemplateFolder structure */ },
"githubRepo": {
"owner": "username",
"repo": "repository-name",
"branch": "main",
"url": "https://github.com/username/repository-name"
}
}Export playground to existing repository
Request:
{
"playgroundId": "playground_123",
"owner": "username",
"repo": "target-repo",
"branch": "main",
"commitMessage": "Update from playground"
}Create new repository from playground
Request:
{
"playgroundId": "playground_123",
"repoName": "my-new-repo",
"description": "Created from playground",
"isPrivate": false
}Location: features/github/components/repo-selector-modal.tsx
Features:
- Browse user's repositories
- Search GitHub repositories
- Filter by language, stars, etc.
- Repository cards with metadata
Usage:
<RepoSelectorModal
isOpen={isModalOpen}
onClose={() => setIsModalOpen(false)}
onSelectRepository={handleRepoSelect}
title="Select Repository"
/>Location: features/github/components/github-export-modal.tsx
Features:
- Export to existing repository
- Create new repository
- Branch selection
- Commit message customization
- Private/public repository options
Usage:
<GitHubExportModal
isOpen={isModalOpen}
onClose={() => setIsModalOpen(false)}
playgroundId="playground_123"
playgroundTitle="My Project"
/>Location: features/github/components/github-sync-status.tsx
Features:
- Display sync status
- Show repository information
- Sync/Export actions
- Last sync timestamp
Usage:
<GitHubSyncStatus
playgroundId="playground_123"
className="w-full"
/>Location: features/playground/components/github-export-button.tsx
Features:
- Quick export button
- Opens export modal
- Can be placed in any playground
- User clicks "Open GitHub Repository" on dashboard
- Repository selector modal opens
- User searches/selects a repository
- System imports repository structure
- New playground created with imported code
- User redirected to playground editor
- User opens playground
- Clicks "Export to GitHub" button
- Export modal opens with two options:
- Existing Repo: Select target repository
- New Repo: Create new repository
- User configures export options
- System pushes files to GitHub
- Success confirmation displayed
- User makes changes in playground
- Auto-save updates local template
- User clicks "Sync" in GitHub status component
- System commits and pushes changes to GitHub
- Sync status updated
- API Client: Add methods to
GitHubAPIClientclass - Git Operations: Add high-level operations to
GitOperationsclass - API Routes: Create new endpoints in
app/api/github/ - UI Components: Create new components in
features/github/components/
All API endpoints follow consistent error handling:
// Success response
{
"success": true,
"message": "Operation completed",
"data": { /* result data */ }
}
// Error response
{
"success": false,
"error": "Error message",
"details": { /* optional error details */ }
}GitHub API has rate limits:
- Authenticated requests: 5,000 requests/hour
- Search requests: 30 requests/minute
The system includes basic rate limiting awareness and retries.
- Maximum file size: 1MB for text files
- Binary files: Skipped with placeholder message
- Ignored files: node_modules, .git, dist, build, etc.
- Required:
repo user:email - Purpose: Repository access and user identification
- GitHub access tokens stored securely in session
- Tokens never exposed to client-side
- Automatic token refresh handled by Auth.js
- Users can only access their own repositories
- Public repositories can be imported by anyone
- Private repositories require explicit access
Cause: User not authenticated with proper GitHub scope Solution: Re-authenticate with GitHub after OAuth scope update
Causes:
- Repository doesn't exist
- No access to private repository
- Network issues Solutions:
- Check repository URL
- Verify repository is public or user has access
- Check network connectivity
Causes:
- No write access to target repository
- OAuth token expired Solutions:
- Verify repository permissions
- Re-authenticate with GitHub
Cause: File size exceeds 1MB limit Solution:
- Increase limit in
git-operations.ts - Add file filtering for large binaries
Enable debug logging by setting:
DEBUG=github:*Run the test suite:
npm run test:github- Repository list cached for 5 minutes
- File content cached during import process
- GitHub API responses cached where appropriate
- Lazy loading of repository contents
- Parallel file operations where possible
- Efficient template structure conversion
- Real-time collaboration with GitHub
- Pull request management
- GitHub Actions integration
- Repository analytics
- Branch comparison tool
- Conflict resolution UI
- GitHub GraphQL API integration
- Webhook support for real-time sync
- GitHub Projects integration
For issues with GitHub integration:
- Check this documentation first
- Review browser console for errors
- Verify environment variables
- Check GitHub OAuth app settings
- Review GitHub API rate limits
This GitHub integration system is part of SyntaxLab and follows the same license terms.
Last Updated: February 2026 Version: 1.0.0