Conversation
Move the Cellix API host bootstrap out of the application package into a framework-owned fluent facade so Azure Functions apps can register infrastructure services, context, and HTTP handlers without keeping that startup code beside application-specific wiring.
Contributor
Reviewer's GuideThis PR extracts the API-host Azure Functions bootstrap into Sequence diagram for the Azure Functions bootstrap lifecyclesequenceDiagram
participant Api as apps/api
participant Cellix as Cellix
participant Azure as AzureFunctions
participant Services as InfrastructureServices
participant Host as AppHost
Api->>Cellix: initializeInfrastructureServices(registerServices)
Api->>Cellix: setContext(contextCreator)
Api->>Cellix: initializeApplicationServices(factory)
Api->>Cellix: registerAzureFunctionHttpHandler(name, options, handlerCreator)
Api->>Cellix: startUp()
Cellix->>Azure: app.http(name, handler)
Cellix->>Azure: app.hook.appStart(...)
Cellix->>Azure: app.hook.appTerminate(...)
Azure->>Cellix: appStart
Cellix->>Services: startUp()
Cellix->>Cellix: contextCreator(registry)
Cellix->>Host: factory(context)
Azure->>Cellix: HTTP request
Cellix->>Host: handlerCreator(host, registry)
Host-->>Azure: request response
Azure->>Cellix: appTerminate
Cellix->>Services: shutDown()
Flow diagram for the Cellix fluent bootstrap phasesflowchart LR
Infrastructure["Infrastructure registration"] --> Context["setContext"]
Context --> AppServices["initializeApplicationServices"]
AppServices --> Handlers["registerAzureFunctionHttpHandler"]
Handlers --> Started["startUp() binds handlers and lifecycle hooks"]
Started --> AppStart["Azure Functions appStart"]
AppStart --> Ready["Services started, context built, AppHost created"]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="packages/cellix/api-core/src/cellix.ts" line_range="143" />
<code_context>
- }
-
- public get context(): ContextType {
- if (!this.contextInternal) {
- throw new Error('Context not initialized');
- }
</code_context>
<issue_to_address>
**issue (bug_risk):** The `context` getter throws `Context not initialized` when a valid context value is falsy, such as `false`, `0`, or an empty string, because initialization is checked with `!this.contextInternal` instead of an undefined check.
**Triggers:** When a consumer uses a falsy `ContextType` value.
**Suggested fix:** Check `this.contextInternal === undefined` rather than relying on truthiness.
```suggestion
if (this.contextInternal === undefined) {
```
</issue_to_address>
### Comment 2
<location path="packages/cellix/api-core/src/cellix.ts" line_range="174-183" />
<code_context>
- await this.tracer.startActiveSpan('cellix.appStart', async (span) => {
- try {
- await this.startAllServicesWithTracing();
- this.serviceInitializedInternal = true;
- if (!this.contextCreatorInternal) {
- throw new Error('Context creator missing at appStart');
</code_context>
<issue_to_address>
**issue (bug_risk):** `servicesInitialized` is set to `true` immediately after infrastructure services start, before context creation and application-host creation complete; if either later step throws, `appStart` fails while the returned facade still reports initialized, contradicting the documented appStart-completion state.
**Triggers:** When the context creator or application-services host builder throws after infrastructure startup succeeds.
**Suggested fix:** Set `serviceInitializedInternal` only after the complete appStart sequence succeeds, or document and expose a state that specifically represents infrastructure-service startup rather than appStart completion.
```suggestion
await this.startAllServicesWithTracing();
if (!this.contextCreatorInternal) {
throw new Error('Context creator missing at appStart');
}
this.contextInternal = this.contextCreatorInternal(this);
if (!this.appServicesHostBuilder) {
throw new Error('Application services factory not provided. Call initializeApplicationServices().');
}
this.appServicesHostInternal = this.appServicesHostBuilder(this.contextInternal);
this.serviceInitializedInternal = true;
```
</issue_to_address>
added 2 commits
September 18, 2026 17:18
Treat only undefined as a missing context so falsy context values remain valid, and set servicesInitialized after context and application-host creation succeed.
Pin patched versions of moment, fast-uri, joi, compression, proxy-addr, postcss-selector-parser, image-size, ai, and @ai-sdk/provider-utils so snyk:test reports no vulnerable paths.
Member
Author
|
@sourcery-ai review |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
CellixAzure Functions bootstrap fromapps/apiinto a new framework package,@cellix/api-core.coreas in startup), not a generic@cellix/coreand not a counterpart to@cellix/ui-core.@apps/apinow consumesCellixfrom the package. Handler names, routes, service registration, andappStart/appTerminatetiming are unchanged.The fluent consumer chain is still:
startUp()still only binds Azure Functions handlers and lifecycle hooks. InfrastructurestartUp(), context creation, and the application host still run later inappStart.Public contract
Runtime export:
CellixSignature types:
InfrastructureServiceRegistry,InitializedServiceRegistry,ContextBuilder,ApplicationServicesInitializer,AzureFunctionHandlerRegistry,StartedApplication,AppHost,ServiceKeyInternal: phase machine details, pending handler records,
InfrastructureServiceStore.This is a new package, so the public surface is the main review target.
Tests
Contract tests import
@cellix/api-coreonly (packages/cellix/api-core/tests/cellix.test.ts), grouped underCellix. They cover registration, phase errors, named vs constructor lookup, lifecycle success/failure (including non-Error rejections), and HTTP handler execution before and afterappStart.The old application-local cucumber suite was removed instead of duplicated; it imported
./cellix.tsand poked private fields.Validation
Passed:
@cellix/api-corebuild, lint, tests (62), coverage (98.33% lines / 92.85% branches)@apps/apibuild and tests@cellix/archunit-testsknip(apps/api still depends on@azure/functionsfor the Functions host; knip now ignores that unused-import finding)verifythrough format, arch, coverage merge, e2e (24 scenarios), knip, and auditSnyk:
snyk teston@cellix/api-core: no vulnerable pathssnyk codeonpackages/cellix/api-coreandapps/api/src: 0 issuessnyk test --all-projectshits the cellixjs org monthly private-test limit, so the pre-commit hook cannot currently complete that stepReview notes
Please focus on:
@cellix/api-coreis the name you want going forwardSummary by Sourcery
Extract the Azure Functions API bootstrap into
@cellix/api-coreand update the API host to consume the reusable package without changing startup behavior.New Features:
@cellix/api-corepackage as the reusable Azure Functions bootstrap for Cellix API applications.Cellixbootstrap facade and its fluent startup contract types from the package root.Enhancements:
Build:
@cellix/api-core.Documentation:
Tests:
Chores: