- packages/core/api: HttpApi contract with ToolsApi + SecretsApi groups SDK tagged errors pass through directly with status annotations (ToolNotFoundError→404, PolicyDeniedError→403, etc.) - apps/server: API handler implementation via HttpApiBuilder Exports createApiHandler() for reuse (no baked-in server runtime) Handlers are pure pass-through — no manual error catching - apps/web: Vite + React frontend served on same port as API Vite plugin forwards /v1/*, /docs, /openapi.json to Effect handler effect-atom integration: AtomHttpApi.Tag typed client, query/mutation atoms RegistryProvider + useAtomValue with Result pattern matching - Catalog pins @effect/platform, platform-bun, platform-node, cluster - All 9 packages typecheck clean
Showing the changes to apps/server/src/main.ts (1 of 26 files). Show all
Unified · Split
| @@ -0,0 +1,40 @@ | |||
| 1 | import { | ||
| 2 | HttpApiBuilder, | ||
| 3 | HttpApiSwagger, | ||
| 4 | HttpMiddleware, | ||
| 5 | HttpServer, | ||
| 6 | } from "@effect/platform"; | ||
| 7 | import { Layer } from "effect"; | ||
| 8 | |||
| 9 | import { ExecutorApi } from "@executor/api"; | ||
| 10 | import { ToolsHandlers } from "./handlers/tools"; | ||
| 11 | import { SecretsHandlers } from "./handlers/secrets"; | ||
| 12 | import { ExecutorServiceLive } from "./services/executor"; | ||
| 13 | |||
| 14 | // --------------------------------------------------------------------------- | ||
| 15 | // API layer — wire handlers | ||
| 16 | // --------------------------------------------------------------------------- | ||
| 17 | |||
| 18 | const ApiLive = HttpApiBuilder.api(ExecutorApi).pipe( | ||
| 19 | Layer.provide([ToolsHandlers, SecretsHandlers]), | ||
| 20 | Layer.provide(ExecutorServiceLive), | ||
| 21 | ); | ||
| 22 | |||
| 23 | // --------------------------------------------------------------------------- | ||
| 24 | // Web handler — usable by Vite plugin, standalone server, tests, etc. | ||
| 25 | // --------------------------------------------------------------------------- | ||
| 26 | |||
| 27 | export const createApiHandler = () => | ||
| 28 | HttpApiBuilder.toWebHandler( | ||
| 29 | HttpApiSwagger.layer().pipe( | ||
| 30 | Layer.provideMerge(HttpApiBuilder.middlewareOpenApi()), | ||
| 31 | Layer.provideMerge(HttpApiBuilder.middlewareCors()), | ||
| 32 | Layer.provideMerge(ApiLive), | ||
| 33 | Layer.provideMerge(HttpServer.layerContext), | ||
| 34 | ), | ||
| 35 | { middleware: HttpMiddleware.logger }, | ||
| 36 | ); | ||
| 37 | |||
| 38 | export type ApiHandler = ReturnType<typeof createApiHandler>; | ||
| 39 | |||
| 40 | export { ExecutorServiceLive } from "./services/executor"; | ||