diff --git a/config/application.rb b/config/application.rb
index 619b66070ce0986a9e99baf3b37884b9aa37297b..6410e0bc18b8651654150eb9dd9ca1409ef48205 100644
--- a/config/application.rb
+++ b/config/application.rb
@@ -1,7 +1,10 @@
 require_relative 'boot'
 
 require 'rails/all'
-Bundler.require(:default, *Bundler.settings.with, Rails.env)
+
+# Require the gems listed in Gemfile, including any gems
+# you've limited to :test, :development, or :production.
+Bundler.require(*Rails.groups(*Bundler.settings.with))
 
 # Do not dump the limit of boolean fields on MySQL,
 # since that generates a db/schema.rb that's incompatible
@@ -24,6 +27,9 @@ require_relative 'asset_sync'
 
 module Diaspora
   class Application < Rails::Application
+    # Initialize configuration defaults for originally generated Rails version.
+    config.load_defaults 5.1
+
     # Settings in config/environments/* take precedence over those specified here.
     # Application configuration should go into files in config/initializers
     # -- all .rb files in that directory are automatically loaded.
@@ -64,8 +70,9 @@ module Diaspora
     # Speed up precompile by not loading the environment
     config.assets.initialize_on_precompile = false
 
-    # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
-    config.assets.precompile += %w(
+    # Precompile additional assets.
+    # (application.js, application.css, and all non-JS/CSS in the app/assets are already added)
+    config.assets.precompile += %w[
       contact-list.js
       ie.js
       jquery3.js
@@ -82,10 +89,7 @@ module Diaspora
       rtl.css
       color_themes/*/desktop.css
       color_themes/*/mobile.css
-    )
-
-    # Version of your assets, change this if you want to expire all your assets
-    config.assets.version = '1.0'
+    ]
 
     # See lib/tasks/assets.rake: non_digest_assets
     config.assets.non_digest_assets = %w(branding/logos/asterisk.png)
@@ -96,9 +100,6 @@ module Diaspora
       g.test_framework  :rspec
     end
 
-    # Will be default with Rails 5
-    config.active_record.raise_in_transactional_callbacks = true
-
     # Setup action mailer early
     config.action_mailer.default_url_options = {
       protocol: AppConfig.pod_uri.scheme,
diff --git a/config/boot.rb b/config/boot.rb
index 6e3d234276dc3d3ec804d6a7db98fdaab64e6e8c..e9f0721fea6ece79a780372c8e491ad914df620e 100644
--- a/config/boot.rb
+++ b/config/boot.rb
@@ -1,9 +1,6 @@
-# Set up gems listed in the Gemfile.
-ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
-require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
+ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
 
-# Ensure Builder is loaded
-require 'active_support/builder' unless defined?(Builder)
+require "bundler/setup" # Set up gems listed in the Gemfile.
 
 # Load configuration early
-require_relative 'load_config'
+require_relative "load_config"
diff --git a/config/environment.rb b/config/environment.rb
index c9482d0eecc907196f9839dfa50808971ed290d5..426333bb46978d897be4cc6fac77b9fcaacf59d0 100644
--- a/config/environment.rb
+++ b/config/environment.rb
@@ -1,5 +1,5 @@
-# Load the rails application
+# Load the Rails application.
 require_relative 'application'
 
-# Initialize the rails application
-Diaspora::Application.initialize!
+# Initialize the Rails application.
+Rails.application.initialize!
diff --git a/config/environments/development.rb b/config/environments/development.rb
index c32bb8287ed12e24863b90efca421462a69ed359..f422f016e68e9f778ee45a66165d0dbf02c8c961 100644
--- a/config/environments/development.rb
+++ b/config/environments/development.rb
@@ -1,5 +1,5 @@
-Diaspora::Application.configure do
-  # Settings specified here will take precedence over those in config/application.rb
+Rails.application.configure do
+  # Settings specified here will take precedence over those in config/application.rb.
 
   # In the development environment your application's code is reloaded on
   # every request. This slows down response time but is perfect for development
@@ -9,30 +9,40 @@ Diaspora::Application.configure do
   # Do not eager load code on boot.
   config.eager_load = false
 
-  # Show full error reports and disable caching
-  config.consider_all_requests_local       = true
-  config.action_controller.perform_caching = false
+  # Show full error reports.
+  config.consider_all_requests_local = true
 
-  # Don't care if the mailer can't send
-  config.action_mailer.raise_delivery_errors = false
+  # Enable/disable caching. By default caching is disabled.
+  if Rails.root.join("tmp", "caching-dev.txt").exist?
+    config.action_controller.perform_caching = true
 
-  # Raise an error on page load if there are pending migrations
-  config.active_record.migration_error = :page_load
+    config.cache_store = :memory_store
+    config.public_file_server.headers = {
+      "Cache-Control" => "public, max-age=#{2.days.seconds.to_i}"
+    }
+  else
+    config.action_controller.perform_caching = false
 
-  # Print deprecation notices to the Rails logger
-  config.active_support.deprecation = :log
+    config.cache_store = :null_store
+  end
 
-  # Only use best-standards-support built into browsers
-  config.action_dispatch.best_standards_support = :builtin
+  # Don't care if the mailer can't send.
+  config.action_mailer.raise_delivery_errors = false
 
+  config.action_mailer.perform_caching = false
 
-  # Do not compress assets
-  config.assets.compress = false
+  # Print deprecation notices to the Rails logger.
+  config.active_support.deprecation = :log
 
-  # Expands the lines which load the assets
+  # Raise an error on page load if there are pending migrations.
+  config.active_record.migration_error = :page_load
+
+  # Debug mode disables concatenation and preprocessing of assets.
+  # This option may cause significant delays in view rendering with a large
+  # number of complex assets.
   config.assets.debug = true
 
-  # No assets request logging
+  # Suppress logger output for asset requests.
   config.assets.quiet = true
 
   # Set the logging destination(s)
@@ -41,6 +51,13 @@ Diaspora::Application.configure do
   # Show the logging configuration on STDOUT
   config.show_log_configuration = true
 
+  # Raises error for missing translations
+  # config.action_view.raise_on_missing_translations = true
+
+  # Use an evented file watcher to asynchronously detect changes in source code,
+  # routes, locales, etc. This feature depends on the listen gem.
+  config.file_watcher = ActiveSupport::EventedFileUpdateChecker
+
   # Speed up asset serving
   config.middleware.insert 0, TurboDevAssets
 end
diff --git a/config/environments/production.rb b/config/environments/production.rb
index a624236ab73c61469edba587f47b0706c13777fd..b6cdb8cab8bc154022cfe46cfba70f1de7d67e46 100644
--- a/config/environments/production.rb
+++ b/config/environments/production.rb
@@ -1,35 +1,51 @@
-Diaspora::Application.configure do
-  # Settings specified here will take precedence over those in config/application.rb
+Rails.application.configure do
+  # Settings specified here will take precedence over those in config/application.rb.
 
-  # Code is not reloaded between requests
+  # Code is not reloaded between requests.
   config.cache_classes = true
 
   # Eager load code on boot. This eager loads most of Rails and
-  # your application in memory, allowing both thread web servers
+  # your application in memory, allowing both threaded web servers
   # and those relying on copy on write to perform better.
   # Rake tasks automatically ignore this option for performance.
   config.eager_load = true
 
-  # Full error reports are disabled and caching is turned on
+  # Full error reports are disabled and caching is turned on.
   config.consider_all_requests_local       = false
   config.action_controller.perform_caching = true
 
-  # Disable Rails's static asset server (Apache or nginx will already do this)
-  config.serve_static_files = false
+  # Attempt to read encrypted secrets from `config/secrets.yml.enc`.
+  # Requires an encryption key in `ENV["RAILS_MASTER_KEY"]` or
+  # `config/secrets.yml.key`.
+  config.read_encrypted_secrets = true
+
+  # Disable serving static files from the `/public` folder by default since
+  # Apache or NGINX already handles this.
+  config.public_file_server.enabled = ENV["RAILS_SERVE_STATIC_FILES"].present?
 
   # Compress JavaScripts and CSS.
   config.assets.js_compressor = :uglifier
   # config.assets.css_compressor = :sass
 
-  # Don't fallback to assets pipeline if a precompiled asset is missed
+  # Do not fallback to assets pipeline if a precompiled asset is missed.
   config.assets.compile = false
 
-  # Generate digests for assets URLs
+  # Generate digests for assets URLs.
   config.assets.digest = true
 
-  # Specifies the header that your server uses for sending files
-  # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
-  # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
+  # Enable serving of images, stylesheets, and JavaScripts from an asset server.
+  if AppConfig.environment.assets.host.present?
+    config.action_controller.asset_host = AppConfig.environment.assets.host.get
+  end
+
+  # Specifies the header that your server uses for sending files.
+  # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
+  # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
+
+  # Mount Action Cable outside main process or domain
+  # config.action_cable.mount_path = nil
+  # config.action_cable.url = 'wss://example.com/cable'
+  # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ]
 
   # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
   # config.force_ssl = true
@@ -37,44 +53,44 @@ Diaspora::Application.configure do
   # Log level
   config.log_level = :info
 
+  # Prepend all log lines with the following tags.
+  # config.log_tags = [ :request_id ]
+
   # Set the logging destination(s)
   config.log_to = %w[file]
 
   # Show the logging configuration on STDOUT
   config.show_log_configuration = false
 
-  # Prepend all log lines with the following tags
-  # config.log_tags = [ :subdomain, :uuid ]
-
-  # Use a different logger for distributed setups
-  # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
-
-  # Use a different cache store in production
+  # Use a different cache store in production.
   # config.cache_store = :mem_cache_store
 
-  # Enable serving of images, stylesheets, and JavaScripts from an asset server
-  # config.action_controller.asset_host = "http://assets.example.com"
-
-  # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
-  # config.assets.precompile += %w( search.js )
+  config.action_mailer.perform_caching = false
 
-  # Disable delivery errors, bad email addresses will be ignored
+  # Ignore bad email addresses and do not raise email delivery errors.
+  # Set this to true and configure the email server for immediate delivery to raise delivery errors.
   # config.action_mailer.raise_delivery_errors = false
 
-  # Enable autoload for rake tasks
-  config.dependency_loading = true if $rails_rake_task
-
   # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
-  # the I18n.default_locale when a translation can not be found)
+  # the I18n.default_locale when a translation cannot be found).
   config.i18n.fallbacks = true
 
-  # Send deprecation notices to registered listeners
+  # Send deprecation notices to registered listeners.
   config.active_support.deprecation = :notify
 
-  # For nginx:
-  config.action_dispatch.x_sendfile_header = "X-Accel-Redirect"
+  # Use default logging formatter so that PID and timestamp are not suppressed.
+  # config.log_formatter = ::Logger::Formatter.new
 
-  if AppConfig.environment.assets.host.present?
-    config.action_controller.asset_host = AppConfig.environment.assets.host.get
-  end
+  # Use a different logger for distributed setups.
+  # require 'syslog/logger'
+  # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
+
+  # if ENV["RAILS_LOG_TO_STDOUT"].present?
+  #  logger           = ActiveSupport::Logger.new(STDOUT)
+  #  logger.formatter = config.log_formatter
+  #  config.logger    = ActiveSupport::TaggedLogging.new(logger)
+  # end
+
+  # Do not dump schema after migrations.
+  config.active_record.dump_schema_after_migration = false
 end
diff --git a/config/environments/test.rb b/config/environments/test.rb
index 7df9c1b93c6ab51f5c0a079cb0891b38f6fb508b..d9d87dbd0c0dc289a5640ec1944401a9b265f496 100644
--- a/config/environments/test.rb
+++ b/config/environments/test.rb
@@ -1,5 +1,5 @@
-Diaspora::Application.configure do
-  # Settings specified here will take precedence over those in config/application.rb
+Rails.application.configure do
+  # Settings specified here will take precedence over those in config/application.rb.
 
   # The test environment is used exclusively to run your application's
   # test suite. You never need to work with it otherwise. Remember that
@@ -12,11 +12,13 @@ Diaspora::Application.configure do
   # preloads Rails for running tests, you may have to set it to true.
   config.eager_load = false
 
-  # Configure static asset server for tests with Cache-Control for performance
-  config.serve_static_files = true
-  config.static_cache_control = "public, max-age=3600"
+  # Configure public file server for tests with Cache-Control for performance.
+  config.public_file_server.enabled = true
+  config.public_file_server.headers = {
+    "Cache-Control" => "public, max-age=#{1.hour.seconds.to_i}"
+  }
 
-  # No assets request logging
+  # Suppress logger output for asset requests.
   config.assets.quiet = true
 
   # Precompile poltergeist_disable_transition.css for tests
@@ -30,24 +32,28 @@ Diaspora::Application.configure do
     color_themes/original/mobile.css
   ]
 
-  # Show full error reports and disable caching
+  # Show full error reports and disable caching.
   config.consider_all_requests_local       = true
   config.action_controller.perform_caching = false
 
-  # Raise exceptions instead of rendering exception templates
-  config.action_dispatch.show_exceptions = true
+  # Raise exceptions instead of rendering exception templates.
+  config.action_dispatch.show_exceptions = false
 
-  # Disable request forgery protection in test environment
-  config.action_controller.allow_forgery_protection    = false
+  # Disable request forgery protection in test environment.
+  config.action_controller.allow_forgery_protection = false
+  config.action_mailer.perform_caching = false
 
   # Tell Action Mailer not to deliver emails to the real world.
   # The :test delivery method accumulates sent emails in the
   # ActionMailer::Base.deliveries array.
   config.action_mailer.delivery_method = :test
 
-  # Print deprecation notices to the stderr
+  # Print deprecation notices to the stderr.
   config.active_support.deprecation = :stderr
 
   # Set the logging destination(s)
   config.log_to = %w[file]
+
+  # Raises error for missing translations
+  # config.action_view.raise_on_missing_translations = true
 end
diff --git a/config/initializers/application_controller_renderer.rb b/config/initializers/application_controller_renderer.rb
new file mode 100644
index 0000000000000000000000000000000000000000..51639b67a00ddba973a92d59ec277f5d97b63ef6
--- /dev/null
+++ b/config/initializers/application_controller_renderer.rb
@@ -0,0 +1,6 @@
+# Be sure to restart your server when you modify this file.
+
+# ApplicationController.renderer.defaults.merge!(
+#   http_host: 'example.org',
+#   https: false
+# )
diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb
index 686871f66f01f75d7f28a32f1208d6fc4497de26..b8d5fb65fcdeffebec2d2dd807444b804bf2300e 100644
--- a/config/initializers/assets.rb
+++ b/config/initializers/assets.rb
@@ -1,6 +1,4 @@
-#   Copyright (c) 2010-2011, Diaspora Inc.  This file is
-#   licensed under the Affero General Public License version 3 or later.  See
-#   the COPYRIGHT file.
+# Be sure to restart your server when you modify this file.
 
 # bootstrap-markdown plugin relies on rails-assets-bootstrap gem but we use
 # bootstrap-sass this line makes sure we exclude every asset comming
@@ -9,7 +7,12 @@ Rails.configuration.assets.paths.reject! do |path|
   path.include?("rails-assets-bootstrap") && !path.include?("rails-assets-bootstrap-markdown")
 end
 
-Diaspora::Application.configure do
-  config.serve_static_files = AppConfig.environment.assets.serve?
-  # config.static_cache_control = "public, max-age=3600" if AppConfig[:serve_static_assets].to_s == 'true'
-end
+# Version of your assets, change this if you want to expire all your assets.
+Rails.application.config.assets.version = "1.0"
+
+# Add additional assets to the asset load path.
+# Rails.application.config.assets.paths << Emoji.images_path
+# Add Yarn node_modules folder to the asset load path.
+# Rails.application.config.assets.paths << Rails.root.join("node_modules")
+
+Rails.application.config.public_file_server.enabled = AppConfig.environment.assets.serve?
diff --git a/config/initializers/backtrace_silencers.rb b/config/initializers/backtrace_silencers.rb
new file mode 100644
index 0000000000000000000000000000000000000000..59385cdf379bd06a8d2326dcd4de6d5cd5d3f5b0
--- /dev/null
+++ b/config/initializers/backtrace_silencers.rb
@@ -0,0 +1,7 @@
+# Be sure to restart your server when you modify this file.
+
+# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
+# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
+
+# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
+# Rails.backtrace_cleaner.remove_silencers!
diff --git a/config/initializers/cookies_serializer.rb b/config/initializers/cookies_serializer.rb
new file mode 100644
index 0000000000000000000000000000000000000000..1389e86a34a7e992b8761b4b2b9b789b5647a406
--- /dev/null
+++ b/config/initializers/cookies_serializer.rb
@@ -0,0 +1,5 @@
+# Be sure to restart your server when you modify this file.
+
+# Specify a serializer for the signed and encrypted cookie jars.
+# Valid options are :json, :marshal, and :hybrid.
+Rails.application.config.action_dispatch.cookies_serializer = :marshal
diff --git a/config/initializers/cors.rb b/config/initializers/cors.rb
index a50aead3e98605d604fea252cde6825c78bf567b..0fccba3fe5c1dac76e5c5bd1fd86b6bd46b27a40 100644
--- a/config/initializers/cors.rb
+++ b/config/initializers/cors.rb
@@ -1,4 +1,11 @@
-Rails.application.config.middleware.insert 0, Rack::Cors do
+# Be sure to restart your server when you modify this file.
+
+# Avoid CORS issues when API is called from the frontend app.
+# Handle Cross-Origin Resource Sharing (CORS) in order to accept cross-origin AJAX requests.
+
+# Read more: https://github.com/cyu/rack-cors
+
+Rails.application.config.middleware.insert_before 0, Rack::Cors do
   allow do
     origins "*"
     resource "/api/openid_connect/user_info", methods: %i(get post)
@@ -6,6 +13,5 @@ Rails.application.config.middleware.insert 0, Rack::Cors do
     resource "/.well-known/host-meta"
     resource "/.well-known/webfinger"
     resource "/.well-known/openid-configuration"
-    resource "/webfinger"
   end
 end
diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb
index d0825039061c7c793bb2df210bf08d5c85649bb3..9d07a384fd08de6e2204ad30a09f44d562c46897 100644
--- a/config/initializers/filter_parameter_logging.rb
+++ b/config/initializers/filter_parameter_logging.rb
@@ -1,4 +1,4 @@
 # Be sure to restart your server when you modify this file.
 
 # Configure sensitive parameters which will be filtered from the log file.
-Rails.application.config.filter_parameters += %i(password message text bio)
+Rails.application.config.filter_parameters += %i[password message text bio]
diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb
new file mode 100644
index 0000000000000000000000000000000000000000..ac033bf9dc846101320c96a5ce8aceb8c96ec098
--- /dev/null
+++ b/config/initializers/inflections.rb
@@ -0,0 +1,16 @@
+# Be sure to restart your server when you modify this file.
+
+# Add new inflection rules using the following format. Inflections
+# are locale specific, and you may define rules for as many different
+# locales as you wish. All of these examples are active by default:
+# ActiveSupport::Inflector.inflections(:en) do |inflect|
+#   inflect.plural /^(ox)$/i, '\1en'
+#   inflect.singular /^(ox)en/i, '\1'
+#   inflect.irregular 'person', 'people'
+#   inflect.uncountable %w( fish sheep )
+# end
+
+# These inflection rules are supported but not enabled by default:
+# ActiveSupport::Inflector.inflections(:en) do |inflect|
+#   inflect.acronym 'RESTful'
+# end
diff --git a/config/initializers/mime_types.rb b/config/initializers/mime_types.rb
new file mode 100644
index 0000000000000000000000000000000000000000..dc1899682b01c3a6d9673faf746e235fb64fc4d2
--- /dev/null
+++ b/config/initializers/mime_types.rb
@@ -0,0 +1,4 @@
+# Be sure to restart your server when you modify this file.
+
+# Add new mime types for use in respond_to blocks:
+# Mime::Type.register "text/richtext", :rtf
diff --git a/config/initializers/wrap_parameters.rb b/config/initializers/wrap_parameters.rb
index ddd9dd5abf7ff77d2506a26ca2974184a3d6698e..c72a9676534cbd5292d9fcac1a0ae4b5b27e24d6 100644
--- a/config/initializers/wrap_parameters.rb
+++ b/config/initializers/wrap_parameters.rb
@@ -5,10 +5,10 @@
 
 # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
 ActiveSupport.on_load(:action_controller) do
-  wrap_parameters format: [:json] if respond_to?(:wrap_parameters)
+  wrap_parameters format: [:json]
 end
 
 # To enable root element in JSON for ActiveRecord objects.
 ActiveSupport.on_load(:active_record) do
- self.include_root_in_json = true
+  self.include_root_in_json = true
 end
diff --git a/config/routes.rb b/config/routes.rb
index 355154a6f21e1a74cbbf6f10bd2e7fdf395825e8..b7d4c69ab8d746e7e92d7e9eff6279e0ab559bdd 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -6,7 +6,8 @@ require "sidekiq/web"
 require "sidekiq/cron/web"
 Sidekiq::Web.set :sessions, false # disable rack session cookie
 
-Diaspora::Application.routes.draw do
+Rails.application.routes.draw do
+  # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
 
   resources :report, except: %i(edit new show)
 
diff --git a/config/spring.rb b/config/spring.rb
new file mode 100644
index 0000000000000000000000000000000000000000..0598e88c309d7fac1aaed6d8fa40c702df49b31d
--- /dev/null
+++ b/config/spring.rb
@@ -0,0 +1,6 @@
+%w[
+  .ruby-version
+  .rbenv-vars
+  tmp/restart.txt
+  tmp/caching-dev.txt
+].each {|path| Spring.watch(path) }