|
|
@@ -0,0 +1,103 @@
|
|
|
+# labML – Stack hybride Next.js + NestJS + FastAPI + Jupyter (Docker Compose)
|
|
|
+
|
|
|
+Ce projet met en place une architecture moderne et modulaire pour le ML et le web :
|
|
|
+
|
|
|
+- Frontend: Next.js (TypeScript)
|
|
|
+- Backend applicatif: NestJS (TypeScript)
|
|
|
+- Backend ML: FastAPI (Python)
|
|
|
+- Notebooks: JupyterLab
|
|
|
+- Orchestration: Docker Compose
|
|
|
+
|
|
|
+Chaînage prévu: Notebook → API (FastAPI) → API (NestJS) → Interface Web (Next.js)
|
|
|
+
|
|
|
+## Structure
|
|
|
+
|
|
|
+```
|
|
|
+labML/
|
|
|
+├─ web/ # Frontend Next.js (TS)
|
|
|
+├─ app-api/ # Backend NestJS (TS)
|
|
|
+├─ ml-api/ # Backend FastAPI (Python)
|
|
|
+│ ├─ app/
|
|
|
+│ │ ├─ main.py # API FastAPI (predict/train)
|
|
|
+│ │ └─ train_iris.py # Script d'entraînement (Iris)
|
|
|
+│ └─ environment.yml # Environnement conda/mamba
|
|
|
+├─ notebooks/ # Notebooks Jupyter
|
|
|
+├─ shared/
|
|
|
+│ └─ models/ # Artefacts modèles (joblib, etc.)
|
|
|
+├─ docker-compose.yml # Orchestration des services
|
|
|
+└─ README.md
|
|
|
+```
|
|
|
+
|
|
|
+## Prérequis
|
|
|
+
|
|
|
+- Docker Desktop + Docker Compose
|
|
|
+- Node.js (pour travailler hors Docker si besoin)
|
|
|
+
|
|
|
+## Démarrage rapide
|
|
|
+
|
|
|
+1. Générer les applications Next.js (web) et NestJS (app-api) si ce n'est pas déjà fait:
|
|
|
+ - Next: `npx create-next-app@latest web --ts --eslint --src-dir --app --import-alias "@/*" --yes`
|
|
|
+ - Nest: `npx @nestjs/cli@latest new app-api -p npm`
|
|
|
+
|
|
|
+2. Lancer l'ensemble des services:
|
|
|
+
|
|
|
+```
|
|
|
+docker compose up
|
|
|
+```
|
|
|
+
|
|
|
+Cela va démarrer:
|
|
|
+- Next.js (web) sur http://localhost:3000
|
|
|
+- NestJS (app-api) sur http://localhost:4000
|
|
|
+- FastAPI (ml-api) sur http://localhost:8000
|
|
|
+- JupyterLab sur http://localhost:8888 (token désactivé pour dev)
|
|
|
+
|
|
|
+3. Entraîner un modèle de démonstration (Iris) via notebook ou API:
|
|
|
+ - Notebook: ouvrir JupyterLab, exécuter un notebook qui appelle `ml-api/app/train_iris.py` ou utilise son contenu.
|
|
|
+ - API: `POST http://localhost:8000/train`
|
|
|
+
|
|
|
+4. Tester la prédiction:
|
|
|
+ - `POST http://localhost:8000/predict` avec le payload:
|
|
|
+ ```json
|
|
|
+ {
|
|
|
+ "sepal_length": 5.1,
|
|
|
+ "sepal_width": 3.5,
|
|
|
+ "petal_length": 1.4,
|
|
|
+ "petal_width": 0.2
|
|
|
+ }
|
|
|
+ ```
|
|
|
+ - Le frontend (web) aura une page de démo pour saisir ces valeurs et afficher la prédiction, en passant par NestJS.
|
|
|
+
|
|
|
+## Paquets inclus côté Python
|
|
|
+
|
|
|
+- jupyterlab, ipykernel
|
|
|
+- matplotlib, seaborn
|
|
|
+- pandas, numpy
|
|
|
+- scikit-learn
|
|
|
+- optuna, mlflow
|
|
|
+- PyTorch (cpuonly) OU possibilité d'ajouter TensorFlow/Keras
|
|
|
+- fastapi, uvicorn, pydantic, joblib
|
|
|
+- streamlit, gradio (interfaces rapides de test)
|
|
|
+- black, flake8, isort, pytest, pre-commit
|
|
|
+
|
|
|
+Note: l'installation via mamba dans les conteneurs peut être longue la première fois.
|
|
|
+
|
|
|
+## Qualité et CI locale
|
|
|
+
|
|
|
+- pre-commit configuré (black/flake8/isort pour Python; possibilité d'ajouter ESLint/Prettier côté TypeScript)
|
|
|
+- pytest pour tests Python
|
|
|
+
|
|
|
+## Variables d'environnement
|
|
|
+
|
|
|
+- Frontend (web): `APP_API_BASE_URL=http://localhost:4000`
|
|
|
+- Backend (app-api): `ML_API_BASE_URL=http://ml-api:8000`
|
|
|
+
|
|
|
+## Développement
|
|
|
+
|
|
|
+- Les services Node (web, app-api) sont montés en volumes (hot reload via `npm run dev`/`start:dev`).
|
|
|
+- Les services Python utilisent mambaforge et installent les dépendances au démarrage (peut être externalisé dans une image Docker dédiée pour accélérer).
|
|
|
+
|
|
|
+## Étapes suivantes
|
|
|
+
|
|
|
+- Ajouter la page Next.js de démo et l'endpoint NestJS `/predict` qui proxie vers FastAPI
|
|
|
+- Ajuster la sécurité (CORS, tokens Jupyter, etc.) pour la prod
|
|
|
+- Intégrer MLflow tracking et Optuna dans le script d'entraînement
|