# greasyfork-org/greasyfork architecture

> Architecture diagram of the GitHub repository greasyfork-org/greasyfork, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/greasyfork-org/greasyfork
- Repository: https://github.com/greasyfork-org/greasyfork

## Overview

##### 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.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Clients
    Browser["Client Browser"]:::client

    %% CI/CD
    CircleCI["CircleCI"]:::cicd
    Deploy["Capistrano Deploy"]:::cicd

    %% External Services
    subgraph "External Services"
        Akismet["Akismet API"]:::external
        RecaptchaService["reCAPTCHA"]:::external
        GitWebhooks["GitHub/GitLab/Bitbucket Webhooks"]:::external
        StripePayPal["Stripe/PayPal"]:::external
        GoogleAnalytics["Google Analytics"]:::external
        SentryService["Sentry Error Tracking"]:::external
        SMTP["Email Provider (SMTP)"]:::external
    end

    %% Monolith
    subgraph "Greasy Fork Monolith"
        direction TB
        subgraph "Web Layer (Rails App)"
            direction TB
            Controllers["Web Controllers"]:::web
            AdminControllers["Admin Controllers"]:::web
            ControllerConcerns["Controller Concerns"]:::web
            Models["ActiveRecord Models"]:::web
            ModelConcerns["Model Concerns"]:::web
            Views["ERB View Templates"]:::web
            JS["JavaScript Entrypoints"]:::web
            CSS["CSS Assets"]:::web
            Services["Service Objects"]:::web
            Routes["Routing Configuration"]:::web
        end

        subgraph "Background Layer (Sidekiq Workers)"
            direction TB
            Jobs["Background Jobs"]:::jobs
            SKMiddleware["Sidekiq Custom Middleware"]:::jobs
            ScriptImporters["Script Importers"]:::jobs
        end

        subgraph "Data Layer"
            direction TB
            Postgres["PostgreSQL DB"]:::data
            Elasticsearch["Elasticsearch"]:::data
            Redis["Redis (Cache & Queue)"]:::data
            ActiveStorage["Active Storage (File Store)"]:::data
        end
    end

    %% CI/CD flow
    CircleCI -->|"deploy"| Deploy
    Deploy -->|"to"| Controllers

    %% Client to Web
    Browser -->|"HTTP/HTTPS"| Controllers

    %% Web internal flow
    Controllers -->|"uses"| ControllerConcerns
    Controllers -->|"calls"| Services
    Controllers -->|"renders"| Views
    Controllers -->|"executes JS/CSS"| JS
    Controllers -->|"executes JS/CSS"| CSS
    Controllers -->|"routes defined in"| Routes
    Controllers -->|"reads/writes"| Models
    Models -->|"shares logic"| ModelConcerns

    Services -->|"accesses"| Models
    Services -->|"enqueue"| Jobs

    %% Web to Data
    Controllers -->|"reads/writes"| Postgres
    Controllers -->|"search queries/index"| Elasticsearch
    Controllers -->|"cache/session"| Redis
    Controllers -->|"file uploads/downloads"| ActiveStorage

    %% Background jobs
    Jobs -->|"uses middleware"| SKMiddleware
    Jobs -->|"consume jobs from"| Redis
    Redis -->|"dequeue"| Jobs
    Jobs -->|"reads/writes"| Postgres
    Jobs -->|"index/update"| Elasticsearch
    Jobs -->|"file ops"| ActiveStorage

    ScriptImporters -->|"handle webhooks"| GitWebhooks
    ScriptImporters -->|"sync scripts"| Postgres

    %% External calls
    Controllers -->|"spam check"| Akismet
    Controllers -->|"captcha verify"| RecaptchaService
    Controllers -->|"send email via"| SMTP
    Controllers -->|"payment"| StripePayPal
    Controllers -->|"track"| GoogleAnalytics
    Controllers -->|"error report"| SentryService

    Jobs -->|"spam check"| Akismet
    Jobs -->|"notify via email"| SMTP
    Jobs -->|"stats update"| GoogleAnalytics

    %% CI/CD external config
    CircleCI -->|".circleci/ and config/deploy/"| Deploy

    %% Click Events
    click Controllers "https://github.com/greasyfork-org/greasyfork/tree/main/app/controllers/"
    click AdminControllers "https://github.com/greasyfork-org/greasyfork/tree/main/app/controllers/admin/"
    click ControllerConcerns "https://github.com/greasyfork-org/greasyfork/tree/main/app/controllers/concerns/"
    click Models "https://github.com/greasyfork-org/greasyfork/tree/main/app/models/"
    click ModelConcerns "https://github.com/greasyfork-org/greasyfork/tree/main/app/models/concerns/"
    click Views "https://github.com/greasyfork-org/greasyfork/tree/main/app/views/"
    click JS "https://github.com/greasyfork-org/greasyfork/tree/main/app/javascript/entrypoints/"
    click CSS "https://github.com/greasyfork-org/greasyfork/tree/main/app/javascript/stylesheets/"
    click Services "https://github.com/greasyfork-org/greasyfork/tree/main/app/services/"
    click Jobs "https://github.com/greasyfork-org/greasyfork/tree/main/app/jobs/"
    click SKMiddleware "https://github.com/greasyfork-org/greasyfork/tree/main/lib/sidekiq/"
    click ScriptImporters "https://github.com/greasyfork-org/greasyfork/tree/main/lib/script_importer/"
    click Akismet "https://github.com/greasyfork-org/greasyfork/blob/main/config/initializers/akismet.rb"
    click RecaptchaService "https://github.com/greasyfork-org/greasyfork/blob/main/config/initializers/recaptcha.rb"
    click RecaptchaJS "https://github.com/greasyfork-org/greasyfork/blob/main/app/javascript/recaptcha.js"
    click Elasticsearch "https://github.com/greasyfork-org/greasyfork/blob/main/config/initializers/elasticsearch.rb"
    click SKMiddleware "https://github.com/greasyfork-org/greasyfork/blob/main/lib/searchkick_disable_middleware.rb"
    click SKConfig "https://github.com/greasyfork-org/greasyfork/blob/main/config/initializers/sidekiq.rb"
    click SKYML "https://github.com/greasyfork-org/greasyfork/blob/main/config/sidekiq.yml"
    click Mailers "https://github.com/greasyfork-org/greasyfork/tree/main/app/mailers/"
    click CircleCI "https://github.com/greasyfork-org/greasyfork/tree/main/.circleci/"
    click Deploy "https://github.com/greasyfork-org/greasyfork/tree/main/config/deploy/"
    click Assets "https://github.com/greasyfork-org/greasyfork/tree/main/public/assets/"
    click Storage "https://github.com/greasyfork-org/greasyfork/blob/main/config/storage.yml"
    click Credentials "https://github.com/greasyfork-org/greasyfork/blob/main/config/credentials/production.yml.enc"
    click GoogleAnalytics "https://github.com/greasyfork-org/greasyfork/blob/main/lib/google_analytics.rb"
    click SentryService "https://github.com/greasyfork-org/greasyfork/blob/main/config/initializers/sentry.rb"
    click Routes "https://github.com/greasyfork-org/greasyfork/blob/main/config/routes.rb"
    click Migrations "https://github.com/greasyfork-org/greasyfork/tree/main/db/migrate/"
    click Schema "https://github.com/greasyfork-org/greasyfork/blob/main/db/schema.rb"
    click Utilities "https://github.com/greasyfork-org/greasyfork/tree/main/lib/"
    click Runners "https://github.com/greasyfork-org/greasyfork/tree/main/runnerscripts/"
    click Shell "https://github.com/greasyfork-org/greasyfork/tree/main/shellscripts/"
    click Pkg "https://github.com/greasyfork-org/greasyfork/tree/main/Gemfile"

    %% Styles
    classDef client fill:#FFFD82,stroke:#333,stroke-width:1px
    classDef web fill:#BFDBFE,stroke:#2B6CB0,stroke-width:1px
    classDef data fill:#C6F6D5,stroke:#2F855A,stroke-width:1px
    classDef jobs fill:#FED7AA,stroke:#DD6B20,stroke-width:1px
    classDef external fill:#E2E8F0,stroke:#718096,stroke-width:1px
    classDef cicd fill:#E9D8FD,stroke:#6B46C1,stroke-width:1px
```
