roda-gen 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (346) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +9 -0
  3. data/LICENSE.txt +21 -0
  4. data/README.md +94 -0
  5. data/bin/roda +11 -0
  6. data/lib/roda-gen.rb +3 -0
  7. data/lib/roda_gen/app_name.rb +29 -0
  8. data/lib/roda_gen/cli.rb +122 -0
  9. data/lib/roda_gen/generators/daemon.rb +78 -0
  10. data/lib/roda_gen/generators/migration.rb +68 -0
  11. data/lib/roda_gen/generators/migration_numbering.rb +21 -0
  12. data/lib/roda_gen/generators/model.rb +75 -0
  13. data/lib/roda_gen/generators/project.rb +145 -0
  14. data/lib/roda_gen/generators/route.rb +71 -0
  15. data/lib/roda_gen/generators/templates/daemon/bin/%daemon_name%.tt +13 -0
  16. data/lib/roda_gen/generators/templates/daemon/lib/daemon/%daemon_name%.rb.tt +22 -0
  17. data/lib/roda_gen/generators/templates/daemon/spec/daemons/%daemon_name%_spec.rb.tt +18 -0
  18. data/lib/roda_gen/generators/templates/migration/db/migrate/%migration_filename%.rb.tt +6 -0
  19. data/lib/roda_gen/generators/templates/model/db/migrate/%migration_filename%.rb.tt +12 -0
  20. data/lib/roda_gen/generators/templates/model/models/%resource_name%.rb.tt +5 -0
  21. data/lib/roda_gen/generators/templates/model/spec/models/%resource_name%_spec.rb.tt +18 -0
  22. data/lib/roda_gen/generators/templates/project/%app_name%.rb.tt +43 -0
  23. data/lib/roda_gen/generators/templates/project/.bundle/config.tt +3 -0
  24. data/lib/roda_gen/generators/templates/project/.erb_lint.yml.tt +29 -0
  25. data/lib/roda_gen/generators/templates/project/.gitignore.tt +19 -0
  26. data/lib/roda_gen/generators/templates/project/.reek.yml.tt +45 -0
  27. data/lib/roda_gen/generators/templates/project/.rspec.tt +4 -0
  28. data/lib/roda_gen/generators/templates/project/.rubocop.yml.tt +119 -0
  29. data/lib/roda_gen/generators/templates/project/.ruby-version.tt +1 -0
  30. data/lib/roda_gen/generators/templates/project/.rubycritic.yml.tt +15 -0
  31. data/lib/roda_gen/generators/templates/project/Gemfile.tt +109 -0
  32. data/lib/roda_gen/generators/templates/project/Procfile.dev.tt +7 -0
  33. data/lib/roda_gen/generators/templates/project/README.md.tt +891 -0
  34. data/lib/roda_gen/generators/templates/project/Rakefile.tt +3 -0
  35. data/lib/roda_gen/generators/templates/project/assets/javascripts/admin.js.tt +84 -0
  36. data/lib/roda_gen/generators/templates/project/assets/javascripts/app.js.tt +29 -0
  37. data/lib/roda_gen/generators/templates/project/assets/javascripts/push.js.tt +53 -0
  38. data/lib/roda_gen/generators/templates/project/assets/javascripts/upload.js.tt +200 -0
  39. data/lib/roda_gen/generators/templates/project/assets/stylesheets/app.css.tt +52 -0
  40. data/lib/roda_gen/generators/templates/project/assets/stylesheets/typography.css.tt +85 -0
  41. data/lib/roda_gen/generators/templates/project/bin/console.tt +2 -0
  42. data/lib/roda_gen/generators/templates/project/bin/dev.tt +8 -0
  43. data/lib/roda_gen/generators/templates/project/bin/gdpr_worker.tt +13 -0
  44. data/lib/roda_gen/generators/templates/project/bin/push_sender.tt +13 -0
  45. data/lib/roda_gen/generators/templates/project/bin/setup.tt +224 -0
  46. data/lib/roda_gen/generators/templates/project/bin/shrine_clean_cache.tt +13 -0
  47. data/lib/roda_gen/generators/templates/project/config/boot.rb.tt +23 -0
  48. data/lib/roda_gen/generators/templates/project/config/console.rb.tt +20 -0
  49. data/lib/roda_gen/generators/templates/project/config/database.rb.tt +45 -0
  50. data/lib/roda_gen/generators/templates/project/config/initializers/00_environments.rb.tt +5 -0
  51. data/lib/roda_gen/generators/templates/project/config/initializers/01_logger.rb.tt +46 -0
  52. data/lib/roda_gen/generators/templates/project/config/initializers/02_app_config.rb.tt +19 -0
  53. data/lib/roda_gen/generators/templates/project/config/initializers/10_database.rb.tt +3 -0
  54. data/lib/roda_gen/generators/templates/project/config/initializers/15_mail.rb.tt +53 -0
  55. data/lib/roda_gen/generators/templates/project/config/initializers/20_redis.rb.tt +13 -0
  56. data/lib/roda_gen/generators/templates/project/config/initializers/25_rack_attack.rb.tt +96 -0
  57. data/lib/roda_gen/generators/templates/project/config/initializers/30_i18n.rb.tt +37 -0
  58. data/lib/roda_gen/generators/templates/project/config/initializers/35_listen_job.rb.tt +4 -0
  59. data/lib/roda_gen/generators/templates/project/config/initializers/37_shrine.rb.tt +20 -0
  60. data/lib/roda_gen/generators/templates/project/config/initializers/40_routing.rb.tt +20 -0
  61. data/lib/roda_gen/generators/templates/project/config/initializers/41_render.rb.tt +10 -0
  62. data/lib/roda_gen/generators/templates/project/config/initializers/43_static.rb.tt +30 -0
  63. data/lib/roda_gen/generators/templates/project/config/initializers/44_sessions.rb.tt +62 -0
  64. data/lib/roda_gen/generators/templates/project/config/initializers/45_security.rb.tt +49 -0
  65. data/lib/roda_gen/generators/templates/project/config/initializers/46_flash.rb.tt +5 -0
  66. data/lib/roda_gen/generators/templates/project/config/initializers/47_json.rb.tt +8 -0
  67. data/lib/roda_gen/generators/templates/project/config/initializers/48_errors.rb.tt +43 -0
  68. data/lib/roda_gen/generators/templates/project/config/initializers/49_misc.rb.tt +26 -0
  69. data/lib/roda_gen/generators/templates/project/config/initializers/50_mailer.rb.tt +52 -0
  70. data/lib/roda_gen/generators/templates/project/config/initializers/51_locale_kit.rb.tt +29 -0
  71. data/lib/roda_gen/generators/templates/project/config/initializers/52_consent_kit.rb.tt +28 -0
  72. data/lib/roda_gen/generators/templates/project/config/initializers/55_audit_log.rb.tt +16 -0
  73. data/lib/roda_gen/generators/templates/project/config/initializers/56_form_helper.rb.tt +7 -0
  74. data/lib/roda_gen/generators/templates/project/config/initializers/57_rodauth.rb.tt +304 -0
  75. data/lib/roda_gen/generators/templates/project/config/initializers/60_web_push.rb.tt +12 -0
  76. data/lib/roda_gen/generators/templates/project/config/initializers/61_flipper.rb.tt +15 -0
  77. data/lib/roda_gen/generators/templates/project/config/initializers/62_split.rb.tt +15 -0
  78. data/lib/roda_gen/generators/templates/project/config/puma.rb.tt +24 -0
  79. data/lib/roda_gen/generators/templates/project/config/settings/development.yml.tt +9 -0
  80. data/lib/roda_gen/generators/templates/project/config/settings/production.yml.tt +13 -0
  81. data/lib/roda_gen/generators/templates/project/config/settings/test.yml.tt +9 -0
  82. data/lib/roda_gen/generators/templates/project/config/settings.yml.tt +45 -0
  83. data/lib/roda_gen/generators/templates/project/config.ru.tt +36 -0
  84. data/lib/roda_gen/generators/templates/project/db/migrate/create_account_profiles.rb.tt +66 -0
  85. data/lib/roda_gen/generators/templates/project/db/migrate/create_accounts.rb.tt +70 -0
  86. data/lib/roda_gen/generators/templates/project/db/migrate/create_audit_log.rb.tt +185 -0
  87. data/lib/roda_gen/generators/templates/project/db/migrate/create_authorization.rb.tt +68 -0
  88. data/lib/roda_gen/generators/templates/project/db/migrate/create_countries.rb.tt +13 -0
  89. data/lib/roda_gen/generators/templates/project/db/migrate/create_country_calling_codes.rb.tt +15 -0
  90. data/lib/roda_gen/generators/templates/project/db/migrate/create_country_exit_codes.rb.tt +13 -0
  91. data/lib/roda_gen/generators/templates/project/db/migrate/create_country_languages.rb.tt +19 -0
  92. data/lib/roda_gen/generators/templates/project/db/migrate/create_country_time_zones.rb.tt +11 -0
  93. data/lib/roda_gen/generators/templates/project/db/migrate/create_currencies.rb.tt +12 -0
  94. data/lib/roda_gen/generators/templates/project/db/migrate/create_gdpr_requests.rb.tt +43 -0
  95. data/lib/roda_gen/generators/templates/project/db/migrate/create_languages.rb.tt +11 -0
  96. data/lib/roda_gen/generators/templates/project/db/migrate/create_push_subscriptions.rb.tt +16 -0
  97. data/lib/roda_gen/generators/templates/project/db/migrate/create_rodauth_features.rb.tt +105 -0
  98. data/lib/roda_gen/generators/templates/project/db/migrate/create_settings.rb.tt +60 -0
  99. data/lib/roda_gen/generators/templates/project/db/seeds/01_countries.csv.tt +250 -0
  100. data/lib/roda_gen/generators/templates/project/db/seeds/01_currencies.csv.tt +162 -0
  101. data/lib/roda_gen/generators/templates/project/db/seeds/01_languages.csv.tt +144 -0
  102. data/lib/roda_gen/generators/templates/project/db/seeds/02_country_calling_codes.csv.tt +237 -0
  103. data/lib/roda_gen/generators/templates/project/db/seeds/02_country_exit_codes.csv.tt +239 -0
  104. data/lib/roda_gen/generators/templates/project/db/seeds/02_country_languages.csv.tt +226 -0
  105. data/lib/roda_gen/generators/templates/project/db/seeds/02_country_time_zones.csv.tt +369 -0
  106. data/lib/roda_gen/generators/templates/project/db/seeds/03_setting_system_defaults.yml.tt +35 -0
  107. data/lib/roda_gen/generators/templates/project/db/seeds.rb.tt +69 -0
  108. data/lib/roda_gen/generators/templates/project/deploy/Caddyfile.tt +69 -0
  109. data/lib/roda_gen/generators/templates/project/deploy/logrotate/%app_name%-caddy.tt +11 -0
  110. data/lib/roda_gen/generators/templates/project/deploy/systemd/%app_name%-audit-partition.service.tt +21 -0
  111. data/lib/roda_gen/generators/templates/project/deploy/systemd/%app_name%-audit-partition.timer.tt +16 -0
  112. data/lib/roda_gen/generators/templates/project/deploy/systemd/%app_name%-gdpr-worker.service.tt +25 -0
  113. data/lib/roda_gen/generators/templates/project/deploy/systemd/%app_name%-push-sender.service.tt +25 -0
  114. data/lib/roda_gen/generators/templates/project/deploy/systemd/%app_name%-shrine-cleanup.service.tt +21 -0
  115. data/lib/roda_gen/generators/templates/project/deploy/systemd/%app_name%-shrine-cleanup.timer.tt +16 -0
  116. data/lib/roda_gen/generators/templates/project/deploy/systemd/%app_name%.service.tt +36 -0
  117. data/lib/roda_gen/generators/templates/project/helpers/audit_helper.rb.tt +59 -0
  118. data/lib/roda_gen/generators/templates/project/helpers/authorization_helper.rb.tt +25 -0
  119. data/lib/roda_gen/generators/templates/project/helpers/current_account_helper.rb.tt +33 -0
  120. data/lib/roda_gen/generators/templates/project/helpers/feature_flag_helper.rb.tt +34 -0
  121. data/lib/roda_gen/generators/templates/project/helpers/form_helper.rb.tt +50 -0
  122. data/lib/roda_gen/generators/templates/project/helpers/http_cache_helper.rb.tt +15 -0
  123. data/lib/roda_gen/generators/templates/project/helpers/logger_helper.rb.tt +7 -0
  124. data/lib/roda_gen/generators/templates/project/helpers/split_helper.rb.tt +22 -0
  125. data/lib/roda_gen/generators/templates/project/lib/audit_context.rb.tt +26 -0
  126. data/lib/roda_gen/generators/templates/project/lib/audit_lookup.rb.tt +21 -0
  127. data/lib/roda_gen/generators/templates/project/lib/daemon/base.rb.tt +104 -0
  128. data/lib/roda_gen/generators/templates/project/lib/daemon/gdpr_worker.rb.tt +53 -0
  129. data/lib/roda_gen/generators/templates/project/lib/daemon/push_sender.rb.tt +47 -0
  130. data/lib/roda_gen/generators/templates/project/lib/daemon/shrine_cache_cleaner.rb.tt +22 -0
  131. data/lib/roda_gen/generators/templates/project/lib/deploy_check.rb.tt +96 -0
  132. data/lib/roda_gen/generators/templates/project/lib/filtered_logger.rb.tt +54 -0
  133. data/lib/roda_gen/generators/templates/project/lib/gdpr.rb.tt +106 -0
  134. data/lib/roda_gen/generators/templates/project/lib/rbac_audit.rb.tt +47 -0
  135. data/lib/roda_gen/generators/templates/project/lib/tasks/.rubocop.yml.tt +4 -0
  136. data/lib/roda_gen/generators/templates/project/lib/tasks/audit.rake.tt +85 -0
  137. data/lib/roda_gen/generators/templates/project/lib/tasks/console.rake.tt +8 -0
  138. data/lib/roda_gen/generators/templates/project/lib/tasks/db.rake.tt +104 -0
  139. data/lib/roda_gen/generators/templates/project/lib/tasks/deploy.rake.tt +38 -0
  140. data/lib/roda_gen/generators/templates/project/lib/tasks/flags.rake.tt +47 -0
  141. data/lib/roda_gen/generators/templates/project/lib/tasks/gdpr.rake.tt +31 -0
  142. data/lib/roda_gen/generators/templates/project/lib/tasks/parser_current_shim.rb.tt +13 -0
  143. data/lib/roda_gen/generators/templates/project/lib/tasks/quality.rake.tt +84 -0
  144. data/lib/roda_gen/generators/templates/project/lib/tasks/secrets.rake.tt +154 -0
  145. data/lib/roda_gen/generators/templates/project/lib/tasks/spec.rake.tt +136 -0
  146. data/lib/roda_gen/generators/templates/project/lib/tasks/split.rake.tt +27 -0
  147. data/lib/roda_gen/generators/templates/project/lib/tasks/tailwind.rake.tt +35 -0
  148. data/lib/roda_gen/generators/templates/project/locales/de.yml.tt +325 -0
  149. data/lib/roda_gen/generators/templates/project/locales/en.yml.tt +321 -0
  150. data/lib/roda_gen/generators/templates/project/locales/es.yml.tt +326 -0
  151. data/lib/roda_gen/generators/templates/project/locales/fr.yml.tt +329 -0
  152. data/lib/roda_gen/generators/templates/project/locales/it.yml.tt +325 -0
  153. data/lib/roda_gen/generators/templates/project/locales/rodauth/de.yml.tt +5 -0
  154. data/lib/roda_gen/generators/templates/project/locales/rodauth/en.yml.tt +6 -0
  155. data/lib/roda_gen/generators/templates/project/locales/rodauth/es.yml.tt +5 -0
  156. data/lib/roda_gen/generators/templates/project/locales/rodauth/fr.yml.tt +5 -0
  157. data/lib/roda_gen/generators/templates/project/locales/rodauth/it.yml.tt +5 -0
  158. data/lib/roda_gen/generators/templates/project/locales/rodauth/sv.yml.tt +274 -0
  159. data/lib/roda_gen/generators/templates/project/locales/rodauth/tru.yml.tt +274 -0
  160. data/lib/roda_gen/generators/templates/project/locales/sv.yml.tt +319 -0
  161. data/lib/roda_gen/generators/templates/project/locales/tru.yml.tt +294 -0
  162. data/lib/roda_gen/generators/templates/project/log/.keep.tt +0 -0
  163. data/lib/roda_gen/generators/templates/project/models/account.rb.tt +50 -0
  164. data/lib/roda_gen/generators/templates/project/models/account_privilege.rb.tt +15 -0
  165. data/lib/roda_gen/generators/templates/project/models/account_profile.rb.tt +115 -0
  166. data/lib/roda_gen/generators/templates/project/models/account_role.rb.tt +14 -0
  167. data/lib/roda_gen/generators/templates/project/models/audit_action.rb.tt +23 -0
  168. data/lib/roda_gen/generators/templates/project/models/audit_actor_type.rb.tt +10 -0
  169. data/lib/roda_gen/generators/templates/project/models/audit_log.rb.tt +257 -0
  170. data/lib/roda_gen/generators/templates/project/models/audit_status.rb.tt +9 -0
  171. data/lib/roda_gen/generators/templates/project/models/country.rb.tt +17 -0
  172. data/lib/roda_gen/generators/templates/project/models/country_calling_code.rb.tt +7 -0
  173. data/lib/roda_gen/generators/templates/project/models/country_exit_code.rb.tt +7 -0
  174. data/lib/roda_gen/generators/templates/project/models/country_language.rb.tt +8 -0
  175. data/lib/roda_gen/generators/templates/project/models/country_time_zone.rb.tt +7 -0
  176. data/lib/roda_gen/generators/templates/project/models/currency.rb.tt +7 -0
  177. data/lib/roda_gen/generators/templates/project/models/gdpr_request.rb.tt +32 -0
  178. data/lib/roda_gen/generators/templates/project/models/gender.rb.tt +7 -0
  179. data/lib/roda_gen/generators/templates/project/models/language.rb.tt +13 -0
  180. data/lib/roda_gen/generators/templates/project/models/privilege.rb.tt +21 -0
  181. data/lib/roda_gen/generators/templates/project/models/push_subscription.rb.tt +10 -0
  182. data/lib/roda_gen/generators/templates/project/models/role.rb.tt +21 -0
  183. data/lib/roda_gen/generators/templates/project/models/role_privilege.rb.tt +14 -0
  184. data/lib/roda_gen/generators/templates/project/models/setting_system_default.rb.tt +11 -0
  185. data/lib/roda_gen/generators/templates/project/models/setting_user_value.rb.tt +12 -0
  186. data/lib/roda_gen/generators/templates/project/models/settings.rb.tt +22 -0
  187. data/lib/roda_gen/generators/templates/project/models/signup_form_data.rb.tt +61 -0
  188. data/lib/roda_gen/generators/templates/project/models.rb.tt +6 -0
  189. data/lib/roda_gen/generators/templates/project/package.json.tt +13 -0
  190. data/lib/roda_gen/generators/templates/project/public/apple-touch-icon.png +0 -0
  191. data/lib/roda_gen/generators/templates/project/public/favicon.ico +0 -0
  192. data/lib/roda_gen/generators/templates/project/public/favicon.svg.tt +5 -0
  193. data/lib/roda_gen/generators/templates/project/public/fonts/JetBrainsMono-Italic-Variable.woff2 +0 -0
  194. data/lib/roda_gen/generators/templates/project/public/fonts/JetBrainsMono-Variable.woff2 +0 -0
  195. data/lib/roda_gen/generators/templates/project/public/fonts/Lato-Bold.woff2 +0 -0
  196. data/lib/roda_gen/generators/templates/project/public/fonts/Lato-BoldItalic.woff2 +0 -0
  197. data/lib/roda_gen/generators/templates/project/public/fonts/Lato-Italic.woff2 +0 -0
  198. data/lib/roda_gen/generators/templates/project/public/fonts/Lato-Regular.woff2 +0 -0
  199. data/lib/roda_gen/generators/templates/project/public/fonts/NOTICE.md +17 -0
  200. data/lib/roda_gen/generators/templates/project/public/fonts/NotoSansSyriac-Bold.woff2 +0 -0
  201. data/lib/roda_gen/generators/templates/project/public/fonts/NotoSansSyriac-Regular.woff2 +0 -0
  202. data/lib/roda_gen/generators/templates/project/public/fonts/NotoSansSyriacWestern-Bold.woff2 +0 -0
  203. data/lib/roda_gen/generators/templates/project/public/fonts/NotoSansSyriacWestern-Regular.woff2 +0 -0
  204. data/lib/roda_gen/generators/templates/project/public/manifest.webmanifest.tt +12 -0
  205. data/lib/roda_gen/generators/templates/project/public/robots.txt.tt +4 -0
  206. data/lib/roda_gen/generators/templates/project/public/service-worker.js.tt +27 -0
  207. data/lib/roda_gen/generators/templates/project/routes/account.rb.tt +10 -0
  208. data/lib/roda_gen/generators/templates/project/routes/admin.rb.tt +118 -0
  209. data/lib/roda_gen/generators/templates/project/routes/gdpr.rb.tt +32 -0
  210. data/lib/roda_gen/generators/templates/project/routes/heartbeat.rb.tt +35 -0
  211. data/lib/roda_gen/generators/templates/project/routes/legal.rb.tt +20 -0
  212. data/lib/roda_gen/generators/templates/project/routes/profile.rb.tt +56 -0
  213. data/lib/roda_gen/generators/templates/project/routes/push.rb.tt +25 -0
  214. data/lib/roda_gen/generators/templates/project/spec/browser/role_boundary_spec.rb.tt +10 -0
  215. data/lib/roda_gen/generators/templates/project/spec/browser/spec_helper.rb.tt +146 -0
  216. data/lib/roda_gen/generators/templates/project/spec/browser/support/auth_helpers.rb.tt +71 -0
  217. data/lib/roda_gen/generators/templates/project/spec/browser/uat/auth_spec.rb.tt +25 -0
  218. data/lib/roda_gen/generators/templates/project/spec/browser/uat/consent_nojs_spec.rb.tt +60 -0
  219. data/lib/roda_gen/generators/templates/project/spec/browser/uat/create_account_form_spec.rb.tt +26 -0
  220. data/lib/roda_gen/generators/templates/project/spec/browser/uat/otp_lifecycle_spec.rb.tt +67 -0
  221. data/lib/roda_gen/generators/templates/project/spec/browser/uat/profile_form_spec.rb.tt +17 -0
  222. data/lib/roda_gen/generators/templates/project/spec/browser/uat/upload_spec.rb.tt +102 -0
  223. data/lib/roda_gen/generators/templates/project/spec/browser/wcag/auth_pages_spec.rb.tt +61 -0
  224. data/lib/roda_gen/generators/templates/project/spec/browser/wcag/legal_pages_spec.rb.tt +33 -0
  225. data/lib/roda_gen/generators/templates/project/spec/daemons/base_spec.rb.tt +106 -0
  226. data/lib/roda_gen/generators/templates/project/spec/daemons/gdpr_worker_spec.rb.tt +72 -0
  227. data/lib/roda_gen/generators/templates/project/spec/daemons/push_sender_spec.rb.tt +74 -0
  228. data/lib/roda_gen/generators/templates/project/spec/locale_parity_spec.rb.tt +58 -0
  229. data/lib/roda_gen/generators/templates/project/spec/models/account_profile_spec.rb.tt +180 -0
  230. data/lib/roda_gen/generators/templates/project/spec/models/account_spec.rb.tt +104 -0
  231. data/lib/roda_gen/generators/templates/project/spec/models/audit_actor_type_spec.rb.tt +7 -0
  232. data/lib/roda_gen/generators/templates/project/spec/models/audit_log_spec.rb.tt +398 -0
  233. data/lib/roda_gen/generators/templates/project/spec/models/audit_status_spec.rb.tt +7 -0
  234. data/lib/roda_gen/generators/templates/project/spec/models/authorization_spec.rb.tt +82 -0
  235. data/lib/roda_gen/generators/templates/project/spec/models/country_calling_code_spec.rb.tt +11 -0
  236. data/lib/roda_gen/generators/templates/project/spec/models/country_exit_code_spec.rb.tt +10 -0
  237. data/lib/roda_gen/generators/templates/project/spec/models/country_language_spec.rb.tt +21 -0
  238. data/lib/roda_gen/generators/templates/project/spec/models/country_spec.rb.tt +29 -0
  239. data/lib/roda_gen/generators/templates/project/spec/models/country_time_zone_spec.rb.tt +9 -0
  240. data/lib/roda_gen/generators/templates/project/spec/models/currency_spec.rb.tt +9 -0
  241. data/lib/roda_gen/generators/templates/project/spec/models/deploy_check_spec.rb.tt +143 -0
  242. data/lib/roda_gen/generators/templates/project/spec/models/gdpr_spec.rb.tt +110 -0
  243. data/lib/roda_gen/generators/templates/project/spec/models/language_spec.rb.tt +15 -0
  244. data/lib/roda_gen/generators/templates/project/spec/models/rbac_audit_spec.rb.tt +110 -0
  245. data/lib/roda_gen/generators/templates/project/spec/models/setting_system_default_spec.rb.tt +26 -0
  246. data/lib/roda_gen/generators/templates/project/spec/models/setting_user_value_spec.rb.tt +33 -0
  247. data/lib/roda_gen/generators/templates/project/spec/models/settings_spec.rb.tt +63 -0
  248. data/lib/roda_gen/generators/templates/project/spec/models/signup_form_data_spec.rb.tt +22 -0
  249. data/lib/roda_gen/generators/templates/project/spec/spec_helper.rb.tt +93 -0
  250. data/lib/roda_gen/generators/templates/project/spec/support/audit_log_helpers.rb.tt +21 -0
  251. data/lib/roda_gen/generators/templates/project/spec/support/audit_lookup_shared_examples.rb.tt +19 -0
  252. data/lib/roda_gen/generators/templates/project/spec/support/auth_helpers.rb.tt +62 -0
  253. data/lib/roda_gen/generators/templates/project/spec/support/faker.rb.tt +30 -0
  254. data/lib/roda_gen/generators/templates/project/spec/web/admin_spec.rb.tt +155 -0
  255. data/lib/roda_gen/generators/templates/project/spec/web/audit_log_spec.rb.tt +159 -0
  256. data/lib/roda_gen/generators/templates/project/spec/web/auth_spec.rb.tt +492 -0
  257. data/lib/roda_gen/generators/templates/project/spec/web/authorization_spec.rb.tt +110 -0
  258. data/lib/roda_gen/generators/templates/project/spec/web/boot_spec.rb.tt +27 -0
  259. data/lib/roda_gen/generators/templates/project/spec/web/consent_banner_spec.rb.tt +46 -0
  260. data/lib/roda_gen/generators/templates/project/spec/web/feature_flag_helper_spec.rb.tt +33 -0
  261. data/lib/roda_gen/generators/templates/project/spec/web/flags_spec.rb.tt +67 -0
  262. data/lib/roda_gen/generators/templates/project/spec/web/gdpr_spec.rb.tt +55 -0
  263. data/lib/roda_gen/generators/templates/project/spec/web/heartbeat_spec.rb.tt +65 -0
  264. data/lib/roda_gen/generators/templates/project/spec/web/host_allowlist_spec.rb.tt +27 -0
  265. data/lib/roda_gen/generators/templates/project/spec/web/legal_spec.rb.tt +61 -0
  266. data/lib/roda_gen/generators/templates/project/spec/web/locale_resolver_spec.rb.tt +34 -0
  267. data/lib/roda_gen/generators/templates/project/spec/web/logger_helper_spec.rb.tt +23 -0
  268. data/lib/roda_gen/generators/templates/project/spec/web/logger_spec.rb.tt +82 -0
  269. data/lib/roda_gen/generators/templates/project/spec/web/otp_audit_spec.rb.tt +147 -0
  270. data/lib/roda_gen/generators/templates/project/spec/web/profile_spec.rb.tt +97 -0
  271. data/lib/roda_gen/generators/templates/project/spec/web/push_spec.rb.tt +55 -0
  272. data/lib/roda_gen/generators/templates/project/spec/web/rack_attack_runtime_spec.rb.tt +52 -0
  273. data/lib/roda_gen/generators/templates/project/spec/web/rack_attack_spec.rb.tt +81 -0
  274. data/lib/roda_gen/generators/templates/project/spec/web/rbac_audit_spec.rb.tt +62 -0
  275. data/lib/roda_gen/generators/templates/project/spec/web/request_id_spec.rb.tt +62 -0
  276. data/lib/roda_gen/generators/templates/project/spec/web/role_boundary_spec.rb.tt +21 -0
  277. data/lib/roda_gen/generators/templates/project/spec/web/session_skip_spec.rb.tt +74 -0
  278. data/lib/roda_gen/generators/templates/project/spec/web/split_helper_spec.rb.tt +38 -0
  279. data/lib/roda_gen/generators/templates/project/spec/web/type_routing_spec.rb.tt +55 -0
  280. data/lib/roda_gen/generators/templates/project/spec/web/upload_zone_spec.rb.tt +91 -0
  281. data/lib/roda_gen/generators/templates/project/tmp/.keep.tt +0 -0
  282. data/lib/roda_gen/generators/templates/project/vendor/.keep.tt +0 -0
  283. data/lib/roda_gen/generators/templates/project/views/403.erb.tt +10 -0
  284. data/lib/roda_gen/generators/templates/project/views/404.erb.tt +10 -0
  285. data/lib/roda_gen/generators/templates/project/views/500.erb.tt +12 -0
  286. data/lib/roda_gen/generators/templates/project/views/_head_meta.erb.tt +29 -0
  287. data/lib/roda_gen/generators/templates/project/views/_impersonate_picker.erb.tt +21 -0
  288. data/lib/roda_gen/generators/templates/project/views/_language_switcher.erb.tt +22 -0
  289. data/lib/roda_gen/generators/templates/project/views/_locked_accounts.erb.tt +18 -0
  290. data/lib/roda_gen/generators/templates/project/views/_upload_zone.erb.tt +35 -0
  291. data/lib/roda_gen/generators/templates/project/views/account/profile.erb.tt +149 -0
  292. data/lib/roda_gen/generators/templates/project/views/admin/flags.erb.tt +51 -0
  293. data/lib/roda_gen/generators/templates/project/views/consent_kit/_banner.erb.tt +59 -0
  294. data/lib/roda_gen/generators/templates/project/views/consent_kit/_preferences.erb.tt +87 -0
  295. data/lib/roda_gen/generators/templates/project/views/gdpr/erased.erb.tt +6 -0
  296. data/lib/roda_gen/generators/templates/project/views/gdpr/index.erb.tt +28 -0
  297. data/lib/roda_gen/generators/templates/project/views/layout.erb.tt +112 -0
  298. data/lib/roda_gen/generators/templates/project/views/legal/contact.erb.tt +44 -0
  299. data/lib/roda_gen/generators/templates/project/views/legal/cookies.erb.tt +47 -0
  300. data/lib/roda_gen/generators/templates/project/views/legal/disclaimer.erb.tt +19 -0
  301. data/lib/roda_gen/generators/templates/project/views/legal/privacy.erb.tt +26 -0
  302. data/lib/roda_gen/generators/templates/project/views/mailers/account_unlocked.erb.tt +5 -0
  303. data/lib/roda_gen/generators/templates/project/views/mailers/data_erased.erb.tt +5 -0
  304. data/lib/roda_gen/generators/templates/project/views/mailers/data_export.erb.tt +5 -0
  305. data/lib/roda_gen/generators/templates/project/views/rodauth/add-recovery-codes.erb.tt +30 -0
  306. data/lib/roda_gen/generators/templates/project/views/rodauth/change-login.erb.tt +44 -0
  307. data/lib/roda_gen/generators/templates/project/views/rodauth/change-password.erb.tt +41 -0
  308. data/lib/roda_gen/generators/templates/project/views/rodauth/close-account.erb.tt +27 -0
  309. data/lib/roda_gen/generators/templates/project/views/rodauth/confirm-password.erb.tt +23 -0
  310. data/lib/roda_gen/generators/templates/project/views/rodauth/create-account.erb.tt +183 -0
  311. data/lib/roda_gen/generators/templates/project/views/rodauth/login.erb.tt +51 -0
  312. data/lib/roda_gen/generators/templates/project/views/rodauth/logout.erb.tt +10 -0
  313. data/lib/roda_gen/generators/templates/project/views/rodauth/otp-auth.erb.tt +26 -0
  314. data/lib/roda_gen/generators/templates/project/views/rodauth/otp-disable.erb.tt +27 -0
  315. data/lib/roda_gen/generators/templates/project/views/rodauth/otp-setup.erb.tt +48 -0
  316. data/lib/roda_gen/generators/templates/project/views/rodauth/otp-unlock-not-available.erb.tt +18 -0
  317. data/lib/roda_gen/generators/templates/project/views/rodauth/otp-unlock.erb.tt +28 -0
  318. data/lib/roda_gen/generators/templates/project/views/rodauth/recovery-auth.erb.tt +23 -0
  319. data/lib/roda_gen/generators/templates/project/views/rodauth/recovery-codes.erb.tt +26 -0
  320. data/lib/roda_gen/generators/templates/project/views/rodauth/remember.erb.tt +35 -0
  321. data/lib/roda_gen/generators/templates/project/views/rodauth/reset-password-request.erb.tt +27 -0
  322. data/lib/roda_gen/generators/templates/project/views/rodauth/reset-password.erb.tt +30 -0
  323. data/lib/roda_gen/generators/templates/project/views/rodauth/two-factor-auth.erb.tt +8 -0
  324. data/lib/roda_gen/generators/templates/project/views/rodauth/two-factor-disable.erb.tt +20 -0
  325. data/lib/roda_gen/generators/templates/project/views/rodauth/two-factor-manage.erb.tt +36 -0
  326. data/lib/roda_gen/generators/templates/project/views/rodauth/unlock-account-request.erb.tt +13 -0
  327. data/lib/roda_gen/generators/templates/project/views/rodauth/unlock-account.erb.tt +23 -0
  328. data/lib/roda_gen/generators/templates/project/views/rodauth/verify-account-resend.erb.tt +26 -0
  329. data/lib/roda_gen/generators/templates/project/views/rodauth/verify-account.erb.tt +32 -0
  330. data/lib/roda_gen/generators/templates/project/views/rodauth/verify-login-change.erb.tt +8 -0
  331. data/lib/roda_gen/generators/templates/route/routes/%plural%.rb.tt +19 -0
  332. data/lib/roda_gen/generators/templates/route/spec/web/%plural%_spec.rb.tt +36 -0
  333. data/lib/roda_gen/generators/templates/route/views/%plural%/index.erb.tt +11 -0
  334. data/lib/roda_gen/generators/templates/route/views/%plural%/show.erb.tt +7 -0
  335. data/lib/roda_gen/generators/templates/upload/db/migrate/%migration_filename%.rb.tt +13 -0
  336. data/lib/roda_gen/generators/templates/upload/helpers/upload_serving.rb.tt +43 -0
  337. data/lib/roda_gen/generators/templates/upload/models/%resource_name%.rb.tt +11 -0
  338. data/lib/roda_gen/generators/templates/upload/models/%resource_name%_uploader.rb.tt +19 -0
  339. data/lib/roda_gen/generators/templates/upload/routes/%plural%.rb.tt +44 -0
  340. data/lib/roda_gen/generators/templates/upload/spec/web/%plural%_spec.rb.tt +56 -0
  341. data/lib/roda_gen/generators/templates/upload/views/%plural%/index.erb.tt +18 -0
  342. data/lib/roda_gen/generators/upload.rb +83 -0
  343. data/lib/roda_gen/project_context.rb +30 -0
  344. data/lib/roda_gen/version.rb +5 -0
  345. data/lib/roda_gen.rb +16 -0
  346. metadata +497 -0
@@ -0,0 +1,891 @@
1
+ # <%= @app.human %>
2
+
3
+ Roda, Sequel, PostgreSQL, Redis, Puma, Caddy and systemd, scaffolded by roda-gen (https://github.com/asio/roda-gen)
4
+
5
+ ## Quickstart
6
+
7
+ config/settings/development.local.yml and config/settings/test.local.yml were written by the first bin/setup with fresh secrets (database URLs, HMAC keys, consent secrets, VAPID keys), both are gitignored.
8
+ vips has to be installed before bin/setup since Shrine's image derivatives need it.
9
+ bin/setup is safe to re-run after a failure, every step skips what already exists. It aborts up front when the configured Redis unix socket (redis.url in config/settings/) is missing or when the PG_LOCALE locale (default sv_SE.UTF-8) is not on the host.
10
+ Two things are easier to change before the first migration than after, db/migrate/0*_create_account_profiles.rb if your signup fields differ from the bundled set, and PARTITION_CADENCE in models/audit_log.rb if you want monthly or yearly audit partitions instead of quarterly.
11
+
12
+ brew install vips
13
+ apt install libvips42
14
+ bin/setup
15
+ bin/dev
16
+
17
+ bin/dev runs Puma and tailwind --watch through foreman on http://localhost:9292.
18
+ Partition rollover is rake audit:add_next[2], the systemd timer in deploy/systemd/ runs it daily, see Audit log below.
19
+
20
+ ### Reproducible baseline
21
+
22
+ The first bin/setup writes Gemfile.lock and package-lock.json, commit both.
23
+ Until they are committed a fresh bundle install or npm install on another machine resolves to whatever currently satisfies the version constraints in the Gemfile and the pins in package.json, which can drift.
24
+ bin/setup prints a banner when it sees the two files untracked.
25
+ Once Gemfile.lock is committed the gem versions are pinned and bundle update <gem> is the only way forward.
26
+
27
+ ## Stack
28
+
29
+ * Ruby <%= @ruby_version %>, pinned in .ruby-version and the Gemfile
30
+ * Roda, tree routing, no controller layer
31
+ * PostgreSQL through Sequel, migrations in db/migrate/
32
+ * Sessions in Redis (Rack::Session::Redis) behind a ConditionalRedisSession wrapper that skips the Redis round-trip for heartbeat probes and static paths, see SessionlessPaths in config/initializers/44_sessions.rb, the cookie carries only the session id
33
+ * rack-attack on Redis, production only
34
+ * Roda :assets, per request in dev and fingerprinted at boot in prod, CSS built by Tailwind v4 with daisyUI and @tailwindcss/typography through the @tailwindcss/cli npm binary pinned in package.json
35
+ * i18n gem, twitter_cldr for CLDR plural rules, locale_kit for URL prefix locales and cookie persistence
36
+ * consent_kit for EU cookie consent and its audit trail, CSP stays app-owned in config/initializers/45_security.rb so consent_kit runs with emit_csp false
37
+ * Roda :mailer and the mail gem, Office365 SMTP defaults
38
+ * RSpec for model, web and daemon specs on rack-test, Capybara and Playwright for browser specs, axe-core for WCAG checks, one shared test DB bounced and seeded per rake test:* run
39
+ * Logger.new($stdout) wrapped in FilteredLogger, which redacts SENSITIVE_PARAMS keys, the same logger for web, daemons and the kits, no per-request line since Caddy's access log covers prod, journald captures everything
40
+ * Daemons as plain Ruby subclasses of Daemons::Base under lib/daemon/, started by bin/<name>, systemd does the daemonizing, sequel-listen_job wraps PG LISTEN/NOTIFY
41
+
42
+ ## Project layout
43
+
44
+ <%= @app.snake %>.rb Roda app class
45
+ config.ru Rack entry, rack-unreloader in dev
46
+ Gemfile, Rakefile
47
+ models.rb, models/ Sequel models
48
+ routes/ one hash_branch per file
49
+ views/ ERB templates
50
+ helpers/ mixed into the Roda class
51
+ lib/
52
+ tasks/ rake tasks (db, console, spec, ...)
53
+ daemon/ background daemons
54
+ config/
55
+ boot.rb Bundler.require
56
+ settings.yml public defaults (site/*, consent/*, ...)
57
+ settings/ per-env overrides, *.local.yml gitignored
58
+ database.rb <%= @app.camel %>Config.database.url -> DB constant
59
+ initializers/ numbered, load in filename order
60
+ db/migrate/, db/seeds/, db/seeds.rb
61
+ locales/ YAML translations
62
+ assets/stylesheets/ Tailwind entry points
63
+ assets/javascripts/ app.js, admin.js, push.js, upload.js
64
+ public/ static files served by :public
65
+ spec/{models,web,daemons,browser}/
66
+ bin/ dev, setup, console, daemon launchers
67
+ deploy/ Caddyfile, logrotate, systemd units
68
+
69
+ ### Where things live
70
+
71
+ model + spec + migration roda g model NAME, --plural for irregulars
72
+ route + views + spec roda g route NAME, after roda g model NAME
73
+ bare migration roda g migration NAME, snake_case, empty change block
74
+ daemon roda g daemon NAME [--channel=CHAN], LISTEN/NOTIFY by default, swap run_listening for run_polling for a poller
75
+ Roda plugins config/initializers/4*_*.rb and 5*_*.rb
76
+ infrastructure (DB, mail, Redis) config/initializers/1*_*.rb, 2*_*.rb, 3*_*.rb
77
+
78
+ ### Configuration tiers
79
+
80
+ Pick the file by environment and by whether the value is secret:
81
+
82
+ config/settings.yml env-neutral, public, committed company name, contact mail, from address, governing law
83
+ config/settings/<env>.yml per env, public, committed redis.url, site.domain, allowed_hosts
84
+ config/settings/<env>.local.yml per env, secret, gitignored DB URLs, Rodauth and consent secrets, SMTP credentials, VAPID keys
85
+ SettingSystemDefault (DB) runtime, admin tunable max_invalid_logins, password_minimum_length
86
+
87
+ The YAML layers feed one frozen <%= @app.camel %>Config constant through the config gem, set up in config/initializers/02_app_config.rb, for instance <%= @app.camel %>Config.site.company.name or <%= @app.camel %>Config.database.url.
88
+ Merge order, later wins: settings.yml, settings/<RACK_ENV>.yml, settings/<RACK_ENV>.local.yml, then SETTINGS__FOO__BAR=value environment variables as the emergency hatch.
89
+ The local files are written by rake secrets:install, rake secrets:print emits the production one.
90
+
91
+ Before going live every [...] placeholder under site.* in config/settings.yml has to be replaced (E-handelslag 2 § 7, EU 2000/31/EC Art. 5, GDPR Art. 13) and the real domain set in config/settings/production.yml, the legal pages under /legal/ and the footer read from <%= @app.camel %>Config.site.*.
92
+
93
+ ## Running
94
+
95
+ ### Application logging
96
+
97
+ Two logs with different purposes: the audit log (PostgreSQL, see GDPR) answers *who did what* and is the business record; the application log answers *what is the system doing* and goes to stdout — your terminal under `bin/dev`, journald in production. The application log carries: a boot line per web process, every mail delivery (recipient and subject, never bodies), daemon activity (`[push_sender] pushed ...`), rack-attack blocks, and 500 traces. Development adds a request line per hit, SQL with timings, and an echo of every audit event; production prints none of those three. Everything flows through `FilteredLogger` (`config/initializers/01_logger.rb`), which masks `SENSITIVE_PARAMS` in hashes and in query-string shaped text. Log from app code via `<%= @app.camel %>.logger.info(...)` — reserve it for operational events, business facts belong in the audit log.
98
+
99
+
100
+ Web, dev:
101
+
102
+ bin/dev
103
+
104
+ foreman runs Puma and one tailwindcss --watch per :assets bundle, bundle exec puma config.ru works too once rake tailwind:build has run.
105
+
106
+ Web, prod:
107
+
108
+ sudo systemctl start <%= @app.snake %>.service
109
+
110
+ The deploy script has to run bundle exec rake tailwind:build first since the app fingerprints the compiled CSS at boot but does not build it, the unit's ExecStartPre runs rake deploy:check, see below.
111
+
112
+ Daemons, dev: bin/dev runs push_sender and gdpr_worker through Procfile.dev (roda g daemon appends new ones), or start one alone in the foreground:
113
+
114
+ bin/push_sender
115
+ bin/gdpr_worker
116
+ bin/shrine_clean_cache # oneshot sweep, prod runs it from a systemd timer
117
+
118
+ Daemons, prod: one systemd unit per daemon, copy deploy/systemd/<%= @app.snake %>-push-sender.service for a long-running one or <%= @app.snake %>-audit-partition.{service,timer} for a cron-like one and swap ExecStart to bundle exec bin/<name>.
119
+
120
+ Console, boots config/console.rb with DB, models, <%= @app.camel %>Mailer, routes and helpers:
121
+
122
+ bundle exec rake irb
123
+ bundle exec rake irb[production]
124
+
125
+ Heartbeat probes:
126
+
127
+ GET /heartbeat/live process is up
128
+ GET /heartbeat/db
129
+ GET /heartbeat/redis
130
+ GET /heartbeat combined JSON
131
+
132
+ Secrets:
133
+
134
+ bundle exec rake secrets:rotate
135
+ bundle exec rake secrets:print > config/settings/production.local.yml
136
+
137
+ rotate overwrites consent.signing_key, consent.ip_hash_salt and the VAPID keypair in settings/{development,test}.local.yml and keeps the comments, the production file then needs the SMTP credentials and the prod DB host and is deployed at mode 0600.
138
+
139
+ ### Deploy pre-flight checks
140
+
141
+ bundle exec rake deploy:check runs every guard the Puma unit needs before it binds its socket, the unit's ExecStartPre calls it and a failure aborts the start with the reasons in journalctl -u <%= @app.snake %>.
142
+
143
+ settings.placeholders no [ORG NR] / [EMAIL] / [STREET] markers left under <%= @app.camel %>Config.site.{company,address,contact,regulator}
144
+ database.web <%= @app.camel %>Config.database.url connects and SELECT 1 returns
145
+ database.app same for <%= @app.camel %>Config.database.app_url
146
+ redis PING on the REDIS pool returns PONG
147
+ mail.smtp every <%= @app.camel %>Config.mail.accounts.<name>.smtp.{address,user_name,password} is set
148
+ audit.partitions the current and the next audit partition exist, otherwise writes land in audit_log_default
149
+ assets.tailwind assets/stylesheets/.compiled/*.css present and non-empty
150
+
151
+ Each check prints OK or the reason, then the task exits 1 with a numbered summary.
152
+ SKIP_DEPLOY_CHECKS=1 in the unit environment (systemctl edit <%= @app.snake %>, an Environment= line under [Service]) skips them when an operator knows better.
153
+
154
+ ## Database
155
+
156
+ rake db:up migrate to latest, RACK_ENV or development
157
+ rake db:up[production]
158
+ rake db:down all the way down
159
+ rake db:down[5] down to version 5
160
+ rake db:down[5,production]
161
+ rake db:bounce down then up
162
+ rake db:seed reference data from db/seeds/
163
+ rake db:seed[test]
164
+
165
+ db:seed is idempotent, ON CONFLICT DO NOTHING skips rows whose primary key exists, so re-running after appending rows to a CSV is safe.
166
+ A new seed table is a CSV at db/seeds/<NN>_<table>.csv, the numeric prefix orders the load, FK parents first, then rake db:seed and rake db:seed[test].
167
+
168
+ Sequel model plugins on by default: :auto_validations, :require_valid_schema, :subclasses (not in development).
169
+ DB extensions loaded in config/database.rb: :pg_auto_parameterize (every literal becomes a bound parameter), :pg_array, :pg_interval, :pg_range, :pg_multirange, :pg_enum, :pg_timestamptz, :pg_extended_date_support (dates before 1900 and after 9999), :pg_json.
170
+
171
+ ### Database users
172
+
173
+ The HTTP layer runs as a web PostgreSQL role with DML only, migrations, rake tasks, daemons, the console and the test boot run as an app role that owns the schema, so a SQL injection in a request handler cannot drop tables or alter the schema.
174
+ ENV['DATABASE_ROLE'] picks the role:
175
+
176
+ config.ru (puma) web (default) <%= @app.camel %>Config.database.url
177
+ rake db:*, rake irb app <%= @app.camel %>Config.database.app_url, falls back to database.url
178
+ bin/push_sender, any daemon app <%= @app.camel %>Config.database.app_url, falls back
179
+ rake test:*, rspec web for spec/web and spec/browser, app elsewhere, web specs also open ADMIN_DB on app_url
180
+
181
+ bin/setup provisions roles and databases, it reads the role names and passwords from config/settings/development.local.yml (database.app_url is app, database.url is web), creates both roles over a superuser psql connection (peer auth as your OS user is usually enough) and creates <%= @app.snake %>_development and <%= @app.snake %>_test owned by the app role.
182
+ The owner matters since PostgreSQL 15+ only lets the owner create objects in public, and migrations run as the app role.
183
+ rake secrets:install fills in random passwords, edit config/settings/development.local.yml afterwards if you need specific ones:
184
+
185
+ database:
186
+ url: postgres://<%= @app.snake %>_web:secret@localhost:5432/<%= @app.snake %>_development
187
+ app_url: postgres://<%= @app.snake %>_app:secret@localhost:5432/<%= @app.snake %>_development
188
+
189
+ By hand, or when bin/setup reports it cannot create roles, run once as a superuser:
190
+
191
+ CREATE ROLE <%= @app.snake %>_app LOGIN PASSWORD 'secret';
192
+ CREATE ROLE <%= @app.snake %>_web LOGIN PASSWORD 'secret';
193
+ ALTER DATABASE <%= @app.snake %>_development OWNER TO <%= @app.snake %>_app;
194
+ ALTER DATABASE <%= @app.snake %>_test OWNER TO <%= @app.snake %>_app;
195
+
196
+ lib/tasks/db.rake then grants the web role DML on the tables and sequences the app role creates and installs an ALTER DEFAULT PRIVILEGES rule so later migrations auto-grant, the target role is parsed from <%= @app.camel %>Config.database.url, it runs after every rake db:up, db:down and db:bounce and is idempotent.
197
+ Single-user dev: point both URLs at your own superuser, role creation becomes a no-op, the DB ends up owned by you and the grants collapse to nothing.
198
+
199
+ ### Audit log
200
+
201
+ Append-only trail under the audit_log PostgreSQL schema, one row per security-relevant event (login, password change, role grant, impersonation, data export, ...) keyed by uuidv7() and partitioned by quarter, or by month or year through AuditLog::PARTITION_CADENCE.
202
+ Requires PostgreSQL 18 or later (uuidv7(), VIRTUAL generated columns).
203
+
204
+ Two APIs with the same kwargs, AuditLog.record works anywhere (rake, daemons, routes), log_audit is the route convenience that fills in request_id, session_id and ip_address, mixed in by config/initializers/55_audit_log.rb:
205
+
206
+ r.post 'login' do
207
+ user = User.authenticate(r.params['email'], r.params['password'])
208
+ if user
209
+ log_audit(action: 'user.login', actor_type: :user, actor_id: user.id)
210
+ else
211
+ log_audit(action: 'user.login', actor_type: :user, status: :failure, error: 'invalid credentials')
212
+ end
213
+ r.redirect '/'
214
+ end
215
+
216
+ AuditLog.record(action: 'data.export', actor_type: :system, actor_id: user.id, payload: { rows: rows.size })
217
+
218
+ Action codes have to exist in audit_log.actions before they are logged, AuditLog.record raises with a copy-pasteable snippet otherwise.
219
+ The bundled codes (user.*, admin.*, rbac.*, authorization.denied, system.data.*) are seeded by db/migrate's create_audit_log, register your own from the console:
220
+
221
+ AuditAction.create(code: 'order.placed', category: 'orders', description: 'Order placed')
222
+ AuditAction.refresh_cache!
223
+
224
+ refresh_cache! drops the in-memory code to id map so the running app sees the new row, a restart does the same.
225
+
226
+ Partitions: bin/setup creates five (current plus four ahead through audit:add_next[5]), rollover afterwards is one of:
227
+
228
+ bundle exec rake audit:add_next[2]
229
+ bundle exec rake audit:add[2027-Q1]
230
+
231
+ add takes YYYY-MM, YYYY-Qn or YYYY.
232
+ PARTITION_CADENCE in models/audit_log.rb sizes new partitions, :monthly, :quarterly (default) or :yearly, forward only, existing partitions keep their size.
233
+ The systemd timer fires daily at 03:15 and is safe to run at any cadence since the task is CREATE TABLE IF NOT EXISTS:
234
+
235
+ sudo cp deploy/systemd/<%= @app.snake %>-audit-partition.{service,timer} /etc/systemd/system/
236
+ sudo systemctl daemon-reload
237
+ sudo systemctl enable --now <%= @app.snake %>-audit-partition.timer
238
+
239
+ Impersonation rides on the row as metadata.impersonator_id, actor_type and actor_id stay whatever the call site passed (the target user).
240
+ log_audit merges impersonator_id in by itself under an impersonated session, so no call site needs to know:
241
+
242
+ log_audit(action: 'user.view_profile', actor_type: :user, actor_id: account.id)
243
+ # normal session metadata = {}
244
+ # impersonated session metadata = { impersonator_id: <admin id> }
245
+
246
+ The session contract is one extra key, account_id stays the admin's id in both cases so Rodauth's view (and :active_sessions) is undisturbed, impersonating_as holds the target's id during impersonation.
247
+ CurrentAccountHelper.lookup resolves impersonating_as first, so current_account is the target everywhere (route helpers, locale_kit's user_locale_resolver) while Rodauth still sees the admin in session_value, logout, password change and active_sessions act on the admin.
248
+ The routes live in routes/admin.rb, POST /admin/impersonate behind require_privilege! 'accounts.impersonate' with an admin.impersonate.start row, POST /admin/stop-impersonating with admin.impersonate.stop.
249
+ The navbar typeahead (views/_impersonate_picker.erb and assets/javascripts/admin.js) searches non-locked accounts through GET /admin/accounts/search and posts the chosen id, picker and banner render only for accounts.impersonate holders, the target id travels in the body so one route_csrf token covers each path.
250
+ A VIRTUAL generated column impersonator_id projects metadata->>'impersonator_id', the partial index idx_audit_log_impersonator covers "everything done as user X by impersonator Y".
251
+
252
+ Grants: the migration gives the web role INSERT on audit_log.audit_log and SELECT on the lookups, no UPDATE or DELETE, plus an explicit REVOKE UPDATE, DELETE, TRUNCATE FROM PUBLIC, so a compromised web layer can write to the log but not change it.
253
+ db.rake's grant_web_privileges! is scoped to schema public and never touches audit_log.
254
+
255
+ Retention is partition level:
256
+
257
+ ALTER TABLE audit_log.audit_log DETACH PARTITION audit_log.audit_log_2024_05;
258
+ DROP TABLE audit_log.audit_log_2024_05;
259
+
260
+ ## Web push
261
+
262
+ A second channel next to the mailer, on the web-push gem (https://github.com/pushpad/web-push), the plumbing is wired and you decide what to notify about.
263
+
264
+ * VAPID keys are a base64 EC keypair handled by the secrets tasks, secrets:install and secrets:print write web_push.public_key and private_key into settings/<env>.local.yml, secrets:rotate regenerates them and rotating invalidates every subscription so clients have to re-subscribe, web_push.subject (the VAPID sub claim) lives in settings.yml, config/initializers/60_web_push.rb assembles <%= @app.camel %>::VAPID_OPTIONS
265
+ * Subscribe: the Enable notifications toggle on views/account/profile.erb runs assets/javascripts/push.js, permission, service worker at /service-worker.js (root scope, served by :public), PushManager.subscribe with the public key, then POST /push/subscribe (routes/push.rb, form-encoded so route_csrf reads _csrf) upserts a push_subscriptions row keyed on the unique endpoint, POST /push/unsubscribe deletes it
266
+ * Send: NOTIFY send_push with an account id as payload, the push_sender daemon (lib/daemon/push_sender.rb) loads that account's subscriptions and WebPush.payload_sends each one, pruning endpoints the push service answers 404 or 410 for, edit #push_message for your payload, public/service-worker.js renders { title, body, url }
267
+
268
+ From the console with bin/push_sender running:
269
+
270
+ DB.notify(:send_push, payload: account.id.to_s)
271
+
272
+ From psql:
273
+
274
+ psql <%= @app.snake %>_development -c "NOTIFY send_push, '1'"
275
+
276
+ In production the daemon runs under deploy/systemd/<%= @app.snake %>-push-sender.service.
277
+
278
+ ## Flags and A/B tests
279
+
280
+ Both are Redis-backed with no mounted third-party UI, no flipper-ui and no Split::Dashboard since those clash with the global check_csrf! and the app-owned CSP, every admin surface is a route of our own.
281
+
282
+ ### Feature flags
283
+
284
+ flag?(key) in helpers/feature_flag_helper.rb wraps Flipper.enabled?(key, current_account), the account is the actor so a percentage-of-actors rollout buckets each user the same way every time, anonymous requests fall back to the boolean or percentage-of-time gate, Account exposes flipper_id for this.
285
+ GET /admin/flags in routes/admin.rb lists flags and state behind flags.read, enable, disable, set percentage and register post to /admin/flags[/:key] behind flags.manage and are audited as admin.flag.update, the nav link shows for flags.read holders.
286
+
287
+ rake flags:list
288
+ rake flags:enable[key]
289
+ rake flags:disable[key]
290
+ rake flags:percentage[key,N]
291
+
292
+ if flag?(:new_dashboard)
293
+ # new code path
294
+ end
295
+
296
+ ### A/B testing
297
+
298
+ ab_test(:experiment, 'control', 'variant') assigns and persists a per-visitor variant in the Rack session, ab_finished(:experiment) records a conversion, both in helpers/split_helper.rb.
299
+ Assignment and conversion tracking is profiling, so both helpers no-op until the visitor has consented to the :analytics category and unconsented visitors always get the control alternative, if your DPO clears an experiment as non-tracking bypass the gate on purpose.
300
+ Results are read with rake split:results, QA can force a variant with ?ab_test[experiment]=alt, handled by Split::Helper without middleware.
301
+
302
+ ## GDPR
303
+
304
+ Self-service export (Art. 15/20) and erasure (Art. 17) live under /account/gdpr behind Rodauth's confirm-password, each action only enqueues a gdpr_requests row and NOTIFYs the gdpr_request channel, lib/daemon/gdpr_worker.rb fulfils it as the app role, which unlike the web role may read the audit_log for the export and redact it for the erasure.
305
+
306
+ * Export: Gdpr.export(account) builds account, profile, roles and privileges, settings, push subscriptions and the account's own audit trail, mailed as a JSON attachment
307
+ * Erasure: Gdpr.erase! is anonymize and retain, the web route closes the account (status_id 3) and logs the user out at once, the daemon then deletes the profile (name, personnummer), scrubs the email, drops the credential and session tables and redacts the account's audit_log PII, what remains is a pseudonymized skeleton (the accounts row with scrubbed email and deleted_at, roles, privileges, settings, the redacted trail), lawful under Art. 17(3)(b)/(e) only while a retention basis holds
308
+ * Purge: rake audit:drop_partitions_before[cutoff] calls Gdpr.purge_retained! after dropping partitions, once no audit row references an erased account its skeleton is hard-deleted (Art. 5(1)(e))
309
+
310
+ Staff-run equivalents after identity verification:
311
+
312
+ rake gdpr:export[account_id]
313
+ rake gdpr:erase[account_id]
314
+
315
+ The worker runs under deploy/systemd/<%= @app.snake %>-gdpr-worker.service in production.
316
+ Gdpr.export and Gdpr.erase! cover the scaffold's own tables, your own per-user tables go into lib/gdpr.rb.
317
+
318
+ ## Uploads and protected serving
319
+
320
+ The Shrine infrastructure is wired: the shrine, image_processing and ruby-vips gems, config/initializers/37_shrine.rb with storage under upload/ outside public/ so bytes are only reachable through an authenticated route, the gitignored upload/ dir, and the browser side, views/_upload_zone.erb plus assets/javascripts/upload.js, drag and drop, folder drops with their structure kept and a progress bar per file, posting each file to the upload_endpoint the generated route mounts.
321
+ The size cap is the file_upload_max_size system setting, 20 MB by default.
322
+ The flow itself is generated:
323
+
324
+ roda generate upload document # --plural for irregulars
325
+
326
+ It creates models/document_uploader.rb and models/document.rb, a create_documents migration, routes/documents.rb with the direct-upload mount at /documents/cache and authenticated per-account serving with thumbnails, views/documents/index.erb with the drop zone and cached-upload replay, and spec/web/documents_spec.rb driving the whole flow. helpers/upload_serving.rb is shared by every upload resource and generated once, re-registering it is a no-op. Each resource gets its own table, route, views and spec, generate as many as the app needs, then rake db:up.
327
+ Add a MIME allowlist to the generated uploader before accepting arbitrary uploads.
328
+
329
+ Limits
330
+
331
+ A folder drop is a burst of requests, so each generated endpoint gets its own ceiling in config/initializers/25_rack_attack.rb, _upload_zone.erb caps one drop client-side at max_files (100 by default) so a legitimate user never reaches it:
332
+
333
+ Rack::Attack.throttle('direct-upload/ip', limit: 120, period: 60) do |req|
334
+ req.ip if req.post? && LocaleKit.strip_locale_prefix(req.path) == '/documents/cache'
335
+ end
336
+
337
+ Raise file_upload_max_size, this throttle and the Caddy body cap below together for an app that takes thousands of files or very large ones.
338
+
339
+ These routes serve by id at extensionless URLs, so :type_routing (see Format dispatch) leaves them alone and the browser gets the filename from Content-Disposition.
340
+ A pretty /reports/2026-q3.pdf download while pdf is a registered format has to be streamed through a route and not r.public, since r.public looks the file up by the stripped path /reports/2026-q3 and misses, r.on 'reports', String still matches as only the extension is stripped, and r.real_remaining_path has the full name.
341
+
342
+ Caddy X-Accel offload
343
+
344
+ Into the reverse_proxy block in deploy/Caddyfile:
345
+
346
+ reverse_proxy unix//var/www/<%= @app.snake %>/tmp/puma.sock {
347
+ trusted_proxies static private_ranges
348
+ header_up X-Real-IP {remote_host}
349
+
350
+ # Fires only on an upstream response carrying X-Accel-Redirect, which only serve_shrine_file sets after authorizing
351
+ # A direct GET to /upload/* is proxied to Puma and 404s without the header, the rewrite target is app-built so it cannot escape upload/
352
+ @accel header X-Accel-Redirect *
353
+ handle_response @accel {
354
+ root * /var/www/<%= @app.snake %>
355
+ rewrite * {rp.header.X-Accel-Redirect}
356
+ file_server
357
+ }
358
+ }
359
+
360
+ At site level next to reverse_proxy, above file_upload_max_size so Shrine's 413 stays the real limit, today neither Caddy nor Puma caps a body:
361
+
362
+ request_body {
363
+ max_size 25MB
364
+ }
365
+
366
+
367
+ ## Authentication and authorization
368
+
369
+ Rodauth (https://rodauth.jeremyevans.net/) with a thin RBAC layer and an account_profiles table written in the same transaction as the account row.
370
+
371
+ ### Enabled Rodauth features
372
+
373
+ Configured in config/initializers/57_rodauth.rb:
374
+
375
+ * Account creation and email verification with grace period
376
+ * Login, logout, remember me
377
+ * Password reset, change password, change login with verify-login-change
378
+ * Close account, confirm password
379
+ * Account expiration, inactivity is tracked but auto-expiry is off, see account_expired? { false }
380
+ * Session expiration, lockout, active sessions
381
+ * Password complexity, common and reused passwords refused
382
+ * Argon2 hashing
383
+ * OTP/TOTP with lockout, unlock and recovery codes
384
+ * Internal requests, JSON responses
385
+ * i18n through rodauth-i18n
386
+
387
+ The JWT features (jwt, jwt_cors, jwt_refresh) are commented out in the initializer, uncomment and add rodauth.jwt_secret to config/settings/<env>.local.yml.
388
+
389
+ ### Routes
390
+
391
+ r.rodauth runs at the top of the route block in <%= @app.snake %>.rb with prefix '/account', so everything sits under it: /account/login, /account/logout, /account/create-account, /account/verify-account, /account/reset-password-request, /account/reset-password, /account/change-password, /account/change-login, /account/close-account, /account/confirm-password, /account/otp-auth, /account/otp-setup, /account/otp-disable, /account/recovery-auth, /account/recovery-codes, /account/remember and a few more.
392
+ The app's own /account/* pages (profile, gdpr) hang under hash_branch('account') in routes/account.rb so the namespace stays one.
393
+
394
+ ### Password hash isolation
395
+
396
+ Rodauth's recommended PostgreSQL pattern with SECURITY DEFINER functions.
397
+ The app role plays Rodauth's ph role, it owns rodauth_secrets.account_password_hashes and the rodauth_get_salt and rodauth_valid_password_hash functions, the web role plays Rodauth's app role with EXECUTE on the two functions and INSERT, UPDATE, DELETE on the table but no SELECT, so a SQL injection in the web layer cannot dump hashes.
398
+ db.rake's grant_web_privileges! only grants on schema public, the explicit grants in db/migrate's create_accounts are the only web-role permissions in rodauth_secrets.
399
+
400
+ ### Account profile
401
+
402
+ Every account has exactly one account_profiles row, 1:1 on accounts.id, the fields are NOT NULL and collected by the create-account form override in views/rodauth/create-account.erb, before_create_account validates them and after_create_account inserts the row in the same transaction, so a failed profile insert rolls the account back.
403
+ To add or rename fields:
404
+
405
+ 1. Edit db/migrate/0*_create_account_profiles.rb, or add a migration in an existing project
406
+ 2. Update views/rodauth/create-account.erb
407
+ 3. Update the validator and inserter in config/initializers/57_rodauth.rb
408
+
409
+ ### RBAC
410
+
411
+ Five tables with text primary keys so queries read without a join:
412
+
413
+ * privileges, fine-grained capabilities such as 'accounts.delete'
414
+ * roles, bundles of privileges such as 'admin' and 'user'
415
+ * account_roles, accounts have many roles
416
+ * role_privileges, roles have many privileges
417
+ * account_privileges, direct grants for one-offs that do not justify a role
418
+
419
+ An account has a privilege through account_privileges or through account_roles and role_privileges.
420
+ The migration seeds two roles (admin, user) and seven privileges (accounts.read, accounts.update, accounts.delete, accounts.impersonate, accounts.unlock, flags.read, flags.manage), admin gets all seven.
421
+ The join tables name their columns role_id and privilege_id although the referenced keys are the text columns role and privilege, that suffix matters since Sequel derives a many_to_one's key from the association name and a column named role would make many_to_one :role shadow the column reader and recurse into SystemStackError.
422
+ Account#all_privileges runs one UNION query and memoises per instance, current_account hands the same instance to every check in a request so a route gating on several privileges still queries once, account.reload drops the memo.
423
+
424
+ r.is 'admin' do
425
+ require_privilege! 'accounts.delete'
426
+ end
427
+
428
+ r.get 'orders' do
429
+ if current_account.privilege?('orders.read')
430
+ view 'orders/index'
431
+ else
432
+ r.halt(403)
433
+ end
434
+ end
435
+
436
+ require_privilege!(*names) is mixed into the route scope by helpers/authorization_helper.rb, halts with 403 and writes an authorization.denied row, Account#privilege?(*names) is the same all-of check on an Account instance, so it works in rake tasks, daemons and the console too.
437
+
438
+ ### Managing roles and privileges
439
+
440
+ The tables are plain rows.
441
+ For one-off work psql as the app role, the only one with INSERT on them:
442
+
443
+ psql "$(ruby -ryaml -e 'puts YAML.safe_load_file("config/settings/development.local.yml")["database"]["app_url"]')"
444
+
445
+ INSERT INTO roles (role) VALUES ('editor');
446
+ INSERT INTO privileges (privilege) VALUES ('orders.update') ON CONFLICT DO NOTHING;
447
+ INSERT INTO role_privileges (role_id, privilege_id) VALUES ('editor', 'orders.update');
448
+ INSERT INTO account_roles (account_id, role_id) VALUES (5, 'admin');
449
+ DELETE FROM account_roles WHERE account_id = 5 AND role_id = 'admin';
450
+ INSERT INTO account_privileges (account_id, privilege_id) VALUES (5, 'accounts.impersonate');
451
+
452
+ Raw SQL leaves no audit trail, use the models when the change should be recorded, AccountRole.create(account_id: 5, role_id: 'admin').
453
+ For day-to-day work build an admin UI on the Role, Privilege and Account models, Account#all_privileges, Role#privileges and Privilege#roles are wired.
454
+
455
+ ### Auditing access changes
456
+
457
+ Every change to the five RBAC tables is logged by the Sequel model hooks in lib/rbac_audit.rb, handing out a role as well as redefining what a role may do:
458
+
459
+ rbac.account_role.grant / .revoke an account gains or loses a role
460
+ rbac.account_privilege.grant / .revoke an account gains or loses a direct privilege
461
+ rbac.role_privilege.grant / .revoke a role gains or loses a privilege
462
+ rbac.role.create / .update / .delete a role is defined, re-described or removed
463
+ rbac.privilege.create / .update / .delete a privilege is defined, re-described or removed
464
+
465
+ The payload is the row that changed, rbac.*.update adds changed with [before, after] per column.
466
+ Hooking the models instead of the admin routes means a grant from a rake task, a daemon or rake irb is recorded like one from the UI, the actor comes from AuditContext, in a request config/initializers/55_audit_log.rb publishes a lazy resolver so the row gets the signed-in account plus request_id, session_id and ip_address (under impersonation the actor is the impersonated account and the admin lands in metadata.impersonator_id), everywhere else the actor is :system unless the change is wrapped:
467
+
468
+ AuditContext.as(actor_type: :system, actor_label: 'rake seed:admins') do
469
+ AccountRole.create(account_id: 1, role_id: 'admin')
470
+ end
471
+
472
+ Raw SQL and dataset writes such as AccountRole.where(account_id: id).delete skip the hooks on purpose, Gdpr.delete_skeleton! uses the latter and logs system.data.erase for the erasure as a whole.
473
+
474
+ ### Audit log integration
475
+
476
+ Rodauth's own audit_logging feature is off, the after_* hooks in the initializer call AuditLog.record so authentication events land in audit_log.audit_log with everything else:
477
+ user.account.create, user.account.verify, user.account.close, user.login (status carries success or failure, bad passwords share the action), user.logout, user.password.change, user.password.reset, user.password.reset_request, user.email.change, user.email.verify, user.otp.setup, user.otp.disable, user.otp.auth, user.otp.unlock, user.lockout, user.lockout.clear, user.remember.set, plus authorization.denied from require_privilege! and the rbac.* codes above.
478
+
479
+ ### Rodauth views
480
+
481
+ Rodauth ships Bootstrap-styled .str templates, config/initializers/57_rodauth.rb sets template_opts views: 'views/rodauth' and every view for every enabled feature is overridden there with daisyUI ERB:
482
+
483
+ * Core: create-account.erb (with the account_profile fields), login.erb, logout.erb, verify-account.erb, verify-account-resend.erb, reset-password-request.erb, reset-password.erb, change-password.erb, change-login.erb, close-account.erb, confirm-password.erb, remember.erb
484
+ * Lockout: unlock-account-request.erb, unlock-account.erb
485
+ * 2FA: two-factor-manage.erb, otp-setup.erb (QR code and secret), otp-auth.erb, otp-disable.erb, otp-unlock.erb, recovery-auth.erb, recovery-codes.erb, add-recovery-codes.erb
486
+
487
+ All of them use the daisyUI form shape, fieldset.fieldset, label.block with a span and an input.input w-full, btn.btn-primary w-full or btn-error for destructive actions, labels and button copy come from rodauth-i18n so the views work in every locale.
488
+ To change one, edit the file.
489
+ For a view that is not overridden (JWT, email-auth) copy the source from the gem and restyle:
490
+
491
+ cp $(bundle info rodauth --path)/templates/email-auth-request-form.str views/rodauth/email-auth-request-form.erb
492
+
493
+ ### First admin
494
+
495
+ bin/setup migrates but creates no user.
496
+ Sign up in the browser, verify through the link in the captured mail (tmp/mail/*.eml in dev) or by flipping the status, then promote:
497
+
498
+ psql "$(ruby -ryaml -e 'puts YAML.safe_load_file("config/settings/development.local.yml")["database"]["app_url"]')" <<SQL
499
+ UPDATE accounts SET status_id = 2 WHERE id = 1;
500
+ INSERT INTO account_roles (account_id, role_id) VALUES (1, 'admin');
501
+ SQL
502
+
503
+ ## UI and styling
504
+
505
+ Tailwind v4 and daisyUI (https://daisyui.com/).
506
+ @tailwindcss/cli, daisyui and @tailwindcss/typography are npm dev dependencies pinned in package.json, bin/setup runs npm install before the first CSS build.
507
+ daisyUI has about 50 components (btn, card, alert, navbar, dropdown, input, select, hero, footer, ...) and 32 themes, switched with <html data-theme="...">, prose and prose-sm come from @tailwindcss/typography and daisyUI maps the prose colours onto the active theme.
508
+
509
+ ### Source layout
510
+
511
+ assets/stylesheets/
512
+ app.css Tailwind entry for the :app bundle
513
+ typography.css imported by app.css
514
+ .compiled/ built output, gitignored
515
+ app.css
516
+
517
+ app.css is the only entry shipped:
518
+
519
+ @import "tailwindcss";
520
+ @plugin "@tailwindcss/typography";
521
+ @plugin "daisyui" {
522
+ themes: fantasy --default, sunset --prefersdark;
523
+ }
524
+ @plugin "daisyui/theme";
525
+ @import "./typography.css";
526
+
527
+ Plugins resolve from node_modules/, versions are pinned in package.json.
528
+ Design tokens go in an @theme block, Tailwind v4 exposes them as CSS custom properties (var(--font-sans)) and as utilities (font-sans), daisyUI's semantic palette (base-100, base-content, primary, success, warning, error, ...) covers app colours and can be overridden per theme inside the daisyui plugin block.
529
+
530
+ ### Build pipeline
531
+
532
+ Dev: bin/dev runs puma and one tailwindcss --watch per bundle, the watcher writes .compiled/<bundle>.css on every change.
533
+ Prod: bundle exec rake tailwind:build compiles each bundle with --minify, Roda's :assets compile_assets (run at production boot by 43_static.rb) then fingerprints the output, so the deploy script has to run tailwind:build BEFORE the app starts, bin/setup does it on first install.
534
+
535
+ ### Adding CSS to a bundle
536
+
537
+ Tailwind v4's CLI takes one input, so files join a bundle by @import from that bundle's entry:
538
+
539
+ @import "tailwindcss";
540
+ @plugin "daisyui";
541
+
542
+ @import "./components/buttons.css";
543
+ @import "./components/forms.css";
544
+
545
+ The watcher follows the import graph, no Procfile or config change.
546
+
547
+ ### Adding a bundle
548
+
549
+ 1. Create the entry, assets/stylesheets/admin.css, with at least @import "tailwindcss"; @plugin "daisyui";
550
+ 2. Uncomment the matching entry in the css: map in config/initializers/43_static.rb
551
+ 3. Uncomment the matching css_admin: line in Procfile.dev
552
+
553
+ The two files carry the same commented-out lines so they stay aligned by hand.
554
+
555
+ ### Theming
556
+
557
+ fantasy is the light default and sunset the dark variant, set in assets/stylesheets/app.css:
558
+
559
+ @plugin "daisyui" {
560
+ themes: fantasy --default, sunset --prefersdark;
561
+ }
562
+
563
+ --default applies when <html data-theme> is unset, --prefersdark under @media (prefers-color-scheme: dark), the layout ships <html> without data-theme so the OS preference decides.
564
+ Other themes: any of daisyUI's 32 built-ins in place of fantasy and sunset.
565
+ One fixed theme: <html data-theme="fantasy"> in views/layout.erb.
566
+ A switcher: a <select> and a few lines of JS setting document.documentElement.dataset.theme, daisyUI's theme generator (https://daisyui.com/theme-generator/) emits a block for a custom palette.
567
+ The two <meta name="theme-color"> literals at the top of views/layout.erb (#faf7f5 light, #202020 dark) are read by the browser before any CSS loads, so they cannot follow the theme and have to be updated by hand when the themes change.
568
+
569
+ ### Own utilities and components
570
+
571
+ * Utilities: @layer utilities { .my-thing { ... } } in app.css or a file it imports
572
+ * Components: @layer components { .card-fancy { @apply card bg-base-200 shadow-xl; } }
573
+ * daisyUI options (themes, prefix, logs): inside the @plugin "daisyui" { ... } block
574
+
575
+ ### Layout shell
576
+
577
+ views/layout.erb is the daisyUI chrome every page renders through:
578
+
579
+ * header .navbar, the app name linking home, then a user-state branch (a dropdown with email, change password, change email and sign out when current_account, otherwise a Sign in button), then the language switcher when more than one locale exists, sign out is a hidden form with csrf_tag('/account/logout') that the dropdown's <button form="logout-form"> submits
580
+ * main.container.mx-auto.p-4.grow holds the page (<%%== yield %>)
581
+ * footer with the legal links and the cookie choices button, replace with your own
582
+ * flash[:notice] and flash[:error] render as a fixed bottom-right toast, alert-info and alert-error, gone on the next page load
583
+ * the consent banner while no consent is recorded and the preferences popover always
584
+ * head: title, description, canonical, Open Graph, hreflang, favicons and manifest through views/_head_meta.erb, override per page with @page_title, @page_description, @canonical_url, @og_image, @og_type in the route
585
+
586
+ ## Asset bundles and consent
587
+
588
+ :assets groups split CSS and JS by section (:app, :admin, :checkout, ...), each group maps one source file under assets/{stylesheets,javascripts}/.
589
+ Consent gating declares which groups need which consent category, groups not listed render unconditionally.
590
+ A bundle can be admin-only, consent-gated, both or neither.
591
+
592
+ ### Gating a bundle
593
+
594
+ Gate analytics.js on the :analytics category:
595
+
596
+ 1. Drop the source at assets/javascripts/analytics.js
597
+ 2. Register the bundle in config/initializers/43_static.rb
598
+ 3. Declare the gate in config/initializers/52_consent_kit.rb
599
+ 4. Emit it in views/layout.erb
600
+
601
+ plugin :assets,
602
+ css: { app: %w[.compiled/app.css] },
603
+ js: {
604
+ app: 'app.js',
605
+ analytics: 'analytics.js'
606
+ },
607
+ css_dir: 'stylesheets',
608
+ js_dir: 'javascripts',
609
+ group_subdirs: false
610
+
611
+ JS bundles are listed as-is, CSS bundles by their compiled output, the Tailwind sources are configured in Procfile.dev and driven by rake tailwind:build.
612
+
613
+ ConsentKit.configure do |c|
614
+ c.gated_bundles = {
615
+ analytics: %i[analytics],
616
+ marketing: %i[fb_pixel]
617
+ }
618
+ end
619
+
620
+ Key is a consent category (:necessary, :functional, :analytics, :marketing, :social), value the :assets group names that need it, a bundle sits under one category only.
621
+
622
+ <%%== consented_assets(:js, :app) %>
623
+ <%%== consented_assets(:js, :analytics) %>
624
+
625
+ ### Gating decision
626
+
627
+ consented_assets(type, bundle) looks the bundle up in gated_bundles, listed under a category it returns assets([type, bundle]) when consented?(category) holds and '' otherwise, not listed it always returns assets([type, bundle]).
628
+ For conditional content that is not a bundle use consented? directly:
629
+
630
+ <%% if consented?(:social) %>
631
+ <iframe src="https://www.youtube.com/embed/abc"></iframe>
632
+ <%% end %>
633
+
634
+ ## Tests
635
+
636
+ rake test:all model, web, daemon, locale, browser and quality, with SimpleCov
637
+ rake test:model
638
+ rake test:web
639
+ rake test:daemon
640
+ rake test:locale key parity across locales/*.yml
641
+ rake test:browser
642
+
643
+ ### Execution
644
+
645
+ Each test:* task runs one rspec subprocess against its directory, test:all chains them (model, web, daemon, locale, browser, then quality:all, rubocop, erb_lint, bundler-audit and rubycritic) on the shared <%= @app.snake %>_test database, which test:db bounces and seeds once at the start, and prints a summary table with each suite's examples and failures and a merged coverage figure.
646
+ DB state is shared and not isolated per example, rows from earlier examples are visible to later ones, so a spec that reads existing state (count, first, last, order by time) has to scope by something unique to the example, a random email, an account_id, a request_id, the audit helpers in spec/support/audit_log_helpers.rb take those filters for that reason.
647
+ Mail::TestMailer.deliveries IS cleared per example by a before hook in spec_helper.rb.
648
+
649
+ spec/models/ :model Sequel models, account_spec.rb, authorization_spec.rb, rbac_audit_spec.rb
650
+ spec/web/ :web routes over Rack::Test, auth_spec.rb, admin_spec.rb
651
+ spec/daemons/ :daemon daemon classes, call handle_<channel> and tick directly, never .run, bundled for push_sender and gdpr_worker
652
+
653
+ ### Browser tests
654
+
655
+ Playwright (https://playwright.dev/) drives the real UI in firefox, chromium or webkit and axe-core (https://github.com/dequelabs/axe-core-gems) checks accessibility, two subdirs plus spec/browser/role_boundary_spec.rb at the top level:
656
+
657
+ spec/browser/wcag/ each example visits a URL and asserts be_axe_clean, always firefox since axe rules are browser-independent, auth_pages_spec.rb and legal_pages_spec.rb
658
+ spec/browser/uat/ behavioural specs through the UI, honours the browser argument, auth_spec.rb, create_account_form_spec.rb, profile_form_spec.rb, otp_lifecycle_spec.rb, consent_nojs_spec.rb, upload_spec.rb
659
+
660
+ ### Running browser tests
661
+
662
+ rake test:browser firefox
663
+ rake test:browser[chromium]
664
+ rake test:browser[webkit]
665
+ rake test:browser:wcag always firefox
666
+ rake test:browser:uat
667
+ rake test:browser:uat[chromium]
668
+
669
+ test:browser runs the browser specs alone, they are slower than the in-process specs so use it after UI changes, test:all includes them.
670
+
671
+ ### Node setup
672
+
673
+ The playwright-ruby-client gem (https://github.com/YusukeIwaki/playwright-ruby-client) drives the playwright npm CLI and the two have to be the same version, bin/setup reads the version the gem expects, stops if package.json disagrees and downloads the browser:
674
+
675
+ npm install --save-dev playwright@$(bundle exec ruby -e "require 'playwright'; print Playwright::COMPATIBLE_PLAYWRIGHT_VERSION")
676
+ npx playwright install firefox
677
+
678
+ node_modules/ is gitignored, package.json and package-lock.json are committed, after a bundle update of the Playwright gems run bin/setup or the two commands again.
679
+
680
+ ### Other browsers
681
+
682
+ bin/setup installs firefox only (about 85 MB):
683
+
684
+ npx playwright install chromium webkit
685
+
686
+ A CI matrix runs rake test:browser:uat[<engine>] once per engine, the WCAG specs once on firefox.
687
+
688
+ ### Axe violations
689
+
690
+ A failing be_axe_clean example prints the rule id (for instance color-contrast), the offending nodes, a one-line description and a dequeuniversity.com URL with the fix, Deque's axe DevTools extension (https://www.deque.com/axe/devtools/) runs the same rules in the browser.
691
+
692
+ ### Adding browser specs
693
+
694
+ WCAG: a file under spec/browser/wcag/ with visit '/some/path' and expect(page).to be_axe_clean per example.
695
+ UAT: a file under spec/browser/uat/ with the Capybara DSL (visit, fill_in, click_button, have_current_path), raw Playwright through Capybara.current_session.driver.browser when needed.
696
+ The browser helper freezes an anonymous subclass of the app, so a spec can mount a test-only route on its own Class.new(<%= @app.camel %>), see spec/browser/uat/upload_spec.rb.
697
+
698
+ ## Code quality
699
+
700
+ rake quality:all rubocop, erb_lint and bundler-audit as gates, then the rubycritic report, part of test:all
701
+ rake quality:rubocop
702
+ rake quality:erb
703
+ rake quality:audit Gemfile.lock against ruby-advisory-db, offline
704
+ rake quality:audit:update refresh the advisory db, then scan
705
+ rake quality:rubycritic report in tmp/rubycritic/, never fails the build
706
+
707
+ bundle exec rubocop works directly, plugins in .rubocop.yml: rubocop-rspec, rubocop-performance, rubocop-capybara, rubocop-rake, rubocop-sequel, rubocop-thread_safety.
708
+ RubyCritic wraps reek, flay and flog, paths in .rubycritic.yml, reek tuning in .reek.yml.
709
+
710
+ ## Deployment
711
+
712
+ * deploy/Caddyfile, automatic HTTPS (ACME DNS-01 through GleSYS), reverse_proxy to the Puma Unix socket, static security headers, asset caching, gzip and zstd, JSON access log and per-server metrics, needs a Caddy built with the DNS provider (xcaddy build --with github.com/caddy-dns/glesys), the X-Accel-Redirect block for Shrine downloads is a paste-in, see Uploads
713
+ * deploy/logrotate/<%= @app.snake %>-caddy, daily rotation of the Caddy access log since Caddy's own roller is size based
714
+ * deploy/systemd/<%= @app.snake %>.service, FilteredLogger and the daemons write to $stdout and journald keeps it (journalctl -u <%= @app.snake %> -f), no log files on disk
715
+ * deploy/systemd/<%= @app.snake %>-push-sender.service and <%= @app.snake %>-gdpr-worker.service, one long-running unit per daemon
716
+ * deploy/systemd/<%= @app.snake %>-audit-partition.{service,timer} and <%= @app.snake %>-shrine-cleanup.{service,timer}, scheduled oneshots, the next audit partition and the orphaned upload cache sweep
717
+
718
+ The units expect a system-wide Ruby, ExecStart calls /usr/local/bin/bundle and ProtectHome=true hides home directories. With a version-managed Ruby (rbenv, frum, rvm) under the deploy user's home, point every ExecStart at that bundle and drop ProtectHome, .ruby-version pins the exact version the app was scaffolded with.
719
+
720
+ ## Plugins reference
721
+
722
+ Every plugin choice is in config/initializers/4*_*.rb and 5*_*.rb, each initializer is short.
723
+
724
+ ### Routing
725
+
726
+ :hash_branches, :hash_paths, :hash_branch_view_subdir, :named_routes, :all_verbs, :typecast_params, :typecast_params_sized_integers, :Integer_matcher_max, :halt, :pass in config/initializers/40_routing.rb.
727
+ One hash_branch per file in routes/, views resolve under views/<branch>/<name>.erb:
728
+
729
+ # routes/orders.rb
730
+ class <%= @app.camel %>
731
+ hash_branch('orders') do |r|
732
+ r.get 'Integer:id' do |id|
733
+ @order = Order[id] or r.halt(404)
734
+ view('orders/show')
735
+ end
736
+ end
737
+ end
738
+
739
+ ### Rendering
740
+
741
+ :render with escape: true so <%%= %> escapes, :partials, :content_for, :link_to, :h, :path in config/initializers/41_render.rb, <%%== for raw HTML.
742
+ link_to is locale aware, locale_kit prefixes the href (string, named route symbol or object) with the current locale, so use it for internal links instead of a bare <a href="/..."> which bounces through a 302 to the default locale:
743
+
744
+ <%%== link_to 'Privacy', '/legal/privacy' %> /<locale>/legal/privacy
745
+ <%%== link_to 'Orders', :orders %> /<locale>/orders
746
+ <%%== link_to 'Order', @order %> /<locale>/orders/1
747
+ <%%= h @order.notes %>
748
+ <%%== render('shared/_card') %>
749
+
750
+ ### Format dispatch
751
+
752
+ Roda's :type_routing in config/initializers/40_routing.rb negotiates on the URL extension (/orders/1.pdf) or the Accept header, each registered type is an r.<type> { } matcher, html, json and xml are built in and the scaffold adds csv, pdf and xlsx to match the shipped caxlsx and prawn, more types go into the types: hash.
753
+ The html default has to come LAST, when no branch matches the requested type execution falls through, there is no automatic 406:
754
+
755
+ r.get 'orders', Integer do |id|
756
+ @order = Order[id]
757
+ r.json { @order.to_json }
758
+ r.csv { OrderCsv.new(@order).render }
759
+ r.pdf { OrderPdf.new(@order).render }
760
+ view('orders/show')
761
+ end
762
+
763
+ Header negotiation sets Vary: Accept.
764
+ The matched extension is stripped from the routed path but env['PATH_INFO'] and r.real_remaining_path keep the original, so a stored report.pdf is streamed through a route with Content-Disposition and not served by r.public or r.assets, which look files up by the stripped path, see Uploads.
765
+
766
+ ### Static and assets
767
+
768
+ :public serves public/ as is, :assets concatenates one Tailwind output per bundle, per request in dev and fingerprinted at boot in prod, the default :app bundle is [.compiled/app.css] and assets/stylesheets/app.css is its Tailwind entry, see UI and styling and Asset bundles and consent:
769
+
770
+ <%%== consented_assets(:css, :app) %>
771
+ <%%== consented_assets(:js, :app) %>
772
+
773
+ ### Sessions
774
+
775
+ Rack::Session::Redis in config/initializers/44_sessions.rb, the Redis connection in 20_redis.rb, the cookie _<%= @app.snake %>.sid carries only the id and the payload lives in Redis with a 7 day TTL:
776
+
777
+ session[:user_id] = user.id
778
+ session.clear
779
+
780
+ ### Security
781
+
782
+ Roda owns :route_csrf with csrf_failure: :empty_403 and the CSP through :content_security_policy in config/initializers/45_security.rb, consent_kit stands down with c.emit_csp = false in 52_consent_kit.rb and the proxy sets none, so there is exactly one Content-Security-Policy header, two would intersect and block things.
783
+ The consent flow ships no JavaScript (server-rendered banner, native popover, form POSTs), so the policy is a plain script-src 'self' without a nonce and pages stay cacheable, with consent_kit gated_bundles either list those domains in the policy or set emit_csp back to true and let consent_kit add the consented domains per request.
784
+ The other static headers, Strict-Transport-Security (1 year with subdomains), X-Frame-Options DENY, X-Content-Type-Options nosniff, Referrer-Policy strict-origin-when-cross-origin and Permissions-Policy (camera, mic, geolocation, payment, usb denied), come from the header block in deploy/Caddyfile.
785
+ request.ip is Rack's default walker (right to left over X-Forwarded-For with the trusted-proxy regex), :ip_from_header is NOT enabled since it returns the whole comma-separated header and breaks the audit_log inet cast, behind a CDN or LB set Caddy's trusted_proxies so the walker sees the client.
786
+
787
+ <form action="/orders" method="post">
788
+ <%%== csrf_tag('/orders') %>
789
+ </form>
790
+
791
+ ### Output
792
+
793
+ :flash, :json (Hash and Array returns are serialised), :json_parser (JSON bodies into r.params) in config/initializers/46_flash.rb and 47_json.rb:
794
+
795
+ flash[:notice] = 'Saved'
796
+ r.redirect orders_path
797
+
798
+ r.post 'api/orders' do
799
+ Order.create(r.params)
800
+ { ok: true }
801
+ end
802
+
803
+ ### Errors
804
+
805
+ :error_handler, :not_found, :exception_page (dev only), :status_handler, :symbol_status in config/initializers/48_errors.rb:
806
+
807
+ r.halt(:unauthorized) unless current_account
808
+ r.halt(404)
809
+
810
+ ### Misc
811
+
812
+ :caching (Last-Modified and ETag), :cookies in config/initializers/49_misc.rb, :hooks (before and after) comes from 01_logger.rb, the heartbeat endpoints are in routes/heartbeat.rb:
813
+
814
+ response.cache_control public: true, max_age: 3600
815
+ response.last_modified @order.updated_at
816
+
817
+ ### Mail
818
+
819
+ Roda :mailer in 50_mailer.rb and the mail gem, Office365 SMTP defaults in config/initializers/15_mail.rb with the alternative host documented inline.
820
+ Sender identities sit under mail.accounts.<name>, the from address in config/settings.yml and the SMTP credentials in config/settings/<env>.local.yml, the default account is required and used unless a route picks another through <%= @app.camel %>Config.mail.accounts.<name>.from:
821
+
822
+ sendmail :welcome, user_id: user.id
823
+
824
+ ### Rate limiting
825
+
826
+ Rack::Attack, production only, three Redis-backed throttles, req/ip at 60 per minute, auth-post/ip at 5 per 20 s over every credential, token and 2FA path Rodauth ships, and auth-post/email at 6 per minute on the submitted login so IP rotation against one account still hits a ceiling.
827
+ AUTH_POST_PATHS in config/initializers/25_rack_attack.rb lists the paths and Rack::Attack.auth_post? strips the /<locale>/ prefix first since rack-attack sits outside LocaleKit, add a path there whenever a new credential-bearing Rodauth route is enabled.
828
+
829
+ ### Daemons
830
+
831
+ Plain Ruby classes under lib/daemon/<name>.rb started by bin/<name>, systemd handles daemonizing, restarts and journald in production.
832
+ They subclass Daemons::Base from lib/daemon/base.rb for signal trapping, logging and two loops, run_polling(interval:) and run_listening(db, channels, timeout:), the latter wraps sequel-listen_job's DB.listen_job loaded in config/initializers/35_listen_job.rb, roda g daemon NAME [--channel=CHAN] scaffolds one:
833
+
834
+ # lib/daemon/orders.rb
835
+ module Daemons
836
+ class Orders < Daemons::Base
837
+ CHANNELS = %w[order_placed].freeze
838
+
839
+ def initialize(db: DB, **)
840
+ super(**)
841
+ @db = db
842
+ end
843
+
844
+ def run = run_listening(@db, CHANNELS)
845
+
846
+ def handle_order_placed(payload)
847
+ @logger.info("[#{tag}] new: #{payload}")
848
+ end
849
+ end
850
+ end
851
+
852
+ DB.notify(:order_placed, payload: order.id.to_s)
853
+
854
+ A polling daemon swaps run_listening for run_polling(interval: 5) and implements tick.
855
+
856
+ ### i18n and LocaleKit
857
+
858
+ The i18n gem loads YAML from locales/, LocaleKit handles the locale URL prefixes (/en/, /sv/ and the rest of available_locales), the detection cascade (account_profile.language, cookie, Accept-Language, default, 51_locale_kit.rb wires the profile and session resolvers), the prefixed *_path and link_to helpers and the POST /locale/:locale switcher, configured in config/initializers/30_i18n.rb and 51_locale_kit.rb.
859
+ A new language is a YAML file in locales/, available_locales follows:
860
+
861
+ <%%= I18n.t('orders.heading') %>
862
+ <a href="<%%= orders_path %>">...</a>
863
+
864
+ ### ConsentKit
865
+
866
+ EU cookie consent without JavaScript, POST /consent saves and POST /consent/withdraw withdraws, there is no GET /consent.
867
+ While no consent is recorded the layout carries a server-rendered open <dialog> banner (views/consent_kit/_banner.erb, a daisyUI override), the preferences UI is a native popover that any <button type="button" popovertarget="consent-preferences"> opens, the footer button and /legal/cookies do, every choice is a form POST so visitors with scripts blocked can still choose.
868
+ Gate your own scripts server-side with consented?(:category) or consented_assets, a JSON audit trail is written, configured in config/initializers/52_consent_kit.rb:
869
+
870
+ <%% if consented?(:analytics) %>
871
+ <script src="https://www.googletagmanager.com/gtag/js"></script>
872
+ <%% end %>
873
+
874
+ ## Settings
875
+
876
+ All config lives on the frozen <%= @app.camel %>Config constant, see Configuration tiers:
877
+
878
+ <%= @app.camel %>Config.database.url PostgreSQL URL for the web role
879
+ <%= @app.camel %>Config.database.app_url PostgreSQL URL for the app role (migrations, daemons, rake, console, specs)
880
+ <%= @app.camel %>Config.redis.url sessions and rack-attack
881
+ <%= @app.camel %>Config.mail.accounts.default.from from address, DMARC aligned
882
+ <%= @app.camel %>Config.mail.accounts.default.smtp.* address, user_name, password
883
+ <%= @app.camel %>Config.rodauth.hmac_secret HMAC pepper for persistent tokens, hex 32
884
+ <%= @app.camel %>Config.rodauth.argon2_secret pepper for the Argon2id hashes, hex 32
885
+ <%= @app.camel %>Config.consent.signing_key HMAC key for the consent cookie, hex 64
886
+ <%= @app.camel %>Config.consent.ip_hash_salt salt for the audit trail IP hash, hex 32
887
+ <%= @app.camel %>Config.consent.policy_version integer, bumping it re-prompts every user
888
+ <%= @app.camel %>Config.site.* company name, address, contact, regulator, domain
889
+
890
+ A few variables stay real ENV since they select a mode rather than configure: RACK_ENV, DATABASE_ROLE (app or web for rake, bin and specs), LOG (force logging on in test), PLAYWRIGHT_BROWSER. The production units also read PORT, PUMA_WORKERS and PUMA_THREADS (config/puma.rb), RELEASE (git SHA, keeps ETags identical across Puma workers) and SKIP_DEPLOY_CHECKS.
891
+ Any setting can be overridden with SETTINGS__FOO__BAR=value, for instance SETTINGS__DATABASE__URL=postgres://override, the YAML is the canonical place and the variable is the emergency hatch