2.9 KiB
Executable File
2.9 KiB
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)
# 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 deviceGET /api/devices/{id}/benchmarks- Historique benchmarksPUT /api/devices/{id}- Modifier un device
Links
GET /api/devices/{id}/links- Liens d'un devicePOST /api/devices/{id}/links- Ajouter un lienPUT /api/links/{id}- Modifier un lienDELETE /api/links/{id}- Supprimer un lien
Documents
GET /api/devices/{id}/docs- Documents d'un devicePOST /api/devices/{id}/docs- Upload documentGET /api/docs/{id}/download- Télécharger documentDELETE /api/docs/{id}- Supprimer document
Autres
GET /api/health- Health checkGET /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 :
Authorization: Bearer YOUR_API_TOKEN
Base de données
SQLite avec 5 tables principales :
devices- Machineshardware_snapshots- Snapshots hardwarebenchmarks- Résultats de benchmarksmanufacturer_links- Liens constructeursdocuments- Documents uploadés
Développement
# Linter
flake8 app/
# Format code
black app/
# Type checking
mypy app/