- Add comprehensive REST API at /api/v1 with modular structure - Implement authentication endpoints (register, login, logout, me) - Add converter listing and format discovery endpoints - Create job management and file download endpoints - Add health check endpoint for monitoring - Set up CORS support for browser-based API clients - Create API middleware for JWT authentication - Add environment variables for API configuration - Include comprehensive API documentation and test script Infrastructure: - Enhanced CI/CD workflow for custom Docker registries - Docker Compose setup with dev, prod, and monitoring profiles - Claude.ai integration files for development workflow - Environment-based configuration with .env.development Known limitations: - JWT authentication context needs fixing (using ALLOW_UNAUTHENTICATED=true) - Swagger UI temporarily disabled due to composition error - File upload endpoint needs multipart/form-data support The API code is isolated in src/api/ directory to maintain separation from the existing codebase, making it easy to maintain or contribute back.
4.5 KiB
4.5 KiB
ConvertX Codebase Documentation
Overview
ConvertX is a self-hosted file conversion service built with Bun and Elysia framework. It supports 1000+ file format conversions using 17 different converter tools.
Tech Stack
- Runtime: Bun
- Framework: Elysia (TypeScript)
- Database: SQLite with Bun's built-in driver
- Frontend: Server-side rendered HTML with HTMX, Tailwind CSS
- Authentication: JWT tokens via @elysiajs/jwt
- Container: Docker (Debian Trixie Slim base)
Project Structure
ConvertX-openAPI/
├── src/
│ ├── index.tsx # Main app entry, route setup
│ ├── api/ # NEW: OpenAPI endpoints
│ │ ├── v1/ # API version 1
│ │ ├── middleware/ # API middleware
│ │ └── schemas/ # Request/response schemas
│ ├── converters/ # File conversion logic
│ │ ├── main.ts # Converter orchestration
│ │ └── [converter].ts # Individual converter wrappers
│ ├── pages/ # Web UI route handlers
│ ├── components/ # UI components
│ ├── db/ # Database schema
│ └── helpers/ # Utilities
├── data/ # Runtime data
│ ├── uploads/ # User uploaded files
│ ├── output/ # Converted files
│ └── mydb.sqlite # SQLite database
└── public/ # Static assets
Key Concepts
Converters
Each converter (ffmpeg, pandoc, etc.) is wrapped in a TypeScript module that:
- Exports
propertiesdefining supported input/output formats - Exports
convertfunction that executes the conversion - Returns status string: "Done", "Failed", or custom message
Job Flow
- User uploads files → creates job with unique ID
- Files stored in
data/uploads/{userId}/{jobId}/ - User selects converter → triggers conversion
- Converted files saved to
data/output/{userId}/{jobId}/ - Job status tracked in database
- Auto-deletion after N hours (configurable)
Authentication
- JWT-based with 7-day expiration
- User ID 0 reserved for unauthenticated users (if enabled)
- First user registration creates admin account
Environment Variables
JWT_SECRET: Secret for JWT signing (auto-generated if not set)WEBROOT: URL prefix for deployment (default: "")ACCOUNT_REGISTRATION: Enable user registrationALLOW_UNAUTHENTICATED: Allow usage without loginHTTP_ALLOWED: Allow HTTP (not just HTTPS)AUTO_DELETE_EVERY_N_HOURS: Cleanup intervalMAX_CONVERT_PROCESS: Parallel conversion limit
Database Schema
users: id, email, password
jobs: id, user_id, date_created, status, num_files
file_names: id, job_id, file_name, output_file_name, status
API Development Guidelines
Adding New Endpoints
- Create route file in
src/api/v1/ - Define schemas in
src/api/schemas/ - Use existing auth middleware from
src/api/middleware/auth.ts - Reuse converter logic from
src/converters/main.ts
Response Format
{
"success": boolean,
"data": any,
"error": string | null,
"jobId": string | null
}
Error Handling
- Use HTTP status codes appropriately
- Include error details in response body
- Log errors with correlation IDs
Testing Commands
# Run type checking
bun run typecheck
# Run linting
bun run lint
# Run tests (when implemented)
bun test
# Build CSS (development)
bun run build
# Start development server
bun run dev
Docker Commands
# Build image
docker build -t convertx-openapi .
# Run container
docker run -p 3000:3000 -v ./data:/app/data convertx-openapi
# With custom registry
docker build -t your-registry.com/convertx:latest .
docker push your-registry.com/convertx:latest
Common Tasks
Adding a New Converter
- Create
src/converters/newconverter.ts - Export
propertiesandconvertfunctions - Import and add to
propertiesobject inmain.ts - Update Dockerfile to install required system package
Debugging Conversions
- Check console logs for converter output
- Verify file permissions in data directories
- Test converter CLI directly in container
- Check
file_namestable for status
Performance Optimization
- Adjust
MAX_CONVERT_PROCESSfor parallelism - Use batch processing in
handleConvert - Enable SQLite WAL mode (already done)
- Consider external job queue for scale