architecture

ruby
class UserRegistrationService
  class Result
    attr_reader :user, :errors

    def initialize(success:, user: nil, errors: [])
      @success = success

Service objects for business logic encapsulation

ruby rails service-objects
by Sarah Mitchell 2 tabs
typescript
import { ReactNode } from 'react'

interface CardProps {
  children: ReactNode
  className?: string
}

React component composition over inheritance

react patterns composition
by Maya Patel 2 tabs
javascript
import { Controller } from "@hotwired/stimulus"

export default class extends Controller {
  static targets = ["input", "results"]
  static outlets = ["results-list"]
  static values = {

Stimulus outlets for inter-controller communication

stimulus javascript architecture
by Jordan Lee 3 tabs
python
INSTALLED_APPS += ['tenant_schemas']

DATABASE_ROUTERS = ['tenant_schemas.routers.TenantSyncRouter']

MIDDLEWARE = [
    'tenant_schemas.middleware.TenantMiddleware',

Django multi-tenancy with django-tenant-schemas

django python multitenancy
by Priya Sharma 2 tabs
swift
import SwiftUI

struct PostDetailView: View {
    @StateObject private var viewModel: PostDetailViewModel

    init(postId: Int) {

MVVM architecture pattern for iOS

swift mvvm architecture
by Sofia Martinez 2 tabs
ruby
class CreatePostService
  def initialize(author:, params:)
    @author = author
    @params = params
  end

Service objects for complex business logic

rails architecture patterns
by Alex Kumar 1 tab
ruby
class ApplicationCommand
  Result = Struct.new(:value, :errors) do
    def success?
      errors.nil? || errors.empty?
    end

Keep Controllers Thin: Use Command Objects

rails architecture command-object
by codesnips 3 tabs
swift
import UIKit

protocol Coordinator: AnyObject {
    var navigationController: UINavigationController { get set }
    var childCoordinators: [Coordinator] { get set }

Coordinator pattern for navigation flow

swift architecture coordinator
by Sofia Martinez 3 tabs
python
from dataclasses import dataclass, field
from datetime import datetime, timezone
from decimal import Decimal


def _now():

Synchronous Domain Event Bus with a Registry-Based Publisher in Python

domain-events event-bus pubsub
by codesnips 3 tabs
ruby
module DomainEvents
  class Registry
    def initialize
      @subscribers = Hash.new { |h, k| h[k] = [] }
    end

Avoid Callback Chains: Use Domain Events (In-App)

rails architecture domain-events
by codesnips 4 tabs
kotlin
package com.example.myapp.ui.detail

import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel

MVVM architecture with ViewModel and LiveData

kotlin android mvvm
by Alex Chen 1 tab
ruby
class ButtonComponent < ViewComponent::Base
  VARIANTS = {
    primary: "bg-blue-600 hover:bg-blue-700 text-white",
    secondary: "bg-gray-200 hover:bg-gray-300 text-gray-900",
    danger: "bg-red-600 hover:bg-red-700 text-white"
  }.freeze

ViewComponent for reusable UI components

rails viewcomponent components
by Jordan Lee 3 tabs