Overview
This is a Ruby on Rails 7.1+ application following the Model-View-Controller (MVC) architectural pattern. The codebase is organized into standard Rails directories, each with a specific purpose. This guide helps you navigate the code and understand where different pieces of functionality live.Directory Structure
App Directory (Main Code)
Theapp/ directory contains the core application logic, organized by responsibility:
Models (app/models/)
Models represent your data and business logic. Each model typically corresponds to a database table.
Core Models:
- person.rb - Central model for members
- membership.rb - Membership periods and renewals
- admin.rb - Administrative users
- donation.rb - Financial contributions
- contact.rb - Email, phone, address information
- equipment.rb - Physical equipment items
- instrument.rb - Equipment types/models
- group.rb - Member groups and categories
- api_key.rb - API authentication tokens
- meetup_event.rb - Events from Meetup.com
- status.rb - Membership status types
- Look here for data validation rules
- Database queries and scopes
- Relationships between entities
- Business logic calculations
Controllers (app/controllers/)
Controllers handle HTTP requests and coordinate between models and views.
Main Controllers:
- people_controller.rb - Member CRUD operations
- memberships_controller.rb - Membership management
- admins_controller.rb - Admin user management
- equipment_controller.rb - Equipment tracking
- donations_controller.rb - Donation records
- groups_controller.rb - Group management
- google_controller.rb - Google Workspace integration
- api_keys_controller.rb - API token management
- widgets_controller.rb - Embeddable widgets
- sessions_controller.rb - Authentication
app/controllers/api/):
- people_controller.rb - RESTful API for member data
- keys_controller.rb - API key management
- Look here for request handling logic
- Form processing and validation
- Redirects and responses
- Before/after action filters
Views (app/views/)
Views contain the HTML templates that render the user interface. Rails uses ERB (Embedded Ruby) for templating.
View Organization:
<% %>- Execute Ruby code (no output)<%= %>- Execute Ruby code and output result- Partials (
_filename.html.erb) - Reusable components - Helpers - Ruby methods available in views
- Look here for HTML structure
- User interface elements
- Form markup
- Display logic
Jobs (app/jobs/)
Background jobs handle asynchronous tasks that don’t need to complete immediately.
Key Jobs:
- calendar_sync_job.rb - Sync events to Google Calendar
- renewal_reminders_job.rb - Send renewal emails
- welcome_email_job.rb - Welcome new members
- Look here for scheduled tasks
- Email sending logic
- API integrations that run periodically
- Long-running operations
Mailers (app/mailers/)
Mailers handle email generation and sending.
Key Mailers:
- person_mailer.rb - Member-related emails
- admin_mailer.rb - Admin notifications
app/views/person_mailer/
welcome_email.html.erb- Welcome email templaterenewal_reminder.html.erb- Renewal reminder template
Policies (app/policies/)
Policies define authorization rules using Pundit. They determine what actions users can perform.
Key Policies:
- person_policy.rb - Member access control
- admin_policy.rb - Admin management permissions
- equipment_policy.rb - Equipment access control
read- View datawrite- Edit datapermit- Manage permissionsverify_members- Verify membership status
Helpers (app/helpers/)
Helpers contain utility methods available in views.
Key Helpers:
- application_helper.rb - Global helper methods
- people_helper.rb - People-specific helpers
- equipment_helper.rb - Equipment display helpers
Assets (app/assets/ and app/javascript/)
Assets include stylesheets, JavaScript, and images.
Stylesheets (app/assets/stylesheets/):
application.css- Main stylesheet manifest- Custom CSS files for specific features
app/javascript/):
application.js- JavaScript entry point- Stimulus controllers for interactive features
- Turbo for dynamic page updates
app/assets/images/):
- Static images and icons
Configuration (config/)
Configuration files control how the application behaves.
Key Files:
- routes.rb - URL routing definitions
- database.yml - Database connection settings
- environments/ - Environment-specific settings
development.rb- Development settingsproduction.rb- Production settingstest.rb- Test settings
/people→PeopleController#index/people/123→PeopleController#show/people/123/edit→PeopleController#edit/api/people→Api::PeopleController#index
- initializers/ - Code that runs at startup
- locales/ - Translation files
- credentials.yml.enc - Encrypted secrets
Database (db/)
Database schema, migrations, and seed data.
Key Files:
- schema.rb - Current database structure (auto-generated)
- seeds.rb - Initial data for new databases
- migrate/ - Migration files that modify the schema
- Never edit
schema.rbdirectly - it’s auto-generated - Create migrations to change the database structure
- Run
rails db:migrateto apply migrations - Migrations are timestamped and run in order
Library Code (lib/)
Custom code that doesn’t fit into the standard Rails structure.
Key Files:
- tasks/ - Custom Rake tasks
generate_data.rake- Generate test datacsv_compare.rake- Compare CSV files
- solid_queue_simple_worker.rb - Background job worker
- calendar_aggregator.rb - Calendar sync logic
Tests (test/)
Comprehensive test suite covering all application functionality.
Test Organization:
- Model tests - Business logic and validations
- Controller tests - Request handling and responses
- System tests - Full user workflows in browser
- Integration tests - Multiple components working together
Public Files (public/)
Static files served directly without Rails processing.
public/ are served at the root URL:
public/robots.txt→/robots.txtpublic/favicon.ico→/favicon.ico
Finding Your Way Around
I need to add a new feature…
- Start with routes (
config/routes.rb) - Define the URL - Create/modify controller (
app/controllers/) - Handle the request - Create/modify model (
app/models/) - Add business logic - Create/modify views (
app/views/) - Build the UI - Add policy (
app/policies/) - Control access - Write tests (
test/) - Verify it works
I need to understand how X works…
Authentication:app/controllers/sessions_controller.rb- Login/logoutapp/controllers/application_controller.rb-authorize_adminmethodapp/models/admin.rb- Admin model with permissions
app/models/person.rb- Member data and statusapp/models/membership.rb- Membership periodsapp/controllers/memberships_controller.rb- Renewal flowapp/jobs/renewal_reminders_job.rb- Automated reminders
app/controllers/google_controller.rb- OAuth and sync operationsapp/jobs/calendar_sync_job.rb- Calendar synchronizationlib/calendar_aggregator.rb- Event aggregation logic
app/mailers/person_mailer.rb- Email definitionsapp/views/person_mailer/- Email templatesconfig/environments/production.rb- SMTP settings
app/controllers/api/- API endpointsapp/models/api_key.rb- Authenticationconfig/routes.rb- API routes (under/api)
I need to modify the database…
- Generate migration:
rails generate migration DescriptionOfChange - Edit migration file in
db/migrate/ - Run migration:
rails db:migrate - Update model in
app/models/if needed - Update tests to reflect changes
I need to debug an issue…
Check these places in order:- Server logs -
docker compose logs app - Controller - Where the request is handled
- Model - Where business logic lives
- View - What’s being rendered
- Routes - How URLs map to controllers
- Policy - Authorization rules
- Database - Data issues via Rails console
Common Patterns
Creating a New Model
Creating a New Controller
Adding a Background Job
Request Flow
Understanding how a request flows through the application:Key Rails Conventions
Naming Conventions
- Models: Singular, CamelCase (
Person,ApiKey) - Controllers: Plural, CamelCase (
PeopleController,ApiKeysController) - Tables: Plural, snake_case (
people,api_keys) - Files: snake_case (
person.rb,api_key.rb)
Directory Mapping
RESTful Actions
Standard controller actions follow REST conventions:index- List all records (GET/people)show- Display one record (GET/people/123)new- Show form for new record (GET/people/new)create- Save new record (POST/people)edit- Show form for editing (GET/people/123/edit)update- Save changes (PATCH/people/123)destroy- Delete record (DELETE/people/123)
Summary
The Rails application structure is organized by responsibility:- Models (
app/models/) - Data and business logic - Controllers (
app/controllers/) - Request handling - Views (
app/views/) - User interface - Jobs (
app/jobs/) - Background tasks - Policies (
app/policies/) - Authorization - Tests (
test/) - Quality assurance - Config (
config/) - Application settings - Database (
db/) - Schema and migrations
- Convention over Configuration - Follow Rails naming conventions
- DRY (Don’t Repeat Yourself) - Reuse code via helpers, partials, and inheritance
- Separation of Concerns - Keep models, views, and controllers focused
- RESTful Design - Use standard CRUD actions where possible
- Data/Logic → Models
- User Interface → Views
- Request Handling → Controllers
- Background Processing → Jobs
- Access Control → Policies
- URL Routing → Config/Routes
