# Sciences Afrique - Guide de Développement

## 🚀 Démarrage Rapide

### Installation
```bash
# Cloner le projet
git clone <repository>
cd sciences-afrique

# Installer les dépendances
composer install
npm install

# Configuration
cp .env.example .env
php artisan key:generate

# Base de données
php artisan migrate
php artisan db:seed

# Démarrer le serveur
php artisan serve
npm run dev
```

### Développement Complet
```bash
composer run dev
```

---

## 📁 Structure du Projet

```
sciences-afrique/
├── app/
│   ├── Http/
│   │   ├── Controllers/
│   │   │   ├── Api/              # Contrôleurs API
│   │   │   ├── Admin/            # Contrôleurs Admin
│   │   │   ├── Teacher/          # Contrôleurs Professeur
│   │   │   ├── Auth/             # Contrôleurs Authentification
│   │   │   ├── GamificationController.php
│   │   │   ├── PaymentController.php
│   │   │   └── ...
│   │   └── Middleware/
│   ├── Models/
│   │   ├── User.php
│   │   ├── Course.php
│   │   ├── Badge.php
│   │   ├── Payment.php
│   │   ├── UserPoint.php
│   │   └── ...
│   ├── Services/
│   │   ├── GamificationService.php
│   │   ├── PaymentServiceInterface.php
│   │   ├── StripePaymentService.php
│   │   └── ...
│   ├── Notifications/
│   │   ├── EnrollmentConfirmation.php
│   │   ├── AssignmentDeadlineReminder.php
│   │   ├── BadgeEarned.php
│   │   └── LiveSessionReminder.php
│   └── Providers/
├── database/
│   ├── migrations/
│   ├── seeders/
│   └── factories/
├── routes/
│   ├── web.php
│   └── api.php
├── resources/
│   ├── views/
│   ├── css/
│   └── js/
├── tests/
│   ├── Feature/
│   └── Unit/
└── ...
```

---

## 🔌 API REST

### Base URL
```
http://localhost:8000/api/v1
```

### Authentification
Utiliser Laravel Sanctum pour les tokens:
```bash
php artisan install:api
```

### Exemples de Requêtes

#### Récupérer les facultés
```bash
curl http://localhost:8000/api/v1/faculties
```

#### Rechercher des cours
```bash
curl "http://localhost:8000/api/v1/search/courses?q=PHP&faculty_id=1"
```

#### S'inscrire à un cours (authentifié)
```bash
curl -X POST http://localhost:8000/api/v1/enrollments \
  -H "Authorization: Bearer TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"course_id": 1}'
```

#### Récupérer mon profil
```bash
curl -H "Authorization: Bearer TOKEN" \
  http://localhost:8000/api/v1/profile
```

---

## 🎮 Gamification

### Ajouter des Points
```php
use App\Services\GamificationService;

$gamification = app(GamificationService::class);
$gamification->addPoints($user, 10, 'Inscription au cours');
```

### Vérifier les Badges
```php
$badges = $gamification->getUserBadges($user);
```

### Obtenir le Classement
```php
$leaderboard = $gamification->getLeaderboard(10);
```

---

## 💳 Paiements

### Créer un Paiement
```php
use App\Services\PaymentServiceInterface;

$paymentService = app(PaymentServiceInterface::class);
$payment = $paymentService->createPayment(
    $user,
    99.99,
    'Inscription au cours Premium',
    'course',
    1
);
```

### Traiter un Paiement
```php
$paymentService->processPayment($payment);
```

### Rembourser un Paiement
```php
$paymentService->cancelPayment($payment);
```

---

## 📧 Notifications

### Envoyer une Notification
```php
use App\Notifications\EnrollmentConfirmation;

$user->notify(new EnrollmentConfirmation($enrollment));
```

### Types de Notifications
- `EnrollmentConfirmation` - Confirmation d'inscription
- `AssignmentDeadlineReminder` - Rappel de devoir
- `BadgeEarned` - Badge débloqué
- `LiveSessionReminder` - Session en direct

---

## 🧪 Tests

### Exécuter tous les tests
```bash
php artisan test
```

### Exécuter les tests d'une classe
```bash
php artisan test tests/Feature/EnrollmentTest.php
```

### Exécuter avec couverture
```bash
php artisan test --coverage
```

### Tests Disponibles
- `EnrollmentTest` - Tests d'inscription
- `AssignmentTest` - Tests de devoirs
- `FacultyTest` - Tests de facultés
- `GamificationServiceTest` - Tests de gamification
- `PaymentServiceTest` - Tests de paiements

---

## 🔍 Recherche

### Recherche Globale
```bash
curl "http://localhost:8000/api/v1/search?q=PHP"
```

### Recherche de Cours
```bash
curl "http://localhost:8000/api/v1/search/courses?q=PHP&faculty_id=1&is_certification=true"
```

### Recherche de Facultés
```bash
curl "http://localhost:8000/api/v1/search/faculties?q=Science"
```

---

## 📊 Rapports

### Rapport de Progression
```bash
curl -H "Authorization: Bearer TOKEN" \
  http://localhost:8000/api/v1/reports/progress
```

### Rapport de Performance
```bash
curl -H "Authorization: Bearer TOKEN" \
  http://localhost:8000/api/v1/reports/performance
```

### Rapport des Certificats
```bash
curl -H "Authorization: Bearer TOKEN" \
  http://localhost:8000/api/v1/reports/certificates
```

---

## 🛠️ Commandes Utiles

### Migrations
```bash
# Exécuter les migrations
php artisan migrate

# Annuler la dernière migration
php artisan migrate:rollback

# Réinitialiser la base de données
php artisan migrate:refresh

# Réinitialiser et seeder
php artisan migrate:refresh --seed
```

### Cache
```bash
# Vider le cache
php artisan cache:clear

# Vider le cache de configuration
php artisan config:clear

# Vider le cache de routes
php artisan route:clear
```

### Autres
```bash
# Générer une clé d'application
php artisan key:generate

# Publier les assets
php artisan vendor:publish

# Lister les routes
php artisan route:list

# Lister les commandes
php artisan list
```

---

## 📝 Conventions de Code

### Nommage
- **Modèles**: Singulier, PascalCase (User, Course, Badge)
- **Contrôleurs**: Singulier + Controller (UserController, CourseController)
- **Migrations**: Verbe + nom (create_users_table, add_points_to_users_table)
- **Routes**: Kebab-case (/api/v1/user-badges)

### Structure des Fichiers
```php
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;

class Course extends Model
{
    protected $fillable = ['title', 'content'];

    public function lessons(): HasMany
    {
        return $this->hasMany(Lesson::class);
    }
}
```

---

## 🔐 Sécurité

### Authentification
- Utiliser `Auth::user()` pour obtenir l'utilisateur actuel
- Vérifier les permissions avec `$user->can('action')`
- Utiliser les middlewares d'authentification

### Validation
```php
$request->validate([
    'email' => 'required|email|unique:users',
    'password' => 'required|min:8',
]);
```

### Protection CSRF
```html
<form method="POST" action="/submit">
    @csrf
    <!-- Formulaire -->
</form>
```

---

## 📚 Ressources

- [Documentation Laravel](https://laravel.com/docs)
- [Spatie Permission](https://spatie.be/docs/laravel-permission)
- [Laravel Sanctum](https://laravel.com/docs/sanctum)
- [Tailwind CSS](https://tailwindcss.com)

---

## 🤝 Contribution

1. Créer une branche pour votre fonctionnalité
2. Faire des commits clairs
3. Écrire des tests
4. Soumettre une pull request

---

## 📞 Support

Pour toute question ou problème, veuillez ouvrir une issue sur le repository.

---

**Dernière mise à jour**: 2026-03-27
