Skip to content

Commit 563c2cb

Browse files
committed
Initial computer vision kit
0 parents  commit 563c2cb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+10711
-0
lines changed

.github/workflows/template-ci.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Template CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
jobs:
10+
verify:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v4
15+
16+
- name: Setup Node
17+
uses: actions/setup-node@v4
18+
with:
19+
node-version-file: .nvmrc
20+
cache: npm
21+
cache-dependency-path: |
22+
package-lock.json
23+
frontend/package-lock.json
24+
25+
- name: Setup Python
26+
uses: actions/setup-python@v5
27+
with:
28+
python-version: "3.12"
29+
30+
- name: Install root tooling
31+
run: npm ci
32+
33+
- name: Install frontend dependencies
34+
run: npm ci
35+
working-directory: frontend
36+
37+
- name: Install backend dependencies
38+
run: |
39+
python -m pip install --upgrade pip
40+
python -m pip install -e ./backend[dev]
41+
42+
- name: Generate API types
43+
run: npm run api:types
44+
45+
- name: Run template checks
46+
run: npm run check

.gitignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
node_modules/
2+
npm-debug.log*
3+
4+
frontend/node_modules/
5+
frontend/.next/
6+
frontend/out/
7+
frontend/tsconfig.tsbuildinfo
8+
frontend/.env.local
9+
frontend/AGENTS.md
10+
frontend/CLAUDE.md
11+
12+
backend/.venv/
13+
backend/.pytest_cache/
14+
backend/__pycache__/
15+
backend/**/*.pyc
16+
backend/**/*.pyo
17+
backend/.env
18+
19+
.DS_Store
20+
Thumbs.db
21+
22+
__reference_nextjs_go_monorepo_kit/
23+
deep-research-report.md

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
22

README.md

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
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

backend/.env.example

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
APP_NAME=Next.js Python Computer Vision Kit API
2+
APP_ENV=development
3+
APP_HOST=127.0.0.1
4+
APP_PORT=8000
5+
CORS_ALLOWED_ORIGINS=http://127.0.0.1:3000,http://localhost:3000
6+
MAX_UPLOAD_SIZE_MB=8
7+
SAMPLE_MAX_DETECTIONS=8

backend/README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Backend
2+
3+
The backend is a FastAPI service designed to be the stable contract layer for a detection-first computer-vision product.
4+
5+
## Responsibilities
6+
7+
- expose typed HTTP endpoints for health, pipeline discovery, and analysis
8+
- make the default sample workflow object detection with bounding boxes
9+
- expose segmentation as an extension through the same inference contract
10+
- validate uploads and normalize errors
11+
- keep model-specific logic behind a small service boundary
12+
- make it easy to swap sample OpenCV processors with heavier inference backends later
13+
14+
## Install
15+
16+
```bash
17+
python -m pip install -e .[dev]
18+
```
19+
20+
## Run
21+
22+
```bash
23+
python -m uvicorn app.main:app --reload --host 127.0.0.1 --port 8000
24+
```
25+
26+
## Test
27+
28+
```bash
29+
python -m pytest
30+
```

backend/app/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

backend/app/api/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

backend/app/api/routes/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

backend/app/api/routes/health.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from fastapi import APIRouter
2+
3+
from app.config import get_settings
4+
from app.schemas import HealthResponse
5+
6+
router = APIRouter()
7+
8+
9+
@router.get("/health", response_model=HealthResponse, tags=["health"])
10+
def health_check() -> HealthResponse:
11+
settings = get_settings()
12+
return HealthResponse(
13+
status="ok",
14+
app=settings.app_name,
15+
environment=settings.app_env,
16+
)

0 commit comments

Comments
 (0)