Aller au contenu

Prompt GPT gabarit

De Marmits Wiki

✅ Exemple Gabarit : Prompt multi-langages (PHP + JS + SQL)

```markdown
Crée une mini-application qui :
- [Décris ton objectif ici, ex. : "Gérer une liste de tâches avec ajout, suppression et affichage"]
- Implémente la logique en **PHP 8.2** (backend), **JavaScript ES2023** (frontend) et **SQL** (base de données PostgreSQL 16)
- Fournit :
  - Un bloc par fichier avec le nom du fichier en commentaire
  - Les commandes pour exécuter le projet
  - Aucun texte en dehors des blocs de code

Structure attendue :
```
project/
├─ public/
│   ├─ index.html
│   ├─ script.js
├─ src/
│   └─ app.php
├─ db/
│   └─ schema.sql
└─ README.md
```

---
```sql
-- file: db/schema.sql
-- dialect: postgresql
CREATE TABLE tasks (
    id SERIAL PRIMARY KEY,
    title VARCHAR(255) NOT NULL,
    done BOOLEAN DEFAULT FALSE
);
```

```php
# file: src/app.php
<?php
declare(strict_types=1);

header('Content-Type: application/json');

$pdo = new PDO('pgsql:host=localhost;dbname=tasks_db', 'user', 'password');

$method = $_SERVER['REQUEST_METHOD'];

if ($method === 'GET') {
    $stmt = $pdo->query('SELECT * FROM tasks ORDER BY id DESC');
    echo json_encode($stmt->fetchAll(PDO::FETCH_ASSOC));
} elseif ($method === 'POST') {
    $data = json_decode(file_get_contents('php://input'), true);
    $stmt = $pdo->prepare('INSERT INTO tasks (title) VALUES (:title)');
    $stmt->execute(['title' => $data['title']]);
    echo json_encode(['status' => 'ok']);
}
```


```javascript
// file: public/script.js
async function fetchTasks() {
  const res = await fetch('/src/app.php');
  const tasks = await res.json();
  const list = document.getElementById('taskList');
  list.innerHTML = '';
  tasks.forEach(t => {
    const li = document.createElement('li');
    li.textContent = t.title;
    list.appendChild(li);
  });
}

async function addTask() {
  const input = document.getElementById('taskInput');
  await fetch('/src/app.php', {
    method: 'POST',
    headers: {'Content-Type': 'application/json'},
    body: JSON.stringify({title: input.value})
  });
  input.value = '';
  fetchTasks();
}

fetchTasks();
```

```bash
# file: README.md
# Commandes pour exécuter
# 1. Créer la base et appliquer le schéma
psql -U user -d tasks_db -f db/schema.sql

# 2. Lancer un serveur PHP
php -S localhost:8000 -t public
```