# Development Guide ## Prerequisites - Node 22 + Python 3.12 - `pip` + `npm` ## Setup ```bash # Clone git clone https://github.com/your-org/safetensors-studio.git cd safetensors-studio # Backend cd backend python -m venv .venv && source .venv/bin/activate # Windows: .venv\Scripts\activate pip install -r requirements.txt cp ../.env.example ../backend/.env # if using env uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload # Frontend (second terminal) cd ../frontend npm install cp ../.env.example .env.local # edit NEXT_PUBLIC_API_URL if needed npm run dev ``` ## Scripts | Command | Description | |---------|-------------| | `npm run dev` | Next.js dev with HMR | | `npm run build` | Production build (Turbopack) | | `npm run lint` | ESLint | | `uvicorn app.main:app --reload` | FastAPI with auto-reload | | `python -m pytest` | Backend tests (add) | ## Project Conventions - **Frontend:** `App Router`, `Tailwind`, `Shadcn/ui`, `Recharts`, `lucide-react`, `clsx/tailwind-merge` - **Backend:** `FastAPI` + `Pydantic v2`, `Transformers` + `Torch` + `Accelerate` - **Commits:** Conventional Commits (`feat:`, `fix:`) - **Branch:** `feat/*`, `fix/*` → PR to `main` ## Testing the Stack ```bash # Backend health curl http://localhost:8000/api/health curl http://localhost:8000/docs # Swagger # Frontend curl http://localhost:3000 # Load demo model (no GPU needed) mkdir -p /tmp/demo && echo '{"model_type":"llama"}' > /tmp/demo/config.json && touch /tmp/demo/model.safetensors curl -X POST http://localhost:8000/api/model/load -H "Content-Type: application/json" -d '{"model_path":"/tmp/demo","dtype":"float16"}' ``` ## Troubleshooting - **Port 8000 in use:** `lsof -i :8000` / `netstat -ano | findstr :8000` then `kill` - **Torch not found:** `pip install torch --index-url https://download.pytorch.org/whl/cpu` (or `cu121` for GPU) - **WS 404:** `TelemetryCharts` falls back to HTTP polling — safe to ignore in dev - **PDF Arabic `?`:** Ensure `tahoma.ttf` exists or install `arabic-reshaper` + `python-bidi` ## IDE - VS Code: recommended extensions `Tailwind CSS IntelliSense`, `Python`, `Pylance` - Format: `prettier` (frontend), `black`/`ruff` (backend, optional)