No description
  • TypeScript 96.7%
  • CSS 3.1%
  • HTML 0.2%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2025-12-29 20:32:36 +00:00
.claude Initial commit 2025-12-29 13:14:51 +00:00
src feat: Replace old demo and dashboard pages with a new markdown-based note management system, adding theme toggling and relevant dependencies. 2025-12-29 14:56:06 +01:00
.gitignore Initial commit 2025-12-29 13:14:51 +00:00
bun.lock feat: Replace old demo and dashboard pages with a new markdown-based note management system, adding theme toggling and relevant dependencies. 2025-12-29 14:56:06 +01:00
bunfig.toml Initial commit 2025-12-29 13:14:51 +00:00
components.json Initial commit 2025-12-29 13:14:51 +00:00
favicon.svg Initial commit 2025-12-29 13:14:51 +00:00
index.html Initial commit 2025-12-29 13:14:51 +00:00
index.tsx Initial commit 2025-12-29 13:14:51 +00:00
package.json feat: Replace old demo and dashboard pages with a new markdown-based note management system, adding theme toggling and relevant dependencies. 2025-12-29 14:56:06 +01:00
README.md Initial commit 2025-12-29 13:14:51 +00:00
server.ts feat: Replace old demo and dashboard pages with a new markdown-based note management system, adding theme toggling and relevant dependencies. 2025-12-29 14:56:06 +01:00
tsconfig.json Initial commit 2025-12-29 13:14:51 +00:00
vite.config.ts Initial commit 2025-12-29 13:14:51 +00:00
zosite.json feat: Replace old demo and dashboard pages with a new markdown-based note management system, adding theme toggling and relevant dependencies. 2025-12-29 14:56:06 +01:00

This file provides guidance when working with code in this repository. The README.md should ALWAYS serve as an accurate, comprehensive piece of documentation for this project. It should describe the broader goals and purpose of this repository along with the technical implementation details. If any aspect of the project changes, the README.md should be updated to reflect that.

Project Notes


Documentation

This is a Zo Site - a web application running on a user's Zo computer that combines:

  • Backend: Bun + Hono server with API routes
  • Frontend: React + Vite with client-side routing, shadcn/ui components, and Tailwind CSS 4
  • Single Process: Vite runs in middleware mode (no separate dev server)

Architecture

Template Variants

When creating a new site, you can choose from several template variants:

  • blank - Minimal starting point with a welcome page
  • blog - Blog with markdown post support and listings
  • event - Event registration form with SQLite database
  • slides - Presentation slides using Reveal.js
  • data - Data dashboard with charts (Recharts) and tables
  • marketing - Professional landing page with hero, features, pricing

The variant is set via the VITE_ZO_SITE_DEMO_VARIANT environment variable in zosite.json. All variant demo components are included in the template at src/pages/demos/ and the root route shows the selected variant.

To change or remove the demo:

  1. Delete src/pages/demos/ directory
  2. Update src/App.tsx to remove variant routing
  3. Create your own pages and routes

File Structure

.
├── server.ts              # Main server (Hono + Vite middleware)
├── index.html             # HTML entry point for React
├── favicon.svg            # Site favicon (replace with your own)
├── vite.config.ts         # Vite configuration
├── package.json           # Dependencies and scripts
├── zosite.json            # Zo deployment config (ports, env vars)
├── backend-lib/
│   └── zo-api.ts         # Helper for calling Zo API
└── src/
    ├── main.tsx          # React entry point
    ├── App.tsx           # Router setup with variant routing
    ├── styles.css        # Global styles
    └── pages/
        ├── Home.tsx      # Original home page
        ├── Dashboard.tsx # Example dashboard with charts
        └── demos/        # Variant demo components
            ├── blank-demo.tsx
            ├── blog-demo.tsx
            ├── event-demo.tsx
            ├── slides-demo.tsx
            ├── data-demo.tsx
            └── marketing-demo.tsx

Development vs Production

Development Mode (bun run dev):

  • Single Bun process running server.ts
  • Vite in middleware mode transforms files on-the-fly
  • API routes: /api/* handled by Hono
  • React app: served via Vite transforms (HMR disabled, use bun --hot for server restart)
  • Client-side routing: any non-API, non-file route falls back to index.html
  • Environment: Site runs at an internal authenticated URL accessible only to you (private site on your Zo computer)

Production Mode (bun run prod):

  • Builds React app to dist/ using Vite
  • Bun serves static files from dist/ via hono/bun serveStatic
  • API routes still handled by Hono
  • SPA fallback: all non-API routes serve dist/index.html
  • Environment: Site is published and accessible to anyone on the internet at a public URL

NEVER use the scripts bun run dev or bun run prod. The Zo system handles running the site in the correct mode based on context. All process management of the server is handled by Zo. Never restart or stop the server manually.

Key Technologies

⚠️ IMPORTANT: This is BUN + HONO (NOT Node.js + Express)

This application uses:

  • Bun as the runtime (NOT Node.js)
  • Hono as the web framework (NOT Express)

Do not use Node.js APIs or Express patterns. Use Bun and Hono equivalents.

Bun Runtime

  • JavaScript runtime (NOT Node.js or Deno)
  • Use bun add <package> to install dependencies
  • Built-in TypeScript support
  • Built-in SQLite via import { Database } from "bun:sqlite"
  • File API: Bun.file() for reading/writing files
  • Process spawning: Bun.spawn() for running commands

Hono Framework

  • Lightweight web framework designed for Bun
  • Documentation: https://honojs.dev/llms-small.txt
  • Import from hono for core, hono/bun for Bun-specific features like serveStatic

Serving Static Files (Bun-specific):

import { serveStatic } from 'hono/bun'

app.use('/static/*', serveStatic({ root: './' }))
app.use('/favicon.ico', serveStatic({ path: './favicon.ico' }))
app.get('*', serveStatic({ path: './static/fallback.txt' }))

// You can reach outside the project root to files in the user's workspace
app.get('/workspace-file', serveStatic({ path: '../some/dir/file.txt' }))
app.get('/absolute-file', serveStatic({ path: '/home/user/file.txt' }))

// Custom MIME types
app.get('/media/*', serveStatic({
  mimes: {
    m3u8: 'application/vnd.apple.mpegurl',
    ts: 'video/mp2t',
  },
}))

Hono Routing:

// REST API endpoints
app.get('/', (c) => c.json({ items: [] }))
app.post('/', (c) => c.json({ created: true }, 201))
app.get('/:id', (c) => c.json({ id: c.req.param('id') }))

// Middleware
import { basicAuth } from 'hono/basic-auth'
app.use('/admin/*', basicAuth({ username: 'admin', password: 'secret' }))

// Multiple middlewares are processed in order
app.use(logger())
app.use('/posts/*', cors())
app.post('/posts/*', basicAuth())

React + Vite

  • React for UI components
  • Vite handles bundling and transforms
  • Dependencies installed via bun add (NOT CDN imports) - all packages bundled by Vite
  • React Router for client-side routing
  • Styling: Tailwind CSS 4 configured with @tailwindcss/vite plugin
  • UI Components: shadcn/ui already set up and configured - components can be added via bunx shadcn@latest add <component-name>
  • Icons: Lucide React icons included and ready to use
  • Sample Implementation: See src/pages/Dashboard.tsx for an example of shadcn/ui components in use (sidebar, charts, data tables, etc.)

Common Tasks

Adding API Routes

Add routes in server.ts before the Vite middleware:

app.get("/api/example", async (c) => {
  return c.json({ data: "example" });
});

Adding React Components

Create components in src/:

// src/components/MyComponent.tsx
import React from "react";

export default function MyComponent() {
  return <div>Hello</div>;
}

Add routes in src/App.tsx:

import MyPage from "./pages/MyPage";

<Routes>
  <Route path="/my-page" element={<MyPage />} />
</Routes>

Calling Zo API from Backend

Use the helper in backend-lib/zo-api.ts:

import { callZo } from "./backend-lib/zo-api";

app.post("/api/ask-zo", async (c) => {
  const { question } = await c.req.json();
  
  const result = await callZo(question, {
    outputFormat: {
      type: "object",
      properties: { answer: { type: "string" } },
      required: ["answer"]
    }
  });
  
  return c.json(result);
});

Static Files

In production, serve from dist/assets/. In development, Vite handles asset imports.

For files outside the build (e.g., user's workspace files):

app.get("/myfile", async (c) => {
  const file = Bun.file("/path/to/file");
  return new Response(file);
});

Database

This application is database-agnostic and doesn't include a database by default. For most use cases, SQLite is recommended.

Using Bun's Built-in SQLite:

import { Database } from "bun:sqlite";

// Create/open database
const db = new Database("mydb.sqlite");

// Create table
db.run(`
  CREATE TABLE IF NOT EXISTS users (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    name TEXT NOT NULL,
    email TEXT UNIQUE
  )
`);

// Insert data
const insert = db.prepare("INSERT INTO users (name, email) VALUES (?, ?)");
insert.run("John Doe", "john@example.com");

// Query data
const query = db.query("SELECT * FROM users WHERE name = ?");
const users = query.all("John Doe");

// Close when done
db.close();

In a Hono route:

app.get("/api/users", (c) => {
  const db = new Database("mydb.sqlite");
  const users = db.query("SELECT * FROM users").all();
  db.close();
  return c.json({ users });
});

app.post("/api/users", async (c) => {
  const { name, email } = await c.req.json();
  const db = new Database("mydb.sqlite");
  
  try {
    const insert = db.prepare("INSERT INTO users (name, email) VALUES (?, ?)");
    insert.run(name, email);
    db.close();
    return c.json({ success: true }, 201);
  } catch (error) {
    db.close();
    return c.json({ error: "Failed to create user" }, 400);
  }
});

Scripts

  • bunx tsc --noEmit - Type check

Important Notes

Server-Side vs Client-Side

  • Server code: server.ts, backend-lib/ - runs on Bun
  • Client code: src/ - runs in browser, bundled by Vite
  • Install ALL dependencies via bun add (React, etc.) - Vite bundles them

Environment Variables

  • NODE_ENV=production switches to production mode
  • ZO_CLIENT_IDENTITY_TOKEN required for calling Zo API
  • VITE_ZO_SITE_DEMO_VARIANT determines which demo variant is shown (blank, blog, event, slides, data, marketing)
  • Access server vars via process.env.VAR_NAME in server code
  • Access client vars prefixed with VITE_ via import.meta.env.VITE_VAR_NAME in React code

File System Access

The server runs on the user's Zo computer and can:

  • Read/write any file on the system
  • Execute commands via Bun.spawn()
  • Access local databases

Configuration

zosite.json defines:

{
  "name": "My Site",
  "local_port": 12345,
  "entrypoint": "bun run dev",
  "env": {
    "VITE_ZO_SITE_DEMO_VARIANT": "blank"
  },
  "publish": {
    "label": "My Site",
    "type": "http",
    "entrypoint": "bun run prod",
    "published_port": 12346,
    "env": {
      "NODE_ENV": "production",
      "ZO_CLIENT_IDENTITY_TOKEN": "none",
      "VITE_ZO_SITE_DEMO_VARIANT": "blank"
    }
  }
}
  • Top-level env: Environment variables for development mode
  • publish.env: Environment variables for production mode
  • Variables prefixed with VITE_ are exposed to client-side code via Vite

Deployment

The site exports { fetch, port } from server.ts for Zo's deployment system. The same code runs in both dev and production - mode is controlled by NODE_ENV.