discourse/backend/README.md
2025-03-25 03:52:30 -04:00

4.2 KiB

VoxPop Backend Services

This directory contains the backend services for the VoxPop platform.

Services

Identity Service

The Identity Service manages user verification and identity proofs using Privado ID's zero-knowledge proofs:

  • ZKP-based citizenship verification without exposing personal data
  • Self-attestation for eligibility with legal disclaimer
  • Support for multiple countries through a modular provider interface
  • Structured error handling for better user experience

Perspective Service

The Perspective Service handles user perspectives and submissions:

  • Submission of perspectives on policy issues
  • Validation of content length and file size
  • Rate limiting for unverified users
  • CAPTCHA verification for unverified users
  • Storage of perspectives in IPFS via Pinata
  • Retrieval of perspectives from IPFS

Feedback Service

The Feedback Service processes user feedback and stores it on the blockchain.

Moderation Service

The Moderation Service provides content moderation capabilities:

  • Content flagging by users
  • AI-based content filtering
  • Moderation queue management
  • Economic barriers for unverified users

Blockchain Service

The Blockchain Service handles interactions with the Polygon blockchain:

  • Submit perspective hashes
  • Propose insights
  • Vote on insights
  • Transaction retry mechanism with gas estimation
  • Mock contract interactions for development

Development Setup

Prerequisites

  • Go 1.20 or higher
  • Docker and Docker Compose
  • PostgreSQL (via Docker)
  • Redis (via Docker)
  • Access to Polygon network (Amoy testnet recommended for development)
  • Private key with sufficient funds for gas fees

Running Locally

  1. Set up environment variables:
export RPC_URL=your_ethereum_rpc_url
export CONTRACT_ADDRESS=your_contract_address
export PRIVATE_KEY=your_private_key
export POLYGON_RPC=your_polygon_rpc_url
export CHAIN_ID=80002  # For Amoy testnet
  1. Start the database and Redis with Docker Compose:
docker-compose up -d postgres redis
  1. Run the backend:
go run main.go

Docker Setup

To run the entire stack using Docker Compose:

docker-compose up -d

API Endpoints

The backend exposes the following API endpoints:

Identity

  • POST /verify - Verify user identity using Privado ID ZKP token
  • GET /verify/disclaimer - Get the legal disclaimer for eligibility self-attestation

Perspective

  • POST /perspective/submit - Submit a perspective which will be stored in IPFS
  • GET /perspective/get/:hash - Get a perspective by its IPFS hash
  • GET /perspective/issue/:issueId - Get all perspectives for a specific issue

Feedback

  • POST /submit-feedback - Submit feedback

Moderation

  • POST /flag-content - Flag content for moderation
  • GET /moderation-queue - Get the moderation queue
  • POST /moderate-content - Moderate content (approve/reject)
  • POST /submit-for-moderation - Submit content for AI moderation

Blockchain

  • POST /blockchain/submit-hash - Submit a perspective hash to the blockchain
  • POST /blockchain/propose-insight - Propose a new insight
  • POST /blockchain/vote - Vote on an insight

Security Considerations

  • Private keys should never be committed to version control
  • Use environment variables or secure secret management
  • Implement rate limiting for API endpoints
  • Validate all input parameters
  • Use HTTPS for all API communications

Environment Variables

The backend services require the following environment variables:

# Database configuration
DATABASE_URL=postgres://postgres:postgres@localhost:5432/voxpop?sslmode=disable

# Redis configuration
REDIS_ADDR=localhost:6379
REDIS_PASSWORD=

# Ethereum configuration
RPC_URL=https://polygon-amoy.g.alchemy.com/v2/your_api_key
CONTRACT_ADDRESS=0xYourContractAddress
PRIVATE_KEY=yourPrivateKey

# Polygon configuration for blockchain service
POLYGON_RPC=https://rpc-amoy.polygon.technology
CHAIN_ID=80002

# IPFS via Pinata configuration
PINATA_API_KEY=your_pinata_api_key
PINATA_API_SECRET=your_pinata_api_secret
PINATA_JWT=your_pinata_jwt_token
PINATA_PRODUCTION=false

# Privado ID configuration
PRIVADO_API_KEY=your_privado_api_key
PRIVADO_API_URL=https://api.privado.ai