Skip to content

Refactor worker into spec-driven server architecture#10

Open
arielpollack wants to merge 5 commits into
maypaz:mainfrom
arielpollack:arielpollack/spec-driven-server-refactor
Open

Refactor worker into spec-driven server architecture#10
arielpollack wants to merge 5 commits into
maypaz:mainfrom
arielpollack:arielpollack/spec-driven-server-refactor

Conversation

@arielpollack

Copy link
Copy Markdown

Summary

This PR refactors md.page from a single-file Worker into a spec-driven server architecture while preserving the existing public behavior and Cloudflare Worker runtime.

The main goals were:

  • split request handling into clear route modules
  • separate business logic into services
  • move pure helpers into domain modules
  • isolate HTML/static rendering concerns
  • document product, API, architecture, and engineering decisions
  • add an AGENTS.md guide so future contributors and agents can navigate the codebase quickly

What Changed

Architecture

  • Replaced the large monolithic src/index.ts implementation with a thin Worker entrypoint
  • Added src/app.ts to assemble the application
  • Added routing primitives under src/server/
  • Split handlers into:
    • src/routes/api-routes.ts
    • src/routes/page-routes.ts
    • src/routes/static-routes.ts
  • Split workflows into services under src/services/
  • Moved pure logic into src/domain/
  • Moved templates and static assets into src/presentation/

Spec-driven docs

Added a small spec set under docs/spec/ covering:

  • product constraints
  • API contract
  • architecture boundaries
  • engineering decisions

Also added AGENTS.md with a code map and instructions for future contributors/agents.

Dev workflow

  • Added wrangler.toml so bun dev and wrangler dev work with the refactored entrypoint
  • Updated README.md and CONTRIBUTING.md to reference the new architecture and docs

Behavior / Compatibility

This refactor intentionally preserves the existing public contract, including:

  • POST /api/publish
  • POST /api/event
  • GET /:id
  • GET /og/:id.png
  • landing page, privacy page, favicon, logo, and fallback OG image
  • existing validation and rate limiting behavior
  • existing response formats and key headers

Verification

  • npm run typecheck
  • npm test

All tests passed after the refactor.

Notes

This PR is mostly architectural and documentation-focused. It should make future feature work much easier without changing the product surface area.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant