--- title: Application Types description: "Stacks enables you to build multiple types of applications from a single codebase: web apps, desktop apps, mobile apps, and CLI tools. Share code between p..." --- # Apps Stacks enables you to build multiple types of applications from a single codebase: web apps, desktop apps, mobile apps, and CLI tools. Share code between platforms while optimizing for each target. ## Overview Stacks app types: - **Web Apps** - SPA, SSR, or static sites - **Desktop Apps** - Native apps with Craft - **Mobile Apps** - iOS and Android with Craft - **CLI Apps** - Command-line tools - **Libraries** - Reusable packages ## Web Applications ### Single Page Applications (SPA) ```bash # Create SPA panx buddy new my-app # Development server buddy dev # Build for production buddy build ``` ### Server-Side Rendering (SSR) ```bash # Create SSR app panx buddy new my-app # Development buddy dev # Build buddy build ``` ### Configuration ```typescript // config/app.ts export default defineAppConfig({ type: 'web', ssr: { enabled: true, streaming: true, }, build: { target: 'esnext', minify: true, sourcemap: true, }, server: { port: 3000, host: 'localhost', }, }) ``` ## Desktop Applications ### Craft Integration Stacks uses the first-party Craft runtime for native desktop apps. Craft opens the same stx application URL served through rpx and tlsx, so desktop and browser clients share routes, actions, authentication, and UI. ```bash # Create desktop app panx buddy new my-app # Development mode buddy dev:desktop # Build buddy build:desktop ``` ### A native Mac app with its own API A local-first app (a browser, an inbox, a notes app) can run its API inside the app instead of on a server. Its screens are stx drawn by Craft's AppKit host, with no web view, and its routes run on 127.0.0.1 in the same app: ```bash buddy new my-browser --desktop # add --minimal for the bare skeleton cd my-browser bun run dev:desktop # build the screens, start the agent, open the window bun run build:desktop # a signed .app in storage/framework/desktop/macos ``` That writes `config/desktop.ts` with `macos.agent: true`, one screen in `resources/native/Main.stx`, and the agent's own routes in `app/Desktop/Agent.ts`. The agent also serves everything in `routes/`, and only the app's own window can call it: it hands that window an HttpOnly session cookie at `/native/session`, new on every launch, and refuses any request without it or with a Host header that is not its own. `macos.webkit`, `macos.defaultBrowser`, `macos.permissions` and `macos.dockMenu` cover what a browser needs; see the `stacks-desktop` skill for each. ### Desktop Configuration ```typescript // config/desktop.ts export default defineDesktopConfig({ productName: 'My App', identifier: 'com.mycompany.myapp', version: '1.0.0', windows: { width: 1200, height: 800, resizable: true, title: 'My Desktop App', }, bundle: { icon: 'public/icon.png', category: 'Productivity', }, security: { csp: "default-src 'self'", }, }) ``` ### Native APIs Craft exposes native APIs through its typed bridge. Put bridge access in a TypeScript function or composable and call that function from stx. The bridge covers windows, files, notifications, clipboard, processes, shortcuts, tray menus, and updates. ### Menu Bar ```typescript // config/desktop.ts export default defineDesktopConfig({ menu: { items: [ { label: 'File', submenu: [ { label: 'New', accelerator: 'CmdOrCtrl+N', action: 'new' }, { label: 'Open', accelerator: 'CmdOrCtrl+O', action: 'open' }, { label: 'Save', accelerator: 'CmdOrCtrl+S', action: 'save' }, { type: 'separator' }, { label: 'Quit', accelerator: 'CmdOrCtrl+Q', action: 'quit' }, ], }, { label: 'Edit', submenu: [ { label: 'Undo', accelerator: 'CmdOrCtrl+Z', action: 'undo' }, { label: 'Redo', accelerator: 'CmdOrCtrl+Shift+Z', action: 'redo' }, { type: 'separator' }, { label: 'Cut', accelerator: 'CmdOrCtrl+X', action: 'cut' }, { label: 'Copy', accelerator: 'CmdOrCtrl+C', action: 'copy' }, { label: 'Paste', accelerator: 'CmdOrCtrl+V', action: 'paste' }, ], }, ], }, }) ``` ## Mobile Applications Stacks builds native iOS and Android apps from the same STX application with Craft: the views, routes and API stay the ones the web app uses, the Native components behave like UIKit's controls, and `@stacksjs/mobile` reaches the phone's native features with a web fallback for each. ```bash buddy build:ios buddy build:android ``` See [Mobile Apps](/guide/mobile) for configuration, the components and the runtime API. ## CLI Applications ### Creating CLI Tools ```bash # Create CLI app panx buddy new my-cli # Run CLI bun run cli # Build distributable buddy build:cli ``` ### CLI Configuration ```typescript // config/cli.ts export default defineCliConfig({ name: 'my-cli', version: '1.0.0', description: 'My awesome CLI tool', commands: [ { name: 'init', description: 'Initialize a new project', options: [ { name: '--template', description: 'Project template' }, { name: '--force', description: 'Overwrite existing files' }, ], }, { name: 'build', description: 'Build the project', options: [ { name: '--watch', description: 'Watch for changes' }, ], }, ], }) ``` ### Command Implementation Commands live in `app/Commands/` and need no registration - every `.ts` file there is a command. `defineCommand()` infers the handler's `options` from the flags it declares, so there is no options interface to keep in sync: ```typescript // app/Commands/Init.ts import { defineCommand, log } from '@stacksjs/cli' export default defineCommand({ name: 'init', description: 'Initialize a new project', options: { '-t, --template