🌟 We are Open Source! Check out our repository on GitHub

Ruby Project Structure

A scalable and maintainable folder structure for Ruby applications

File Structure

  • lib
    • myapp.rb
    • myapp
      • version.rb
      • cli.rb
      • configuration.rb
      • core
        • application.rb
        • router.rb
      • models
        • user.rb
        • post.rb
        • base.rb
      • services
        • user_service.rb
        • email_service.rb
      • controllers
        • users_controller.rb
        • base_controller.rb
      • middleware
        • auth_middleware.rb
        • cors_middleware.rb
      • utils
        • string_helpers.rb
        • date_helpers.rb
  • bin
    • myapp
    • console
    • setup
  • spec
    • spec_helper.rb
    • support
    • lib
      • myapp_spec.rb
    • models
      • user_spec.rb
    • services
      • user_service_spec.rb
  • config
    • database.yml
    • application.yml
  • db
    • migrate
    • seeds.rb
  • docs
    • api.md
    • installation.md
  • Gemfile
  • Gemfile.lock
  • Rakefile
  • myapp.gemspec
  • .rspec
  • .rubocop.yml
  • .gitignore
  • README.md

Directory Structure Explanation

lib/myapp/core/

Contains core application components like the main application class and router.

lib/myapp/controllers/

Contains controller classes for handling HTTP requests and responses.

lib/myapp/middleware/

Contains middleware classes for processing requests before they reach controllers.

lib/myapp/utils/

Contains utility modules and helper methods used throughout the application.

spec/support/

Contains shared test helpers, factories, and support files for testing.

config/

Contains configuration files for database, application settings, and environment-specific configs.

db/

Contains database-related files including migrations and seed data.

db/migrate/

Contains database migration files for version-controlled schema changes.

docs/

Contains project documentation including API docs and installation guides.

.rspec

RSpec configuration file defining default options for running tests.

.rubocop.yml

RuboCop configuration for code style and quality enforcement.