Unlisted
Like
Prompt_Improver
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.
Viewing readonly version of main branch: v254View latest version
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
// Create a new Val at https://val.town
// Copy the contents of index.http.ts as your main Val
The application uses these Val Town imports:
npm:hono- Web frameworkhttps://esm.town/v/std/sqlite- Val Town SQLite database
The database schema is automatically created on first run via:
import database from './backend/database.js';
// Schema is initialized in the constructor
Since Val Town doesn't support file imports, use the bundled version:
- Use
BundledApp.jsfor the frontend (all code inline) - Keep backend logic modular for maintainability
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 improvementPOST /api/improve/resource-aware- Resource-aware improvement
GET /api/history/:userId- Get user's prompt historyGET /api/favorites/:userId- Get user's favorite promptsPOST /api/history/favorite- Toggle favorite statusDELETE /api/history- Delete history itemGET /api/stats/:userId- Get user statistics
GET /api/library/categories- Get template categoriesGET /api/library/category/:categoryKey- Get templates in categoryGET /api/library/search?q=query- Search templatesGET /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 lookupidx_history_created- Chronological sortingidx_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
// Clean expired sessions periodically
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