This repository serves as a hybrid template for a Ruby on Rails (RoR) application with grape. It includes a pre-configured setup with essential gems and tools to streamline development.
Clone the repository
git clone https://github.com/Grigore-George-Mihai/hybrid_template
1. Rename the Application
This will update the app name everywhere it appears (module name, titles, DB names, cable prefixes, Docker volumes, etc.).
bin/rails setup:rename_app
2. Create Environment Files
Copy environment template files into .env.development
and .env.test
.
bin/rails setup:copy_env
Then open each file and update values as needed:
- Database credentials (
POSTGRES_USER
,POSTGRES_PASSWORD
) - Any other environment-specific variables
3. Set Up the Database
bin/rails db:prepare # Creates and migrates the database
bin/rails db:seed # Loads seed data
4. Optional Integrations
- Devise — Adjust configuration in
config/initializers/devise.rb
if needed. - Scout APM — Add your SCOUT_KEY value in .env.development (or the appropriate .env file) to enable. If left blank, ScoutAPM stays disabled.
- Rollbar — Add your ROLLBAR_ACCESS_TOKEN value in .env.development (or the appropriate .env file) to enable. If left blank, Rollbar stays disabled.
✅ You’re now ready to start development!
Database and Monitoring
- Pg: PostgreSQL driver for Ruby, providing fast and efficient database connectivity.
- PgHero: A tool for monitoring PostgreSQL database performance, including query insights, index suggestions, and table size analysis.
Grape
- Grape: A REST-like API framework for Ruby that is designed to run on Rack or complement existing web application frameworks like Rails.
- Grape Entity: A framework-agnostic entity layer to decorate and serialize data objects for API responses.
- Grape Swagger: Adds Swagger-compliant documentation to your Grape API.
- Grape Swagger Entity: Extends
grape-entity
to generate Swagger documentation automatically. - Grape Swagger Rails: Integrates
grape-swagger
into Rails applications for serving Swagger UI.
Authentication
- Devise: Flexible authentication solution for Rails based on Warden.
- Devise-JWT: Adds stateless token-based authentication to Devise using JSON Web Tokens (JWT) for secure API authentication.
Admin Interface
- ActiveAdmin: A flexible and extensible admin framework for Ruby on Rails applications, making it easy to build custom admin panels.
Pagination
- Pagy: A fast, efficient, and lightweight pagination gem for Rails, providing easy customization and flexibility with minimal overhead.
Background Processing
- Sidekiq: Efficient background processing for Ruby applications.
- Sidekiq-Scheduler: Extends Sidekiq to support scheduled and recurring jobs using a simple configuration.
- Redis: In-memory data structure store used by Sidekiq for managing background job queues, scheduling, and retries.
Forms
- Simple Form: Simplifies form creation with a clean and flexible syntax.
Performance Monitoring
- Scout APM: Application monitoring tool.
- Bullet: Detects N+1 queries and unused eager loading.
- Rack Mini Profiler: Performance profiling tool.
Error Tracking
- Rollbar: Real-time error tracking and reporting.
Code Quality & Linting
- Rubocop Rails Suite: A custom suite that bundles Rubocop with various plugins for Rails projects.
Testing
- Factory Bot Rails: Provides fixtures replacement with a straightforward definition syntax.
- Faker: A library for generating fake data.
- RSpec Rails: Testing framework for Rails.
- Shoulda Matchers: Simplifies testing Rails applications with RSpec.
- SimpleCov: Code coverage analysis tool.
- Rspec-Sidekiq: Testing framework for Sidekiq jobs.
Security
- Brakeman: Static analysis tool for finding security vulnerabilities in Rails applications.
- Bundler Audit: Scans your Gemfile for known vulnerabilities.
Environment Management
- Dotenv Rails: Loads environment variables from
.env
.
Run the following rake task to check for security risks in your application:
bin/rails security:check
- This task runs tools like Brakeman and Bundler Audit to ensure your application is secure.
This repository includes a custom Rails generator for creating Grape resources, entities, and corresponding RSpec tests. The generator helps streamline the process of adding new API endpoints to your application.
Generate a new Grape API resource:
rails generate grape_resource <ResourceName> field:type field:type
Replace with the name of your resource (e.g., Book) and field:type with the attributes and types (e.g., title:string description:text).
- Auto Mounting: Automatically mounts new resources in the API.
- Swagger Integration: Adds entities to Swagger models.
- Optional Model Generation: Prompts to generate the corresponding model.
rails generate grape_resource Book title:string description:text
- A Grape resource in app/api/v1/resources/books.rb
- A Grape entity in app/api/v1/entities/book_entity.rb
- A corresponding RSpec test in spec/api/v1/resources/books_spec.rb
- The resource will be automatically mounted in the API
- The entity will be added to Swagger documentation
- The generator also gives you the option to create the User model with the specified attributes.
If you prefer to run the application inside a Docker container, follow these steps:
- Build the Docker image:
docker-compose build
- Start the Application and services:
docker-compose up
- Stop the Application:
docker-compose down
- Remove named Volumes:
docker-compose down --volumes
For questions or further information, feel free to reach out via LinkedIn.