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

Jamesllllllllll

like-anything

Add a "Like" button anywhere on the web
Remix of maxm/ipv4-counter
Public
Like
like-anything
Home
Code
11
.claude
1
backend
1
frontend
1
.vtignore
CLAUDE.md
PAGE_LIKES_DOCUMENTATION.md
README.md
deno.json
H
index.ts
script.js
test-embed.html
Branches
1
Pull requests
Remixes
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
/
CLAUDE.md
Code
/
CLAUDE.md
Search
8/10/2025
CLAUDE.md

CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

Architecture Overview

This is a Val Town project that implements a likes tracking API using unique IDs with the following structure:

  • Val Town Platform: Built for Val Town's serverless environment using Deno runtime
  • Backend: Hono web framework with SQLite database for ID-based likes tracking
  • API Service: RESTful endpoints with CORS support for cross-origin requests
  • Entry Point: index.ts exports app.fetch as the HTTP handler

Key Components

Backend (backend/database.ts)

  • Uses Val Town's hosted SQLite service (stevekrouse/sqlite)
  • Table name: likes_by_id_v1 (increment version when changing schema)
  • Core functions: initDatabase(), recordLike(), getAllLikes(), getLikeCount(), getTotalLikes()
  • Database tracks likes by unique ID (string identifier)
  • Schema: id (TEXT PRIMARY KEY), likes (INTEGER), created_at, updated_at
  • Database initializes automatically on startup

Frontend (frontend/index.html)

  • Self-contained HTML documentation and demo page
  • Interactive testing interface for all API endpoints
  • Code examples for integration
  • Styled with custom CSS for professional appearance

Main Application (index.ts)

  • Hono app with error unwrapping for debugging and CORS support
  • Routes: / (documentation page), POST /api/like (record like), GET /api/likes/:id (get count for specific ID), GET /api/likes (all data)
  • Accepts JSON payloads with id field (string)
  • Returns updated like counts for real-time UI updates

Common Development Commands

# Run/test the application locally deno run --allow-net --allow-read index.ts # Lint code deno lint # Format code deno fmt # Type checking deno check index.ts

Val Town Specific Patterns

Database Schema Changes

When modifying the database schema, increment the table name (e.g., likes_by_id_v1 → likes_by_id_v2) rather than using ALTER TABLE operations.

API Usage

The API is designed for cross-origin requests. Example usage from any website:

// Record a like for a specific content ID fetch("https://your-val-url.val.run/api/like", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ id: "post-123", // Any unique identifier }), }) .then((res) => res.json()) .then((data) => console.log("New like count:", data.likeCount)); // Get like count for a specific ID fetch("https://your-val-url.val.run/api/likes/post-123") .then((res) => res.json()) .then((data) => console.log("Like count:", data.likeCount));

File Serving

Uses Val Town utility functions for proper file serving:

import { readFile, serveFile, } from "https://esm.town/v/std/utils@85-main/index.ts";

Error Handling

Include this pattern in Hono apps for better error visibility:

app.onError((err, c) => { throw err; });

CORS Configuration

The API includes CORS headers to allow requests from any origin:

app.use( "*", cors({ origin: "*", allowMethods: ["GET", "POST", "OPTIONS"], allowHeaders: ["Content-Type"], }), );

Configuration Notes

  • TypeScript: Configured with relaxed settings (noImplicitAny: false, strict: false)
  • Imports: Uses https://esm.sh for npm packages and https://esm.town/v/ for Val Town utilities
  • Styling: TailwindCSS via CDN script tag
  • Error Debugging: Includes <script src="https://esm.town/v/std/catch"></script> for client-side error capture
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.