Skip to content

svdberg/marktplaatser

Repository files navigation

πŸ€– Marktplaats AI Assistant

An AI-powered application that automatically generates Marktplaats listings from product images. Uses AWS Rekognition for image analysis, Claude Sonnet for intelligent content generation, and includes smart price estimation based on the Dutch second-hand market.

✨ Features

  • πŸ“Έ Image Analysis: Upload product photos and get automatic object detection
  • 🧠 AI-Generated Listings: Claude Sonnet creates titles, descriptions, and categories
  • πŸ’° Smart Price Estimation: AI suggests realistic prices for the Dutch market
  • πŸ” OAuth Integration: Secure Marktplaats account authorization
  • πŸ“± Mobile Optimized: Automatic image compression for mobile devices
  • πŸ“‹ Full CRUD: Create, read, update, and delete advertisements
  • πŸ–ΌοΈ Image Management: Upload and display advertisement images

πŸ—οΈ Architecture

Backend (AWS Lambda + Serverless)

  • Runtime: Python 3.11
  • Framework: Serverless Framework
  • Services: AWS Lambda, API Gateway, S3, DynamoDB, Rekognition, Bedrock
  • AI Model: Claude Sonnet 3.7 via AWS Bedrock

Frontend (Nuxt.js + Vue 3)

  • Framework: Nuxt.js 3 with Vue 3 Composition API
  • Styling: Tailwind CSS with custom components
  • Deployment: Static site on AWS S3
  • Features: PWA ready with offline support

External APIs

  • Marktplaats API: OAuth, category management, advertisement CRUD
  • AWS Rekognition: Image analysis and text extraction
  • AWS Bedrock: Claude Sonnet for content generation

πŸš€ Quick Start

Prerequisites

  • Node.js 18+ and npm
  • Python 3.11+
  • AWS CLI configured with appropriate permissions
  • Serverless Framework (npm install -g serverless)
  • Marktplaats API credentials (client ID and secret)

1. Clone and Setup

git clone <repository-url>
cd marktplaatser

# Install dependencies
npm run install:all

2. Environment Configuration

Backend Environment

# Required environment variables
export MARKTPLAATS_CLIENT_ID=your_client_id
export MARKTPLAATS_CLIENT_SECRET=your_client_secret

# Optional for local development
export IS_LOCAL=true

Frontend Configuration

Update marktplaats-frontend/.env.production:

NUXT_PUBLIC_API_BASE_URL=your_api_gateway_url

3. Deploy Everything

# Deploy both backend and frontend
./deploy.sh

# Or deploy individually
npm run deploy:backend
npm run deploy:frontend

πŸ“ Project Structure

marktplaatser/
β”œβ”€β”€ README.md                          # This file
β”œβ”€β”€ deploy.sh                          # Root deployment script
β”œβ”€β”€ package.json                       # Root package.json with scripts
β”‚
β”œβ”€β”€ marktplaats-backend/               # AWS Lambda backend
β”‚   β”œβ”€β”€ src/marktplaats_backend/       # Python source code
β”‚   β”‚   β”œβ”€β”€ generate_listing_lambda.py # Main listing generation
β”‚   β”‚   β”œβ”€β”€ bedrock_utils.py           # Claude Sonnet integration
β”‚   β”‚   β”œβ”€β”€ rekognition_utils.py       # AWS Rekognition utilities
β”‚   β”‚   β”œβ”€β”€ marktplaats_auth.py        # OAuth and token management
β”‚   β”‚   β”œβ”€β”€ marktplaats_ads_api.py     # Marktplaats API integration
β”‚   β”‚   β”œβ”€β”€ category_matcher.py        # Category matching logic
β”‚   β”‚   └── attribute_mapper.py        # Attribute mapping utilities
β”‚   β”œβ”€β”€ tests/                         # Unit and integration tests
β”‚   β”œβ”€β”€ serverless.yaml               # Serverless configuration
β”‚   β”œβ”€β”€ requirements.txt              # Python dependencies
β”‚   └── deploy.sh                     # Backend deployment script
β”‚
└── marktplaats-frontend/             # Nuxt.js frontend
    β”œβ”€β”€ pages/                        # Vue.js pages
    β”‚   β”œβ”€β”€ index.vue                 # Main image upload and listing generation
    β”‚   β”œβ”€β”€ listings.vue              # Advertisement management
    β”‚   └── callback.vue              # OAuth callback handler
    β”œβ”€β”€ components/                   # Reusable Vue components
    β”‚   β”œβ”€β”€ EditListingModal.vue      # Advertisement editing modal
    β”‚   └── CategorySelector.vue      # Category selection component
    β”œβ”€β”€ nuxt.config.ts               # Nuxt configuration
    β”œβ”€β”€ serverless.yml              # Frontend deployment config
    └── deploy.sh                   # Frontend deployment script

πŸ”§ Development

Backend Development

cd marktplaats-backend

# Install dependencies
pip install -r requirements.txt
pip install -e ".[dev]"

# Run tests
python -m pytest tests/ -v

# Code quality
flake8 src/ tests/
black src/ tests/
mypy src/

# Local testing
serverless invoke local -f generateListing

# Deploy single function
serverless deploy function -f generateListing

Frontend Development

cd marktplaats-frontend

# Install dependencies
npm install

# Development server
npm run dev

# Build for production
npm run generate

# Deploy to S3
./deploy.sh

Key Development Files

Backend Core Functions

  • generate_listing_lambda.py - Main entry point for image analysis and listing generation
  • bedrock_utils.py - Claude Sonnet integration with vision capabilities and price estimation
  • marktplaats_ads_api.py - Complete Marktplaats API wrapper with CRUD operations
  • manage_advertisement_lambda.py - Advertisement management endpoints

Frontend Core Pages

  • pages/index.vue - Main application with image upload and AI generation
  • pages/listings.vue - Advertisement management with edit/delete functionality
  • components/EditListingModal.vue - Modal for editing advertisements

πŸ”‘ API Endpoints

Backend Endpoints (API Gateway)

Method Endpoint Description
POST /generate-listing Generate listing from image
POST /create-advertisement Create advertisement on Marktplaats
GET /oauth/authorize Start OAuth flow
GET /oauth/callback Handle OAuth callback
GET /categories Get Marktplaats categories
GET /list-advertisements List user advertisements
GET /advertisement-images/{id} Get advertisement images
GET /manage-advertisement/{id} Get advertisement details
PATCH /manage-advertisement/{id} Update advertisement
DELETE /manage-advertisement/{id} Delete advertisement

Request/Response Examples

Generate Listing

curl -X POST https://your-api.com/dev/generate-listing \
  -H "Content-Type: application/json" \
  -d '{"image": "base64_encoded_image_data"}'

Response:

{
  "title": "Vintage houten tafel - eiken",
  "description": "Mooie vintage eiken tafel...",
  "categoryId": 621,
  "categoryName": "Tafels > Eettafels",
  "attributes": [...],
  "estimatedPrice": 150,
  "priceRange": {"min": 120, "max": 180},
  "priceConfidence": "hoog"
}

πŸ› οΈ Configuration

AWS Services Setup

Required AWS Permissions

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "lambda:*",
        "apigateway:*",
        "s3:*",
        "dynamodb:*",
        "rekognition:DetectLabels",
        "rekognition:DetectText",
        "bedrock:InvokeModel"
      ],
      "Resource": "*"
    }
  ]
}

DynamoDB Table

The marktplaats-user-tokens table is automatically created by Serverless Framework.

S3 Buckets

  • marktplaatser-images - Image storage (auto-created)
  • marktplaats-frontend-simple-prod-website - Frontend hosting

Environment Variables

Variable Description Required
MARKTPLAATS_CLIENT_ID Marktplaats API client ID Yes
MARKTPLAATS_CLIENT_SECRET Marktplaats API client secret Yes
AWS_REGION AWS region (default: eu-west-1) No
IS_LOCAL Enable local development mode No

πŸ§ͺ Testing

Backend Tests

cd marktplaats-backend

# Run all tests
python -m pytest tests/ -v

# Run specific test categories
python tests/test_integration.py  # Integration tests
python tests/test_attribute_mapping.py  # Unit tests

# Test deployed function
./test.sh sample.jpg

Frontend Testing

cd marktplaats-frontend

# Build test
npm run generate

# Manual testing
npm run dev  # Test at http://localhost:3000

πŸ“± Mobile Optimization

The application includes several mobile-specific optimizations:

  • Image Compression: Automatic resizing to 1024x1024 with 80% quality
  • Progress Feedback: Loading states for compression and AI processing
  • Responsive Design: Tailwind CSS with mobile-first approach
  • Touch-Friendly: Large buttons and intuitive gestures

πŸ”’ Security

  • OAuth 2.0: Secure Marktplaats account integration
  • Token Storage: Encrypted user tokens in DynamoDB
  • CORS Protection: Configured for specific frontend domains
  • Input Validation: Client and server-side validation
  • API Rate Limiting: Handled by AWS API Gateway

🚦 Deployment

Production Deployment

# Full deployment
./deploy.sh

# Backend only
cd marktplaats-backend && ./deploy.sh

# Frontend only
cd marktplaats-frontend && ./deploy.sh

Deployment Checklist

  • AWS credentials configured
  • Marktplaats API credentials set
  • Environment variables configured
  • Tests passing
  • CORS domains updated for production

πŸ› Troubleshooting

Common Issues

"Image too large" errors on mobile

  • Solution: Image compression is automatic, but very large images (>10MB) may still timeout
  • Workaround: Use the 1024x1024 compression setting

OAuth callback errors

  • Solution: Ensure callback URL matches Marktplaats app configuration
  • Check: FRONTEND_DOMAIN environment variable

Category matching failures

  • Solution: Categories are fetched from Marktplaats API in real-time
  • Check: Internet connectivity and API credentials

Price estimation not working

  • Solution: Ensure AWS Bedrock has access to Claude Sonnet 3.7
  • Check: AWS region (must be eu-west-1) and model permissions

Logging and Debugging

Backend Logs

# CloudWatch logs
aws logs tail /aws/lambda/marktplaats-backend-dev-generateListing --follow

# Specific function
serverless logs -f generateListing -t

Frontend Debugging

  • Open browser developer tools
  • Check console for compression logs
  • Network tab for API call failures

🀝 Contributing

Development Workflow

  1. Fork and Clone: Fork the repository and clone locally
  2. Feature Branch: Create a feature branch (git checkout -b feature/amazing-feature)
  3. Development: Make changes and test thoroughly
  4. Tests: Ensure all tests pass
  5. Documentation: Update README if needed
  6. Pull Request: Submit PR with clear description

Code Style

Backend (Python)

  • Formatter: Black
  • Linter: Flake8
  • Type Checking: MyPy
  • Docstrings: Google style

Frontend (Vue/TypeScript)

  • Formatter: Prettier
  • Linter: ESLint
  • Style: Vue 3 Composition API
  • CSS: Tailwind CSS classes

πŸ“š Additional Resources

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™‹β€β™‚οΈ Support

For questions, issues, or contributions:

  1. Check Issues: Look for existing GitHub issues
  2. Create Issue: Describe your problem with steps to reproduce
  3. Discussion: Use GitHub Discussions for questions

Made with ❀️ and πŸ€– AI assistance

About

No description, website, or topics provided.

Resources

License

Stars

2 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors