Initial commit: API Anime Tracker avec authentification et synchronisation
This commit is contained in:
162
README.md
Normal file
162
README.md
Normal file
@@ -0,0 +1,162 @@
|
||||
# API Anime Tracker
|
||||
|
||||
API de synchronisation pour l'extension Chrome Anime Tracker, permettant de synchroniser l'historique des animés sur plusieurs appareils.
|
||||
|
||||
## Fonctionnalités
|
||||
|
||||
- ✅ Authentification JWT (inscription, connexion)
|
||||
- ✅ Synchronisation des animés entre appareils
|
||||
- ✅ CRUD complet pour les animés
|
||||
- ✅ Endpoint de synchronisation en masse
|
||||
- ✅ Base de données PostgreSQL (service externe)
|
||||
|
||||
## Configuration
|
||||
|
||||
### Variables d'environnement
|
||||
|
||||
Créez un fichier `.env` à partir de `env.example` :
|
||||
|
||||
```bash
|
||||
cp env.example .env
|
||||
```
|
||||
|
||||
Éditez `.env` et configurez :
|
||||
|
||||
- `SECRET_KEY`: Clé secrète pour JWT (minimum 32 caractères, générer une clé aléatoire)
|
||||
- `DATABASE_URL`: URL de connexion PostgreSQL (format: `postgresql://user:password@host:port/database`)
|
||||
|
||||
### Exemple de configuration
|
||||
|
||||
```env
|
||||
SECRET_KEY=votre-cle-secrete-tres-longue-et-aleatoire-minimum-32-caracteres
|
||||
DATABASE_URL=postgresql://username:password@postgres.holo795.fr:5432/anime_tracker
|
||||
```
|
||||
|
||||
## Installation avec Docker
|
||||
|
||||
### 1. Lancer avec Docker Compose
|
||||
|
||||
```bash
|
||||
docker-compose up -d
|
||||
```
|
||||
|
||||
L'API sera accessible sur `https://anime-tracker.holo795.fr` (ou le port configuré)
|
||||
|
||||
### 2. Vérifier le statut
|
||||
|
||||
```bash
|
||||
docker-compose ps
|
||||
docker-compose logs -f api
|
||||
```
|
||||
|
||||
## Développement local (sans Docker)
|
||||
|
||||
```bash
|
||||
# Créer un environnement virtuel
|
||||
python -m venv venv
|
||||
source venv/bin/activate # Sur Windows: venv\Scripts\activate
|
||||
|
||||
# Installer les dépendances
|
||||
pip install -r requirements.txt
|
||||
|
||||
# Lancer l'API
|
||||
uvicorn main:app --reload --host 0.0.0.0 --port 8000
|
||||
```
|
||||
|
||||
## Documentation API
|
||||
|
||||
Une fois l'API lancée, accédez à :
|
||||
- **Swagger UI**: https://anime-tracker.holo795.fr/docs
|
||||
- **ReDoc**: https://anime-tracker.holo795.fr/redoc
|
||||
|
||||
## Endpoints principaux
|
||||
|
||||
### Authentification
|
||||
|
||||
- `POST /api/auth/register` - Inscription
|
||||
```json
|
||||
{
|
||||
"username": "mon_username",
|
||||
"email": "email@example.com",
|
||||
"password": "motdepasse123"
|
||||
}
|
||||
```
|
||||
|
||||
- `POST /api/auth/login` - Connexion
|
||||
```json
|
||||
{
|
||||
"email_or_username": "email@example.com",
|
||||
"password": "motdepasse123"
|
||||
}
|
||||
```
|
||||
|
||||
- `GET /api/auth/me` - Informations utilisateur (nécessite authentification)
|
||||
|
||||
### Animés
|
||||
|
||||
- `GET /api/animes` - Liste des animés (nécessite authentification)
|
||||
- `POST /api/animes` - Créer/mettre à jour un animé (nécessite authentification)
|
||||
- `PUT /api/animes/{anime_id}` - Mettre à jour un animé (nécessite authentification)
|
||||
- `DELETE /api/animes/{anime_id}` - Supprimer un animé (nécessite authentification)
|
||||
- `POST /api/animes/sync` - Synchroniser plusieurs animés (nécessite authentification)
|
||||
|
||||
### Santé
|
||||
|
||||
- `GET /api/health` - Vérification de l'état
|
||||
|
||||
## Production
|
||||
|
||||
### Déploiement
|
||||
|
||||
1. Configurez les variables d'environnement sur votre serveur
|
||||
2. Assurez-vous que PostgreSQL est accessible depuis le conteneur Docker
|
||||
3. Utilisez un reverse proxy (nginx) avec HTTPS
|
||||
4. Configurez les certificats SSL
|
||||
|
||||
### Sécurité
|
||||
|
||||
- ✅ Utilisez une `SECRET_KEY` forte et unique
|
||||
- ✅ Utilisez HTTPS en production
|
||||
- ✅ Configurez CORS pour limiter les origines autorisées
|
||||
- ✅ Utilisez un mot de passe fort pour PostgreSQL
|
||||
- ✅ Limitez les connexions réseau à PostgreSQL
|
||||
|
||||
### Exemple de configuration nginx
|
||||
|
||||
```nginx
|
||||
server {
|
||||
listen 443 ssl;
|
||||
server_name anime-tracker.holo795.fr;
|
||||
|
||||
ssl_certificate /path/to/cert.pem;
|
||||
ssl_certificate_key /path/to/key.pem;
|
||||
|
||||
location / {
|
||||
proxy_pass http://localhost:8000;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Base de données
|
||||
|
||||
### Création de la base de données PostgreSQL
|
||||
|
||||
```sql
|
||||
CREATE DATABASE anime_tracker;
|
||||
CREATE USER anime_user WITH PASSWORD 'votre_mot_de_passe';
|
||||
GRANT ALL PRIVILEGES ON DATABASE anime_tracker TO anime_user;
|
||||
```
|
||||
|
||||
Les tables seront créées automatiquement au premier démarrage de l'API.
|
||||
|
||||
### Migration
|
||||
|
||||
Si vous devez migrer depuis SQLite vers PostgreSQL :
|
||||
|
||||
1. Exportez les données depuis SQLite
|
||||
2. Importez-les dans PostgreSQL
|
||||
3. Mettez à jour `DATABASE_URL` dans `.env`
|
||||
Reference in New Issue
Block a user