• Townie
    AI
  • Blog
  • Docs
  • Pricing
  • We’re hiring!
Log inSign up
dinavinter

dinavinter

registry

Public
Like
registry
Home
Code
7
README.md
config.json
H
file
C
sync
test-kv
H
zon
H
zons
Branches
1
Pull requests
Remixes
1
History
Environment variables
1
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Sign up now
Code
/
README.md
Code
/
README.md
Search
6/7/2025
Viewing readonly version of main branch: v189
View latest version
README.md

Zon File Management System

A comprehensive file management system for Val Town that handles different file types including HTTP, cron, email, JSON, and more with collaborative editing capabilities.

Features

  • Multi-file type support: HTTP, cron, email, JSON, TypeScript, and more
  • Collaborative editing: Real-time collaboration using YJS with ts-editor component
  • TypeScript editor: Full-featured TypeScript editor with syntax highlighting
  • File type detection: Automatic file type detection and appropriate handling
  • Local-first architecture: Yjs data is always available locally with KV backup
  • Real-time sync: Automatic synchronization between Yjs and KV storage
  • Configurable URLs: All service URLs are configurable via config.json

Architecture

Data Flow

  1. Sync Service (/sync):

    • Periodically syncs Val Town files to Yjs documents
    • Backs up all changes to KV storage individually
    • Sets up observers for real-time KV backup
  2. HTTP Services (/zons, /zon, /file):

    • Middleware: Ensures Yjs is populated from KV on first request
    • Handlers: Use only Yjs as data source for consistent performance
    • Real-time: Get live updates when Yjs connects to remote
  3. KV Storage: Acts as persistent backup and bootstrap data source

Benefits

  • Always Available: Yjs data is guaranteed to be available locally
  • Real-time Updates: When Yjs connects, get live collaborative updates
  • Performance: No API calls in request handlers, only local Yjs access
  • Resilience: KV backup ensures data persistence across restarts

Project Structure

├── config.json          # Configuration file with URLs and file type definitions
├── zons                 # Main gallery view showing all zons (HTTP)
├── zon                  # Individual zon view with file listings (HTTP)  
├── file                 # File editor interface with TypeScript support (HTTP)
├── sync                 # Background sync service for YJS collaboration (Cron)
└── README.md           # This file

Configuration

The system uses /config.json for configuration:

{ "urls": { "zons": "https://zons.val.run", // Main gallery URL "zon": "https://zon.val.run", // Individual zon view URL "files": "https://svc.val.run" // File editor URL }, "editor": { "yjs": { "room": "@vals", // YJS collaboration room "url": "wss://hp.cfapps.us10-001.hana.ondemand.com" // YJS WebSocket URL } }, "fileTypes": { // File type definitions with icons, colors, templates, etc. } }

File Types Supported

  • HTTP (http) - Web endpoints and APIs
  • Cron (cron) - Scheduled tasks
  • Email (email) - Email handlers
  • JSON (json) - Configuration and data files
  • TypeScript (ts) - General TypeScript files
  • JavaScript (js) - JavaScript files
  • Markdown (md) - Documentation files

Routing

Main Gallery (/zons)

  • GET / - Main gallery showing all zons
  • Displays all available zons with metadata

Zon File Browser (/zon)

  • GET / - Redirects to main gallery
  • GET /{zon-name} - View files in specific zon
  • GET /{zon-name}/files - API endpoint returning JSON list of files
  • Groups files by type and shows file metadata

File Editor (/file)

  • GET / - Redirects to main gallery (configurable)
  • GET /{zon-name}/{file-name} - Edit specific file with ts-editor
  • GET /{zon-name}/{file-name}/raw - Get raw file content as JSON
  • POST /{zon-name}/{file-name} - Save file changes

Background Sync (/sync)

  • Cron job that syncs Val Town files to YJS documents
  • Enables real-time collaborative editing
  • Runs periodically to keep YJS documents up to date

Usage Flow

  1. Browse zons: Visit main gallery to see all available zons
  2. Select zon: Click on a zon to view its files grouped by type
  3. Edit file: Click on a file to open it in the collaborative editor
  4. Save changes: Use the Save button to persist changes back to Val Town
  5. Run HTTP files: Use the Run button to test HTTP endpoints

API Integration

The system integrates with:

  • Yjs: Primary data source for real-time collaborative editing
  • KV Storage: Backup data source when Yjs is not available or still connecting
  • ts-editor: For TypeScript/JavaScript editing with syntax highlighting

Data Flow

  1. Sync Service: Periodically syncs Val Town files to Yjs documents and backs them up to KV storage
  2. Middleware: Ensures Yjs is populated from KV storage on first request
  3. HTTP Services: Use only Yjs as data source for consistent performance
  4. Real-time Updates: Yjs observers automatically backup changes to KV storage

KV Storage Structure

  • yjs:val:{valName} - Val metadata (name, id, files list, etc.)
  • yjs:file:{valName}:{fileName} - File metadata (type, path, etc.)
  • yjs:text:{valName}:{fileName} - File content (up to 1MB per file)

Middleware Architecture

Each HTTP service includes middleware that:

  1. Checks if Yjs has data locally
  2. If empty, syncs from KV storage to populate Yjs
  3. Ensures handlers always have data available in Yjs
  4. Allows real-time updates when Yjs connects to remote

Development

  • All URLs are configurable via config.json
  • File types can be extended by adding to the fileTypes configuration
  • Authorization is currently disabled for development (returns true)
  • Error handling includes proper error propagation and user feedback
FeaturesVersion controlCode intelligenceCLI
Use cases
TeamsAI agentsSlackGTM
DocsShowcaseTemplatesNewestTrendingAPI examplesNPM packages
PricingNewsletterBlogAboutCareers
We’re hiring!
Brandhi@val.townStatus
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Open Source Pledge
Terms of usePrivacy policyAbuse contact
© 2025 Val Town, Inc.