ai-prompted
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data โ all from the browser, and deployed in milliseconds.
Viewing readonly version of main branch: v22View latest version
This Val Town project demonstrates the plugin host pattern for managing upstream/downstream changes in a modular application architecture.
When you have a fork of an existing full-stack app that you need to customize while keeping up with upstream changes, traditional approaches create maintenance headaches. This pattern provides a clean solution.
- Plugin Host: Central registry for extension points
- Hook Points: Defined lifecycle moments where plugins can inject behavior
- Stable API: Typed interfaces that don't break with updates
- Plugins: Modular customizations that register with hook points
- Clean Separation: Your code lives outside the upstream subtree
- Future-Proof: Upstream updates don't break your customizations
- Widget Component: Simulated upstream component with plugin hooks
- Analytics Plugin: Tracks interactions and sends metrics
- Customization Plugin: Modifies default behavior and adds features
- Live Console: Watch plugin hooks fire in real-time
- โ Maintainable: Clear separation between upstream and downstream code
- โ Testable: Plugin contracts are explicit and typed
- โ Flexible: Add new plugins without modifying upstream code
- โ Trackable: Use git subtree to track upstream SHA, not just version strings
- โ Conflict-Free: Merge conflicts only occur at hook layer boundaries
// 1. Upstream defines hook points
const hooks = pluginHost.getHooks('ComponentName');
for (const hook of hooks) {
state = hook.beforeInit?.(state) ?? state;
}
// 2. Downstream registers plugins
pluginHost.register('ComponentName', {
beforeInit: (state) => ({ ...state, customField: true }),
mounted: ({ state, update }) => console.log('Mounted!'),
updated: ({ state }) => sendAnalytics(state)
});
โโโ backend/ # Hono server
โโโ frontend/ # Client-side demo
โโโ shared/ # Shared types and utilities
โโโ README.md # This file
- Click the widget button to see plugins in action
- Open browser console to watch hook execution
- Notice how plugins modify behavior without touching upstream code
This pattern scales from simple customizations to complex enterprise integrations while maintaining clean boundaries and upgrade paths.