This is the background processor service for JuzBuild that handles long-running website creation workflows separately from the main application.
The background processor was separated from the main JuzBuild application to:
- Improve User Experience: Website creation no longer blocks the main application
- Handle Long-Running Tasks: GitHub uploads and deployments can take several minutes
- Better Resource Management: Heavy processing is isolated from the user-facing application
- Scalability: Can be deployed separately and scaled independently
┌─────────────────┐ HTTP Request ┌──────────────────────┐
│ Main JuzBuild │ ──────────────────► │ Background Processor │
│ Application │ │ │
│ (Port 3000) │ ◄────────────────── │ (Port 3001) │
└─────────────────┘ Job Queued └──────────────────────┘
│
▼
┌──────────────────────┐
│ Website Creation │
│ Workflow │
│ │
│ 1. Create Database │
│ 2. Generate Template │
│ 3. Push to GitHub │
│ 4. Deploy to Vercel │
│ 5. Setup Domain │
│ 6. Send Notification │
│ 7. Log to Database │
└──────────────────────┘
- Node.js 18+
- MongoDB connection
- GitHub token
- Vercel token
- Email configuration
-
Navigate to the background processor directory:
cd juzbuild-background-processor -
Install dependencies:
npm install
-
Configure environment variables: Copy the
.envfile and update with your credentials:PORT=3001 MONGODB_URI=your_mongodb_connection_string GITHUB_TOKEN=your_github_token VERCEL_TOKEN=your_vercel_token EMAIL_HOST=your_email_host EMAIL_USER=your_email_user EMAIL_PASS=your_email_password BACKGROUND_PROCESSOR_SECRET=your_secret_key
-
Build the project:
npm run build
-
Start the server:
npm start # or for development npm run dev
GET /healthReturns the health status of the background processor.
POST /process-website-creation
Headers:
Content-Type: application/json
x-processor-secret: your_secret_key
Body: {
"userId": "string",
"websiteName": "string",
"userEmail": "string",
"companyName": "string",
"domainName": "string",
"brandColors": ["#color1", "#color2"],
"tagline": "string",
"aboutSection": "string",
"selectedTheme": "string",
"layoutStyle": "string",
"propertyTypes": ["type1", "type2"],
"includedPages": ["page1", "page2"],
"preferredContactMethod": ["method1", "method2"]
}GET /job-status/:jobId
Headers:
x-processor-secret: your_secret_keyThe background processor executes the following steps for each website creation request:
- Database Creation: Creates a MongoDB database with initial collections and sample data
- Template Generation: Copies and customizes the Homely template with user data
- GitHub Repository: Creates a new GitHub repository and pushes the template files
- Vercel Deployment: Deploys the website to Vercel and waits for completion
- Domain Setup: Configures subdomain (placeholder implementation)
- Email Notification: Sends completion email to the user
- Database Logging: Logs the created site information
- Cleanup: Removes temporary template files
The background processor includes a copy of the templates/homely directory which contains:
- Complete Next.js real estate website template
- Components, pages, and API routes
- Sample data and configurations
- Responsive design and modern UI
The main JuzBuild application has been updated to:
- Send requests to background processor instead of processing locally
- Return immediate response to users indicating the job has been queued
- Provide health check endpoints to monitor processor status
- Handle processor unavailability gracefully
POST /api/workflow/create-site: Now queues jobs with background processorGET /api/workflow/health: Checks background processor healthGET /api/workflow/status/[jobId]: Gets job status (future enhancement)
- Run both services locally on different ports
- Main app:
http://localhost:3000 - Background processor:
http://localhost:3001
- Deploy background processor as separate service
- Update
BACKGROUND_PROCESSOR_URLenvironment variable - Ensure network connectivity between services
- Consider using Redis for job queue management
- Secret-based authentication: All requests require
x-processor-secretheader - Environment isolation: Sensitive credentials stored in environment variables
- Input validation: All incoming requests are validated using Zod schemas
- Structured logging: All steps include timestamps and context
- Health checks: Endpoint available for monitoring systems
- Error tracking: Detailed error messages and stack traces
- Job tracking: Future enhancement for job status monitoring
For high-traffic scenarios, consider:
- Horizontal scaling: Run multiple processor instances
- Load balancing: Distribute requests across instances
- Queue management: Use Redis or RabbitMQ for job queuing
- Database optimization: Separate databases for different tenants
- Caching: Cache templates and configurations
- Port conflicts: Change
PORTin environment variables - Missing dependencies: Run
npm installin processor directory - Authentication errors: Verify
BACKGROUND_PROCESSOR_SECRETmatches in both services - GitHub/Vercel failures: Check token permissions and rate limits
- Database connection: Verify MongoDB URI and network connectivity
- Development: Console output
- Production: Consider using PM2 or similar for log management
- Job Queue System: Implement Redis-based job queue
- Status Tracking: Real-time job status updates
- Retry Logic: Automatic retry for failed operations
- Metrics Collection: Performance and success rate metrics
- Admin Dashboard: Web interface for monitoring jobs
- Multi-tenant Support: Separate processing for different clients
- Template Marketplace: Support for multiple website templates
When making changes to the background processor:
- Update both services if API changes
- Test integration thoroughly
- Update environment variables documentation
- Consider backward compatibility
- Update this README with new features
Same license as the main JuzBuild application.