NextRouteNextRoute

Route Generation

How the rolling-window generation engine creates daily routes from master templates — cron jobs, manual generation, and preview.

Route Generation

The route generation engine transforms your master route templates into concrete daily routes. It can run automatically on a schedule or be triggered manually.

How It Works

The generation engine processes a date range and, for each date:

  1. Finds matching templates — active templates where day_of_week matches the target date's day
  2. Filters stops by frequency — determines which template stops should appear based on their frequency, week parity, and month week settings
  3. Applies exclusions — removes stops for:
    • Customers with active vacation holds covering the date
    • Customers with service skips on the date
    • Dates that are blackout dates
  4. Checks for duplicates — skips generation if a route already exists for that template and date (unless force mode is used)
  5. Creates draft routes — one route per template per date, with the filtered stops in template sequence

Automatic Generation (Cron)

When auto_generate_routes is enabled in tenant settings, a daily cron job runs and generates routes for upcoming dates.

Rolling Window

The auto_generate_days setting controls how many days ahead the engine looks. For example:

SettingBehavior
auto_generate_days = 7Routes are generated 7 days in advance
auto_generate_days = 14Routes are generated 14 days in advance
auto_generate_days = 30Routes are generated 30 days in advance

Each cron run generates any missing routes within the window. Routes already created for a date are not duplicated.

Enabling Auto-Generation

  1. Go to Settings > Routes & Scheduling
  2. Toggle Auto-generate routes on
  3. Set the Days ahead value
  4. Save

Manual Generation

You can generate routes on-demand from the dashboard or API.

From the Dashboard

  1. Go to Daily Routes
  2. Click Generate Routes
  3. Select the start and end date
  4. Optionally filter to a specific template
  5. Click Generate

From the API

POST https://api.nextroute.app/api/generate-routes
Authorization: Bearer <token>
Content-Type: application/json

{
  "start_date": "2026-03-24",
  "end_date": "2026-03-28"
}

Optional parameters:

ParameterDescription
template_idGenerate only for a specific template
forceIf true, regenerates even if routes already exist for the date

The response includes the count of routes and stops created:

{
  "routes_created": 3,
  "stops_created": 47,
  "skipped_dates": ["2026-03-25"]
}

Note: The date range is capped at 60 days to prevent excessive generation.

Preview (Dry Run)

Before committing, you can preview what the engine would generate:

POST https://api.nextroute.app/api/generate-routes/preview
Authorization: Bearer <token>
Content-Type: application/json

{
  "start_date": "2026-03-24",
  "end_date": "2026-03-28"
}

The response shows the same output structure but with "preview": true — no routes are actually created.

Frequency Filtering Logic

FrequencyInclusion Rule
WeeklyAlways included for matching day
BiweeklyIncluded if current week matches stop's week_parity (A or B)
MonthlyIncluded if the occurrence matches month_week (1st, 2nd, 3rd, 4th, last)
QuarterlyIncluded in months 1, 4, 7, 10 (first month of each quarter)
AnnuallyIncluded once per year
SeasonalIncluded only during seasonal_active_months (configurable per tenant)
One-timeIncluded once, then deactivated on the template

Cascading Effects

Changes to scheduling data automatically affect generation:

  • Adding a blackout date → soft-deletes stops from draft routes on that date
  • Adding a vacation hold → soft-deletes the customer's stops from draft routes in the hold range
  • Adding a service skip → soft-deletes the customer's stop from the draft route on that date
  • Removing a blackout/hold/skip → triggers regeneration for the affected dates to restore stops