A comprehensive backend implementation for TechMarkets, a cryptocurrency-denominated marketplace for electronic devices with depreciation tracking. Built on Supabase with multi-method authentication including wallet-based sign-in.
TechMarkets is a marketplace that tracks the depreciation rate of electronic devices, allowing users to buy and sell those devices exclusively in cryptocurrency. This repository contains the Supabase backend implementation with:
- Multi-method Authentication: Wallet (Tezos) + Email/Google
- PostgreSQL Database: Complete schema for marketplace operations
- Edge Functions: Custom API endpoints for business logic
- Real-time Features: Live updates and notifications
- Smart Contract Integration: Ready for blockchain integration
- Wallet Authentication: Sign in with Tezos wallet using SIWT (Sign in with Tezos)
- Traditional Auth: Email/password and Google OAuth
- Account Linking: Link multiple authentication methods to one account
- Security: JWT tokens, session management, and replay attack prevention
- User Profiles: Extended user data with verification status
- Categories: Hierarchical product categorization
- Listings: Product listings with images and metadata
- Transactions: Purchase tracking with smart contract integration
- Depreciation Data: Device value tracking over time
- Authentication and user management
- Listing CRUD operations
- Transaction processing
- Depreciation data management
- Smart contract integration
- Backend: Supabase (PostgreSQL + Edge Functions)
- Authentication: Supabase Auth + Custom SIWT implementation
- Database: PostgreSQL with Row Level Security (RLS)
- Runtime: Deno (for Edge Functions)
- Blockchain: Tezos integration ready
techmarkets-supabase/
βββ supabase/
β βββ config.toml # Supabase configuration
β βββ functions/ # Edge Functions
β β βββ auth/ # Authentication endpoints
β β β βββ index.ts # Main auth function
β β β βββ @siwt/ # SIWT implementation
β β βββ _shared/ # Shared utilities
β βββ migrations/ # Database migrations
β βββ 20250806224921_siwt-nonces.sql
β βββ 20250916032755_profiles.sql
β βββ 20250916032852_categories.sql
β βββ 20250916032936_listings.sql
β βββ 20250916033025_transactions.sql
βββ package.json # Node.js dependencies
βββ README.md # This file
- id: UUID (references auth.users)
- user_type: 'buyer' | 'seller' | 'admin'
- wallet_address: TEXT (unique)
- verification flags: google_verified, seller_verified
- personal info: firstname, lastname, address, etc.
- social links: instagram, twitter, linkedin, website
- crypto addresses: lunc_address, xtz_address
- location: what3words, pluscode
- profile_image_url: TEXT
- id: UUID (primary key)
- name: TEXT (category name)
- slug: TEXT (unique URL slug)
- description: TEXT
- parent_id: UUID (self-reference for hierarchy)
- id: UUID (primary key)
- seller_id: UUID (references auth.users)
- category_id: UUID (references categories)
- title, description: TEXT
- make, model: TEXT
- condition: 'new' | 'like-new' | 'good' | 'fair' | 'poor'
- price: NUMERIC
- currency: 'usd' | 'xtz'
- status: 'active' | 'sold' | 'removed' | 'pending'
- smart_contract_listing_id: TEXT
- id: UUID (primary key)
- listing_id: UUID (references listings)
- image_url, image_path: TEXT
- is_primary: BOOLEAN
- sort_order: INTEGER
- id: UUID (primary key)
- listing_id: UUID (references listings)
- buyer_id, seller_id: UUID (references auth.users)
- amount: DECIMAL(18,8)
- currency: TEXT
- smart_contract_tx_hash: TEXT
- status: 'pending' | 'paid' | 'shipped' | 'completed' | 'disputed' | 'cancelled'
- shipping_address: JSONB
- tracking_number: TEXT
- id: UUID (primary key)
- nonce: TEXT (unique)
- address: TEXT
- status: 'pending' | 'used' | 'expired'
- created_at, expires_at, used_at: TIMESTAMP
- User connects Tezos wallet
- Signs authentication message with wallet
- Custom Edge Function validates signature
- Creates or retrieves user account
- Returns JWT token for API access
- Standard Supabase email/password flow
- Google OAuth integration
- Account linking between methods
- Node.js 18+
- Supabase CLI
- Git
-
Clone the repository
git clone <repository-url> cd techmarkets-supabase
-
Install dependencies
npm install
-
Start Supabase locally
npm run sb:start
-
Apply database migrations
npx supabase db reset
# Supabase Management
npm run sb:start # Start local Supabase
npm run sb:stop # Stop local Supabase
npm run sb:status # Check Supabase status
npm run sb:db:list # List databases
npm run sb:db:create # Create new database
npm run sb:db:drop # Drop database
POST /auth/wallet
- Authenticate with wallet signaturePOST /auth/link-wallet
- Link wallet to existing accountPOST /auth/verify-seller
- Verify seller requirementsGET /auth/profile
- Get current user profile
GET /listings
- Get all active listings (with filters)GET /listings/:id
- Get specific listingPOST /listings
- Create new listing (sellers only)PUT /listings/:id
- Update listing (owner only)DELETE /listings/:id
- Remove listing (owner only)POST /listings/:id/images
- Upload listing images
POST /transactions
- Initialize purchaseGET /transactions/:id
- Get transaction detailsPUT /transactions/:id/ship
- Mark as shipped (seller only)PUT /transactions/:id/complete
- Mark as completed
Create a .env.local
file in the supabase directory:
# Supabase
SUPABASE_URL=your_supabase_url
SUPABASE_ANON_KEY=your_anon_key
SUPABASE_SERVICE_ROLE_KEY=your_service_role_key
# SIWT Configuration
SIWT_DOMAIN=your_domain.com
SIWT_STATEMENT=Sign in to TechMarkets
# Optional: External Services
OPENAI_API_KEY=your_openai_key
SENDGRID_API_KEY=your_sendgrid_key
The supabase/config.toml
file contains all local development settings:
- Database configuration (PostgreSQL 17)
- Authentication settings
- Storage configuration
- Edge Functions runtime settings
- Row Level Security (RLS): Database-level access control
- JWT Authentication: Secure token-based auth
- Nonce System: Prevents replay attacks in wallet auth
- Input Validation: Server-side validation for all inputs
- Rate Limiting: API endpoint protection
- CORS Configuration: Cross-origin request handling
- Users can only view/update their own profiles
- Anyone can view active listings
- Sellers can manage their own listings
- Users can view their own transactions
- Service role has full access to nonces table
The system is designed to integrate with Tezos smart contracts for:
- Listing creation and management
- Escrow-based transactions
- Automated dispute resolution
- Platform fee collection
createListing()
- Store listing metadata on-chainpurchaseItem()
- Handle payment escrowmarkShipped()
- Update shipping statuscompletePurchase()
- Release funds to sellerdisputeTransaction()
- Initiate dispute resolution
- Database Indexing: Optimized queries on frequently accessed fields
- Image CDN: Automatic image optimization and delivery
- Real-time Updates: WebSocket connections for live data
- Connection Pooling: Efficient database connections
- Start Supabase:
npm run sb:start
- Access Supabase Studio: http://localhost:54333
- View API docs: http://localhost:54331/rest/v1/
- Test Edge Functions: http://localhost:54321/functions/v1/
- Use Supabase Studio for database testing
- Test Edge Functions with curl or Postman
- Verify authentication flows with wallet integration
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
This project is licensed under the ISC License - see the package.json file for details.
- Supabase Documentation
- SIWT (Sign in with Tezos) Specification
- Tezos Documentation
- Implementation Guide
For questions and support:
- Check the Implementation Guide
- Review Supabase documentation
- Open an issue in this repository
Note: This is a backend implementation. The frontend application would be in a separate repository and would consume these APIs.