π¨βπ» Developer Guide
Getting Started
This guide is for developers who want to contribute to the TikTok Downloader project or integrate with our API.
Project Structure
tiktok-downloader/
βββ src/
β βββ app/ # Next.js App Router pages
β β βββ page.tsx # Home page
β β βββ download/page.tsx # Download page
β β βββ history/page.tsx # History page
β β βββ settings/page.tsx # Settings page
β β βββ docs/page.tsx # Documentation page
β β βββ docs/[slug]/page.tsx # Dynamic docs pages
β βββ components/ # React components
β β βββ common/ # Shared components
β β βββ layout/ # Layout components
β β βββ pages/ # Page-specific components
β β βββ preview/ # Media preview components
β β βββ ui/ # UI component library
β βββ lib/ # Utility libraries
β β βββ api.ts # TikTok API wrapper
β β βββ storage.ts # Local storage management
β β βββ utils.ts # General utilities
β β βββ ... # Other utilities
β βββ types/ # TypeScript definitions
β βββ styles/ # CSS and styling
βββ public/
β βββ docs/ # Documentation markdown files
β βββ ... # Static assets
βββ workers-api/ # Cloudflare Workers API
βββ build/ # Android build files
Tech Stack
- Framework: Next.js 15 with App Router
- Language: TypeScript
- Styling: Tailwind CSS
- Animations: Framer Motion
- UI Components: Radix UI + Custom components
- Icons: Lucide React
- State Management: React hooks + Context
- API: Cloudflare Workers
- Mobile: Capacitor (Android)
Development Setup
Prerequisites
- Node.js 18+
- npm or pnpm
- Git
Installation
-
Clone the repository
Bashgit clone https://github.com/zamdevio/clipx.git cd clipx -
Install dependencies
Bashnpm install # or pnpm install -
Run development server
Bashnpm run dev # or pnpm dev -
Open in browser Navigate to http://localhost:3000
Environment Variables
Create a .env.local file:
# API Configuration
NEXT_PUBLIC_API_URL=https://clipx.zamdev.workers.dev
NEXT_PUBLIC_APP_NAME="TikTok Downloader"
# Development
NODE_ENV=development
Architecture Overview
Frontend Architecture
The application uses Next.js 15 with the App Router pattern:
- Pages: Located in
src/app/directory - Components: Reusable UI components in
src/components/ - Utilities: Helper functions in
src/lib/ - Types: TypeScript definitions in
src/types/
State Management
The app uses React Context for global state:
- SettingsContext: User preferences and settings
- VolumeContext: Audio volume management
- Theme: System theme detection and management
API Integration
The frontend communicates with a Cloudflare Workers API:
- TikTokAPI: Main API wrapper class
- Error Handling: Comprehensive error management
- Retry Logic: Automatic retry for failed requests
- Type Safety: Full TypeScript support
Component Development
Creating New Components
-
Create component file
TYPESCRIPT// src/components/ui/my-component.tsx import { cn } from '@/lib/utils'; interface MyComponentProps { className?: string; children: React.ReactNode; } export function MyComponent({ className, children }: MyComponentProps) { return ( <div className={cn('base-styles', className)}> {children} </div> ); } -
Add to index file
TYPESCRIPT// src/components/ui/index.ts export { MyComponent } from './my-component'; -
Use in pages
TYPESCRIPTimport { MyComponent } from '@/components/ui';
Component Guidelines
- Use TypeScript: Always define proper interfaces
- Follow naming: Use PascalCase for components
- Include className: Allow style customization
- Add accessibility: Include ARIA labels and roles
- Use motion: Add animations with Framer Motion
- Export from index: Export from component index files
UI Component Library
The project includes a custom UI component library:
- Button: Enhanced button with animations
- Input: Form input with validation
- Modal: Accessible modal dialogs
- Tooltip: Contextual help tooltips
- Progress: Download progress indicators
- Skeleton: Loading state components
API Development
TikTok API Wrapper
The TikTokAPI class handles all TikTok-related operations:
// src/lib/api.ts
export class TikTokAPI {
static async getVideoInfo(url: string): Promise<TikTokResponse> {
// Implementation
}
static async downloadVideo(url: string): Promise<Blob> {
// Implementation
}
static getContentType(data: TikTokData): 'video' | 'image' {
// Implementation
}
}
Error Handling
Comprehensive error handling with user-friendly messages:
interface ErrorInfo {
message: string;
type: 'error' | 'warning' | 'info';
code?: string;
details?: string;
}
export function createErrorInfo(error: Error, context: string): ErrorInfo {
// Implementation
}
API Best Practices
- Type Safety: Use TypeScript interfaces
- Error Handling: Always handle errors gracefully
- Retry Logic: Implement exponential backoff
- Validation: Validate inputs before processing
- Documentation: Document all public methods
Testing
Testing Strategy
The project uses a comprehensive testing approach:
- Unit Tests: Test individual functions and components
- Integration Tests: Test component interactions
- E2E Tests: Test complete user journeys
- API Tests: Test API endpoints and responses
Running Tests
# Unit tests
npm run test
# Integration tests
npm run test:integration
# E2E tests
npm run test:e2e
# All tests
npm run test:all
Writing Tests
// Example component test
import { render, screen } from '@testing-library/react';
import { MyComponent } from '@/components/ui';
describe('MyComponent', () => {
it('renders correctly', () => {
render(<MyComponent>Test content</MyComponent>);
expect(screen.getByText('Test content')).toBeInTheDocument();
});
});
Documentation System
Markdown Documentation
Documentation is stored as markdown files in public/docs/:
- api.md: API documentation
- user-guide.md: User guide
- troubleshooting.md: Troubleshooting guide
- faq.md: Frequently asked questions
- developer-guide.md: This guide
Dynamic Documentation Pages
The /docs route dynamically loads markdown files:
// src/app/docs/[slug]/page.tsx
export default async function DocPage({ params }: { params: { slug: string } }) {
const content = await getMarkdownContent(params.slug);
return <MarkdownRenderer content={content} />;
}
Adding New Documentation
-
Create markdown file
Bash# Create new doc file touch public/docs/new-feature.md -
Add to navigation
TYPESCRIPT// Update navigation constants const DOCS_NAV_ITEMS = [ { title: 'New Feature', url: '/docs/new-feature' }, // ... other items ]; -
Access via URL Navigate to
/docs/new-feature
Mobile Development
Capacitor Integration
The project includes Capacitor for mobile app development:
- Android: Full Android app support
- iOS: iOS support (planned)
- Native Features: Access to device APIs
Building Mobile App
# Build web app
npm run build
# Sync with Capacitor
npx cap sync
# Build Android
npx cap build android
# Run on device
npx cap run android
Mobile-Specific Features
- File Downloads: Native file download handling
- Storage: Local storage for offline functionality
- Notifications: Push notifications (planned)
- Sharing: Native sharing capabilities
Performance Optimization
Code Splitting
The app uses dynamic imports for code splitting:
// Lazy load components
const HeavyComponent = dynamic(() => import('./HeavyComponent'), {
loading: () => <Skeleton />,
});
Image Optimization
- Lazy Loading: Images load only when needed
- Blur Placeholders: Smooth loading experience
- Responsive Images: Different sizes for different screens
Bundle Analysis
# Analyze bundle size
npm run analyze
# Check for unused code
npm run check-unused
Deployment
Web Deployment
The app can be deployed to various platforms:
- Vercel: Recommended for Next.js apps
- Netlify: Static site deployment
- Cloudflare Pages: Edge deployment
- Railway: Full-stack deployment
Environment Configuration
# Production build
npm run build
# Start production server
npm run start
# Export static files
npm run export
CI/CD Pipeline
# .github/workflows/deploy.yml
name: Deploy
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- run: npm install
- run: npm run build
- run: npm run deploy
Contributing
Getting Started
- Fork the repository
- Create feature branch
Bash
git checkout -b feature/amazing-feature - Make changes
- Run tests
Bash
npm run test - Commit changes
Bash
git commit -m 'Add amazing feature' - Push to branch
Bash
git push origin feature/amazing-feature - Open Pull Request
Code Style
- TypeScript: Use strict TypeScript
- ESLint: Follow ESLint rules
- Prettier: Use Prettier for formatting
- Conventional Commits: Use conventional commit messages
Pull Request Guidelines
- Clear description: Explain what and why
- Tests: Include tests for new features
- Documentation: Update docs if needed
- Breaking changes: Clearly mark breaking changes
Troubleshooting Development Issues
Common Issues
Build Errors
# Clear cache
rm -rf .next
npm run build
Type Errors
# Check types
npx tsc --noEmit
Dependency Issues
# Clear node_modules
rm -rf node_modules package-lock.json
npm install
Hot Reload Issues
# Restart dev server
npm run dev
Debugging
- Browser DevTools: Use React DevTools
- Console Logging: Add strategic console.logs
- Network Tab: Monitor API requests
- Performance Tab: Check for performance issues
Resources
Documentation
- Next.js Documentation
- React Documentation
- TypeScript Documentation
- Tailwind CSS Documentation
- Framer Motion Documentation
Tools
Community
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
For development support:
- GitHub Issues: Technical problems
- Discussions: General questions
- Email: [email protected]
- Discord: Community support