Skip to content

julerex/reputest

Rust PostgreSQL Twitter MIT License

✨ Reputest

A social reputation graph built on good vibes
Track positive relationships on Twitter/X and discover connection degrees between users

What It Does β€’ How It Works β€’ Quick Start β€’ API β€’ Deployment


🎯 What It Does

The reputest bot monitors Twitter/X for #gmgv (Gives Me Good Vibes) hashtag tweets and builds a directed social graph of positive relationships. When someone tweets @username #gmgv (or username #gmgv for stealth mode 🀫), they're attesting to the good vibes they get from that X user, creating a connection in the reputation graph.

Key Features:

  • πŸ” Hashtag Monitoring β€” Automatically scans for #gmgv tweets every 5 minutes
  • πŸ“Š Multi-Degree Analysis β€” Calculates 1st through 4th degree connection paths
  • πŸ€– Twitter Bot β€” Users can query vibe scores by mentioning @reputest
  • πŸ” Encrypted Token Storage β€” AES-256-GCM encryption for all OAuth tokens
  • ⚑ High Performance β€” Built with Axum and async Rust for speed
  • πŸ›‘οΈ Production Security β€” Rate limiting, security headers, and XSS protection

🧠 How It Works

The Good Vibes Graph

 Alice ──gmgv──▢ Bob ──gmgv──▢ Charlie ──gmgv──▢ Diana
   β”‚                              β”‚
   └──────────gmgvβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Άβ”˜

Arrows show attestations: who tweeted β†’ who was mentioned

  • Emitter: The person emitting good vibes (mentioned user)
  • Sensor: The person sensing/attesting to those vibes (author of the #gmgv tweet)

Degree Paths

When Alice queries her vibe score with Diana:

Degree Meaning Example Path
1st Direct connection Alice β†’ Diana
2nd One intermediary Alice β†’ Bob β†’ Diana
3rd Two intermediaries Alice β†’ Bob β†’ Charlie β†’ Diana
4th Three intermediaries Alice β†’ X β†’ Y β†’ Z β†’ Diana

Query Your Vibes

Tweet @reputest @username? to get your vibe scores with that user:

@reputest @elonmusk?

Reply:

Your vibes for @elonmusk are:
1st degree: 0
2nd degree: 3
3rd degree: 12

πŸš€ Quick Start

Prerequisites

1. Clone & Setup

git clone https://github.com/julerex/reputest.git
cd reputest

2. Database Setup

Create the database and run the schema:

createdb reputest
psql -d reputest -f sql/database_ddl.sql

3. Environment Variables

# Required
export DATABASE_URL="postgres://user:password@localhost/reputest"
export TOKEN_ENCRYPTION_KEY="$(openssl rand -hex 32)"  # 32-byte hex key

# Optional
export PORT=3000           # Default: 3000
export RUST_LOG=info       # Options: debug, info, warn, error

4. Twitter Bot Authorization

# Run the OAuth 2.0 authorization flow
cargo run --bin authorize_bot

This will guide you through:

  1. Entering your Twitter OAuth 2.0 Client ID & Secret
  2. Authorizing the app in your browser
  3. Storing encrypted tokens in the database

5. Run

cargo run

Visit http://localhost:3000 to see the Good Vibes dashboard.

πŸ“‘ API Reference

Method Endpoint Description
GET / Good Vibes dashboard β€” displays all relationships with degree paths
GET /reputest Test endpoint β€” returns "Reputesting!"
POST /reputest Test endpoint β€” returns "Reputesting!"
GET /health Health check β€” returns {"status": "healthy", "service": "reputest"}

Dashboard

The homepage displays a comprehensive table showing all sensor-emitter pairs with their path counts across all four degrees:

sensor sensor name emitter emitter name 1Β° 2Β° 3Β° 4Β°
@alice Alice Smith @bob Bob Jones 1 0 0 0
@alice Alice Smith @charlie Charlie Brown 0 2 5 8

βš™οΈ Configuration

Required Environment Variables

Variable Description
DATABASE_URL PostgreSQL connection string
TOKEN_ENCRYPTION_KEY 32-byte hex key for AES-256-GCM encryption

Optional Environment Variables

Variable Default Description
PORT 3000 HTTP server port
RUST_LOG info Log level (debug, info, warn, error)

Generating an Encryption Key

# Generate a secure 32-byte key
openssl rand -hex 32

⚠️ Security Note: The server will refuse to start without a valid encryption key. All OAuth tokens are encrypted at rest.

πŸ—„οΈ Database Schema

Core Tables

-- Twitter users in the vibes graph
users (id, username, name, created_at)

-- Good vibes relationships (directed graph edges)
good_vibes (tweet_id, emitter_id, sensor_id, created_at)

-- OAuth tokens (encrypted)
access_tokens (id, token, created_at)
refresh_tokens (id, token, created_at)

-- Processed tweet tracking
vibe_requests (tweet_id)

Pre-built Views

The schema includes optimized views for path counting:

  • view_good_vibes_degree_one through view_good_vibes_degree_four
  • view_all_good_vibes_degrees β€” Combined view used by the dashboard
  • view_easy_* variants with human-readable usernames

πŸ“ Project Structure

reputest/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ main.rs          # Server initialization, routes, middleware
β”‚   β”œβ”€β”€ config.rs        # Environment configuration
β”‚   β”œβ”€β”€ handlers.rs      # HTTP route handlers
β”‚   β”œβ”€β”€ db.rs            # Database operations & graph queries
β”‚   β”œβ”€β”€ crypto.rs        # AES-256-GCM token encryption
β”‚   β”œβ”€β”€ cronjob.rs       # Scheduled Twitter monitoring
β”‚   β”œβ”€β”€ oauth.rs         # OAuth 2.0 token refresh
β”‚   β”œβ”€β”€ twitter/
β”‚   β”‚   β”œβ”€β”€ mod.rs       # Twitter module exports
β”‚   β”‚   β”œβ”€β”€ api.rs       # API client & utilities
β”‚   β”‚   β”œβ”€β”€ search.rs    # Hashtag & mention search
β”‚   β”‚   β”œβ”€β”€ tweets.rs    # Tweet posting & replies
β”‚   β”‚   └── parsing.rs   # Tweet text parsing
β”‚   β”œβ”€β”€ lib.rs           # Library exports
β”‚   └── tests.rs         # Test suite
β”œβ”€β”€ scripts/
β”‚   β”œβ”€β”€ authorize_bot.rs      # OAuth 2.0 authorization flow
β”‚   β”œβ”€β”€ refresh_access_token.rs  # Manual token refresh
β”‚   └── encrypt_token.rs      # Token encryption utility
β”œβ”€β”€ sql/
β”‚   β”œβ”€β”€ database_ddl.sql      # Schema & views
β”‚   └── database_init.sql     # Initial data (if any)
β”œβ”€β”€ docs/
β”‚   β”œβ”€β”€ BOT_SETUP.md          # Twitter OAuth 2.0 setup guide
β”‚   β”œβ”€β”€ CLOUDFLARE_DOMAIN_SETUP.md  # Custom domain configuration
β”‚   β”œβ”€β”€ TROUBLESHOOTING.md    # Common issues & solutions
β”‚   └── DEBUGGING.md          # Developer debugging guide
β”œβ”€β”€ Cargo.toml
β”œβ”€β”€ Dockerfile
└── fly.toml              # Fly.io deployment config

🐳 Docker

# Build
docker build -t reputest .

# Run
docker run -p 3000:3000 \
  -e DATABASE_URL="postgres://..." \
  -e TOKEN_ENCRYPTION_KEY="$(openssl rand -hex 32)" \
  reputest

☁️ Deployment

Fly.io

The project includes ready-to-use Fly.io configuration:

# Install Fly CLI
curl -L https://fly.io/install.sh | sh

# Login
fly auth login

# Deploy
fly launch  # First time
fly deploy  # Updates

# Set secrets
fly secrets set DATABASE_URL="postgres://..."
fly secrets set TOKEN_ENCRYPTION_KEY="$(openssl rand -hex 32)"

The app is configured for:

  • Region: Frankfurt (fra)
  • Memory: 1GB
  • Port: 8080 (internal)
  • HTTPS: Forced
  • Minimum machines: 1

πŸ”§ Development

Running Tests

cargo test                    # All tests
cargo test -- --nocapture     # With output
cargo test handlers           # Specific module

Building for Release

cargo build --release

Release builds are optimized for size (opt-level = "z") with LTO enabled.

Utility Scripts

# Authorize bot (OAuth 2.0 flow)
cargo run --bin authorize_bot

# Manually refresh access token
cargo run --bin refresh_token

# Encrypt a token for database storage
cargo run --bin encrypt_token

πŸ”’ Security

  • Token Encryption: All OAuth tokens encrypted with AES-256-GCM
  • Rate Limiting: 30 requests/minute per IP via tower_governor
  • Security Headers: X-Content-Type-Options, X-Frame-Options, CSP, etc.
  • XSS Protection: HTML escaping on all user-generated content
  • Input Validation: Log sanitization to prevent injection attacks
  • Automatic Cleanup: Old tokens purged after 24 hours

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing)
  3. Make your changes with tests
  4. Run cargo test and cargo clippy
  5. Commit (git commit -m 'Add amazing feature')
  6. Push (git push origin feature/amazing)
  7. Open a Pull Request

See CONTRIBUTING.md for detailed guidelines.

πŸ“„ License

MIT License β€” see LICENSE for details.

πŸ™ Acknowledgments


Built with πŸ¦€ and good vibes

About

Experimenting with reputation algorithms in X

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published