These rules apply to work under backend/.
This is a Rails API app using Active Record, RSpec, request specs, service objects, representation classes, and version tables for post/tag/wiki history.
Use commands backed by files and dependencies in this directory:
bin/setup
bin/dev
bin/rails
bin/rake
bin/rubocop
bin/brakeman
bundle exec rspec
Common checks:
bundle exec rspec
bin/rubocop
bin/brakeman
Common Rails commands:
bin/rails db:prepare
bin/rails db:migrate
bin/rails routes
bin/rails server
After backend behavior changes, run the relevant RSpec files. For broad backend changes, run:
bundle exec rspec
If a command cannot be run or fails, report the exact command and failure.
app/controllers: API controllers.app/models: Active Record models and concerns.app/representations: JSON response shaping.app/services: domain services such as version recorders, wiki commit, YouTube sync, and similarity calculation.config/routes.rb: public API routes.db/migrate: migrations.db/schema.rb: schema snapshot.lib/tasks: custom Rake tasks.spec: RSpec tests.Before changing behavior, inspect the matching route, controller, model, service, representation, and spec.
%w or %i in new Ruby code.X-Transfer-Code header in ApplicationController#authenticate_user.current_user is set by looking up User.inheritance_code.X-Transfer-Code flow unless the task explicitly changes authentication.:unauthorized consistently with existing controllers.User enum roles: guest, member, and admin.current_user.gte_member? for member-or-admin write permissions where existing controllers do so.current_user.admin? only for admin-only paths, such as tag child relationship changes.ApplicationController runs these before actions in order:
reject_banned_ip_address!authenticate_userreject_banned_user!banned_at, not a boolean banned column.User#banned? and IpAddress#banned? check banned_at.present?.spec/requests.spec/models.spec/services.spec/tasks.spec/rails_helper.rb loads spec/support/**/*.rb.AuthHelper and JsonHelper.AuthHelper#sign_in_as(user) stubs ApplicationController#current_user; use it when matching existing request spec style.db/schema.rb consistent.up and down.ActiveRecord::Base classes with self.table_name.after:.version_no; version tables have positive version_no with unique indexes scoped to the parent record.create, update, discard, and restore.VersionRecord concern.PostVersionRecorderTagVersionRecorderNicoTagVersionRecorderWikiVersionRecorderTagVersioningVersionRecorder locks the current record, validates sequence consistency, skips unchanged update snapshots, creates the next version row, and updates the record version_no.base_version_no, force, and merge semantics and cover conflicts in request specs.TagName, categories, parent implications, discard behavior, and version snapshots.app/representations when existing endpoints do.:unauthorized for no user, :forbidden for insufficient role or banned user, :not_found for missing records, and :unprocessable_entity for validation failures.tmp/, log/, storage/, vendor/, or dependency directories unless explicitly needed.