RailsForge

CI Status Gem Version License

RailsForge is a comprehensive command-line tool for automatically generating essential Rails application components, including monitoring configurations, DevOps setups, and security/performance analyzers.

Project Overview

RailsForge streamlines Rails development by providing automated generators and analyzers for common tasks:

  • Monitoring Configuration - Sentry error tracking and Lograge structured logging
  • DevOps Setup - Docker containerization and CI/CD pipeline configuration
  • Security Analysis - Automated vulnerability detection
  • Performance Analysis - Performance optimization recommendations
  • Code Generation - Services, queries, jobs, and more with template versioning

Key Features

  • 🔧 Automated Generators - Generate services, queries, jobs, components with a single command
  • 📊 Code Analyzers - Security, performance, and architectural analysis
  • 🐳 DevOps Ready - Docker and CI/CD configuration out of the box
  • 📈 Monitoring - Sentry and Lograge integration
  • 🎨 Template System - v1, v2, and v3 template versions with advanced patterns
  • 🧩 Plugin System - Extensible architecture for custom functionality
  • ⚙️ Configuration - Customizable via .railsforgerc YAML file

Installation

Requirements

  • Ruby version 3.0 or higher
  • Bundler for gem management

Setup Steps

# Install the gem
gem install railsforge

# Verify installation
railsforge --version

Option 2: Install from Source

# Clone the repository
git clone https://github.com/mfifth/railsforge.git
cd railsforge

# Install dependencies
bundle install

# Make the binary executable
chmod +x bin/railsforge

# Run locally
./bin/railsforge --version

Option 3: Add to Gemfile

# Add to your Rails project's Gemfile
group :development do
  gem 'railsforge', require: false
end

Then run:

bundle install

Usage Documentation

Getting Help

railsforge --help
railsforge --version

Generate Commands

Monitoring Configuration

Add Sentry error tracking and Lograge structured logging to your Rails application:

railsforge generate monitoring
railsforge generate monitoring --sentry_dsn=your_dsn_here
railsforge generate monitoring --environment=production

This creates:

  • config/initializers/sentry.rb - Sentry configuration
  • config/initializers/lograge.rb - Lograge setup
  • Updates environment configurations

DevOps Configuration

Generate Docker and CI/CD pipeline configurations:

railsforge generate devops
railsforge generate devops --docker
railsforge generate devops --ci=github
railsforge generate devops --ci=gitlab

This creates:

  • Dockerfile - Container definition
  • docker-compose.yml - Multi-service setup
  • .github/workflows/ci.yml - GitHub Actions CI/CD
  • .gitlab-ci.yml - GitLab CI configuration
  • config/kubernetes/ - Kubernetes manifests
  • bin/deploy - Deployment script

Demo Project

Create a sample Rails project for learning or prototyping:

railsforge generate demo my_demo
railsforge generate demo my_demo --type=blog
railsforge generate demo my_api --type=api

Test Files

Generate comprehensive test files:

railsforge generate test User
railsforge generate test PostsController --type=controller
railsforge generate test UserService --type=service
railsforge generate test SendEmailJob --type=job

Standard Generators

Generate Rails components with template versioning:

# Service objects
railsforge generate service user_creator
railsforge generate service user_creator --template=v2
railsforge generate service user_creator --template=v3

# Query objects  
railsforge generate query active_users
railsforge generate query posts --template=v2

# Jobs
railsforge generate job send_email
railsforge generate job process_data --template=v3

# Form objects
railsforge generate form contact_form

# Presenters
railsforge generate presenter user_presenter

# Policies
railsforge generate policy post_policy

# Serializers
railsforge generate serializer post_serializer

# View Components
railsforge generate component button
railsforge generate component modal --template=v2

# Stimulus Controllers
railsforge generate stimulus dropdown

# Mailers
railsforge generate mailer user_mailer

# Features
railsforge generate feature user_signup

# API Resources
railsforge generate api posts

Analyze Commands

Security Analysis

Run security vulnerability checks on your codebase:

railsforge analyze security
railsforge analyze security --verbose

Checks for:

  • SQL injection vulnerabilities
  • Cross-site scripting (XSS) risks
  • Authentication/authorization issues
  • Insecure configuration patterns
  • Sensitive data exposure

Performance Analysis

Identify performance optimization opportunities:

railsforge analyze performance
railsforge analyze performance --verbose

Checks for:

  • N+1 query patterns
  • Missing database indexes
  • Inefficient queries
  • Memory leak patterns
  • Unoptimized asset loading

Other Analyzers

# Analyze controllers
railsforge analyze controllers
railsforge analyze c

# Analyze models
railsforge analyze models
railsforge analyze m

# Analyze specs
railsforge analyze specs
railsforge analyze spec

# Analyze database
railsforge analyze db
railsforge analyze database

# Analyze metrics
railsforge analyze metrics

# Run all analyzers
railsforge analyze all
railsforge analyze full

Other Commands

Doctor - Health Check

Comprehensive project health report:

railsforge doctor

Combines all analyzers and calculates an architecture score (0-100).

Dependency Graph

Generate a Graphviz diagram of your Rails architecture:

railsforge graph

Outputs .dot and .svg files to tmp/railsforge/.

Wizard - Interactive Setup

Interactive project configuration:

railsforge wizard
railsforge wizard --profile=blog

Plugin Management

# List available plugins
railsforge plugins list

# Load a specific plugin
railsforge plugins load my_plugin

Configuration

# View current configuration
railsforge config

# Set configuration values
railsforge config set default_template v2
railsforge config set analyzer_threshold 10

Profiles

List available project profiles:

railsforge profiles

Available profiles: blog, admin_app, api_only, standard

Configuration Options

.railsforgerc

Create a .railsforgerc file in your project root to customize RailsForge behavior:

# .railsforgerc
default_template: v2
analyzer_threshold: 10

# Generator settings
generators:
  with_specs: true
  template_version: v2

# Analyzer settings  
security:
  strict_mode: true
performance:
  check_n_plus_queries: true

Available Flags

Flag Description Default
--sentry_dsn Sentry DSN for error tracking -
--environment Rails environment development
--template Template version (v1, v2, v3) v1
--dry-run Preview changes without executing false
--no-spec Generate without spec files false

Template System

RailsForge supports multiple template versions for each component:

v1 - Standard Templates

Basic templates suitable for simple applications:

class UserCreator
  def initialize(params)
    @params = params
  end

  def call
    # Basic implementation
  end
end

v2 - Enhanced Templates

Enhanced templates with additional features:

class UserCreator < BaseService
  option :name

  def call
    # Enhanced with Dry::Schema validation
  end
end

v3 - Advanced Templates

Advanced templates with best practices:

class UserCreator
  include Dry::Monads[:result, :do]

  def call
    yield validate!
    yield process!
    Success(result_data)
  end
end

Examples

Complete Workflow Example

# 1. Create a new Rails app (optional)
railsforge new my_app --profile=api

# 2. Add monitoring
cd my_app
railsforge generate monitoring --sentry_dsn=https://[email protected]/123

# 3. Add DevOps setup
railsforge generate devops --ci=github

# 4. Generate components
railsforge generate service user_creator --template=v3
railsforge generate job send_welcome_email --template=v3
railsforge generate query active_users --template=v3

# 5. Run analysis
railsforge analyze all
railsforge doctor

# 6. Check architecture
railsforge graph

Output Examples

$ railsforge generate monitoring
Generating Monitoring configurations...
Created config/initializers/sentry.rb
Created config/initializers/lograge.rb
Updated production.rb

$ railsforge analyze security
Security Analysis
==================================================
✓ No security issues found

$ railsforge analyze performance
Performance Analysis
==================================================
✓ No performance issues found

Contributing

We welcome contributions! Please see our contributing guidelines:

Development Setup

# Fork the repository
git clone https://github.com/mfifth/RailsForge.git
cd railsforge

# Install dependencies
bundle install

# Run tests
bundle exec rake test

# Run linter
bundle exec rubocop

Submitting Changes

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Code Style

  • Follow Ruby community style guides
  • Write tests for new features
  • Update documentation for any changes
  • Use meaningful commit messages

License

RailsForge is released under the MIT License.

Copyright (c) 2024 RailsForge Contributors

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Support


Built with ❤️ for the Rails community