creact-labs/creact: CReact is a meta-runtime for building domain-specific, reactive execution engines.


npm version
license

A meta-runtime for building reactive execution engines.

Components can declare anything you want, for example infrastructure, side effects, and AI calls using JSX. The runtime handles lifecycle, state persistence, and dependency tracking.

CReact demo

Working demo at https://github.com/creact-labs/ai-powered-aws-website-generator

This is a multi-site platform that generates websites with AI and deploys them to AWS. An HTTP API accepts prompts, Claude generates HTML, and each site gets its own S3 bucket. State persists across restarts.

export function App() {
  const [sites, setSites] = createSignalSiteConfig[]>([]);
  const [initialized, setInitialized] = createSignal(false);

  const persistence = useAsyncOutput{ sites: SiteConfig[] }>(
    () => ({ sites: sites() }),
    async (props, setOutputs) => {
      setOutputs(prev => {
        if (!initialized() && prev?.sites && prev.sites.length > 0) {
          setSites(prev.sites);
          setInitialized(true);
          return prev;
        }
        setInitialized(true);
        return { sites: props.sites };
      });
    }
  );

  const {
    shouldCleanup, pendingGeneration,
    handleList, handleGenerate, handleUpdate,
    handleCleanupSite, handleCleanupAll,
    updateSiteContent, onDeployed, onCleanupComplete,
    clearPendingGeneration,
  } = useSites(sites, setSites);

  return (
    >
      Channel
        port={3000}
        onList={handleList}
        onGenerate={handleGenerate}
        onUpdate={handleUpdate}
        onCleanupSite={handleCleanupSite}
        onCleanupAll={handleCleanupAll}
      />

      HttpServer port={8080} path="./resources/admin" />

      Claude>
        Show when={() => pendingGeneration()}>
          {(gen) => {
            const { id, path, prompt } = gen();
            const [content, setContent] = createSignal('');
            return (
              >
                Read path={path} file="index.html">
                  {(existingContent) => (
                    GenerateHtml
                      existingContent={existingContent}
                      prompt={prompt}
                      onGenerated={setContent}
                    />
                  )}
                Read>
                Show when={() => content()}>
                  {() => (
                    Write
                      path={path}
                      file="index.html"
                      content={() => content()}
                      onWritten={() => {
                        updateSiteContent(id, content());
                        clearPendingGeneration();
                      }}
                    />
                  )}
                Show>
              >
            );
          }}
        Show>
      Claude>

      AWS region="us-east-1" shouldCleanup={() => shouldCleanup()} onCleanupComplete={onCleanupComplete}>
        For each={() => persistence.sites() ?? []} keyFn={(s) => s.id}>
          {(site) => (
            Show when={() => site().content}>
              {() => (
                WebSite
                  name={() => site().path}
                  content={() => site().content}
                  onDeployed={(url) => onDeployed(site().id, url)}
                />
              )}
            Show>
          )}
        For>
      AWS>
    >
  );
}
npm install @creact-labs/creact

Build the app above from scratch across five chapters:

  1. Your First CReact App — State persistence with a counter
  2. Hello World — Components, handlers, and AWS deployment
  3. AI-Powered Website — Claude integration and HTML generation
  4. Creating the Control Plane — HTTP API, multi-site management
  5. Giving It a Pretty Face — Admin dashboard and static file serving

Apache-2.0



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *