Building a Deterministic Fire-Code CAD Engine in TypeScript and Cloudflare Workers
When an event producer or tent rental company pulls an operational fire permit for a 40x60 tent or a 200-guest hotel ballroom gala, the local fire marshal does not accept a rough sketch from Canva or Lucidchart. Inspectors check concrete numbers: occupant load under IFC Table 1004.5, minimum exit count and 72-inch tent exit widths under IFC Table 3103.11, the one-half diagonal exit remoteness…
Developing a pure-TypeScript 13x13 crossword crossword solver and 100-page vector PDF engine on Cloudflare Workers proved challenging. Cloudflare Workers restrict the use of Python runtimes or headless browsers, limiting our ability to efficiently process complex tasks. To overcome this limitation, we built a deterministic 13x13 bitmask CSP solver that tackles contributor clues, which are short, irregular, and unpredictable.
This solver divides the grid construction process into two bounded stages: skeleton placement and bitmask CSP fill. By limiting the number of steps in the skeleton placement stage and governing the bitmask CSP fill stage, we ensured that even dense intersections would not exceed Worker CPU budgets. The deterministic nature of this solver guarantees that regenerating a book after moderation or order fulfillment yields the exact same puzzles and answer keys.
For the 100-page 6x9 vector PDF, we opted against rendering HTML through Chromium, which could add cold starts and memory spikes. Instead, we directly built the entire interior and dynamic-spine cover wrap with pdf-lib. This approach ensures vector grid lines, crisp clue numbering, dedication pages, and answer keys stream out without rasterization bloat.
The 100-page interior renders in under 200ms, while the cover wrap completes in under 30ms, providing a fast and efficient printing process. Idempotent fulfillment on D1 paid print orders is managed through an atomic compare-and-swap state transition in Cloudflare D1, backed by an idempotent Stripe webhook log. This ensures retried webhooks never create duplicate print jobs.
The live 13x13 solver and 3-page sample PDF layout can be tested in the ClueBook Preview, or users can create a group puzzle at getcluebook.com.
Rewritten by urgent.news; may contain errors — check the original.
Source: dev.to
This story
This is one outlet's version. Read the fullest account.