|
| 1 | +# Better Together Community Engine – Rails App & Engine Guidelines |
| 2 | + |
| 3 | +This repository contains the **Better Together Community Engine** (an isolated Rails engine under the `BetterTogether` namespace) and/or a host Rails app that mounts it. Use these instructions for all code generation. |
| 4 | + |
| 5 | +## Core Principles |
| 6 | + |
| 7 | +- **Accessibility first** (WCAG AA/AAA): semantic HTML, ARIA roles, keyboard nav, proper contrast. |
| 8 | +- **Hotwire everywhere**: Turbo for navigation/updates; Stimulus controllers for interactivity. |
| 9 | +- **Keep controllers thin**; move business logic to POROs/service objects or concerns. |
| 10 | +- **Prefer explicit join models** over polymorphic associations when validation matters. |
| 11 | +- **Avoid the term “STI”** in code/comments; use “single-table inheritance” or alternate designs. |
| 12 | +- **Use `ENV.fetch`** rather than `ENV[]`. |
| 13 | +- **Always add policy/authorization checks** on links/buttons to controller actions. |
| 14 | +- **i18n & Mobility**: every user-facing string must be translatable; include missing keys. |
| 15 | + |
| 16 | +## Technology Stack |
| 17 | + |
| 18 | +- **Rails 7.1+** (engine & current hosts) – compatible with Rails 8 targets |
| 19 | +- **Ruby 3.3+** |
| 20 | +- **PostgreSQL (+ PostGIS, pgcrypto)** |
| 21 | +- **Redis** for caching & Sidekiq queues |
| 22 | +- **Sidekiq** for background jobs (queue namespaced, e.g. `:metrics`) |
| 23 | +- **Hotwire (Turbo, Stimulus)** |
| 24 | +- **Bootstrap 5.3 & Font Awesome 6** (not Tailwind) |
| 25 | +- **Trix / Action Text** for rich text |
| 26 | +- **Active Record Encryption** for sensitive fields; encrypted Active Storage files |
| 27 | +- **Mobility** for attribute translations |
| 28 | +- **Elasticsearch 7** via `elasticsearch-rails` |
| 29 | +- **Importmap-Rails** for JS deps (no bundler by default) |
| 30 | +- **Dokku** (Docker-based PaaS) for deployment; Cloudflare for DNS/DDoS/tunnels |
| 31 | +- **AWS S3 / MinIO** for file storage (transitioning to self-hosted MinIO) |
| 32 | +- **Action Mailer + locale-aware emails** |
| 33 | +- **Noticed** for notifications |
| 34 | + |
| 35 | +> Dev DB: PostgreSQL (not SQLite). Production: PostgreSQL. PostGIS enabled for geospatial needs. |
| 36 | +
|
| 37 | + |
| 38 | +## Coding Guidelines |
| 39 | + |
| 40 | +- **Ruby/Rails** |
| 41 | + - 2-space indent, snake_case methods, Rails conventions |
| 42 | + - Service objects in `app/services/` |
| 43 | + - Concerns for reusable model/controller logic |
| 44 | + - Strong params, Pundit/Policy checks (or equivalent) everywhere |
| 45 | + - Avoid fat callbacks; keep models lean |
| 46 | +- **Views** |
| 47 | + - ERB with semantic HTML |
| 48 | + - Bootstrap utility classes; respect prefers-reduced-motion & other a11y prefs |
| 49 | + - Avoid inline JS; use Stimulus |
| 50 | + - External links in `.trix-content` get FA external-link icon unless internal/mailto/tel/pdf |
| 51 | +- **Hotwire** |
| 52 | + - Use Turbo Streams for CRUD updates |
| 53 | + - Stimulus controllers in `app/javascript/controllers/` |
| 54 | + - No direct DOM manipulation without Stimulus targets/actions |
| 55 | +- **Background Jobs** |
| 56 | + - Sidekiq jobs under appropriate queues (`:default`, `:mailers`, `:metrics`, etc.) |
| 57 | + - Idempotent job design; handle retries |
| 58 | +- **Search** |
| 59 | + - Update `as_indexed_json` to include translated/plain-text fields as needed |
| 60 | +- **Encryption & Privacy** |
| 61 | + - Use AR encryption for sensitive columns |
| 62 | + - Ensure blobs are encrypted at rest |
| 63 | +- **Testing** |
| 64 | + - RSpec (if present) or Minitest – follow existing test framework |
| 65 | + - All RSpec specs **must use FactoryBot factories** for model instances (do not use `Model.create` or `Model.new` directly in specs). |
| 66 | + - **A FactoryBot factory must exist for every model**. When generating a new model, also generate a factory for it. |
| 67 | + - **Factories must use the Faker gem** to provide realistic, varied test data for all attributes (e.g., names, emails, addresses, etc.). |
| 68 | + - System tests for Turbo flows where possible |
| 69 | + |
| 70 | +## Project Architecture Notes |
| 71 | + |
| 72 | +- Engine code is namespaced under `BetterTogether`. |
| 73 | +- Host app extends/overrides engine components where needed. |
| 74 | +- Content blocks & page builder use configurable relationships (content areas, background images, etc.). |
| 75 | +- Journey/Lists features use polymorphic items but with care (or explicit join models). |
| 76 | +- Agreements system models participants, roles, terms, and timelines. |
| 77 | + |
| 78 | +## Specialized Instruction Files |
| 79 | + |
| 80 | +- `.github/instructions/rails_engine.instructions.md` – Engine isolation & namespacing |
| 81 | +- `.github/instructions/hotwire.instructions.md` – Turbo/Stimulus patterns |
| 82 | +- `.github/instructions/hotwire-native.instructions.md` – Hotwire Native patterns |
| 83 | +- `.github/instructions/sidekiq-redis.instructions.md` – Background jobs & Redis |
| 84 | +- `.github/instructions/search-elasticsearch.instructions.md` – Elasticsearch indexing patterns |
| 85 | +- `.github/instructions/i18n-mobility.instructions.md` – Translations (Mobility + I18n) |
| 86 | +- `.github/instructions/accessibility.instructions.md` – A11y checklist & patterns |
| 87 | +- `.github/instructions/notifications-noticed.instructions.md` – Notification patterns |
| 88 | +- `.github/instructions/deployment.instructions.md` – Dokku, Cloudflare, backups (S3/MinIO) |
| 89 | +- `.github/instructions/security-encryption.instructions.md` – AR encryption, secrets |
| 90 | +- `.github/instructions/bootstrap.instructions.md` – Styling, theming, icon usage |
| 91 | +- `.github/instructions/importmaps.instructions.md` – JS dependency management |
| 92 | +- `.github/instructions/view-helpers.instructions.md` – Consistency in Rails views |
| 93 | + |
| 94 | +--- |
| 95 | + |
| 96 | +_If you generate code that touches any of these areas, consult the relevant instruction file and follow it._ |
0 commit comments