# StoryGen AI

AI-powered user story and feature list generator for business users.

## What it does

1. **Business user provides input** — free-text description, PDF/DOCX/DOC/TXT/MD upload, or URL of an existing application.
2. **AI generates a detailed user story** — markdown format with overview, actors, goals, workflow, acceptance criteria, assumptions.
3. **User edits the story** in-app if changes are needed.
4. **On confirmation, AI generates a detailed feature list** with these columns:

   | Sr. No | Feature Cluster | Feature | Detailed Workflow | Feature Description | Table Name | Table Columns | Actor / User | Related AI Agent |

5. **Export the feature list to CSV.**

## Stack

| Layer     | Choice                                          |
|-----------|-------------------------------------------------|
| Framework | Laravel 11 (PHP 8.2+)                           |
| Database  | MySQL 8                                         |
| Auth      | Email + password (built-in)                     |
| Frontend  | Blade + vanilla JS                              |
| AI        | Anthropic Claude API (via Guzzle HTTP client)   |
| Model     | `claude-opus-4-7` (configurable via env)        |

## Local setup

```bash
cp .env.example .env
composer install
php artisan key:generate
# Configure DB_* and ANTHROPIC_API_KEY in .env
php artisan migrate --seed
php artisan serve
```

Visit `http://localhost:8000`. The seeder creates a demo user:

- Email: `demo@storygen.local`
- Password: `ChangeMe!234`

Or register a new account at `/register`.

## Required environment variables

- `DB_*` — MySQL connection details
- `ANTHROPIC_API_KEY` — from https://console.anthropic.com
- `ANTHROPIC_MODEL` — defaults to `claude-opus-4-7`. Set to `claude-sonnet-4-6` for cheaper/faster generation.

## Flow

```
[Dashboard] → [New Story]
                 ↓ (text / file upload / URL)
            [Extract content]
                 ↓
            [Claude generates user story]
                 ↓
            [User reviews & edits]
                 ↓
            [Confirm]
                 ↓
            [Claude generates feature list JSON]
                 ↓
            [View features table] → [Export CSV]
```

## Project layout

- `app/Http/Controllers/StoryController.php` — full story lifecycle (create → edit → confirm → features → export)
- `app/Services/AnthropicClient.php` — thin Guzzle client for the Messages API
- `app/Services/InputProcessor.php` — text/PDF/DOCX/URL extraction (smalot/pdfparser, phpoffice/phpword, Guzzle)
- `app/Services/StoryGenerator.php` — user story generation prompt
- `app/Services/FeatureListGenerator.php` — feature list generation prompt + JSON parsing
- `resources/views/stories/` — Blade views for each step
- `database/migrations/` — users/sessions/stories/features

## Notes

- Input content is truncated to 120K characters before being sent to Claude.
- Feature-list generation uses a JSON-shaped prompt and robustly parses the response (strips code fences, slices to the outermost `[...]`).
- All story operations are scoped to the authenticated user.
