113 lines
2.9 KiB
Markdown
Executable File
113 lines
2.9 KiB
Markdown
Executable File
# Linux BenchTools - Backend
|
|
|
|
Backend API FastAPI pour Linux BenchTools.
|
|
|
|
## Structure
|
|
|
|
```
|
|
backend/
|
|
├── app/
|
|
│ ├── api/ # Endpoints API
|
|
│ ├── core/ # Configuration et sécurité
|
|
│ ├── models/ # Modèles SQLAlchemy
|
|
│ ├── schemas/ # Schémas Pydantic
|
|
│ ├── db/ # Configuration base de données
|
|
│ ├── utils/ # Utilitaires
|
|
│ └── main.py # Application principale
|
|
├── data/ # Base SQLite (gitignored)
|
|
├── Dockerfile
|
|
└── requirements.txt
|
|
```
|
|
|
|
## Installation locale (développement)
|
|
|
|
```bash
|
|
# Créer un environnement virtuel
|
|
python3 -m venv venv
|
|
source venv/bin/activate
|
|
|
|
# Installer les dépendances
|
|
pip install -r requirements.txt
|
|
|
|
# Définir les variables d'environnement
|
|
export API_TOKEN="your-secret-token"
|
|
export DATABASE_URL="sqlite:///./backend/data/data.db"
|
|
export UPLOAD_DIR="./uploads"
|
|
|
|
# Lancer le serveur
|
|
uvicorn app.main:app --reload --host 0.0.0.0 --port 8007
|
|
```
|
|
|
|
## Endpoints API
|
|
|
|
### Benchmarks
|
|
- `POST /api/benchmark` - Soumettre un benchmark (auth required)
|
|
- `GET /api/benchmarks/{id}` - Détails d'un benchmark
|
|
|
|
### Devices
|
|
- `GET /api/devices` - Liste des devices (pagination + recherche)
|
|
- `GET /api/devices/{id}` - Détails d'un device
|
|
- `GET /api/devices/{id}/benchmarks` - Historique benchmarks
|
|
- `PUT /api/devices/{id}` - Modifier un device
|
|
|
|
### Links
|
|
- `GET /api/devices/{id}/links` - Liens d'un device
|
|
- `POST /api/devices/{id}/links` - Ajouter un lien
|
|
- `PUT /api/links/{id}` - Modifier un lien
|
|
- `DELETE /api/links/{id}` - Supprimer un lien
|
|
|
|
### Documents
|
|
- `GET /api/devices/{id}/docs` - Documents d'un device
|
|
- `POST /api/devices/{id}/docs` - Upload document
|
|
- `GET /api/docs/{id}/download` - Télécharger document
|
|
- `DELETE /api/docs/{id}` - Supprimer document
|
|
|
|
### Autres
|
|
- `GET /api/health` - Health check
|
|
- `GET /api/stats` - Statistiques globales
|
|
|
|
## Documentation interactive
|
|
|
|
Une fois le serveur lancé, accédez à :
|
|
- Swagger UI : http://localhost:8007/docs
|
|
- ReDoc : http://localhost:8007/redoc
|
|
|
|
## Variables d'environnement
|
|
|
|
| Variable | Description | Défaut |
|
|
|----------|-------------|--------|
|
|
| `API_TOKEN` | Token d'authentification | `CHANGE_ME` |
|
|
| `DATABASE_URL` | URL de la base SQLite | `sqlite:///./backend/data/data.db` |
|
|
| `UPLOAD_DIR` | Répertoire des uploads | `./uploads` |
|
|
| `CORS_ORIGINS` | Origins CORS autorisées | `["*"]` |
|
|
|
|
## Authentification
|
|
|
|
L'API utilise un token Bearer simple pour l'endpoint POST /api/benchmark :
|
|
|
|
```http
|
|
Authorization: Bearer YOUR_API_TOKEN
|
|
```
|
|
|
|
## Base de données
|
|
|
|
SQLite avec 5 tables principales :
|
|
- `devices` - Machines
|
|
- `hardware_snapshots` - Snapshots hardware
|
|
- `benchmarks` - Résultats de benchmarks
|
|
- `manufacturer_links` - Liens constructeurs
|
|
- `documents` - Documents uploadés
|
|
|
|
## Développement
|
|
|
|
```bash
|
|
# Linter
|
|
flake8 app/
|
|
|
|
# Format code
|
|
black app/
|
|
|
|
# Type checking
|
|
mypy app/
|
|
```
|