|
| 1 | +# nextjs-python-computer-vision-kit |
| 2 | + |
| 3 | +A full-stack starter monorepo for detection-first computer vision products built with Next.js and FastAPI. |
| 4 | + |
| 5 | +It combines a polished frontend, a Python API designed for image-processing workloads, shared root scripts, a documented OpenAPI contract, and a sample detection pipeline that runs on CPU with OpenCV so teams can start shipping product workflows before committing to a heavier model stack. |
| 6 | + |
| 7 | +## Stack |
| 8 | + |
| 9 | +- Next.js 16 |
| 10 | +- React 19 |
| 11 | +- TypeScript |
| 12 | +- Tailwind CSS 4 |
| 13 | +- Python 3.12+ |
| 14 | +- FastAPI |
| 15 | +- OpenCV |
| 16 | +- Docker Compose |
| 17 | + |
| 18 | +## Monorepo Structure |
| 19 | + |
| 20 | +- `frontend/`: Next.js app with a vision-console UI, API client helpers, and generated OpenAPI types |
| 21 | +- `backend/`: FastAPI service with health, pipeline catalog, and image-analysis routes |
| 22 | +- `docs/`: shared API contract |
| 23 | +- `scripts/`: root development and verification scripts |
| 24 | +- `.github/`: CI workflow for the template |
| 25 | + |
| 26 | +## Recommended Shape |
| 27 | + |
| 28 | +- architecture: inference-first |
| 29 | +- default demo: detection-first |
| 30 | +- optional frontend extension: webcam capture |
| 31 | +- later backend extension: segmentation |
| 32 | +- later workspace/package: training pipeline |
| 33 | + |
| 34 | +This keeps the template easy to understand while still leaving a clean path into more advanced CV workflows. |
| 35 | + |
| 36 | +## Why This Template Exists |
| 37 | + |
| 38 | +Most computer-vision starters are either model notebooks with no product layer or web templates with no real inference shape. This template sits in the middle: |
| 39 | + |
| 40 | +- product-minded frontend by default |
| 41 | +- backend structure ready for image upload, preprocessing, and model-serving extensions |
| 42 | +- typed API contract between the web app and the inference service |
| 43 | +- one-command local development from the repo root |
| 44 | + |
| 45 | +## Quick Start |
| 46 | + |
| 47 | +1. Install Node.js 22+ and Python 3.12+. |
| 48 | +2. Run `npm install` in the repo root. |
| 49 | +3. Run `npm install` in `frontend/`. |
| 50 | +4. Run `python -m pip install -e ./backend[dev]`. |
| 51 | +5. Run `npm run api:types`. |
| 52 | +6. Run `npm run dev`. |
| 53 | + |
| 54 | +Frontend: `http://localhost:3000` |
| 55 | +Backend: `http://127.0.0.1:8000` |
| 56 | + |
| 57 | +## Commands |
| 58 | + |
| 59 | +```bash |
| 60 | +npm run dev |
| 61 | +npm run dev:down |
| 62 | +npm run api:types |
| 63 | +npm run check |
| 64 | +``` |
| 65 | + |
| 66 | +## API Contract |
| 67 | + |
| 68 | +- `docs/openapi.yaml` is the source of truth for the shared HTTP contract. |
| 69 | +- `frontend/src/generated/openapi.ts` is generated from that spec with `openapi-typescript`. |
| 70 | +- Run `npm run api:types` whenever backend payloads change. |
| 71 | + |
| 72 | +## Sample Pipelines Included |
| 73 | + |
| 74 | +- `starter-detection`: the default object-style detection sample used by the main frontend flow |
| 75 | +- `foreground-segmentation`: the first live extension pipeline, returning region polygons and derived boxes |
| 76 | +- `document-layout`: document-oriented box extraction for scanning and capture products |
| 77 | +- `dominant-color`: metrics-only extension pipeline for QA and analytics |
| 78 | + |
| 79 | +These are intentionally lightweight starter pipelines. They are there to prove the architecture and developer workflow, not to lock you into toy logic. Swap them for YOLO, ONNX Runtime, PyTorch, TensorRT, or a custom service when you are ready. |
| 80 | + |
| 81 | +## What You Get |
| 82 | + |
| 83 | +- reusable Next.js + Python computer-vision monorepo layout |
| 84 | +- upload-and-detect frontend starter UI |
| 85 | +- optional webcam capture mode that reuses the same inference contract |
| 86 | +- first segmentation extension pipeline using the same response boundary |
| 87 | +- FastAPI inference endpoint with typed response models |
| 88 | +- OpenCV-based sample processing that runs without a GPU |
| 89 | +- root scripts for local dev and checks |
| 90 | +- GitHub Actions workflow for frontend and backend verification |
| 91 | +- Docker Compose dev option |
| 92 | + |
| 93 | +## Notes |
| 94 | + |
| 95 | +- The backend in this starter is CPU-first on purpose so it is easier to clone, run, and extend. |
| 96 | +- The main story is intentionally detection-first so the template stays easy to explain and demo. |
| 97 | +- The current environment used to build this template did not have Python installed, so the frontend was verified locally but backend execution was prepared rather than run here. |
| 98 | +- If you move to heavier vision workloads, add a worker or model-service layer and keep the current API as the contract boundary. |
| 99 | + |
| 100 | +## Next Expansions |
| 101 | + |
| 102 | +- async job queue for long-running inference |
| 103 | +- persistent artifact storage |
| 104 | +- model registry and experiment tracking |
| 105 | +- richer segmentation overlays and mask visualizations |
| 106 | +- video ingestion pipelines |
| 107 | +- training or experiment workspace in a separate `ml/` or `training/` package |
0 commit comments