mucahitkantepe commited on
Commit
8d87873
·
1 Parent(s): 48f200e

Add web app: FastAPI backend + React/TS frontend

Browse files

Backend (FastAPI):
- /api/products — paginated, filterable, sortable product browsing
- /api/ratings — CRUD for reference images (like/dislike/remove/upload)
- /api/stats — dashboard stats
- /api/scan — trigger scan with background polling
- /api/images — serve reference images

Frontend (React + TypeScript + Vite + Bun):
- Browse page: product grid with store filters, search, sort, pagination
- Profile page: manage reference images, upload, like/dislike/remove
- Dashboard: stats cards, per-store table, scan trigger
- Dark theme matching existing design language

backend/app/__init__.py ADDED
File without changes
backend/app/deps.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Shared dependencies — singletons for config, engine, store."""
2
+
3
+ import sys
4
+ from pathlib import Path
5
+
6
+ # Add project root so `taste` package is importable
7
+ sys.path.insert(0, str(Path(__file__).resolve().parents[2]))
8
+
9
+ from taste.config import Config, UserProfile, load_config, load_profile
10
+ from taste.engine import TasteEngine
11
+ from taste.store import ProductStore
12
+
13
+ _config: Config | None = None
14
+ _profile: UserProfile | None = None
15
+ _engine: TasteEngine | None = None
16
+ _store: ProductStore | None = None
17
+
18
+
19
+ def init():
20
+ global _config, _profile, _engine, _store
21
+ _config = load_config()
22
+ _profile = load_profile("default", _config)
23
+ _engine = TasteEngine(data_dir=_config.data_dir)
24
+ _store = ProductStore(db_path=_profile.db_path(_config))
25
+
26
+
27
+ def get_config() -> Config:
28
+ assert _config is not None
29
+ return _config
30
+
31
+ def get_profile() -> UserProfile:
32
+ assert _profile is not None
33
+ return _profile
34
+
35
+ def get_engine() -> TasteEngine:
36
+ assert _engine is not None
37
+ return _engine
38
+
39
+ def get_store() -> ProductStore:
40
+ assert _store is not None
41
+ return _store
backend/app/main.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """FastAPI application for taste-engine."""
2
+
3
+ from contextlib import asynccontextmanager
4
+
5
+ from fastapi import FastAPI
6
+ from fastapi.middleware.cors import CORSMiddleware
7
+
8
+ from backend.app import deps
9
+ from backend.app.routers import products, ratings, stats, scan, images
10
+
11
+
12
+ @asynccontextmanager
13
+ async def lifespan(app: FastAPI):
14
+ deps.init()
15
+ yield
16
+
17
+
18
+ app = FastAPI(title="Taste Engine", version="0.2.0", lifespan=lifespan)
19
+
20
+ app.add_middleware(
21
+ CORSMiddleware,
22
+ allow_origins=["http://localhost:5173", "http://localhost:3000"],
23
+ allow_methods=["*"],
24
+ allow_headers=["*"],
25
+ )
26
+
27
+ app.include_router(products.router)
28
+ app.include_router(ratings.router)
29
+ app.include_router(stats.router)
30
+ app.include_router(scan.router)
31
+ app.include_router(images.router)
32
+
33
+
34
+ @app.get("/api/health")
35
+ def health():
36
+ return {"status": "ok"}
37
+
38
+
39
+ def run():
40
+ import uvicorn
41
+ uvicorn.run("backend.app.main:app", host="0.0.0.0", port=8000, reload=True)
42
+
43
+
44
+ if __name__ == "__main__":
45
+ run()
backend/app/routers/__init__.py ADDED
File without changes
backend/app/routers/images.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Image serving endpoints."""
2
+
3
+ from pathlib import Path
4
+
5
+ from fastapi import APIRouter, HTTPException
6
+ from fastapi.responses import FileResponse
7
+
8
+ from backend.app.deps import get_config
9
+
10
+ router = APIRouter(prefix="/api/images", tags=["images"])
11
+
12
+
13
+ @router.get("/reference/{filename}")
14
+ def serve_reference_image(filename: str):
15
+ config = get_config()
16
+ ref_dir = config.data_dir / "reference-images"
17
+
18
+ # Check both flat and subdirectories
19
+ for candidate in [ref_dir / filename, ref_dir / "bags" / filename]:
20
+ if candidate.exists() and candidate.is_file():
21
+ return FileResponse(candidate, media_type="image/jpeg")
22
+
23
+ raise HTTPException(status_code=404, detail="Image not found")
backend/app/routers/products.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Product browsing endpoints."""
2
+
3
+ from fastapi import APIRouter, Query
4
+
5
+ from backend.app.deps import get_store
6
+ from backend.app.schemas import ProductOut, ProductsResponse
7
+
8
+ router = APIRouter(prefix="/api/products", tags=["products"])
9
+
10
+
11
+ @router.get("", response_model=ProductsResponse)
12
+ def list_products(
13
+ page: int = Query(1, ge=1),
14
+ page_size: int = Query(48, ge=1, le=200),
15
+ store: str | None = None,
16
+ brand: str | None = None,
17
+ min_score: float = 0.01,
18
+ sort: str = "score",
19
+ search: str | None = None,
20
+ ):
21
+ db = get_store()
22
+ conn = db.conn
23
+
24
+ where = ["score >= ?"]
25
+ params: list = [min_score]
26
+
27
+ if store:
28
+ where.append("store = ?")
29
+ params.append(store)
30
+ if brand:
31
+ where.append("LOWER(brand) = ?")
32
+ params.append(brand.lower())
33
+ if search:
34
+ where.append("(brand LIKE ? OR name LIKE ?)")
35
+ params.extend([f"%{search}%", f"%{search}%"])
36
+
37
+ where_sql = " AND ".join(where)
38
+
39
+ order = {
40
+ "score": "score DESC",
41
+ "price_asc": "price_nok ASC",
42
+ "price_desc": "price_nok DESC",
43
+ "newest": "created_at DESC",
44
+ }.get(sort, "score DESC")
45
+
46
+ total = conn.execute(f"SELECT COUNT(*) FROM products WHERE {where_sql}", params).fetchone()[0]
47
+
48
+ offset = (page - 1) * page_size
49
+ rows = conn.execute(
50
+ f"SELECT * FROM products WHERE {where_sql} ORDER BY {order} LIMIT ? OFFSET ?",
51
+ params + [page_size, offset],
52
+ ).fetchall()
53
+
54
+ items = [ProductOut(**dict(r)) for r in rows]
55
+ return ProductsResponse(items=items, total=total, page=page, page_size=page_size)
56
+
57
+
58
+ @router.get("/stores")
59
+ def list_stores():
60
+ db = get_store()
61
+ stats = db.get_stats()
62
+ return [
63
+ {"name": name, "count": s["count"], "top": s["top"], "avg": s["avg"]}
64
+ for name, s in stats["stores"].items()
65
+ ]
backend/app/routers/ratings.py ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Reference image / ratings endpoints."""
2
+
3
+ import shutil
4
+ from pathlib import Path
5
+
6
+ from fastapi import APIRouter, UploadFile, File, Body
7
+
8
+ from backend.app.deps import get_engine, get_config
9
+ from backend.app.schemas import RatingOut, RatingsResponse
10
+
11
+ router = APIRouter(prefix="/api/ratings", tags=["ratings"])
12
+
13
+
14
+ @router.get("", response_model=RatingsResponse)
15
+ def list_ratings():
16
+ engine = get_engine()
17
+ ratings = engine.load_ratings()
18
+
19
+ items = []
20
+ liked = disliked = 0
21
+ for path_str, rating in ratings.items():
22
+ p = Path(path_str)
23
+ if not p.exists():
24
+ continue
25
+ items.append(RatingOut(
26
+ path=path_str,
27
+ filename=p.name,
28
+ rating=rating,
29
+ image_url=f"/api/images/reference/{p.name}",
30
+ ))
31
+ if rating == 1:
32
+ liked += 1
33
+ elif rating == -1:
34
+ disliked += 1
35
+
36
+ items.sort(key=lambda x: (-x.rating, x.filename))
37
+ return RatingsResponse(ratings=items, total=len(items), liked=liked, disliked=disliked)
38
+
39
+
40
+ @router.post("")
41
+ def set_rating(path: str = Body(...), rating: int = Body(...)):
42
+ engine = get_engine()
43
+ engine.save_rating(Path(path), rating)
44
+ return {"ok": True}
45
+
46
+
47
+ @router.delete("")
48
+ def delete_ratings(paths: list[str] = Body(...)):
49
+ engine = get_engine()
50
+ engine.clear_ratings([Path(p) for p in paths])
51
+ return {"ok": True, "removed": len(paths)}
52
+
53
+
54
+ @router.post("/upload")
55
+ async def upload_image(file: UploadFile = File(...)):
56
+ config = get_config()
57
+ engine = get_engine()
58
+
59
+ ref_dir = config.data_dir / "reference-images"
60
+ ref_dir.mkdir(parents=True, exist_ok=True)
61
+
62
+ dest = ref_dir / file.filename
63
+ with dest.open("wb") as f:
64
+ shutil.copyfileobj(file.file, f)
65
+
66
+ engine.save_rating(dest, 1)
67
+
68
+ return RatingOut(
69
+ path=str(dest.resolve()),
70
+ filename=dest.name,
71
+ rating=1,
72
+ image_url=f"/api/images/reference/{dest.name}",
73
+ )
backend/app/routers/scan.py ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Scan trigger + status endpoints."""
2
+
3
+ import threading
4
+ import time
5
+ from datetime import datetime
6
+
7
+ from fastapi import APIRouter, Body
8
+
9
+ from backend.app.deps import get_config, get_profile, get_engine, get_store
10
+ from backend.app.schemas import ScanStatusOut
11
+
12
+ router = APIRouter(prefix="/api/scan", tags=["scan"])
13
+
14
+ _status = {
15
+ "running": False,
16
+ "step": "idle",
17
+ "progress": 0.0,
18
+ "error": None,
19
+ "started_at": None,
20
+ }
21
+ _lock = threading.Lock()
22
+
23
+
24
+ def _run_scan_bg(stores_filter: list[str] | None):
25
+ from taste.pipeline import _run_scrapers, _score_unscored
26
+
27
+ config = get_config()
28
+ profile = get_profile()
29
+ engine = get_engine()
30
+ store = get_store()
31
+
32
+ try:
33
+ with _lock:
34
+ _status["running"] = True
35
+ _status["step"] = "Building taste model..."
36
+ _status["progress"] = 0.1
37
+ _status["error"] = None
38
+ _status["started_at"] = datetime.now().isoformat()
39
+
40
+ centroids = engine.build_taste_vector()
41
+ if centroids is None:
42
+ with _lock:
43
+ _status["step"] = "Error: no reference images"
44
+ _status["running"] = False
45
+ return
46
+
47
+ # Filter stores if requested
48
+ if stores_filter:
49
+ enabled = set(s.lower() for s in stores_filter)
50
+ for name, sc in config.stores.items():
51
+ sc.enabled = name.lower() in enabled
52
+
53
+ with _lock:
54
+ _status["step"] = "Scraping stores..."
55
+ _status["progress"] = 0.3
56
+
57
+ _run_scrapers(config, profile, store)
58
+
59
+ with _lock:
60
+ _status["step"] = "Scoring products..."
61
+ _status["progress"] = 0.7
62
+
63
+ _score_unscored(engine, store, centroids, config.batch_size)
64
+
65
+ with _lock:
66
+ _status["step"] = "Done"
67
+ _status["progress"] = 1.0
68
+ _status["running"] = False
69
+
70
+ except Exception as e:
71
+ with _lock:
72
+ _status["error"] = str(e)
73
+ _status["running"] = False
74
+
75
+
76
+ @router.post("")
77
+ def start_scan(stores: list[str] | None = Body(None)):
78
+ with _lock:
79
+ if _status["running"]:
80
+ return {"ok": False, "message": "Scan already running"}
81
+
82
+ t = threading.Thread(target=_run_scan_bg, args=(stores,), daemon=True)
83
+ t.start()
84
+ return {"ok": True, "message": "Scan started"}
85
+
86
+
87
+ @router.get("/status", response_model=ScanStatusOut)
88
+ def scan_status():
89
+ with _lock:
90
+ return ScanStatusOut(**_status)
backend/app/routers/stats.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Stats endpoints."""
2
+
3
+ from fastapi import APIRouter
4
+
5
+ from backend.app.deps import get_store, get_engine
6
+ from backend.app.schemas import StatsResponse, StoreStatsOut
7
+
8
+ router = APIRouter(prefix="/api/stats", tags=["stats"])
9
+
10
+
11
+ @router.get("", response_model=StatsResponse)
12
+ def get_stats():
13
+ store = get_store()
14
+ engine = get_engine()
15
+
16
+ db_stats = store.get_stats()
17
+ taste_stats = engine.stats()
18
+
19
+ stores = {
20
+ name: StoreStatsOut(**s) for name, s in db_stats["stores"].items()
21
+ }
22
+
23
+ return StatsResponse(
24
+ total_products=db_stats["total"],
25
+ stores=stores,
26
+ taste=taste_stats,
27
+ )
backend/app/schemas.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Pydantic models for API responses."""
2
+
3
+ from pydantic import BaseModel
4
+
5
+
6
+ class ProductOut(BaseModel):
7
+ url: str
8
+ image_url: str
9
+ brand: str
10
+ name: str
11
+ price_text: str
12
+ price_nok: float
13
+ store: str
14
+ score: float
15
+
16
+
17
+ class ProductsResponse(BaseModel):
18
+ items: list[ProductOut]
19
+ total: int
20
+ page: int
21
+ page_size: int
22
+
23
+
24
+ class RatingOut(BaseModel):
25
+ path: str
26
+ filename: str
27
+ rating: int
28
+ image_url: str
29
+
30
+
31
+ class RatingsResponse(BaseModel):
32
+ ratings: list[RatingOut]
33
+ total: int
34
+ liked: int
35
+ disliked: int
36
+
37
+
38
+ class StoreStatsOut(BaseModel):
39
+ count: int
40
+ top: float
41
+ avg: float
42
+
43
+
44
+ class StatsResponse(BaseModel):
45
+ total_products: int
46
+ stores: dict[str, StoreStatsOut]
47
+ taste: dict
48
+
49
+
50
+ class ScanStatusOut(BaseModel):
51
+ running: bool
52
+ step: str
53
+ progress: float
54
+ error: str | None = None
frontend/.gitignore ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Logs
2
+ logs
3
+ *.log
4
+ npm-debug.log*
5
+ yarn-debug.log*
6
+ yarn-error.log*
7
+ pnpm-debug.log*
8
+ lerna-debug.log*
9
+
10
+ node_modules
11
+ dist
12
+ dist-ssr
13
+ *.local
14
+
15
+ # Editor directories and files
16
+ .vscode/*
17
+ !.vscode/extensions.json
18
+ .idea
19
+ .DS_Store
20
+ *.suo
21
+ *.ntvs*
22
+ *.njsproj
23
+ *.sln
24
+ *.sw?
frontend/index.html ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <link rel="icon" type="image/svg+xml" href="/favicon.svg" />
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
+ <title>Taste Engine</title>
8
+ </head>
9
+ <body>
10
+ <div id="root"></div>
11
+ <script type="module" src="/src/main.tsx"></script>
12
+ </body>
13
+ </html>
frontend/package.json ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "frontend",
3
+ "private": true,
4
+ "version": "0.0.0",
5
+ "type": "module",
6
+ "scripts": {
7
+ "dev": "vite",
8
+ "build": "tsc && vite build",
9
+ "preview": "vite preview"
10
+ },
11
+ "devDependencies": {
12
+ "@types/react": "^19.2.14",
13
+ "@types/react-dom": "^19.2.3",
14
+ "@vitejs/plugin-react": "^6.0.1",
15
+ "typescript": "~6.0.2",
16
+ "vite": "^8.0.4"
17
+ },
18
+ "dependencies": {
19
+ "react": "^19.2.5",
20
+ "react-dom": "^19.2.5",
21
+ "react-router-dom": "^7.14.0"
22
+ }
23
+ }
frontend/src/App.tsx ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { Routes, Route } from "react-router-dom";
2
+ import { Layout } from "./components/Layout";
3
+ import { BrowsePage } from "./pages/BrowsePage";
4
+ import { ProfilePage } from "./pages/ProfilePage";
5
+ import { DashboardPage } from "./pages/DashboardPage";
6
+
7
+ export function App() {
8
+ return (
9
+ <Routes>
10
+ <Route element={<Layout />}>
11
+ <Route index element={<BrowsePage />} />
12
+ <Route path="profile" element={<ProfilePage />} />
13
+ <Route path="dashboard" element={<DashboardPage />} />
14
+ </Route>
15
+ </Routes>
16
+ );
17
+ }
frontend/src/api.ts ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import type {
2
+ ProductsResponse,
3
+ StoreInfo,
4
+ RatingsResponse,
5
+ Stats,
6
+ ScanStatus,
7
+ } from "./types";
8
+
9
+ const BASE = "/api";
10
+
11
+ async function request<T>(path: string, init?: RequestInit): Promise<T> {
12
+ const res = await fetch(`${BASE}${path}`, init);
13
+ if (!res.ok) {
14
+ const text = await res.text().catch(() => res.statusText);
15
+ throw new Error(`API ${res.status}: ${text}`);
16
+ }
17
+ return res.json() as Promise<T>;
18
+ }
19
+
20
+ export async function getProducts(params: {
21
+ page?: number;
22
+ page_size?: number;
23
+ store?: string;
24
+ sort?: string;
25
+ min_score?: number;
26
+ search?: string;
27
+ }): Promise<ProductsResponse> {
28
+ const sp = new URLSearchParams();
29
+ if (params.page) sp.set("page", String(params.page));
30
+ if (params.page_size) sp.set("page_size", String(params.page_size));
31
+ if (params.store) sp.set("store", params.store);
32
+ if (params.sort) sp.set("sort", params.sort);
33
+ if (params.min_score !== undefined) sp.set("min_score", String(params.min_score));
34
+ if (params.search) sp.set("search", params.search);
35
+ return request<ProductsResponse>(`/products?${sp}`);
36
+ }
37
+
38
+ export async function getStores(): Promise<StoreInfo[]> {
39
+ return request<StoreInfo[]>("/products/stores");
40
+ }
41
+
42
+ export async function getRatings(): Promise<RatingsResponse> {
43
+ return request<RatingsResponse>("/ratings");
44
+ }
45
+
46
+ export async function setRating(path: string, rating: number): Promise<void> {
47
+ await request<unknown>("/ratings", {
48
+ method: "POST",
49
+ headers: { "Content-Type": "application/json" },
50
+ body: JSON.stringify({ path, rating }),
51
+ });
52
+ }
53
+
54
+ export async function deleteRating(paths: string[]): Promise<void> {
55
+ await request<unknown>("/ratings", {
56
+ method: "DELETE",
57
+ headers: { "Content-Type": "application/json" },
58
+ body: JSON.stringify({ paths }),
59
+ });
60
+ }
61
+
62
+ export async function uploadImage(file: File): Promise<unknown> {
63
+ const form = new FormData();
64
+ form.append("file", file);
65
+ return request<unknown>("/ratings/upload", {
66
+ method: "POST",
67
+ body: form,
68
+ });
69
+ }
70
+
71
+ export async function getStats(): Promise<Stats> {
72
+ return request<Stats>("/stats");
73
+ }
74
+
75
+ export async function startScan(stores?: string[]): Promise<void> {
76
+ await request<unknown>("/scan", {
77
+ method: "POST",
78
+ headers: { "Content-Type": "application/json" },
79
+ body: JSON.stringify(stores ? { stores } : {}),
80
+ });
81
+ }
82
+
83
+ export async function getScanStatus(): Promise<ScanStatus> {
84
+ return request<ScanStatus>("/scan/status");
85
+ }
frontend/src/components/Layout.tsx ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { NavLink, Outlet } from "react-router-dom";
2
+
3
+ function BrowseIcon() {
4
+ return (
5
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={2} strokeLinecap="round" strokeLinejoin="round">
6
+ <rect x="3" y="3" width="7" height="7" />
7
+ <rect x="14" y="3" width="7" height="7" />
8
+ <rect x="3" y="14" width="7" height="7" />
9
+ <rect x="14" y="14" width="7" height="7" />
10
+ </svg>
11
+ );
12
+ }
13
+
14
+ function ProfileIcon() {
15
+ return (
16
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={2} strokeLinecap="round" strokeLinejoin="round">
17
+ <path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2" />
18
+ <circle cx="12" cy="7" r="4" />
19
+ </svg>
20
+ );
21
+ }
22
+
23
+ function DashboardIcon() {
24
+ return (
25
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={2} strokeLinecap="round" strokeLinejoin="round">
26
+ <path d="M3 3v18h18" />
27
+ <path d="M18 17V9" />
28
+ <path d="M13 17V5" />
29
+ <path d="M8 17v-3" />
30
+ </svg>
31
+ );
32
+ }
33
+
34
+ export function Layout() {
35
+ return (
36
+ <div className="app-shell">
37
+ <aside className="sidebar">
38
+ <div className="sidebar-brand">
39
+ <span>Taste</span> Engine
40
+ </div>
41
+ <nav>
42
+ <NavLink to="/" end className={({ isActive }) => isActive ? "active" : ""}>
43
+ <BrowseIcon />
44
+ Browse
45
+ </NavLink>
46
+ <NavLink to="/profile" className={({ isActive }) => isActive ? "active" : ""}>
47
+ <ProfileIcon />
48
+ Profile
49
+ </NavLink>
50
+ <NavLink to="/dashboard" className={({ isActive }) => isActive ? "active" : ""}>
51
+ <DashboardIcon />
52
+ Dashboard
53
+ </NavLink>
54
+ </nav>
55
+ </aside>
56
+ <main className="main-content">
57
+ <Outlet />
58
+ </main>
59
+ </div>
60
+ );
61
+ }
frontend/src/index.css ADDED
@@ -0,0 +1,629 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *,
2
+ *::before,
3
+ *::after {
4
+ box-sizing: border-box;
5
+ margin: 0;
6
+ padding: 0;
7
+ }
8
+
9
+ :root {
10
+ --bg: #0a0a0a;
11
+ --card: #171717;
12
+ --border: #262626;
13
+ --text: #e5e5e5;
14
+ --text-secondary: #a3a3a3;
15
+ --text-muted: #737373;
16
+ --accent: #3b82f6;
17
+ --green: #22c55e;
18
+ --red: #ef4444;
19
+ --amber: #f59e0b;
20
+ --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
21
+ --radius: 8px;
22
+ }
23
+
24
+ html {
25
+ color-scheme: dark;
26
+ }
27
+
28
+ body {
29
+ font-family: var(--font);
30
+ background: var(--bg);
31
+ color: var(--text);
32
+ line-height: 1.5;
33
+ -webkit-font-smoothing: antialiased;
34
+ -moz-osx-font-smoothing: grayscale;
35
+ }
36
+
37
+ a {
38
+ color: var(--accent);
39
+ text-decoration: none;
40
+ }
41
+ a:hover {
42
+ text-decoration: underline;
43
+ }
44
+
45
+ button {
46
+ font-family: var(--font);
47
+ cursor: pointer;
48
+ border: none;
49
+ background: none;
50
+ color: inherit;
51
+ }
52
+
53
+ input,
54
+ select {
55
+ font-family: var(--font);
56
+ color: var(--text);
57
+ background: var(--card);
58
+ border: 1px solid var(--border);
59
+ border-radius: var(--radius);
60
+ padding: 8px 12px;
61
+ font-size: 14px;
62
+ outline: none;
63
+ transition: border-color 0.2s;
64
+ }
65
+ input:focus,
66
+ select:focus {
67
+ border-color: var(--accent);
68
+ }
69
+
70
+ /* ---------- Shell layout ---------- */
71
+ .app-shell {
72
+ display: flex;
73
+ min-height: 100vh;
74
+ }
75
+
76
+ .sidebar {
77
+ width: 220px;
78
+ flex-shrink: 0;
79
+ background: var(--card);
80
+ border-right: 1px solid var(--border);
81
+ padding: 24px 0;
82
+ display: flex;
83
+ flex-direction: column;
84
+ position: sticky;
85
+ top: 0;
86
+ height: 100vh;
87
+ }
88
+
89
+ .sidebar-brand {
90
+ padding: 0 20px 24px;
91
+ font-size: 18px;
92
+ font-weight: 700;
93
+ color: var(--text);
94
+ letter-spacing: -0.3px;
95
+ border-bottom: 1px solid var(--border);
96
+ margin-bottom: 12px;
97
+ }
98
+ .sidebar-brand span {
99
+ color: var(--accent);
100
+ }
101
+
102
+ .sidebar nav {
103
+ display: flex;
104
+ flex-direction: column;
105
+ gap: 2px;
106
+ padding: 0 8px;
107
+ }
108
+
109
+ .sidebar nav a {
110
+ display: flex;
111
+ align-items: center;
112
+ gap: 10px;
113
+ padding: 10px 12px;
114
+ border-radius: 6px;
115
+ font-size: 14px;
116
+ font-weight: 500;
117
+ color: var(--text-secondary);
118
+ text-decoration: none;
119
+ transition: background 0.15s, color 0.15s;
120
+ }
121
+ .sidebar nav a:hover {
122
+ background: rgba(255, 255, 255, 0.05);
123
+ color: var(--text);
124
+ text-decoration: none;
125
+ }
126
+ .sidebar nav a.active {
127
+ background: rgba(59, 130, 246, 0.12);
128
+ color: var(--accent);
129
+ }
130
+
131
+ .sidebar nav a svg {
132
+ width: 18px;
133
+ height: 18px;
134
+ flex-shrink: 0;
135
+ }
136
+
137
+ .main-content {
138
+ flex: 1;
139
+ padding: 32px 40px;
140
+ min-width: 0;
141
+ max-width: 1400px;
142
+ }
143
+
144
+ /* ---------- Page header ---------- */
145
+ .page-header {
146
+ margin-bottom: 28px;
147
+ }
148
+ .page-header h1 {
149
+ font-size: 24px;
150
+ font-weight: 700;
151
+ letter-spacing: -0.3px;
152
+ }
153
+ .page-header p {
154
+ color: var(--text-secondary);
155
+ font-size: 14px;
156
+ margin-top: 4px;
157
+ }
158
+
159
+ /* ---------- Controls bar ---------- */
160
+ .controls {
161
+ display: flex;
162
+ flex-wrap: wrap;
163
+ gap: 12px;
164
+ align-items: center;
165
+ margin-bottom: 24px;
166
+ }
167
+
168
+ .search-input {
169
+ width: 260px;
170
+ }
171
+
172
+ .sort-select {
173
+ min-width: 150px;
174
+ }
175
+
176
+ /* ---------- Store pills ---------- */
177
+ .store-pills {
178
+ display: flex;
179
+ flex-wrap: wrap;
180
+ gap: 6px;
181
+ margin-bottom: 20px;
182
+ }
183
+
184
+ .pill {
185
+ font-size: 13px;
186
+ font-weight: 500;
187
+ padding: 5px 14px;
188
+ border-radius: 20px;
189
+ border: 1px solid var(--border);
190
+ background: transparent;
191
+ color: var(--text-secondary);
192
+ transition: all 0.15s;
193
+ }
194
+ .pill:hover {
195
+ border-color: var(--text-muted);
196
+ color: var(--text);
197
+ }
198
+ .pill.active {
199
+ background: var(--accent);
200
+ border-color: var(--accent);
201
+ color: #fff;
202
+ }
203
+
204
+ /* ---------- Product grid ---------- */
205
+ .product-grid {
206
+ display: grid;
207
+ grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
208
+ gap: 16px;
209
+ }
210
+
211
+ .product-card {
212
+ background: var(--card);
213
+ border: 1px solid var(--border);
214
+ border-radius: var(--radius);
215
+ overflow: hidden;
216
+ transition: transform 0.2s, box-shadow 0.2s;
217
+ display: flex;
218
+ flex-direction: column;
219
+ }
220
+ .product-card:hover {
221
+ transform: translateY(-3px);
222
+ box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
223
+ }
224
+
225
+ .product-card-img {
226
+ width: 100%;
227
+ aspect-ratio: 1;
228
+ object-fit: contain;
229
+ background: #fff;
230
+ padding: 12px;
231
+ }
232
+
233
+ .product-card-body {
234
+ padding: 12px;
235
+ flex: 1;
236
+ display: flex;
237
+ flex-direction: column;
238
+ gap: 4px;
239
+ }
240
+
241
+ .product-card-brand {
242
+ font-size: 11px;
243
+ font-weight: 600;
244
+ text-transform: uppercase;
245
+ letter-spacing: 0.5px;
246
+ color: var(--text-muted);
247
+ }
248
+
249
+ .product-card-name {
250
+ font-size: 14px;
251
+ font-weight: 500;
252
+ color: var(--text);
253
+ display: -webkit-box;
254
+ -webkit-line-clamp: 2;
255
+ -webkit-box-orient: vertical;
256
+ overflow: hidden;
257
+ line-height: 1.35;
258
+ }
259
+
260
+ .product-card-footer {
261
+ display: flex;
262
+ align-items: center;
263
+ justify-content: space-between;
264
+ margin-top: auto;
265
+ padding-top: 8px;
266
+ }
267
+
268
+ .product-card-price {
269
+ font-size: 14px;
270
+ font-weight: 600;
271
+ color: var(--text);
272
+ }
273
+
274
+ .score-badge {
275
+ font-size: 12px;
276
+ font-weight: 700;
277
+ padding: 3px 8px;
278
+ border-radius: 4px;
279
+ color: #fff;
280
+ }
281
+ .score-badge.green {
282
+ background: var(--green);
283
+ }
284
+ .score-badge.blue {
285
+ background: var(--accent);
286
+ }
287
+ .score-badge.amber {
288
+ background: var(--amber);
289
+ }
290
+
291
+ .product-card-store {
292
+ font-size: 11px;
293
+ color: var(--text-muted);
294
+ padding: 0 12px 10px;
295
+ }
296
+ .product-card-store a {
297
+ color: var(--text-muted);
298
+ }
299
+ .product-card-store a:hover {
300
+ color: var(--accent);
301
+ }
302
+
303
+ /* ---------- Pagination ---------- */
304
+ .pagination {
305
+ display: flex;
306
+ align-items: center;
307
+ justify-content: center;
308
+ gap: 8px;
309
+ margin-top: 32px;
310
+ }
311
+
312
+ .pagination button {
313
+ padding: 8px 16px;
314
+ border-radius: var(--radius);
315
+ font-size: 14px;
316
+ font-weight: 500;
317
+ background: var(--card);
318
+ border: 1px solid var(--border);
319
+ color: var(--text-secondary);
320
+ transition: all 0.15s;
321
+ }
322
+ .pagination button:hover:not(:disabled) {
323
+ border-color: var(--accent);
324
+ color: var(--text);
325
+ }
326
+ .pagination button:disabled {
327
+ opacity: 0.35;
328
+ cursor: default;
329
+ }
330
+
331
+ .pagination span {
332
+ font-size: 14px;
333
+ color: var(--text-secondary);
334
+ padding: 0 8px;
335
+ }
336
+
337
+ /* ---------- Stats cards ---------- */
338
+ .stats-row {
339
+ display: flex;
340
+ gap: 16px;
341
+ flex-wrap: wrap;
342
+ margin-bottom: 28px;
343
+ }
344
+
345
+ .stat-card {
346
+ background: var(--card);
347
+ border: 1px solid var(--border);
348
+ border-radius: var(--radius);
349
+ padding: 20px 24px;
350
+ flex: 1;
351
+ min-width: 160px;
352
+ }
353
+
354
+ .stat-card-label {
355
+ font-size: 12px;
356
+ font-weight: 600;
357
+ text-transform: uppercase;
358
+ letter-spacing: 0.5px;
359
+ color: var(--text-muted);
360
+ margin-bottom: 6px;
361
+ }
362
+
363
+ .stat-card-value {
364
+ font-size: 28px;
365
+ font-weight: 700;
366
+ letter-spacing: -0.5px;
367
+ }
368
+
369
+ /* ---------- Profile page ---------- */
370
+ .profile-stats {
371
+ display: flex;
372
+ gap: 16px;
373
+ margin-bottom: 28px;
374
+ }
375
+
376
+ .profile-stat {
377
+ background: var(--card);
378
+ border: 1px solid var(--border);
379
+ border-radius: var(--radius);
380
+ padding: 16px 20px;
381
+ text-align: center;
382
+ min-width: 120px;
383
+ }
384
+ .profile-stat .value {
385
+ font-size: 28px;
386
+ font-weight: 700;
387
+ }
388
+ .profile-stat .label {
389
+ font-size: 12px;
390
+ color: var(--text-muted);
391
+ text-transform: uppercase;
392
+ letter-spacing: 0.5px;
393
+ margin-top: 2px;
394
+ }
395
+ .profile-stat.liked .value {
396
+ color: var(--green);
397
+ }
398
+ .profile-stat.disliked .value {
399
+ color: var(--red);
400
+ }
401
+
402
+ /* ---------- Upload zone ---------- */
403
+ .upload-zone {
404
+ border: 2px dashed var(--border);
405
+ border-radius: var(--radius);
406
+ padding: 40px;
407
+ text-align: center;
408
+ color: var(--text-muted);
409
+ cursor: pointer;
410
+ transition: border-color 0.2s, background 0.2s;
411
+ margin-bottom: 28px;
412
+ }
413
+ .upload-zone:hover,
414
+ .upload-zone.dragging {
415
+ border-color: var(--accent);
416
+ background: rgba(59, 130, 246, 0.05);
417
+ }
418
+ .upload-zone p {
419
+ font-size: 14px;
420
+ }
421
+ .upload-zone .upload-icon {
422
+ font-size: 32px;
423
+ margin-bottom: 8px;
424
+ }
425
+ .upload-zone .upload-hint {
426
+ font-size: 12px;
427
+ margin-top: 4px;
428
+ }
429
+
430
+ /* ---------- Rating grid ---------- */
431
+ .rating-grid {
432
+ display: grid;
433
+ grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
434
+ gap: 16px;
435
+ }
436
+
437
+ .rating-card {
438
+ background: var(--card);
439
+ border: 1px solid var(--border);
440
+ border-radius: var(--radius);
441
+ overflow: hidden;
442
+ position: relative;
443
+ }
444
+
445
+ .rating-card img {
446
+ width: 100%;
447
+ aspect-ratio: 1;
448
+ object-fit: cover;
449
+ }
450
+
451
+ .rating-card-actions {
452
+ display: flex;
453
+ gap: 4px;
454
+ padding: 8px;
455
+ justify-content: center;
456
+ }
457
+
458
+ .rating-card-actions button {
459
+ width: 36px;
460
+ height: 36px;
461
+ border-radius: 6px;
462
+ display: flex;
463
+ align-items: center;
464
+ justify-content: center;
465
+ font-size: 16px;
466
+ border: 1px solid var(--border);
467
+ background: var(--bg);
468
+ transition: all 0.15s;
469
+ }
470
+ .rating-card-actions button:hover {
471
+ border-color: var(--text-muted);
472
+ }
473
+ .rating-card-actions button.liked {
474
+ background: rgba(34, 197, 94, 0.15);
475
+ border-color: var(--green);
476
+ color: var(--green);
477
+ }
478
+ .rating-card-actions button.disliked {
479
+ background: rgba(239, 68, 68, 0.15);
480
+ border-color: var(--red);
481
+ color: var(--red);
482
+ }
483
+ .rating-card-actions button.remove:hover {
484
+ border-color: var(--red);
485
+ color: var(--red);
486
+ }
487
+
488
+ .rating-card-name {
489
+ font-size: 11px;
490
+ color: var(--text-muted);
491
+ padding: 0 8px 4px;
492
+ text-align: center;
493
+ overflow: hidden;
494
+ text-overflow: ellipsis;
495
+ white-space: nowrap;
496
+ }
497
+
498
+ /* ---------- Dashboard table ---------- */
499
+ .table-wrap {
500
+ background: var(--card);
501
+ border: 1px solid var(--border);
502
+ border-radius: var(--radius);
503
+ overflow-x: auto;
504
+ margin-bottom: 28px;
505
+ }
506
+
507
+ .table-wrap table {
508
+ width: 100%;
509
+ border-collapse: collapse;
510
+ font-size: 14px;
511
+ }
512
+
513
+ .table-wrap th {
514
+ text-align: left;
515
+ font-size: 11px;
516
+ font-weight: 600;
517
+ text-transform: uppercase;
518
+ letter-spacing: 0.5px;
519
+ color: var(--text-muted);
520
+ padding: 12px 16px;
521
+ border-bottom: 1px solid var(--border);
522
+ }
523
+
524
+ .table-wrap td {
525
+ padding: 12px 16px;
526
+ border-bottom: 1px solid var(--border);
527
+ color: var(--text-secondary);
528
+ }
529
+
530
+ .table-wrap tr:last-child td {
531
+ border-bottom: none;
532
+ }
533
+
534
+ .table-wrap tr:hover td {
535
+ background: rgba(255, 255, 255, 0.02);
536
+ }
537
+
538
+ /* ---------- Scan area ---------- */
539
+ .scan-section {
540
+ background: var(--card);
541
+ border: 1px solid var(--border);
542
+ border-radius: var(--radius);
543
+ padding: 24px;
544
+ }
545
+
546
+ .scan-section h3 {
547
+ font-size: 16px;
548
+ font-weight: 600;
549
+ margin-bottom: 12px;
550
+ }
551
+
552
+ .btn {
553
+ display: inline-flex;
554
+ align-items: center;
555
+ gap: 6px;
556
+ padding: 10px 20px;
557
+ border-radius: var(--radius);
558
+ font-size: 14px;
559
+ font-weight: 600;
560
+ transition: all 0.15s;
561
+ }
562
+
563
+ .btn-primary {
564
+ background: var(--accent);
565
+ color: #fff;
566
+ }
567
+ .btn-primary:hover {
568
+ background: #2563eb;
569
+ }
570
+ .btn-primary:disabled {
571
+ opacity: 0.5;
572
+ cursor: default;
573
+ }
574
+
575
+ .progress-bar {
576
+ width: 100%;
577
+ height: 6px;
578
+ background: var(--border);
579
+ border-radius: 3px;
580
+ overflow: hidden;
581
+ margin-top: 12px;
582
+ }
583
+
584
+ .progress-bar-fill {
585
+ height: 100%;
586
+ background: var(--accent);
587
+ border-radius: 3px;
588
+ transition: width 0.3s ease;
589
+ }
590
+
591
+ .scan-step {
592
+ font-size: 13px;
593
+ color: var(--text-secondary);
594
+ margin-top: 8px;
595
+ }
596
+
597
+ .scan-error {
598
+ font-size: 13px;
599
+ color: var(--red);
600
+ margin-top: 8px;
601
+ }
602
+
603
+ /* ---------- Loading / empty ---------- */
604
+ .loading {
605
+ text-align: center;
606
+ padding: 60px 20px;
607
+ color: var(--text-muted);
608
+ font-size: 14px;
609
+ }
610
+
611
+ .empty {
612
+ text-align: center;
613
+ padding: 60px 20px;
614
+ color: var(--text-muted);
615
+ font-size: 14px;
616
+ }
617
+
618
+ /* ---------- Responsive ---------- */
619
+ @media (max-width: 768px) {
620
+ .sidebar {
621
+ display: none;
622
+ }
623
+ .main-content {
624
+ padding: 20px 16px;
625
+ }
626
+ .product-grid {
627
+ grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
628
+ }
629
+ }
frontend/src/main.tsx ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { StrictMode } from "react";
2
+ import { createRoot } from "react-dom/client";
3
+ import { BrowserRouter } from "react-router-dom";
4
+ import { App } from "./App";
5
+ import "./index.css";
6
+
7
+ createRoot(document.getElementById("root")!).render(
8
+ <StrictMode>
9
+ <BrowserRouter>
10
+ <App />
11
+ </BrowserRouter>
12
+ </StrictMode>,
13
+ );
frontend/src/pages/BrowsePage.tsx ADDED
@@ -0,0 +1,196 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { useState, useEffect, useCallback } from "react";
2
+ import { getProducts, getStores } from "../api";
3
+ import type { Product, StoreInfo } from "../types";
4
+
5
+ function scoreBadgeClass(score: number): string {
6
+ if (score >= 70) return "score-badge green";
7
+ if (score >= 40) return "score-badge blue";
8
+ return "score-badge amber";
9
+ }
10
+
11
+ export function BrowsePage() {
12
+ const [products, setProducts] = useState<Product[]>([]);
13
+ const [total, setTotal] = useState(0);
14
+ const [page, setPage] = useState(1);
15
+ const [pageSize] = useState(48);
16
+ const [store, setStore] = useState("");
17
+ const [sort, setSort] = useState("score");
18
+ const [search, setSearch] = useState("");
19
+ const [searchInput, setSearchInput] = useState("");
20
+ const [stores, setStores] = useState<StoreInfo[]>([]);
21
+ const [loading, setLoading] = useState(true);
22
+ const [scoreRange, setScoreRange] = useState<{ min: number; max: number }>({ min: 0, max: 1 });
23
+
24
+ useEffect(() => {
25
+ getStores().then(setStores).catch(console.error);
26
+ }, []);
27
+
28
+ const fetchProducts = useCallback(async () => {
29
+ setLoading(true);
30
+ try {
31
+ const res = await getProducts({
32
+ page,
33
+ page_size: pageSize,
34
+ store: store || undefined,
35
+ sort,
36
+ min_score: 0.01,
37
+ search: search || undefined,
38
+ });
39
+ setProducts(res.items);
40
+ setTotal(res.total);
41
+
42
+ if (res.items.length > 0) {
43
+ const scores = res.items.map((p) => p.score);
44
+ setScoreRange({ min: Math.min(...scores), max: Math.max(...scores) });
45
+ }
46
+ } catch (err) {
47
+ console.error(err);
48
+ } finally {
49
+ setLoading(false);
50
+ }
51
+ }, [page, pageSize, store, sort, search]);
52
+
53
+ useEffect(() => {
54
+ fetchProducts();
55
+ }, [fetchProducts]);
56
+
57
+ const totalPages = Math.ceil(total / pageSize);
58
+
59
+ function normalizeScore(score: number): number {
60
+ const { min, max } = scoreRange;
61
+ if (max === min) return 50;
62
+ return Math.round(((score - min) / (max - min)) * 100);
63
+ }
64
+
65
+ function handleSearch(e: React.FormEvent) {
66
+ e.preventDefault();
67
+ setPage(1);
68
+ setSearch(searchInput);
69
+ }
70
+
71
+ return (
72
+ <>
73
+ <div className="page-header">
74
+ <h1>Browse Products</h1>
75
+ <p>
76
+ {total.toLocaleString()} products scored by your taste profile
77
+ </p>
78
+ </div>
79
+
80
+ <div className="store-pills">
81
+ <button
82
+ className={`pill ${store === "" ? "active" : ""}`}
83
+ onClick={() => {
84
+ setStore("");
85
+ setPage(1);
86
+ }}
87
+ >
88
+ All Stores
89
+ </button>
90
+ {stores.map((s) => (
91
+ <button
92
+ key={s.name}
93
+ className={`pill ${store === s.name ? "active" : ""}`}
94
+ onClick={() => {
95
+ setStore(s.name);
96
+ setPage(1);
97
+ }}
98
+ >
99
+ {s.name} ({s.count})
100
+ </button>
101
+ ))}
102
+ </div>
103
+
104
+ <div className="controls">
105
+ <form onSubmit={handleSearch} style={{ display: "contents" }}>
106
+ <input
107
+ className="search-input"
108
+ type="text"
109
+ placeholder="Search products..."
110
+ value={searchInput}
111
+ onChange={(e) => setSearchInput(e.target.value)}
112
+ />
113
+ </form>
114
+ <select
115
+ className="sort-select"
116
+ value={sort}
117
+ onChange={(e) => {
118
+ setSort(e.target.value);
119
+ setPage(1);
120
+ }}
121
+ >
122
+ <option value="score">Highest Score</option>
123
+ <option value="-score">Lowest Score</option>
124
+ <option value="price">Price: Low to High</option>
125
+ <option value="-price">Price: High to Low</option>
126
+ <option value="name">Name A-Z</option>
127
+ </select>
128
+ </div>
129
+
130
+ {loading ? (
131
+ <div className="loading">Loading products...</div>
132
+ ) : products.length === 0 ? (
133
+ <div className="empty">
134
+ No products found. Try adjusting your filters or run a scan first.
135
+ </div>
136
+ ) : (
137
+ <>
138
+ <div className="product-grid">
139
+ {products.map((p, i) => {
140
+ const normalized = normalizeScore(p.score);
141
+ return (
142
+ <div className="product-card" key={`${p.store}-${p.name}-${i}`}>
143
+ <img
144
+ className="product-card-img"
145
+ src={p.image_url}
146
+ alt={p.name}
147
+ loading="lazy"
148
+ onError={(e) => {
149
+ (e.target as HTMLImageElement).src =
150
+ "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Crect fill='%23262626' width='100' height='100'/%3E%3Ctext x='50' y='55' text-anchor='middle' fill='%23737373' font-size='12'%3ENo Image%3C/text%3E%3C/svg%3E";
151
+ }}
152
+ />
153
+ <div className="product-card-body">
154
+ <span className="product-card-brand">{p.brand}</span>
155
+ <span className="product-card-name">{p.name}</span>
156
+ <div className="product-card-footer">
157
+ <span className="product-card-price">{p.price}</span>
158
+ <span className={scoreBadgeClass(normalized)}>
159
+ {normalized}
160
+ </span>
161
+ </div>
162
+ </div>
163
+ <div className="product-card-store">
164
+ <a href={p.url} target="_blank" rel="noopener noreferrer">
165
+ {p.store} &#8599;
166
+ </a>
167
+ </div>
168
+ </div>
169
+ );
170
+ })}
171
+ </div>
172
+
173
+ {totalPages > 1 && (
174
+ <div className="pagination">
175
+ <button
176
+ disabled={page <= 1}
177
+ onClick={() => setPage((p) => p - 1)}
178
+ >
179
+ Previous
180
+ </button>
181
+ <span>
182
+ Page {page} of {totalPages}
183
+ </span>
184
+ <button
185
+ disabled={page >= totalPages}
186
+ onClick={() => setPage((p) => p + 1)}
187
+ >
188
+ Next
189
+ </button>
190
+ </div>
191
+ )}
192
+ </>
193
+ )}
194
+ </>
195
+ );
196
+ }
frontend/src/pages/DashboardPage.tsx ADDED
@@ -0,0 +1,186 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { useState, useEffect, useCallback, useRef } from "react";
2
+ import { getStats, startScan, getScanStatus } from "../api";
3
+ import type { Stats, ScanStatus } from "../types";
4
+
5
+ export function DashboardPage() {
6
+ const [stats, setStats] = useState<Stats | null>(null);
7
+ const [scanStatus, setScanStatus] = useState<ScanStatus | null>(null);
8
+ const [loading, setLoading] = useState(true);
9
+ const pollRef = useRef<ReturnType<typeof setInterval> | null>(null);
10
+
11
+ const fetchStats = useCallback(async () => {
12
+ try {
13
+ const s = await getStats();
14
+ setStats(s);
15
+ } catch (err) {
16
+ console.error(err);
17
+ } finally {
18
+ setLoading(false);
19
+ }
20
+ }, []);
21
+
22
+ const fetchScanStatus = useCallback(async () => {
23
+ try {
24
+ const s = await getScanStatus();
25
+ setScanStatus(s);
26
+ return s;
27
+ } catch {
28
+ return null;
29
+ }
30
+ }, []);
31
+
32
+ useEffect(() => {
33
+ fetchStats();
34
+ fetchScanStatus();
35
+ }, [fetchStats, fetchScanStatus]);
36
+
37
+ useEffect(() => {
38
+ if (scanStatus?.running && !pollRef.current) {
39
+ pollRef.current = setInterval(async () => {
40
+ const s = await fetchScanStatus();
41
+ if (s && !s.running) {
42
+ if (pollRef.current) clearInterval(pollRef.current);
43
+ pollRef.current = null;
44
+ fetchStats();
45
+ }
46
+ }, 1500);
47
+ }
48
+ return () => {
49
+ if (pollRef.current) {
50
+ clearInterval(pollRef.current);
51
+ pollRef.current = null;
52
+ }
53
+ };
54
+ }, [scanStatus?.running, fetchScanStatus, fetchStats]);
55
+
56
+ async function handleScan() {
57
+ try {
58
+ await startScan();
59
+ const s = await fetchScanStatus();
60
+ if (s?.running && !pollRef.current) {
61
+ pollRef.current = setInterval(async () => {
62
+ const status = await fetchScanStatus();
63
+ if (status && !status.running) {
64
+ if (pollRef.current) clearInterval(pollRef.current);
65
+ pollRef.current = null;
66
+ fetchStats();
67
+ }
68
+ }, 1500);
69
+ }
70
+ } catch (err) {
71
+ console.error(err);
72
+ }
73
+ }
74
+
75
+ if (loading) {
76
+ return <div className="loading">Loading dashboard...</div>;
77
+ }
78
+
79
+ const storeEntries = stats ? Object.entries(stats.stores) : [];
80
+
81
+ return (
82
+ <>
83
+ <div className="page-header">
84
+ <h1>Dashboard</h1>
85
+ <p>Overview of your product catalog and taste engine</p>
86
+ </div>
87
+
88
+ <div className="stats-row">
89
+ <div className="stat-card">
90
+ <div className="stat-card-label">Total Products</div>
91
+ <div className="stat-card-value">
92
+ {stats?.total_products.toLocaleString() ?? "---"}
93
+ </div>
94
+ </div>
95
+ <div className="stat-card">
96
+ <div className="stat-card-label">Stores</div>
97
+ <div className="stat-card-value">{storeEntries.length}</div>
98
+ </div>
99
+ <div className="stat-card">
100
+ <div className="stat-card-label">Reference Images</div>
101
+ <div className="stat-card-value">
102
+ {stats?.taste.total ?? "---"}
103
+ </div>
104
+ </div>
105
+ <div className="stat-card">
106
+ <div className="stat-card-label">Liked / Disliked</div>
107
+ <div className="stat-card-value">
108
+ <span style={{ color: "var(--green)" }}>
109
+ {stats?.taste.liked ?? 0}
110
+ </span>
111
+ {" / "}
112
+ <span style={{ color: "var(--red)" }}>
113
+ {stats?.taste.disliked ?? 0}
114
+ </span>
115
+ </div>
116
+ </div>
117
+ </div>
118
+
119
+ {storeEntries.length > 0 && (
120
+ <>
121
+ <div className="page-header" style={{ marginBottom: 16 }}>
122
+ <h2 style={{ fontSize: 18, fontWeight: 600 }}>
123
+ Per-Store Breakdown
124
+ </h2>
125
+ </div>
126
+ <div className="table-wrap">
127
+ <table>
128
+ <thead>
129
+ <tr>
130
+ <th>Store</th>
131
+ <th>Products</th>
132
+ <th>Top Score</th>
133
+ <th>Avg Score</th>
134
+ </tr>
135
+ </thead>
136
+ <tbody>
137
+ {storeEntries.map(([name, info]) => (
138
+ <tr key={name}>
139
+ <td style={{ color: "var(--text)", fontWeight: 500 }}>
140
+ {name}
141
+ </td>
142
+ <td>{info.count.toLocaleString()}</td>
143
+ <td>{info.top.toFixed(3)}</td>
144
+ <td>{info.avg.toFixed(3)}</td>
145
+ </tr>
146
+ ))}
147
+ </tbody>
148
+ </table>
149
+ </div>
150
+ </>
151
+ )}
152
+
153
+ <div className="scan-section">
154
+ <h3>Product Scanner</h3>
155
+ <p style={{ color: "var(--text-secondary)", fontSize: 14, marginBottom: 16 }}>
156
+ Scan stores to discover and score new products based on your taste profile.
157
+ </p>
158
+ <button
159
+ className="btn btn-primary"
160
+ onClick={handleScan}
161
+ disabled={scanStatus?.running ?? false}
162
+ >
163
+ {scanStatus?.running ? "Scanning..." : "Start Scan"}
164
+ </button>
165
+
166
+ {scanStatus?.running && (
167
+ <>
168
+ <div className="progress-bar">
169
+ <div
170
+ className="progress-bar-fill"
171
+ style={{ width: `${Math.round(scanStatus.progress * 100)}%` }}
172
+ />
173
+ </div>
174
+ <div className="scan-step">
175
+ {scanStatus.step} ({Math.round(scanStatus.progress * 100)}%)
176
+ </div>
177
+ </>
178
+ )}
179
+
180
+ {scanStatus?.error && (
181
+ <div className="scan-error">{scanStatus.error}</div>
182
+ )}
183
+ </div>
184
+ </>
185
+ );
186
+ }
frontend/src/pages/ProfilePage.tsx ADDED
@@ -0,0 +1,182 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { useState, useEffect, useCallback, useRef } from "react";
2
+ import { getRatings, setRating, deleteRating, uploadImage } from "../api";
3
+ import type { Rating } from "../types";
4
+
5
+ export function ProfilePage() {
6
+ const [ratings, setRatings] = useState<Rating[]>([]);
7
+ const [total, setTotal] = useState(0);
8
+ const [liked, setLiked] = useState(0);
9
+ const [disliked, setDisliked] = useState(0);
10
+ const [loading, setLoading] = useState(true);
11
+ const [dragging, setDragging] = useState(false);
12
+ const [uploading, setUploading] = useState(false);
13
+ const fileInputRef = useRef<HTMLInputElement>(null);
14
+
15
+ const fetchRatings = useCallback(async () => {
16
+ try {
17
+ const res = await getRatings();
18
+ setRatings(res.ratings);
19
+ setTotal(res.total);
20
+ setLiked(res.liked);
21
+ setDisliked(res.disliked);
22
+ } catch (err) {
23
+ console.error(err);
24
+ } finally {
25
+ setLoading(false);
26
+ }
27
+ }, []);
28
+
29
+ useEffect(() => {
30
+ fetchRatings();
31
+ }, [fetchRatings]);
32
+
33
+ async function handleRate(path: string, rating: number) {
34
+ try {
35
+ await setRating(path, rating);
36
+ await fetchRatings();
37
+ } catch (err) {
38
+ console.error(err);
39
+ }
40
+ }
41
+
42
+ async function handleDelete(path: string) {
43
+ try {
44
+ await deleteRating([path]);
45
+ await fetchRatings();
46
+ } catch (err) {
47
+ console.error(err);
48
+ }
49
+ }
50
+
51
+ async function handleFiles(files: FileList | null) {
52
+ if (!files || files.length === 0) return;
53
+ setUploading(true);
54
+ try {
55
+ for (const file of Array.from(files)) {
56
+ await uploadImage(file);
57
+ }
58
+ await fetchRatings();
59
+ } catch (err) {
60
+ console.error(err);
61
+ } finally {
62
+ setUploading(false);
63
+ }
64
+ }
65
+
66
+ function handleDragOver(e: React.DragEvent) {
67
+ e.preventDefault();
68
+ setDragging(true);
69
+ }
70
+
71
+ function handleDragLeave(e: React.DragEvent) {
72
+ e.preventDefault();
73
+ setDragging(false);
74
+ }
75
+
76
+ function handleDrop(e: React.DragEvent) {
77
+ e.preventDefault();
78
+ setDragging(false);
79
+ handleFiles(e.dataTransfer.files);
80
+ }
81
+
82
+ function imageUrl(rating: Rating): string {
83
+ if (rating.image_url) return rating.image_url;
84
+ return `/api/images/reference/${rating.filename}`;
85
+ }
86
+
87
+ if (loading) {
88
+ return <div className="loading">Loading profile...</div>;
89
+ }
90
+
91
+ return (
92
+ <>
93
+ <div className="page-header">
94
+ <h1>Taste Profile</h1>
95
+ <p>Your reference images that define your taste</p>
96
+ </div>
97
+
98
+ <div className="profile-stats">
99
+ <div className="profile-stat">
100
+ <div className="value">{total}</div>
101
+ <div className="label">Total</div>
102
+ </div>
103
+ <div className="profile-stat liked">
104
+ <div className="value">{liked}</div>
105
+ <div className="label">Liked</div>
106
+ </div>
107
+ <div className="profile-stat disliked">
108
+ <div className="value">{disliked}</div>
109
+ <div className="label">Disliked</div>
110
+ </div>
111
+ </div>
112
+
113
+ <div
114
+ className={`upload-zone ${dragging ? "dragging" : ""}`}
115
+ onDragOver={handleDragOver}
116
+ onDragLeave={handleDragLeave}
117
+ onDrop={handleDrop}
118
+ onClick={() => fileInputRef.current?.click()}
119
+ >
120
+ <div className="upload-icon">
121
+ {uploading ? "\u23F3" : "\u2B06"}
122
+ </div>
123
+ <p>{uploading ? "Uploading..." : "Drop images here or click to upload"}</p>
124
+ <p className="upload-hint">JPG, PNG, or WebP</p>
125
+ <input
126
+ ref={fileInputRef}
127
+ type="file"
128
+ accept="image/*"
129
+ multiple
130
+ hidden
131
+ onChange={(e) => handleFiles(e.target.files)}
132
+ />
133
+ </div>
134
+
135
+ {ratings.length === 0 ? (
136
+ <div className="empty">
137
+ No reference images yet. Upload some to get started.
138
+ </div>
139
+ ) : (
140
+ <div className="rating-grid">
141
+ {ratings.map((r) => (
142
+ <div className="rating-card" key={r.path}>
143
+ <img
144
+ src={imageUrl(r)}
145
+ alt={r.filename}
146
+ loading="lazy"
147
+ onError={(e) => {
148
+ (e.target as HTMLImageElement).src =
149
+ "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Crect fill='%23262626' width='100' height='100'/%3E%3Ctext x='50' y='55' text-anchor='middle' fill='%23737373' font-size='12'%3ENo Image%3C/text%3E%3C/svg%3E";
150
+ }}
151
+ />
152
+ <div className="rating-card-name">{r.filename}</div>
153
+ <div className="rating-card-actions">
154
+ <button
155
+ className={r.rating === 1 ? "liked" : ""}
156
+ onClick={() => handleRate(r.path, 1)}
157
+ title="Like"
158
+ >
159
+ &#x1F44D;
160
+ </button>
161
+ <button
162
+ className={r.rating === -1 ? "disliked" : ""}
163
+ onClick={() => handleRate(r.path, -1)}
164
+ title="Dislike"
165
+ >
166
+ &#x1F44E;
167
+ </button>
168
+ <button
169
+ className="remove"
170
+ onClick={() => handleDelete(r.path)}
171
+ title="Remove"
172
+ >
173
+ &#x2715;
174
+ </button>
175
+ </div>
176
+ </div>
177
+ ))}
178
+ </div>
179
+ )}
180
+ </>
181
+ );
182
+ }
frontend/src/types.ts ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ export interface Product {
2
+ name: string;
3
+ brand: string;
4
+ price: string;
5
+ image_url: string;
6
+ url: string;
7
+ store: string;
8
+ score: number;
9
+ filename: string;
10
+ }
11
+
12
+ export interface ProductsResponse {
13
+ items: Product[];
14
+ total: number;
15
+ page: number;
16
+ page_size: number;
17
+ }
18
+
19
+ export interface StoreInfo {
20
+ name: string;
21
+ count: number;
22
+ top: number;
23
+ avg: number;
24
+ }
25
+
26
+ export interface Rating {
27
+ path: string;
28
+ filename: string;
29
+ rating: number;
30
+ image_url: string;
31
+ }
32
+
33
+ export interface RatingsResponse {
34
+ ratings: Rating[];
35
+ total: number;
36
+ liked: number;
37
+ disliked: number;
38
+ }
39
+
40
+ export interface StoreStats {
41
+ count: number;
42
+ top: number;
43
+ avg: number;
44
+ }
45
+
46
+ export interface TasteStats {
47
+ total: number;
48
+ liked: number;
49
+ disliked: number;
50
+ }
51
+
52
+ export interface Stats {
53
+ total_products: number;
54
+ stores: Record<string, StoreStats>;
55
+ taste: TasteStats;
56
+ }
57
+
58
+ export interface ScanStatus {
59
+ running: boolean;
60
+ step: string;
61
+ progress: number;
62
+ error: string | null;
63
+ }
frontend/tsconfig.json ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "compilerOptions": {
3
+ "target": "es2023",
4
+ "module": "esnext",
5
+ "lib": ["ES2023", "DOM", "DOM.Iterable"],
6
+ "types": ["vite/client"],
7
+ "skipLibCheck": true,
8
+
9
+ /* JSX */
10
+ "jsx": "react-jsx",
11
+
12
+ /* Bundler mode */
13
+ "moduleResolution": "bundler",
14
+ "allowImportingTsExtensions": true,
15
+ "verbatimModuleSyntax": true,
16
+ "moduleDetection": "force",
17
+ "noEmit": true,
18
+
19
+ /* Linting */
20
+ "noUnusedLocals": true,
21
+ "noUnusedParameters": true,
22
+ "erasableSyntaxOnly": true,
23
+ "noFallthroughCasesInSwitch": true
24
+ },
25
+ "include": ["src"]
26
+ }
frontend/vite.config.ts ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { defineConfig } from "vite";
2
+ import react from "@vitejs/plugin-react";
3
+
4
+ export default defineConfig({
5
+ plugins: [react()],
6
+ server: {
7
+ proxy: {
8
+ "/api": {
9
+ target: "http://localhost:8000",
10
+ changeOrigin: true,
11
+ },
12
+ },
13
+ },
14
+ });
taste/store.py CHANGED
@@ -11,7 +11,7 @@ class ProductStore:
11
  def __init__(self, db_path: Path):
12
  self.db_path = Path(db_path)
13
  self.db_path.parent.mkdir(parents=True, exist_ok=True)
14
- self.conn = sqlite3.connect(str(self.db_path))
15
  self.conn.row_factory = sqlite3.Row
16
  self.conn.execute("PRAGMA journal_mode=WAL")
17
  self.conn.execute("PRAGMA synchronous=NORMAL")
 
11
  def __init__(self, db_path: Path):
12
  self.db_path = Path(db_path)
13
  self.db_path.parent.mkdir(parents=True, exist_ok=True)
14
+ self.conn = sqlite3.connect(str(self.db_path), check_same_thread=False)
15
  self.conn.row_factory = sqlite3.Row
16
  self.conn.execute("PRAGMA journal_mode=WAL")
17
  self.conn.execute("PRAGMA synchronous=NORMAL")