Val Town Deployment Guide for Prompt Improver
This application is now fully integrated with Val Town's SQLite database for persistent storage of user data, prompt history, and templates.
- 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
- User Authentication: Simple username-based login with session management
- Prompt History: All improved prompts are saved automatically when logged in
- Favorites: Users can star their best prompts for quick access
- Search: Full-text search across prompt history
- Templates vs History:
- Templates = Pre-written examples in the library
- History = User's generated/improved prompts
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';
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.
# Test database integration
node test_database.js
# Test the main server
npm start # or however you run the Hono server locally
- Deploy the Val
- Visit the Val's URL
- Test user flow:
- Enter username to login
- Submit a prompt for improvement
- Check history appears
- Test favorites and search
POST /api/auth/login - Login with username
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
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
- 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
- User sessions persist for 7 days
- All improved prompts are saved automatically
- LocalStorage used for session persistence on frontend
-
Database not initializing
- Check Val Town SQLite is imported correctly
- Verify schema creation in database.js
-
History not saving
- Ensure user is logged in
- Check userId is passed to /api/improve endpoint
-
Module import errors
- Use BundledApp.js which has all code inline
- Val Town doesn't serve individual module files
-
Session persistence
- Sessions stored in localStorage
- Check browser storage is not disabled
-
Database Indexes: Created for common queries
idx_history_user - Fast user history lookup
idx_history_created - Chronological sorting
idx_templates_category - Template browsing
-
Caching:
- Frontend caches user data
- Templates cached after first load
-
Pagination:
- History limited to 50 items by default
- Use offset/limit for large datasets
- Authentication: Simple username-based (add password hashing for production)
- Sessions: HttpOnly cookies with 7-day expiry
- Input Validation: All user inputs sanitized
- SQL Injection: Using parameterized queries
- Add password-based authentication
- Implement OAuth providers
- Add export functionality for prompt history
- Create shareable prompt links
- Add collaborative features
- Implement prompt versioning
- Add analytics dashboard
- Create API keys for programmatic access
await database.cleanupExpiredSessions();
Val Town automatically backs up SQLite databases. For additional safety:
- Export critical data via API
- Maintain local backups of templates
- Document custom templates separately
For issues or questions:
- Check Val Town documentation: https://docs.val.town
- Review SQLite integration: https://docs.val.town/sqlite
- Test with the provided test_database.js script