How greasyfork-org/greasyfork works
Project type and purpose
• This is a full-stack, monolithic Ruby on Rails application called “Greasy Fork,” which hosts and serves user scripts/styles, supports a discussion forum, handles webhooks for script synchronization, and manages background spam-checking, notifications, and analytics.
High-level directory structure
• app/
• controllers (MVC controllers, including an Admin namespace)
• models (ActiveRecord models + concerns)
• views (ERB templates)
• helpers, mailers, jobs (ActiveJob → Sidekiq), services (business logic)
• javascript (Webpacker/Vite entrypoints, JS modules, CSS assets)
• config/ (Rails, Sidekiq, Webpacker, CI/CD, deploy via Capistrano)
• db/ (migrations + schema)
• lib/ (utility libraries, script importers, Sidekiq custom middleware)
• public/ (static assets, error pages, 3rd-party libraries)
• bin/, shellscripts/, runnerscripts/ (startup scripts, maintenance tasks)
• .circleci/ (CI pipeline), Gemfile, package.json, Procfile.dev, etc.
Key architectural components
a. Frontend layer
• Client browsers/mobile clients run HTML/ERB views plus JavaScript (bundled via Webpacker/Vite).
• Assets served either from Rails asset pipeline or CDN.
b. Web application layer
• Rails application running under a web server (Puma/Passenger).
• Controllers handle HTTP requests, route through config/routes.rb.
• Concern modules embedded in controllers/models for cross-cutting features (authentication via Devise, localization, caching, API support).
c. Data layer
• Primary store: PostgreSQL (ActiveRecord).
• Search index: Elasticsearch via Searchkick.
• Cache & job queue store: Redis (for Rails cache, session store, Sidekiq queues).
• File storage: Active Storage (local or cloud S3).
d. Background processing
• Sidekiq workers (app/jobs + lib/sidekiq) consume jobs from Redis.
• Jobs include spam checks (Akismet), code cleaning, notifications, statistics updates, script sync tasks.
e. External integrations
• Spam detection: Akismet API.
• reCAPTCHA.
• Webhooks: GitHub, GitLab, Bitbucket → script_importer modules.
• Email delivery: Action Mailer → SMTP or external provider.
• Donations: Stripe and PayPal.
• Analytics: Google Analytics.
• Error tracking: Sentry.
Relationships and data flows
• User ↔ Browser UI: HTTP/HTTPS → Rails controllers → ERB/JSON responses + JS/CSS
• Browser assets ← Asset pipeline/CDN
• Rails app ↔ PostgreSQL (reads/writes via ActiveRecord)
• Rails app ↔ Elasticsearch (indexing & search queries via Searchkick)
• Rails app → Redis (caching, sessions, enqueuing jobs)
• Sidekiq workers ← Redis (consume jobs) → PostgreSQL / External APIs
• Webhooks → Rails API endpoints → enqueue sync jobs → DB updates
• Rails app → External services (Akismet, reCAPTCHA, Mail, Payment gateways)
Architectural patterns and design principles
• Monolithic MVC with clear separation of concerns: controllers, models, views, services, jobs.
• Service objects in app/services to encapsulate business logic (script_checking, comment_checking, ping_request_checking).
• Use of concerns for DRY controller/model code.
• Background processing abstracted via ActiveJob over Sidekiq.
• Modular JS entrypoints reflect feature boundaries.