Skip to content

RoboBaby/PromptBuilder

Repository files navigation

Prompt Builder

A comprehensive system for managing, versioning, and serving system prompts for LLM applications.

Overview

Prompt Builder is a dual-stack application that provides:

  1. Laravel Admin Interface - Full-featured web UI for editing and managing prompts
  2. Slim/RoadRunner API - High-performance public API for serving prompts to external services

Features

  • Version Control: Track different versions of prompts with draft/active/archived status
  • Sectioned Organization: Organize prompt content into logical sections (identity, safety, style, etc.)
  • Granular Editing: Edit individual lines within prompts
  • Drag-and-Drop Reordering: Easily reorder prompt lines and sections
  • Section Filtering: Work on specific sections at a time
  • Enable/Disable: Toggle individual lines or entire sections without deletion
  • Full-Text Rendering: Generate complete prompts for API consumption
  • Statistics: Track prompt length, line counts, and usage metrics
  • Cloning: Duplicate versions for iterative development
  • Preview Mode: View rendered prompts before activation

Architecture

┌─────────────────────────────────────────────────────────────┐
│                     Prompt Builder System                    │
├─────────────────────────────────────────────────────────────┤
│                                                               │
│  ┌──────────────────┐           ┌──────────────────┐        │
│  │  Laravel Admin   │           │  Slim/RoadRunner │        │
│  │    Interface     │           │       API        │        │
│  │                  │           │                  │        │
│  │ - Version Mgmt   │           │ - Get Active     │        │
│  │ - Line Editor    │           │ - Get by Version │        │
│  │ - Section Mgmt   │           │ - List Versions  │        │
│  │ - Preview        │           │ - Statistics     │        │
│  └────────┬─────────┘           └────────┬─────────┘        │
│           │                              │                  │
│           └──────────────┬───────────────┘                  │
│                          │                                  │
│                   ┌──────▼──────┐                           │
│                   │  PostgreSQL │                           │
│                   │  Database   │                           │
│                   └─────────────┘                           │
│                                                               │
└─────────────────────────────────────────────────────────────┘

Database Schema

Tables

  1. prompt_version - Stores versions of prompts
  2. prompt_section - Defines organizational sections
  3. prompt_line - Individual lines of prompt content

See database/schema.sql for complete DDL.

Directory Structure

PromptBuilder/
├── app/
│   ├── Models/              # Eloquent models
│   │   ├── PromptVersion.php
│   │   ├── PromptSection.php
│   │   └── PromptLine.php
│   ├── Services/            # Business logic layer
│   │   └── PromptService.php
│   └── Http/
│       └── Controllers/     # Laravel controllers
│           ├── PromptVersionController.php
│           ├── PromptLineController.php
│           ├── PromptSectionController.php
│           └── PromptApiController.php
├── routes/
│   ├── web.php             # Laravel web routes
│   └── api.php             # Laravel API routes
├── resources/
│   └── views/
│       └── prompts/        # Blade templates
│           ├── layout.blade.php
│           ├── index.blade.php
│           ├── edit.blade.php
│           ├── show.blade.php
│           └── create.blade.php
├── database/
│   └── migrations/         # Database migrations
├── SLIM_API_INTEGRATION.md # Slim/RoadRunner setup guide
└── README.md               # This file

Installation

Requirements

  • PHP 8.1+
  • PostgreSQL 12+
  • Composer
  • Node.js & NPM (for frontend assets)

Setup Laravel Backend

  1. Clone the repository
git clone <repository-url>
cd PromptBuilder
  1. Install dependencies
composer install
npm install
  1. Configure environment
cp .env.example .env
# Edit .env with your database credentials
  1. Run migrations
php artisan migrate
  1. Seed sections (optional)
php artisan db:seed --class=PromptSectionSeeder
  1. Start Laravel server
php artisan serve

Visit http://localhost:8000 to access the admin interface.

Setup Slim/RoadRunner API

See SLIM_API_INTEGRATION.md for complete setup instructions.

Quick start:

# Install Slim dependencies
composer require slim/slim slim/psr7

# Download RoadRunner
wget https://github.com/roadrunner-server/roadrunner/releases/download/v2023.3.0/roadrunner-2023.3.0-linux-amd64.tar.gz
tar -xzf roadrunner-*.tar.gz

# Run RoadRunner
./rr serve

API available at http://localhost:8080/api/v1/

Usage

Admin Interface (Laravel)

Creating a New Version

  1. Navigate to "Create Version"
  2. Enter:
    • Prompt Name (e.g., "AskGVT")
    • Version Label (e.g., "v2025-10-28")
    • Status (draft/active/archived)
    • Notes (optional)
  3. Click "Create Version"

Editing Prompt Lines

  1. Select a version from the list
  2. Click "Edit"
  3. Use the editor to:
    • Add new lines with "+" button
    • Edit existing lines inline
    • Drag lines to reorder
    • Toggle enabled/disabled
    • Move lines between sections
    • Delete unwanted lines
  4. Click "Save All Changes"

Activating a Version

  1. From the versions list, click the activation button
  2. Confirm - this will deactivate other versions with the same name
  3. The API will now serve this version as "active"

Cloning a Version

  1. Click the clone button on any version
  2. Enter a new version label
  3. Add notes about the changes
  4. Edit the cloned version

API Usage (Slim/RoadRunner)

Get Active Prompt

curl http://localhost:8080/api/v1/prompts/AskGVT/active

Response:

{
  "success": true,
  "data": {
    "prompt_name": "AskGVT",
    "version_id": 1,
    "version_label": "v2025-10-28",
    "prompt": "Your system is AskGVT...",
    "generated_at": "2025-10-28T12:00:00+00:00"
  }
}

Get Specific Version

curl http://localhost:8080/api/v1/prompts/versions/1

Get Version by Label

curl http://localhost:8080/api/v1/prompts/AskGVT/versions/v2025-10-28

List All Versions

curl http://localhost:8080/api/v1/prompts/AskGVT/versions

Get Statistics

curl http://localhost:8080/api/v1/prompts/versions/1/stats

See SLIM_API_INTEGRATION.md for complete API documentation.

Models

PromptVersion

Represents a version of a prompt.

Key Methods:

  • renderPrompt() - Generate full text output
  • renderPromptWithSections() - Generate output with section headers
  • cloneVersion() - Duplicate a version
  • enabledLines() - Get only enabled lines
  • linesBySection() - Get lines grouped by section

PromptSection

Represents an organizational section.

Key Methods:

  • linesForVersion() - Get lines for a specific version
  • reorder() - Reorder sections
  • getNextOrderIndex() - Get next available position

PromptLine

Represents an individual line of content.

Key Methods:

  • moveToSection() - Move line to different section
  • reorder() - Reorder lines within a section
  • duplicateToVersion() - Copy line to another version

Service Layer

PromptService

Centralized business logic for all prompt operations.

Key Methods:

  • Version management: getVersions(), createVersion(), updateVersion(), deleteVersion()
  • Line management: getLines(), createLine(), updateLine(), deleteLine(), reorderLines()
  • Section management: getSections(), createSection(), updateSection(), deleteSection()
  • Rendering: renderPrompt(), renderActivePrompt()
  • Statistics: getVersionStats()

Controllers

Web Controllers (Laravel)

  • PromptVersionController - Manages versions (CRUD, clone, activate)
  • PromptLineController - Manages individual lines (CRUD, reorder, move)
  • PromptSectionController - Manages sections (CRUD, reorder)

API Controller (Laravel/Slim)

  • PromptApiController - Public API for external services

Routes

Web Routes (Admin Interface)

GET  /prompts                    - List all versions
GET  /prompts/create             - Create new version form
POST /prompts                    - Store new version
GET  /prompts/{id}               - View version
GET  /prompts/{id}/edit          - Edit version
PUT  /prompts/{id}               - Update version
DELETE /prompts/{id}             - Delete version

POST /prompts/{id}/clone         - Clone version
POST /prompts/{id}/activate      - Activate version
GET  /prompts/{id}/render        - Render full prompt
GET  /prompts/{id}/stats         - Get statistics

GET  /lines                      - Get lines (filtered)
POST /lines                      - Create line
PUT  /lines/{id}                 - Update line
DELETE /lines/{id}               - Delete line
POST /lines/reorder              - Reorder lines
POST /lines/{id}/move            - Move line to section

GET  /sections                   - List sections
POST /sections                   - Create section
PUT  /sections/{id}              - Update section
DELETE /sections/{id}            - Delete section
POST /sections/reorder           - Reorder sections

API Routes (Public)

GET /api/v1/health                                          - Health check
GET /api/v1/prompts/{name}/active                          - Get active prompt
GET /api/v1/prompts/versions/{id}                          - Get by version ID
GET /api/v1/prompts/{name}/versions/{label}                - Get by version label
GET /api/v1/prompts/{name}/versions                        - List versions
GET /api/v1/prompts/versions/{id}/stats                    - Get statistics

Frontend Technologies

  • Bootstrap 5 - UI framework
  • jQuery - DOM manipulation and AJAX
  • SortableJS - Drag-and-drop functionality
  • Bootstrap Icons - Icon library

Database Indexes

Recommended indexes for performance:

CREATE INDEX idx_prompt_version_name_status ON prompt_version(prompt_name, status);
CREATE INDEX idx_prompt_version_name_label ON prompt_version(prompt_name, version_label);
CREATE INDEX idx_prompt_line_version_section ON prompt_line(version_id, section_id);
CREATE INDEX idx_prompt_line_order ON prompt_line(order_index);
CREATE INDEX idx_prompt_section_order ON prompt_section(order_index);

Best Practices

Version Management

  1. Use semantic versioning or date-based labels
  2. Keep drafts for work-in-progress changes
  3. Only one active version per prompt name
  4. Archive old versions instead of deleting
  5. Clone before major changes to preserve history

Content Organization

  1. Use sections to organize related content
  2. Keep lines focused - one concept per line
  3. Use meaningful section keys (lowercase, underscore-separated)
  4. Order sections logically (identity → rules → examples)
  5. Disable, don't delete when testing changes

API Integration

  1. Cache rendered prompts in your application
  2. Use version IDs for deterministic retrieval
  3. Monitor stats endpoint for prompt growth
  4. Handle 404s gracefully for missing versions
  5. Use include_sections for debugging only

Testing

Unit Tests

php artisan test

API Tests

# Test health check
curl http://localhost:8080/api/v1/health

# Test active prompt retrieval
curl http://localhost:8080/api/v1/prompts/AskGVT/active

# Test version listing
curl http://localhost:8080/api/v1/prompts/AskGVT/versions

Performance Tuning

Database

  • Use connection pooling
  • Add indexes on frequently queried columns
  • Consider read replicas for API

API

  • Implement response caching (Redis, Memcached)
  • Use RoadRunner for concurrent request handling
  • Monitor worker pool size

Frontend

  • Minimize DOM operations
  • Lazy-load sections with many lines
  • Debounce auto-save operations

Security

Authentication

Add authentication middleware:

  • Laravel: Use built-in auth or Sanctum
  • Slim: Implement API key middleware

Authorization

  • Restrict write operations to admin users
  • Rate limit public API endpoints
  • Validate all inputs

Best Practices

  • Use prepared statements (implemented)
  • Sanitize user input
  • Enable HTTPS in production
  • Regular security audits

Troubleshooting

Database Connection Issues

# Check PostgreSQL is running
sudo systemctl status postgresql

# Test connection
psql -h localhost -U postgres -d prompt_builder

Laravel Issues

# Clear cache
php artisan cache:clear
php artisan config:clear
php artisan route:clear

# Check logs
tail -f storage/logs/laravel.log

API Issues

# Check RoadRunner status
./rr reset

# View logs
tail -f .rr.log

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests
  5. Submit a pull request

License

[Your License Here]

Support

For issues and questions:

  • GitHub Issues: [repository-url]/issues
  • Documentation: See SLIM_API_INTEGRATION.md
  • Email: [your-email]

Changelog

v1.0.0 (2025-10-28)

  • Initial release
  • Laravel admin interface
  • Slim/RoadRunner API
  • Version management
  • Section organization
  • Line editing with drag-and-drop
  • Statistics and reporting

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published