#Owning Alepha
Every piece of Alepha is a class you can replace, its source can live in your project, and what you write on top of it is standard TypeScript. So the day the framework does not do what you need, the answer is never "wait for a release".
| You want to | Use |
|---|---|
| Replace a piece of the framework | alepha.with({ provide, use }) |
| Change a module you installed | override(), substitution, the module's atom |
| Read the framework's source, or fix it | the vendor plugin |
| Know what you would carry out | the last section of this page |
#Replace a provider
Everything the framework does goes through a provider: a class the container builds. The HTTP server, the database driver, the queue, the cache, the mail transport and the clock are all providers, and none is sealed. Name the one to replace and the class to use instead:
1import { Alepha, run } from "alepha"; 2import { 3 EmailProvider, 4 type EmailSendOptions, 5 type EmailSendResult, 6} from "alepha/email"; 7 8class AcmeEmailProvider extends EmailProvider { 9 async send(options: EmailSendOptions): Promise<EmailSendResult> {10 const response = await fetch("https://mail.example.app/send", {11 method: "POST",12 headers: { "content-type": "application/json" },13 body: JSON.stringify(options),14 });15 const receipt = (await response.json()) as { id: string };16 return { messageId: receipt.id };17 }18}19 20const alepha = Alepha.create().with({21 provide: EmailProvider,22 use: AcmeEmailProvider,23});24 25run(alepha);
Every class that injects EmailProvider now sends through yours, the framework's own
modules included. Your business code does not change, and neither does theirs.
This is the mechanism tests use to swap the mail server for an array, and it is not a testing trick: it is how the framework picks a provider for each runtime, and how an app picks its own. The one rule is the order: a substitution comes before anything builds the original. See Swapping Implementations.
#Change a module you installed
A module is a group of ordinary classes, so an app changes one from its own code, without forking the package:
primitive.override({ ... })replaces any option of a primitive the module declared: a page's component, an action's handler, a job's schedule.alepha.with({ provide, use })replaces one of its services, as above.alepha.set(atom, value)changes a setting it exposes.
Extending a Module walks through each on one example.
#Read the source, and fix it
The vendor plugin copies the framework's source into your project:
1import { defineConfig } from "alepha/cli/config"; 2import { vendor } from "alepha/cli/vendor"; 3 4export default defineConfig({ 5 plugins: [ 6 vendor({ 7 packages: ["alepha"], 8 }), 9 ],10});
npx alepha vendor sync # copy the source into .vendor/
npx alepha vendor diff # list the changes you made to it
From then on the framework is code in your repository. A coding agent reads it beside your
app, and a bug you hit is a local edit away from fixed, today. vendor diff lists the
patches you carry, and vendor sync refuses to overwrite them without --force.
A patch is yours to carry until it lands upstream, so keep the list short: substitute a class when that is enough, and patch the source when it is not.
#What you would carry out
If you leave, what you wrote on top of Alepha is not in a private format:
- The data. PostgreSQL, SQLite or D1, with files in S3, R2 or on disk. Nothing is stored in a format only Alepha reads.
- The migrations. SQL files in
migrations/, generated by Drizzle Kit. - The schemas. Zod schemas, with a few extra formats.
- The pages. React components. A component takes props and renders them.
- The business logic. Plain classes with plain methods.
What you would rewrite is the declarations: each $action, $page and $job becomes a
route, a page and a job in whatever comes next. That is the real cost of leaving, and it is
the cost of leaving any framework. The two sections above exist so that you rarely have a
reason to pay it.