Skip to content

KNYTT-dev/knytt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

326 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Knytt - AI-Powered Product Discovery Platform

A full-stack AI-powered product discovery platform with semantic search, personalized recommendations, and intelligent user interactions. Built with FastAPI, Next.js, PostgreSQL (Supabase), and CLIP embeddings.

๐ŸŒŸ Features

  • AI-Powered Search: Semantic product search using CLIP embeddings and FAISS similarity search
  • Personalized Recommendations: Context-aware recommendations based on user behavior and preferences
  • User Interactions: Track views, clicks, likes, and purchases to improve personalization
  • Modern Frontend: Beautiful, responsive UI built with Next.js 16 and Tailwind CSS
  • Real-time Updates: React Query for efficient data fetching and caching
  • Production Ready: Full authentication, error handling, and monitoring

๐Ÿ“‹ Requirements

  • Python 3.12+
  • Node.js 18+
  • Supabase CLI (for local development)
  • PostgreSQL 15+ with pgvector extension
  • Redis 7+ (optional, for caching)

๐Ÿš€ Quick Start

1. Install Supabase CLI

# Download Supabase CLI binary
curl -L https://github.com/supabase/cli/releases/download/v2.54.11/supabase_darwin_amd64.tar.gz -o /tmp/supabase.tar.gz
mkdir -p ~/bin
tar -xzf /tmp/supabase.tar.gz -C ~/bin
export PATH="$HOME/bin:$PATH"

2. Start Supabase

# Start local Supabase stack (PostgreSQL, Auth, Storage, Studio)
supabase start

# Access Supabase Studio at: http://localhost:54323
# PostgreSQL: postgresql://postgres:postgres@127.0.0.1:54322/postgres

3. Set Up Backend

# Create Python virtual environment
python3.12 -m venv venv
source venv/bin/activate

# Install dependencies
pip install -r requirements.txt
pip install -r requirements-dev.txt  # For development tools

# Set up pre-commit hooks (catches formatting issues before commit)
pre-commit install

# Copy environment file
cp .env .env.local  # Edit if needed

# Create database schema
python create_db.py

# Start backend API
python -m uvicorn backend.api.main:app --host 0.0.0.0 --port 8001 --reload

# API will be available at: http://localhost:8001
# API Docs: http://localhost:8001/docs

4. Set Up Frontend

cd frontend

# Install dependencies
npm install

# Copy environment file
cp .env.local.example .env.local

# Start frontend
npm run dev

# Frontend will be available at: http://localhost:3000

๐Ÿ“ Project Structure

knytt/
โ”œโ”€โ”€ backend/                    # Python FastAPI backend
โ”‚   โ”œโ”€โ”€ api/                    # API routes and endpoints
โ”‚   โ”‚   โ”œโ”€โ”€ main.py            # FastAPI app entry point
โ”‚   โ”‚   โ”œโ”€โ”€ routers/           # API route handlers
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ auth.py        # Authentication (login, register)
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ search.py      # Product search
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ recommend.py   # Recommendations
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ feedback.py    # User interactions
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ users.py       # User management
โ”‚   โ”‚   โ”œโ”€โ”€ schemas/           # Pydantic request/response models
โ”‚   โ”‚   โ”œโ”€โ”€ dependencies.py    # Dependency injection
โ”‚   โ”‚   โ”œโ”€โ”€ security.py        # JWT auth, password hashing
โ”‚   โ”‚   โ””โ”€โ”€ middleware.py      # Request logging, timing
โ”‚   โ”œโ”€โ”€ db/                    # Database layer
โ”‚   โ”‚   โ”œโ”€โ”€ models.py          # SQLAlchemy ORM models
โ”‚   โ”‚   โ””โ”€โ”€ session.py         # Database connection
โ”‚   โ”œโ”€โ”€ ml/                    # Machine learning components
โ”‚   โ”‚   โ”œโ”€โ”€ retrieval.py       # FAISS index management
โ”‚   โ”‚   โ”œโ”€โ”€ search.py          # Search service
โ”‚   โ”‚   โ””โ”€โ”€ caching.py         # Embedding cache
โ”‚   โ””โ”€โ”€ celery/                # Background tasks (Celery)
โ”œโ”€โ”€ frontend/                   # Next.js 16 frontend
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ app/               # Next.js App Router pages
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ page.tsx       # Home page
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ search/        # Search page
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ login/         # Login page
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ register/      # Register page
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ favorites/     # User favorites
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ history/       # Interaction history
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ products/[id]/ # Product details
โ”‚   โ”‚   โ”œโ”€โ”€ components/        # React components
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ layout/        # Header, Footer
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ home/          # Hero, CategoryPills, MasonryGrid
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ search/        # SearchFilters, SearchResults
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ recommendations/ # RecommendationCarousel
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ products/      # ProductCard, ProductGrid
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ ui/            # Reusable UI components
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ providers/     # Context providers
โ”‚   โ”‚   โ”œโ”€โ”€ lib/               # Core utilities
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ query-client.ts  # React Query config
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ queries/         # Data fetching hooks
โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ auth.ts      # Auth queries (login, register, useAuth)
โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ search.ts    # Search queries
โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ recommendations.ts  # Recommendation queries
โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ feedback.ts  # Interaction tracking
โ”‚   โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ user.ts      # User data queries
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ stores/          # Zustand state stores
โ”‚   โ”‚   โ”‚       โ””โ”€โ”€ cartStore.ts # Shopping cart
โ”‚   โ”‚   โ”œโ”€โ”€ types/             # TypeScript types
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ api.ts         # API request/response types
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ product.ts     # Product types
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ enums.ts       # Enums and constants
โ”‚   โ”‚   โ””โ”€โ”€ styles/            # Global styles
โ”‚   โ””โ”€โ”€ public/                # Static assets
โ”œโ”€โ”€ supabase/                   # Supabase configuration
โ”‚   โ””โ”€โ”€ migrations/            # Database migrations (legacy)
โ”œโ”€โ”€ create_db.py               # Database schema creation script
โ”œโ”€โ”€ .env                       # Environment variables
โ””โ”€โ”€ README.md                  # This file

๐Ÿ—„๏ธ Database Schema

The application uses 6 main tables:

  • users: User accounts and authentication
  • user_embeddings: ML-powered user preference embeddings
  • user_interactions: Tracking user behavior (views, clicks, likes)
  • products: Product catalog
  • product_embeddings: Vector embeddings for products (512-dim CLIP)
  • task_executions: Background job tracking

๐Ÿ”ง Development

Backend Development

# Activate virtual environment
source venv/bin/activate

# Run backend with auto-reload
python -m uvicorn backend.api.main:app --host 0.0.0.0 --port 8001 --reload

# Create database schema
python create_db.py

# Access API docs
open http://localhost:8001/docs

Frontend Development

cd frontend

# Start dev server
npm run dev

# Build for production
npm run build

# Start production server
npm run start

# Run linting
npm run lint

# Type check
npm run type-check

Database Management

# Access Supabase Studio
open http://localhost:54323

# Connect to PostgreSQL directly
PGPASSWORD=postgres psql -h 127.0.0.1 -p 54322 -U postgres -d postgres

# Reset database (recreate schema)
python create_db.py

๐Ÿ“ˆ API Endpoints

Authentication

  • POST /auth/register - Register new user
  • POST /auth/login - Login and receive JWT tokens
  • POST /auth/logout - Logout (clear cookies)
  • GET /auth/me - Get current authenticated user
  • POST /auth/refresh - Refresh access token

Search & Discovery

  • POST /api/v1/search - Semantic product search
  • POST /api/v1/recommend - Personalized recommendations

User Interactions

  • POST /api/v1/feedback - Track user interactions (view, click, like, etc.)
  • GET /api/v1/users/{user_id}/stats - User statistics
  • GET /api/v1/users/{user_id}/history - Interaction history
  • GET /api/v1/users/{user_id}/favorites - User favorites

Health & Monitoring

  • GET /health - Health check
  • GET /status - Detailed system status
  • GET /metrics - Performance metrics

๐ŸŒ Environment Variables

Backend (.env)

# Supabase (Local)
SUPABASE_URL=http://127.0.0.1:54321
SUPABASE_ANON_KEY=sb_publishable_ACJWlzQHlZjBrEguHvfOxg_3BJgxAaH
SUPABASE_SERVICE_KEY=sb_secret_N7UND0UgjKTVK-Uodkm0Hg_xSvEMPvz

# Database
DATABASE_URL=postgresql://postgres:postgres@127.0.0.1:54322/postgres

# API
API_HOST=0.0.0.0
API_PORT=8001

# Redis (Optional)
REDIS_HOST=localhost
REDIS_PORT=6379

# ML Configuration
CLIP_MODEL=ViT-B/32
EMBEDDING_DIMENSION=512

Frontend (.env.local)

NEXT_PUBLIC_SUPABASE_URL=http://127.0.0.1:54321
NEXT_PUBLIC_SUPABASE_ANON_KEY=sb_publishable_ACJWlzQHlZjBrEguHvfOxg_3BJgxAaH
NEXT_PUBLIC_API_URL=http://localhost:8001

๐Ÿงช Testing

# Backend tests
pytest tests/ -v

# Frontend tests
cd frontend
npm run test

๐Ÿšข Deployment

See docs/deployment/README.md for deployment guides:

  • Supabase Cloud + GCP Cloud Run (Recommended)
  • Docker Compose (Development)
  • Kubernetes (Production)

๐Ÿ”ฎ Features & Roadmap

โœ… Completed

  • FastAPI backend with authentication
  • SQLAlchemy database models
  • Supabase integration (PostgreSQL, Auth)
  • Next.js 16 frontend with App Router
  • React Query for data fetching
  • Zustand for state management
  • User authentication (JWT)
  • Product search and recommendations
  • User interaction tracking
  • Responsive UI with Tailwind CSS

๐Ÿšง In Progress

  • CLIP embeddings generation
  • FAISS similarity search
  • ML model integration

๐Ÿ“‹ Planned

  • Image upload and processing
  • Real-time notifications
  • Social features (sharing, following)
  • Analytics dashboard
  • A/B testing framework
  • Multi-language support

๐Ÿ“š Documentation

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Install development dependencies and pre-commit hooks:
    pip install -r requirements-dev.txt
    pre-commit install
  4. Make your changes (pre-commit hooks will auto-format on commit)
  5. Commit your changes (git commit -m 'Add amazing feature')
  6. Push to the branch (git push origin feature/amazing-feature)
  7. Open a Pull Request

Note: Pre-commit hooks will automatically run Black, isort, flake8, and other checks before each commit. This ensures code quality and prevents CI failures.

๐Ÿ“„ License

MIT License - see LICENSE file for details

๐Ÿ“ž Support

For questions and support, please open an issue in the repository.


Built with โค๏ธ using FastAPI, Next.js, and Supabase

About

No description, website, or topics provided.

Resources

License

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors