• Blog
  • Docs
  • Pricing
  • We’re hiring!
Log inSign up
toowired

toowired

Prompt_Improver

Unlisted
Like
Prompt_Improver
Home
Code
21
.github
1
backend
11
frontend
9
shared
1
workers
3
.vtignore
API_DOCUMENTATION.md
DEPLOY.md
DEPLOYMENT.md
README.md
VALTOWN_BENEFITS.md
deno.json
deploy.sh
H
index.http.ts
resource_example.html
test_all_endpoints.js
test_database.js
test_prompt_library.js
test_resources.js
test_ui_ux.js
val.json
Branches
3
Pull requests
Remixes
History
Environment variables
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
/
DEPLOYMENT.md
Code
/
DEPLOYMENT.md
Search
9/6/2025
Viewing readonly version of main branch: v236
View latest version
DEPLOYMENT.md

Val Town Deployment Guide for Prompt Improver

Overview

This application is now fully integrated with Val Town's SQLite database for persistent storage of user data, prompt history, and templates.

Architecture

Database Structure

  • users: Stores user accounts with profiles and preferences
  • prompt_history: Tracks all improved prompts per user (user-generated)
  • prompt_templates: Pre-written template library (curated examples)
  • sessions: User authentication sessions
  • analytics: Usage tracking and metrics

Key Features

  1. User Authentication: Simple username-based login with session management
  2. Prompt History: All improved prompts are saved automatically when logged in
  3. Favorites: Users can star their best prompts for quick access
  4. Search: Full-text search across prompt history
  5. Templates vs History:
    • Templates = Pre-written examples in the library
    • History = User's generated/improved prompts

Deployment Steps

1. Deploy to Val Town

// Create a new Val at https://val.town // Copy the contents of index.http.ts as your main Val

2. Import Dependencies

The application uses these Val Town imports:

  • npm:hono - Web framework
  • https://esm.town/v/std/sqlite - Val Town SQLite database

3. Database Initialization

The database schema is automatically created on first run via:

import database from './backend/database.js'; // Schema is initialized in the constructor

4. File Structure in Val Town

Since Val Town doesn't support file imports, use the bundled version:

  • Use BundledApp.js for the frontend (all code inline)
  • Keep backend logic modular for maintainability

5. Environment Configuration

No environment variables needed - Val Town SQLite is automatically available.

Testing

Local Testing

# Test database integration node test_database.js # Test the main server npm start # or however you run the Hono server locally

Val Town Testing

  1. Deploy the Val
  2. Visit the Val's URL
  3. Test user flow:
    • Enter username to login
    • Submit a prompt for improvement
    • Check history appears
    • Test favorites and search

API Endpoints

Authentication

  • POST /api/auth/login - Login with username

Prompt Operations

  • POST /api/improve - Improve a prompt (saves to history if logged in)
  • POST /api/improve/batch - Batch improvement
  • POST /api/improve/resource-aware - Resource-aware improvement

User Data

  • GET /api/history/:userId - Get user's prompt history
  • GET /api/favorites/:userId - Get user's favorite prompts
  • POST /api/history/favorite - Toggle favorite status
  • DELETE /api/history - Delete history item
  • GET /api/stats/:userId - Get user statistics

Templates (Pre-written Library)

  • GET /api/library/categories - Get template categories
  • GET /api/library/category/:categoryKey - Get templates in category
  • GET /api/library/search?q=query - Search templates
  • GET /api/templates/db?category=name - Get database templates

Frontend Features

User Interface

  • Login Bar: Simple username entry
  • History Modal: View, search, and manage prompt history
  • Favorites: Quick access to starred prompts
  • Templates Library: Pre-written prompt examples
  • Statistics: Track usage metrics

Data Persistence

  • User sessions persist for 7 days
  • All improved prompts are saved automatically
  • LocalStorage used for session persistence on frontend

Troubleshooting

Common Issues

  1. Database not initializing

    • Check Val Town SQLite is imported correctly
    • Verify schema creation in database.js
  2. History not saving

    • Ensure user is logged in
    • Check userId is passed to /api/improve endpoint
  3. Module import errors

    • Use BundledApp.js which has all code inline
    • Val Town doesn't serve individual module files
  4. Session persistence

    • Sessions stored in localStorage
    • Check browser storage is not disabled

Performance Optimization

  1. Database Indexes: Created for common queries

    • idx_history_user - Fast user history lookup
    • idx_history_created - Chronological sorting
    • idx_templates_category - Template browsing
  2. Caching:

    • Frontend caches user data
    • Templates cached after first load
  3. Pagination:

    • History limited to 50 items by default
    • Use offset/limit for large datasets

Security Considerations

  1. Authentication: Simple username-based (add password hashing for production)
  2. Sessions: HttpOnly cookies with 7-day expiry
  3. Input Validation: All user inputs sanitized
  4. SQL Injection: Using parameterized queries

Future Enhancements

  1. Add password-based authentication
  2. Implement OAuth providers
  3. Add export functionality for prompt history
  4. Create shareable prompt links
  5. Add collaborative features
  6. Implement prompt versioning
  7. Add analytics dashboard
  8. Create API keys for programmatic access

Maintenance

Database Cleanup

// Clean expired sessions periodically await database.cleanupExpiredSessions();

Backup Strategy

Val Town automatically backs up SQLite databases. For additional safety:

  1. Export critical data via API
  2. Maintain local backups of templates
  3. Document custom templates separately

Support

For issues or questions:

  1. Check Val Town documentation: https://docs.val.town
  2. Review SQLite integration: https://docs.val.town/sqlite
  3. Test with the provided test_database.js script
FeaturesVersion controlCode intelligenceCLIMCP
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.