Development

UnifiedCron Development Guide

This guide will help you set up and develop UnifiedCron locally.

Prerequisites

  • Node.js 20+
  • pnpm (recommended) or npm
  • PostgreSQL database
  • Git

Quick Start

  1. Clone and setup:

    git clone <repository-url>
    cd unifiedcron
    chmod +x scripts/setup.sh
    ./scripts/setup.sh
  2. Configure environment:

    cp env.example .env.local
    # Edit .env.local with your database URL and other settings
  3. Set up database:

    # Make sure PostgreSQL is running
    createdb unifiedcron
     
    # Run migrations
    pnpm db:migrate
  4. Start development servers:

    pnpm dev

This will start:

Project Structure

unifiedcron/
├── apps/
│   ├── web/          # Next.js frontend
│   ├── api/          # Express.js backend
│   └── worker/       # Background worker
├── packages/
│   ├── shared/       # Shared types and utilities
│   ├── database/     # Database schema and client
│   └── integrations/ # Platform-specific parsers
├── docs/            # Documentation
└── scripts/         # Setup and utility scripts

Development Commands

# Install dependencies
pnpm install
 
# Start all development servers
pnpm dev
 
# Start individual services
pnpm dev:web     # Frontend only
pnpm dev:api     # API only  
pnpm dev:worker  # Worker only
 
# Build all packages
pnpm build
 
# Run tests
pnpm test
 
# Lint code
pnpm lint
 
# Type check
pnpm type-check
 
# Database migrations
pnpm db:migrate

Platform Integration

Supabase

  1. Run the SQL in docs/supabase-setup.sql in your Supabase SQL editor
  2. Get your project URL and anonymous key from Supabase dashboard
  3. Add connection in UnifiedCron with these credentials

GitHub Actions

  1. Create a Personal Access Token with repo scope
  2. Add connection with repository name (owner/repo) and token

Vercel/Netlify

  1. These require GitHub integration for automatic discovery
  2. Add GitHub connection first, then Vercel/Netlify can parse config files

n8n

  1. Get your n8n instance URL and API key
  2. Add connection with base URL and API key

Note: GitHub Actions, Vercel, Netlify, and n8n integrations are planned but not yet implemented in the current release.

API Endpoints

Authentication

  • POST /api/auth/register - Register user
  • POST /api/auth/login - Login user
  • GET /api/auth/me - Get current user from bearer token
  • GET /api/users/me - Get authenticated user profile

Connections

  • GET /api/connections - List connections
  • POST /api/connections - Create connection
  • GET /api/connections/:id - Get connection
  • PUT /api/connections/:id - Update connection
  • DELETE /api/connections/:id - Delete connection
  • POST /api/connections/:id/test - Test connection

Jobs

  • GET /api/jobs - List jobs
  • GET /api/jobs/:id - Get job details
  • POST /api/jobs/:connectionId/refresh - Refresh jobs
  • GET /api/jobs/:id/runs - Get job runs
  • GET /api/jobs/:id/stats - Get job statistics

Alerts

  • GET /api/alerts - List alerts (status=open|resolved, type=failure)
  • GET /api/alerts/:id - Get alert
  • PATCH /api/alerts/:id/resolve - Resolve alert
  • GET /api/alerts/stats/overview - Get alert statistics

Notifications

  • GET /api/notifications/webhooks - List webhook endpoints
  • POST /api/notifications/webhooks - Create webhook endpoint
  • PATCH /api/notifications/webhooks/:id - Edit or pause endpoint; rotate signing secret
  • DELETE /api/notifications/webhooks/:id - Delete webhook endpoint
  • POST /api/notifications/webhooks/:id/test - Queue test event (HTTP 202)
  • GET /api/notifications/deliveries - Filtered, paginated delivery history
  • GET /api/notifications/deliveries/:id - Delivery detail and attempt history
  • GET /api/notifications/metrics - Current user's delivery status counts

See Webhook Notifications for signing verification, retries and destination policy.

Database Schema

Tables

  • users - User accounts
  • connections - Platform connections (encrypted config)
  • jobs - Normalized cron jobs
  • jobRuns - Job execution history
  • alerts - Failure alerts and notifications
  • notification_endpoints - Webhook endpoint configuration
  • notification_deliveries - Webhook delivery attempts and retries
  • notification_delivery_attempts - Per-attempt outcomes and lease recovery history
  • ingestion_state - Stream cursors, freshness and connection retry state
  • ingestion_gaps - Possible upstream history gaps

Views

  • job_details - Jobs with connection and statistics

Security

  • All connection credentials are encrypted using AES-256-GCM
  • Database uses camelCase column names
  • API includes proper error handling and validation
  • Frontend uses secure HTTP practices

Monitoring

The worker normally polls each Supabase connection once per minute, with jitter, bounded concurrency and error backoff. It rediscovers stable job IDs, pages numerically by runid, refreshes unfinished statuses and commits run changes with cursor checkpoints. Initial backfill is bounded; upstream purge gaps and catch-up state remain visible. Missing jobs are archived, and names are display-only. Failures accumulate in one open incident per job/type; a newer successful run resolves it. Notifications fire on open/resolve, not on each failure.

Webhook dispatch runs independently every 15 seconds, including when monitoring is disabled. Database leases prevent concurrent claims; retries use 1/5/15/30/60-minute backoff. The sixth unsuccessful attempt is terminal. Outbox reconciliation repairs missed enqueue operations.

Worker observability endpoints:

  • GET http://localhost:3003/health
  • GET http://localhost:3003/metrics

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

Troubleshooting

Database Connection Issues

  • Ensure PostgreSQL is running
  • Check DATABASE_URL in .env.local
  • Verify database exists and user has permissions

Platform Connection Issues

  • Verify credentials are correct
  • Check platform-specific setup requirements
  • Review API rate limits

Build Issues

  • Clear node_modules and reinstall: rm -rf node_modules && pnpm install
  • Check Node.js version compatibility
  • Ensure all packages are built: pnpm build

Environment Variables

Required:

  • DATABASE_URL - PostgreSQL connection string
  • ENCRYPTION_KEY - 32-byte base64 key for encrypting secrets

Optional:

  • API_PORT - API server port (default: 3001)
  • NODE_ENV - Environment (development/production)
  • NEXT_PUBLIC_API_URL - Frontend API URL
  • TEST_* - Test credentials for development

License

AGPL-3.0 License