Devmachinist /Docs
Sign in Start
All docs

Project structure

Every Devmachinist project is a real Vite + React + Tailwind CSS v4 app. The builder, the AI and the code editor all edit the same files on disk, and the files are the source of truth: the builder never overwrites a page or component you wrote. This page explains the layout, which files are generated for you, and the rules that keep your code working both in the live preview and on the published site.

The workspace #

Each project lives in its own folder on the server (users/<account>/sites/<project>/ inside the data directory). You see it in the Files tab and get it out with git.

text
my-site/
  index.html            generated: title, description, favicon, fonts, link-preview tags
  package.json          generated from the project's packages
  vite.config.js        generated, only used when you run the project elsewhere
  .gitignore            created once, then yours
  public/
    brand/              logo and favicon (More → Brand)
    media/              uploaded pictures, video, fonts, PDFs
  src/
    main.jsx            generated: mounts <App/>, adds the sign-in provider
    App.jsx             generated: the hash router over your pages
    site.js             generated: brand, page list, route helpers
    index.css           yours, with two managed blocks
    pages/              one file per page: Home.jsx, About.jsx …
    components/         one file per section or component: Hero.jsx …
    api/                generated data and sign-in clients for connected APIs
    lib/  hooks/  utils/  your own modules
    styles/  data/      extra CSS and JSON
    game.js             generated when there's a game server: its address and gameClient()
  server/               a multiplayer game server's rooms (Colyseus), if the project has one
  shared/               code both the site and the game server import

Other folders show up when you use the features that need them: public/vendor/ and public/models/ for files imported from the web, uploads/ for chat attachments that aren't media, and designs/ for the image editor's layer files.

Generated files and your files #

Some files are written by Devmachinist every time it sets the workspace up (starting a preview, running a check, publishing, installing packages, building an app). Editing them by hand is pointless, because your change is replaced the next time.

FileWho owns itWhat changes it
src/site.jsGeneratedPages and brand (More → Pages, More → Brand)
src/App.jsxGeneratedAdding, renaming or removing pages, page access
src/main.jsxGeneratedConnecting an API with sign-in
src/api/GeneratedThe API builder (models, sign-in)
src/game.jsGeneratedA game server in server/ (see Multiplayer games)
server/, shared/YoursNever touched; published with the site
index.htmlGeneratedBrand, theme fonts, publishing address
package.jsonGeneratedInstalling or removing packages in the builder
vite.config.jsGeneratedNothing, it is the same in every project
src/index.cssYoursTwo managed blocks are kept up to date
src/pages/, src/components/YoursOnly created when missing
src/lib/, src/hooks/, public/ …YoursNever touched

Project search and replace and the AI never write the generated source files (site.js, App.jsx, main.jsx, game.js, src/api/). Old Tailwind v3 files (tailwind.config.js, postcss.config.js and friends) are deleted when the workspace is set up, since Tailwind v4 needs none of them.

To change what a generated file contains, change its input: pages in More → Pages, brand and theme in More → Brand, data in the API builder, packages in More → Packages.

package.json and base versions #

Every project runs the current major versions of its base packages. genPkg writes them, and an older workspace is moved up automatically the next time it is installed.

PackageVersion rangeUsed for
react, react-dom^19.0.0The app
vite^8.0.0Preview and local dev
@vitejs/plugin-react^6.0.0Preview and local dev
tailwindcss, @tailwindcss/vite^4.0.0Styling
@tailwindcss/postcss^4.0.0The published Next.js build
next^16.0.0The published Next.js build

A newer range you installed yourself is kept. More → Packages shows the installed versions and, when a project is behind, an Update now button.

json
{
  "name": "my-site",
  "version": "0.0.1",
  "private": true,
  "type": "module",
  "scripts": { "dev": "vite", "build": "vite build", "preview": "vite preview" },
  "dependencies": { "react": "^19.0.0", "react-dom": "^19.0.0", "quill": "^2.0.3" },
  "devDependencies": {
    "@vitejs/plugin-react": "^6.0.0",
    "@tailwindcss/vite": "^4.0.0",
    "@tailwindcss/postcss": "^4.0.0",
    "next": "^16.0.0",
    "tailwindcss": "^4.0.0",
    "vite": "^8.0.0"
  }
}

Pages and components #

A page is src/pages/<Name>.jsx with a default export of the same name. Its slug (the part after #) is usually the lower-case name, as listed in site.allPages. A section or component is src/components/<Name>.jsx, PascalCase, one primary component as the default export.

jsx
// src/pages/About.jsx
import React from 'react'
import SiteNav from '../components/SiteNav.jsx'
import Team from '../components/Team.jsx'

export default function About() {
  return (
    <div className="min-h-screen">
      <SiteNav />
      <Team />
    </div>
  )
}

From a page, import a component as '../components/Name.jsx'; from one component, another as './Name.jsx'. Components the Library tab inserts are copied into src/components/, so the project never depends on files outside its folder.

The site.js API #

src/site.js is regenerated whenever pages or the brand change. Navs, footers and pages import from it instead of hard-coding names and links.

js
import site, { pagesFor, route, routeParam, currentSlug } from '../site.js'
// or: import { site } from '../site.js'
ExportWhat it is
site.name, site.taglineBrand name and tagline (More → Brand)
site.logoLogo path under public/, for example brand/logo.svg, or null
site.colorsThe brand color families: primary, secondary, accent
site.pagesMenu pages everyone may open, in order
site.allPagesMenu pages including those limited to some roles (each carries roles)
pagesFor(user)The menu for one visitor: everyone's pages plus the ones their role opens
route()The current route, for example product/3
routeParam(i)Part i of the route, decoded: routeParam(1) is 3 for product/3
currentSlug()The page being shown; falls back to the first page

Each page entry looks like this:

js
{ name: 'About', slug: 'about', label: 'About', href: '#about' }
// a page limited to some accounts also has: roles: ['admin']

Pages hidden from the menu (More → Pages) are left out of both lists. So are the sign-in and account pages, and for the store and blog templates their internal pages (admin, cart, checkout, order, product, post), unless such a page has roles of its own.

pagesFor(user) includes a role page when the page allows user (any signed-in account), when the visitor is an admin, or when the visitor's role is one the page lists.

A nav that maps the pages #

jsx
// src/components/SiteNav.jsx
import React, { useEffect, useState } from 'react'
import { site, currentSlug } from '../site.js'

export default function SiteNav() {
  const [slug, setSlug] = useState(currentSlug())
  useEffect(() => {
    const onChange = () => setSlug(currentSlug())
    window.addEventListener('hashchange', onChange)
    return () => window.removeEventListener('hashchange', onChange)
  }, [])

  return (
    <nav className="flex items-center gap-6 px-6 py-4">
      <a href="#" className="font-heading text-lg font-bold text-secondary-900">{site.name}</a>
      {site.pages.map((p) => (
        <a
          key={p.slug}
          href={p.href}
          className={p.slug === slug ? 'font-semibold text-brand-600' : 'text-secondary-600 hover:text-secondary-900'}
        >
          {p.label}
        </a>
      ))}
    </nav>
  )
}

With sign-in, map pagesFor(user) instead, so admins see the admin page and visitors don't. useAuth() comes from the generated sign-in client (see the client reference); it never returns null.

jsx
import { useAuth } from '../api/my-shop-auth.jsx'
import { pagesFor } from '../site.js'

export default function SiteNav() {
  const { user } = useAuth()
  return (
    <nav className="flex gap-6 px-6 py-4">
      {pagesFor(user).map((p) => <a key={p.slug} href={p.href}>{p.label}</a>)}
    </nav>
  )
}

A product page reading routeParam(1) #

Link to a detail page as #product/<id> and read the id with routeParam(1). Never read window.location.hash yourself: on the published site the address is /product/3/ and there is no hash.

jsx
// src/pages/Product.jsx
import React, { useEffect, useState } from 'react'
import { routeParam } from '../site.js'
import { useProduct } from '../api/my-shop.js'

export default function Product() {
  const [id, setId] = useState(routeParam(1))
  useEffect(() => {
    const onChange = () => setId(routeParam(1))
    window.addEventListener('hashchange', onChange)
    return () => window.removeEventListener('hashchange', onChange)
  }, [])

  const { data: product, loading, error } = useProduct(id || null)
  if (loading) return <p className="p-8">Loading…</p>
  if (error || !product) return <p className="p-8">This product isn’t available.</p>

  return (
    <main className="mx-auto max-w-3xl p-8">
      <h1 className="text-3xl">{product.name}</h1>
      <p className="mt-2 text-brand-700">${product.price}</p>
      <p className="mt-6 text-secondary-700">{product.description}</p>
    </main>
  )
}
jsx
// a card on another page
<a href={`#product/${p.id}`} className="block rounded-lg border p-4">{p.name}</a>

The data client's file name comes from the API's slug (src/api/<slug>.js, and <slug>-auth.jsx when sign-in is on); src/api/index.js re-exports them all. See Data API for the hooks and methods.

Routing #

Projects use hash routing. There is no router package and no server routes.

  • App.jsx takes the first segment of the hash as the page: #about shows About, #product/3 shows Product. The rest of the route is for the page to read with routeParam.
  • An unknown or empty hash shows the default page (the page marked active in the builder, else the first one).
  • A project with one page renders it directly.
  • When the site has sign-in, pages limited to some roles are wrapped in the sign-in client's <Auth>; signed-out visitors get the site's Login page (or the built-in LoginForm), and accounts without the role get a short "This page isn’t for your account" message.
  • Link with href="#slug" or the href from site.pages. href="#" goes home.
  • Don't use react-router, <Link>, /about-style paths or window.location.pathname.
  • Don't use in-page anchors like #features: in the preview any hash is read as a page, so an anchor that isn't a page slug switches to the default page. Scroll with element.scrollIntoView() instead.

On the published site #

Published sites are built with Next.js as a static export (see Publishing). Your app stays the same React app: Next mounts App.jsx in the browser and gives every page its own address, title, description and preview image.

  • The home page is at the site's root and every other page at /<slug>/.
  • A click on #about changes the address to /about/ (with history.replaceState) and tells the app through the same hashchange event App.jsx already listens to. Back and forward work too.
  • #product/3 becomes /product/3/ only when no file of yours reads location.hash (App.jsx, site.js, main.jsx and src/api/ don't count; assigning location.hash = '…' is fine). If one does, links with ids stay hash links on the whole site.
  • A hash containing ?, and an anchor that isn't a page slug, are left alone.
  • route() and routeParam() read the hash in the preview and the real address on the published site, which is why pages must use them.
  • window.__PB_BASE__ holds the site's base path (for example /@you/my-site/), useful for return URLs.

Code that works in both builds #

The preview runs your project with Vite; publishing builds it with Next.js. The same code has to work in both. The AI's checks build both ways, and build_check reports both.

  • No Vite-only import suffixes: no ?raw, ?url or ?react, and no other Vite-only features.
  • No Node APIs (fs, path, process and so on). The app only ever runs in the browser.
  • Reference files in public/ with relative paths: media/team.jpg, not /media/team.jpg. Published sites can live in a sub-folder like /@you/my-site/.
  • For URLs you build in code, prefix import.meta.env.BASE_URL, which is ./ in builds and the preview's own base path in the preview: import.meta.env.BASE_URL + 'models/chair.glb'.
  • Only import.meta.env.BASE_URL, MODE, DEV, PROD and SSR are defined in the published build. The preview doesn't read .env files, so don't rely on VITE_ variables.
  • Your project's own vite.config.js, PostCSS config or Next config is never loaded. The server configures both builds itself.
  • Tailwind @plugin and @config are refused unless the plugin is on the allowlist: @tailwindcss/typography, @tailwindcss/forms, @tailwindcss/aspect-ratio, @tailwindcss/container-queries, tailwindcss-animate, daisyui. Install the package first.
  • Avoid module-level side effects and timers that never stop; keep state in components and hooks.
jsx
// Good: works in the preview, at /@you/my-site/ and on a custom domain
<img src="media/team.jpg" alt="Our team" />

// Bad: breaks when the site is in a sub-folder
<img src="/media/team.jpg" alt="Our team" />

Styling: Tailwind v4, CSS-first #

There is no tailwind.config.js. Configuration lives in src/index.css, which belongs to you except for two managed blocks:

css
@import "tailwindcss";
/* pb:sources — managed by Devmachinist */
@source "/…/library/**/*.{js,jsx,ts,tsx}";
/* /pb:sources */
/* pb:brand — managed by Devmachinist (More → Brand) */
@theme {
  --color-brand-50: oklch(96.2% 0.018 272.314);
  /* … brand, secondary and accent shades 50–950 … */
  --font-sans: "Inter", ui-sans-serif, system-ui, sans-serif;
  --font-heading: "Fraunces", ui-serif, Georgia, serif;
}
@layer base {
  h1, h2, h3, h4, h5, h6 { font-family: var(--font-heading); }
}
/* /pb:brand */
@source "./**/*.{js,jsx,ts,tsx}";

*,*::before,*::after { box-sizing: border-box; }
body { margin: 0; font-family: ui-sans-serif, system-ui, sans-serif; }
img { max-width: 100%; }
  • pb:sources lists the component library folders on the server so Tailwind finds their classes.
  • pb:brand holds the brand colors and theme as Tailwind theme variables. Change them in More → Brand (or ask the AI), never by editing the block.
  • Everything outside the two blocks is yours: add @theme tokens, @layer rules, @import other stylesheets from src/styles/.

Brand colors #

Three aliases cover every shade from 50 to 950, filled in with Tailwind's own oklch values for the families you picked (default indigo, slate and amber):

AliasRoleExample
brand-*Actions and the active statebg-brand-600 text-white
secondary-*Surfaces, structure, texttext-secondary-700 border-secondary-200
accent-*Small highlightsbg-accent-100 text-accent-800

Use the aliases rather than fixed families like indigo-600, so a brand change restyles the whole site. Up to 8 extra named palettes can be added in the theme (for example success from emerald gives bg-success-500).

Theme options #

More → Brand → Theme writes these into the same managed block, so ordinary classes follow them:

OptionValuesWhat follows it
Heading fontGoogle Fonts or systemfont-heading, and h1–h6 automatically
Standard fontGoogle Fonts or systemfont-sans, the body text
Cornersnone, sm, md, lg, xlEvery rounded-* class
Densitycompact, cozy, roomyPadding, margin and gap (--spacing)
Shadowsnone, soft, boldEvery shadow-* class
Text sizesmall, normal, largeThe root font size (15, 16 or 17 px)
Appearancesystem, light, darkWhether dark: variants apply
Text stylesper elementBase rules for h1–h4, p, links, buttons and more

Fonts are loaded with a Google Fonts link that the builder adds to index.html. With appearance set to light or dark, dark: variants never or always apply, whatever the visitor's device says.

Packages #

Install packages from More → Packages (or let the AI do it). What happens:

  • npm runs on the server in your account's sandbox with --ignore-scripts, against the public registry (registry.npmjs.org). Install scripts (postinstall and friends) never run.
  • Only registry names are accepted, optionally with a version, range or tag: quill, three@0.170, @react-three/fiber@latest. Git, URL, file and npm: alias specs are refused.
  • Installs have network access; previews and builds don't. A package that downloads something at runtime or needs its install script won't work.
  • Missing packages imported by your code lists imports that aren't installed, with a button to install them all.
  • + Add TypeScript installs typescript and the React type definitions and writes a tsconfig.json (JS files keep working next to .tsx).
package.json is regenerated from the project's tracked packages, so install and remove packages through the builder. A dependency you type into package.json by hand is dropped the next time the workspace is set up.

Environment #

ValueWhereMeaning
import.meta.env.BASE_URLEverywhere./ in builds, /_preview/<project>/ in the preview
globalThis.__PB_API_ORIGIN__Data clientsPrefix for /_api/…; empty on the web, set by app exports and hosts elsewhere
window.__PB_PAGE__, window.__PB_PARAMS__Published siteThe page and route parts from the address (read them through route())
window.__PB_BASE__Published siteThe site's base path

The generated data clients call (globalThis.__PB_API_ORIGIN__ || '') + '/_api/<api id>'. On a published Devmachinist site that is the same origin. Android and desktop builds set it to the server's address, and a copy you host elsewhere sets it in index.html (see Hosting on other providers).

Running it on your own machine #

Push the project with git (below), then clone it anywhere with a current Node.js LTS:

bash
git clone https://github.com/you/my-site.git
cd my-site
npm install
npm run dev        # Vite dev server
npm run build      # production build into dist/
npm run preview    # serve dist/ locally

The generated vite.config.js is a plain config for exactly this:

js
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import tailwindcss from '@tailwindcss/vite'

export default defineConfig({
  plugins: [react(), tailwindcss()],
  // Relative asset URLs: the build works from any path or static host.
  base: './',
})
  • Devmachinist never loads this file; it only exists so the project runs elsewhere.
  • The pb:sources lines in src/index.css point at folders on the Devmachinist server. They aren't needed on your machine, because library components are already copied into src/components/.
  • Data and sign-in keep talking to the API on Devmachinist once __PB_API_ORIGIN__ is set. Hosting on other providers has the steps for each host.

Git #

Each workspace can be a git repository. More → Git covers it: set your name and email, commit (with ✦ Write message to draft the message from the diff), branches, remotes, push, pull and fetch.

  • git runs in your account's sandbox with hooks, custom SSH commands and the ext/file transports turned off.
  • Remotes are https:// or SSH URLs. For HTTPS, store a token for the host in More → Git; it is saved with git's credential store in your account's private sandbox home, not in the project.
  • Pull is fast-forward only unless you choose rebase.
  • The default .gitignore excludes node_modules, dist, .env, .env.local, logs and caches. It is created once and then yours.
  • Generated files are committed like any other file, so a clone runs as-is.
  • While an AI experiment branch is running, commit, push, pull, checkout and branch changes are paused (fetch still works).
bash
# On your machine, after pushing from More → Git
git pull
# edit src/components/Hero.jsx …
git commit -am "Tighter hero copy"
git push
# then More → Git → Pull in the builder

Edits pulled into the builder show up in the preview right away. Remember that the generated files are rewritten from the project's settings, so make page, brand and package changes in the builder rather than in a clone.