Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
R

rails_api_base

> 后端框架
Open source

API boilerplate project for Ruby on Rails 8

630 stars0 likes2 views
WebsiteGitHub

About

API boilerplate project for Ruby on Rails 8

Rails API Template

Rails API Base is a boilerplate project for JSON RESTful APIs. It follows the community best practices in terms of standards, security and maintainability, integrating a variety of testing and code quality tools. It's based on Rails 8.1 and Ruby 4.0.

Finally, it contains a plug an play Administration console (thanks to ActiveAdmin).

Features

This template comes with:

  • Schema
    • Users table
    • Admin users table
  • Endpoints
    • Sign up with user credentials
    • Sign in with user credentials
    • Sign out
    • Reset password
    • Get and update user profile
  • Administration panel
  • Feature flags support with a UI for management
  • Code quality tools
  • RSpec tests
  • RSpec API Doc Generator
  • API documentation following OpenAPI
  • Docker support

How to use

  1. Clone this repo
  2. Install PostgreSQL in case you don't have it
  3. Install node. The expected node version is defined in .nvmrc file.
  4. Install yarn. You can run corepack enable to install the required yarn binaries. Corepack is already included in newest node versions.
  5. Run bootstrap.sh with the name of your project like ./bin/bootstrap.sh --name=my_awesome_project.
  6. Run yarn install and yarn build --watch. This bundles the JS assets in the administration site using esbuild.
  7. bundle exec rspec and make sure all tests pass (non-headless mode) or HEADLESS=true bundle exec rspec (headless mode)
  8. Run bin/dev.
  9. You can now try your REST services!

How to use with Docker

  1. Have docker and docker-compose installed (You can check this by doing docker -v and docker-compose -v)
  2. Run bootstrap.sh with the name of your project and the -d or --for-docker flag like ./bin/bootstrap.sh --name=my_awesome_project -d
    1. Run ./bin/bootstrap.sh --help for the full details.
  3. (Optional) If you want to deny access to the database from outside of the docker-compose network, remove the ports key in the docker-compose.yml from the db service.
  4. (Optional) Run the tests to make sure everything is working with: bin/rspec ..
  5. You can now try your REST services!

See Docker docs for more info

Dev scripts

This template provides a handful of scripts to make your dev experience better!

  • bin/bundle to run any bundle commands.
    • bin/bundle install
  • bin/rails to run any rails commands
    • bin/rails console
  • bin/web to run any bash commands
    • bin/web ls
  • bin/rspec to run specs
    • bin/rspec .
  • bin/dev to run both Rails and JS build processes at the same time in a single terminal tab.
    • bin/dev

You don't have to use these but they are designed to run the same when running with Docker or not. To illustrate, bin/rails console will run the console in the docker container when running with docker and locally when not.

Gems

  • ActiveAdmin for easy administration
  • Arctic Admin for responsive active admin
  • Annotaterb for documenting the schema in the classes
  • Brakeman for security static analysis
  • Byebug for debugging
  • Devise for basic authentication
  • Devise Token Auth for API authentication
  • Dotenv for handling environment variables
  • Draper for decorators
  • Factory Bot for testing data
  • Faker for generating test data
  • Flipper for feature flag support
  • GoodJob for background processing
  • Jbuilder for JSON views
  • JS Bundling for bundling JS assets
  • Knapsack for splitting tests evenly based on execution time
  • Letter Opener for previewing emails in the browser
  • New Relic for monitoring and debugging
  • Pagy for pagination
  • Parallel Tests for running the tests in multiple cores
  • Prosopite to detect N+1 queries
  • Pry for enhancing the Ruby shell
  • Puma for the web server
  • Pundit for authorization management
  • Rack CORS for handling CORS
  • Rails Best Practices for Rails linting
  • Reek for Ruby linting
  • RSpec for testing
  • RSpec OpenAPI for generating API documentation
  • Rswag for serving the API documentation
  • Rubocop for Ruby linting
  • Shoulda Matchers for other testing matchers
  • Simplecov for code coverage
  • Strong Migrations for catching unsafe migrations in development
  • Webmock for stubbing http requests
  • YAAF for form objects

Email support

This template includes built-in email delivery support via SendGrid, using Rails' Action Mailer.

Email sending with SendGrid is enabled by configuring the environment variable:

bash
SENDGRID_API_KEY=your_api_key

Optional configuration

  • Set your frontend URL in config/initializers/rack_cors.rb
  • Set your mail sender in config/initializers/devise.rb
  • Config your timezone accordingly in application.rb
  • Config CI parallel execution. See docs
  • Fullstack development. See docs.

API Docs

  • RSpec API Doc Generator you can generate the docs after writing requests specs
  • Rswag you can expose the generated docs

See API documentation docs for more info

Code quality

With bundle exec rails code:analysis you can run the code analysis tool, you can omit rules with:

  • Rubocop Edit .rubocop.yml
  • Reek Edit config.reek
  • Rails Best Practices Edit config/rails_best_practices.yml
  • Brakeman Run brakeman -I to generate config/brakeman.ignore

Code quality and test coverage

The project uses SonarQube Community Edition to ensure code quality and monitor test coverage. The configuration can be found in sonar-project.properties.

To set up SonarQube:

  1. Install SonarQube locally (see CI documentation for details)
  2. Configure your environment variables:
    bash
    export SONAR_TOKEN=your_token
    export SONAR_HOST_URL=http://localhost:9000
  3. Run the analysis:
    bash
    bundle exec rspec
    sonar-scanner

For more details about the CI process and SonarQube setup, check the CI documentation.

More linters

  • Hadolint Install with brew install hadolint and run hadolint Dockerfile*. Edit .hadolint.yml to omit additional rules.

Claude Code setup

This template ships with project-level Claude Code skills under .claude/skills/ that auto-activate while Claude edits code in your project:

  • ruby-conventions — triggers on Ruby files; applies Rootstrap's Ruby style guide.
  • rails-conventions — triggers on Rails code (controllers, models, migrations, config); applies Rootstrap's Rails conventions.
  • rspec-conventions — triggers on spec files; applies Rootstrap's RSpec style guide.

They are distilled from rootstrap/tech-guides. No setup required — Claude Code loads them automatically based on the files being edited. If you don't use Claude Code, or want to customize the conventions, simply edit or remove the files under .claude/skills/.

Impersonation

The rails_api_base incorporates a user impersonation feature, allowing AdminUsers to assume the identity of other Users. This feature is disabled by default.

See Impersonation docs for more info

Monitoring

In order to use New Relic to monitor your application requests and metrics, you must setup NEW_RELIC_API_KEY and NEW_RELIC_APP_NAME environment variables. To obtain an API key you must create an account in the platform.

Code Owners

You can use CODEOWNERS file to define individuals or teams that are responsible for code in the repository.

Code owners are automatically requested for review when someone opens a pull request that modifies code that they own.

Credits

Rails API Base is maintained by Rootstrap with the help of our contributors.

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Rubyapiapi-boilerplateboilerplatehacktoberfest

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category后端框架
PricingOpen source

> Related tools

N
Node.js
基于 V8 的 JavaScript 运行时
D
Django
Python 高级 Web 框架
S
Spring Boot
Java 生态主流微服务框架