saas_platform 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +143 -0
  4. data/Rakefile +14 -0
  5. data/app/assets/stylesheets/saas_platform/application.css +15 -0
  6. data/app/assets/stylesheets/saas_platform/application.tailwind.css +25 -0
  7. data/app/components/saas_platform/button_component.rb +46 -0
  8. data/app/components/saas_platform/card_component.html.erb +3 -0
  9. data/app/components/saas_platform/card_component.rb +29 -0
  10. data/app/components/saas_platform/notification_component.html.erb +27 -0
  11. data/app/components/saas_platform/notification_component.rb +11 -0
  12. data/app/components/saas_platform/order_list_component.html.erb +28 -0
  13. data/app/components/saas_platform/order_list_component.rb +18 -0
  14. data/app/controllers/saas_platform/application_controller.rb +31 -0
  15. data/app/controllers/saas_platform/audit_logs_controller.rb +22 -0
  16. data/app/controllers/saas_platform/dashboard_controller.rb +14 -0
  17. data/app/controllers/saas_platform/devise/confirmations_controller.rb +7 -0
  18. data/app/controllers/saas_platform/devise/passwords_controller.rb +7 -0
  19. data/app/controllers/saas_platform/devise/registrations_controller.rb +7 -0
  20. data/app/controllers/saas_platform/devise/sessions_controller.rb +7 -0
  21. data/app/controllers/saas_platform/devise/unlocks_controller.rb +7 -0
  22. data/app/controllers/saas_platform/search_controller.rb +15 -0
  23. data/app/helpers/saas_platform/application_helper.rb +4 -0
  24. data/app/jobs/saas_platform/application_job.rb +4 -0
  25. data/app/mailers/saas_platform/application_mailer.rb +6 -0
  26. data/app/models/saas_platform/account.rb +36 -0
  27. data/app/models/saas_platform/api_key.rb +24 -0
  28. data/app/models/saas_platform/application_record.rb +5 -0
  29. data/app/models/saas_platform/notification.rb +19 -0
  30. data/app/models/saas_platform/order.rb +43 -0
  31. data/app/models/saas_platform/order_item.rb +18 -0
  32. data/app/models/saas_platform/product.rb +15 -0
  33. data/app/models/saas_platform/role.rb +15 -0
  34. data/app/models/saas_platform/transaction.rb +15 -0
  35. data/app/models/saas_platform/user.rb +52 -0
  36. data/app/models/saas_platform/wallet.rb +38 -0
  37. data/app/models/saas_platform/webhook_endpoint.rb +18 -0
  38. data/app/models/saas_platform/webhook_event.rb +10 -0
  39. data/app/policies/saas_platform/application_policy.rb +53 -0
  40. data/app/services/saas_platform/analytics_service.rb +29 -0
  41. data/app/services/saas_platform/payment_service.rb +32 -0
  42. data/app/services/saas_platform/plan_service.rb +45 -0
  43. data/app/services/saas_platform/search_service.rb +20 -0
  44. data/app/views/devise/registrations/new.html.erb +59 -0
  45. data/app/views/devise/saas_platform_users/confirmations/new.html.erb +16 -0
  46. data/app/views/devise/saas_platform_users/mailer/confirmation_instructions.html.erb +5 -0
  47. data/app/views/devise/saas_platform_users/mailer/email_changed.html.erb +7 -0
  48. data/app/views/devise/saas_platform_users/mailer/password_change.html.erb +3 -0
  49. data/app/views/devise/saas_platform_users/mailer/reset_password_instructions.html.erb +8 -0
  50. data/app/views/devise/saas_platform_users/mailer/unlock_instructions.html.erb +7 -0
  51. data/app/views/devise/saas_platform_users/passwords/edit.html.erb +25 -0
  52. data/app/views/devise/saas_platform_users/passwords/new.html.erb +16 -0
  53. data/app/views/devise/saas_platform_users/registrations/edit.html.erb +43 -0
  54. data/app/views/devise/saas_platform_users/registrations/new.html.erb +29 -0
  55. data/app/views/devise/saas_platform_users/sessions/new.html.erb +26 -0
  56. data/app/views/devise/saas_platform_users/shared/_error_messages.html.erb +15 -0
  57. data/app/views/devise/saas_platform_users/shared/_links.html.erb +25 -0
  58. data/app/views/devise/saas_platform_users/unlocks/new.html.erb +16 -0
  59. data/app/views/devise/sessions/new.html.erb +47 -0
  60. data/app/views/layouts/saas_platform/application.html.erb +17 -0
  61. data/app/views/layouts/saas_platform/auth.html.erb +48 -0
  62. data/app/views/layouts/saas_platform/dashboard.html.erb +76 -0
  63. data/app/views/saas_platform/audit_logs/index.html.erb +43 -0
  64. data/app/views/saas_platform/dashboard/index.html.erb +50 -0
  65. data/app/views/saas_platform/search/index.html.erb +75 -0
  66. data/config/initializers/devise.rb +313 -0
  67. data/config/initializers/money.rb +115 -0
  68. data/config/initializers/rack_attack.rb +27 -0
  69. data/config/locales/devise.en.yml +65 -0
  70. data/config/routes.rb +16 -0
  71. data/config/tailwind.config.js +45 -0
  72. data/db/migrate/20260603000000_devise_create_saas_platform_users.rb +53 -0
  73. data/db/migrate/20260603000001_rolify_create_saas_platform_roles.rb +19 -0
  74. data/db/migrate/20260603000002_create_saas_platform_accounts.rb +20 -0
  75. data/db/migrate/20260603000003_create_saas_platform_banking.rb +28 -0
  76. data/db/migrate/20260603000004_create_saas_platform_ecommerce.rb +37 -0
  77. data/db/migrate/20260603000005_create_versions.rb +14 -0
  78. data/db/migrate/20260603000006_create_saas_platform_api_keys.rb +17 -0
  79. data/db/migrate/20260603000007_create_saas_platform_webhooks.rb +25 -0
  80. data/db/migrate/20260603000008_create_saas_platform_notifications.rb +14 -0
  81. data/db/migrate/20260603000009_add_subscription_to_saas_platform_accounts.rb +12 -0
  82. data/lib/saas_platform/engine.rb +5 -0
  83. data/lib/saas_platform/version.rb +3 -0
  84. data/lib/saas_platform.rb +27 -0
  85. data/lib/tasks/saas_platform_tasks.rake +4 -0
  86. metadata +562 -0
@@ -0,0 +1,28 @@
1
+ class CreateSaasPlatformBanking < ActiveRecord::Migration[8.0]
2
+ def change
3
+ create_table :saas_platform_wallets do |t|
4
+ t.references :account, null: false, index: { name: 'idx_sp_wallets_on_account_id' }
5
+ t.integer :balance_cents, default: 0, null: false
6
+ t.string :currency, default: 'USD', null: false
7
+ t.string :status, default: 'active'
8
+
9
+ t.timestamps
10
+ end
11
+
12
+ create_table :saas_platform_transactions do |t|
13
+ t.references :wallet, null: false, index: { name: 'idx_sp_transactions_on_wallet_id' }
14
+ t.integer :amount_cents, null: false
15
+ t.string :currency, default: 'USD', null: false
16
+ t.string :transaction_type, null: false # credit, debit
17
+ t.string :category # subscription, payout, refund, sale
18
+ t.string :status, default: 'pending'
19
+ t.string :reference_type
20
+ t.bigint :reference_id
21
+ t.jsonb :metadata, default: {}
22
+
23
+ t.timestamps
24
+ end
25
+
26
+ add_index :saas_platform_transactions, [:reference_type, :reference_id], name: 'idx_sp_transactions_on_reference'
27
+ end
28
+ end
@@ -0,0 +1,37 @@
1
+ class CreateSaasPlatformEcommerce < ActiveRecord::Migration[8.0]
2
+ def change
3
+ create_table :saas_platform_products do |t|
4
+ t.references :account, null: false, index: { name: 'idx_sp_products_on_account_id' }
5
+ t.string :name, null: false
6
+ t.text :description
7
+ t.integer :price_cents, default: 0, null: false
8
+ t.string :currency, default: 'USD', null: false
9
+ t.string :status, default: 'active'
10
+ t.integer :stock_quantity, default: 0
11
+
12
+ t.timestamps
13
+ end
14
+
15
+ create_table :saas_platform_orders do |t|
16
+ t.references :account, null: false, index: { name: 'idx_sp_orders_on_account_id' }
17
+ t.references :user, null: false, index: { name: 'idx_sp_orders_on_user_id' }
18
+ t.integer :total_cents, default: 0, null: false
19
+ t.string :currency, default: 'USD', null: false
20
+ t.string :status, default: 'pending'
21
+ t.string :payment_status, default: 'unpaid'
22
+ t.string :stripe_checkout_id
23
+
24
+ t.timestamps
25
+ end
26
+
27
+ create_table :saas_platform_order_items do |t|
28
+ t.references :order, null: false, index: { name: 'idx_sp_order_items_on_order_id' }
29
+ t.references :product, null: false, index: { name: 'idx_sp_order_items_on_product_id' }
30
+ t.integer :quantity, default: 1, null: false
31
+ t.integer :unit_price_cents, null: false
32
+ t.string :currency, default: 'USD', null: false
33
+
34
+ t.timestamps
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,14 @@
1
+ class CreateVersions < ActiveRecord::Migration[8.0]
2
+ def change
3
+ create_table :versions do |t|
4
+ t.string :item_type, null: false
5
+ t.bigint :item_id, null: false
6
+ t.string :event, null: false
7
+ t.string :whodunnit
8
+ t.text :object
9
+ t.text :object_changes
10
+ t.datetime :created_at
11
+ end
12
+ add_index :versions, [:item_type, :item_id]
13
+ end
14
+ end
@@ -0,0 +1,17 @@
1
+ class CreateSaasPlatformApiKeys < ActiveRecord::Migration[8.0]
2
+ def change
3
+ create_table :saas_platform_api_keys do |t|
4
+ t.references :account, null: false, index: { name: 'idx_sp_api_keys_on_account_id' }
5
+ t.references :user, null: false, index: { name: 'idx_sp_api_keys_on_user_id' }
6
+ t.string :access_token, null: false
7
+ t.string :name
8
+ t.datetime :last_used_at
9
+ t.datetime :expires_at
10
+ t.boolean :active, default: true
11
+
12
+ t.timestamps
13
+ end
14
+
15
+ add_index :saas_platform_api_keys, :access_token, unique: true
16
+ end
17
+ end
@@ -0,0 +1,25 @@
1
+ class CreateSaasPlatformWebhooks < ActiveRecord::Migration[8.0]
2
+ def change
3
+ create_table :saas_platform_webhook_endpoints do |t|
4
+ t.references :account, null: false, index: { name: 'idx_sp_webhook_endpoints_on_account_id' }
5
+ t.string :url, null: false
6
+ t.string :secret, null: false
7
+ t.jsonb :events, default: ["*"]
8
+ t.boolean :active, default: true
9
+
10
+ t.timestamps
11
+ end
12
+
13
+ create_table :saas_platform_webhook_events do |t|
14
+ t.references :account, null: false, index: { name: 'idx_sp_webhook_events_on_account_id' }
15
+ t.references :webhook_endpoint, null: false, index: { name: 'idx_sp_webhook_events_on_endpoint_id' }
16
+ t.string :event_type, null: false
17
+ t.jsonb :payload, default: {}
18
+ t.integer :response_code
19
+ t.text :response_body
20
+ t.datetime :processed_at
21
+
22
+ t.timestamps
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,14 @@
1
+ class CreateSaasPlatformNotifications < ActiveRecord::Migration[8.0]
2
+ def change
3
+ create_table :saas_platform_notifications do |t|
4
+ t.references :account, null: false, index: { name: 'idx_sp_notifications_on_account_id' }
5
+ t.references :recipient, polymorphic: true, null: false, index: { name: 'idx_sp_notifications_on_recipient' }
6
+ t.string :type, null: false
7
+ t.jsonb :params
8
+ t.datetime :read_at
9
+
10
+ t.timestamps
11
+ end
12
+ add_index :saas_platform_notifications, :read_at
13
+ end
14
+ end
@@ -0,0 +1,12 @@
1
+ class AddSubscriptionToSaasPlatformAccounts < ActiveRecord::Migration[8.0]
2
+ def change
3
+ add_column :saas_platform_accounts, :plan_name, :string, default: 'free'
4
+ add_column :saas_platform_accounts, :subscription_status, :string, default: 'trialing'
5
+ add_column :saas_platform_accounts, :trial_ends_at, :datetime
6
+ add_column :saas_platform_accounts, :stripe_customer_id, :string
7
+ add_column :saas_platform_accounts, :stripe_subscription_id, :string
8
+
9
+ add_index :saas_platform_accounts, :stripe_customer_id, unique: true
10
+ add_index :saas_platform_accounts, :stripe_subscription_id, unique: true
11
+ end
12
+ end
@@ -0,0 +1,5 @@
1
+ module SaasPlatform
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace SaasPlatform
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module SaasPlatform
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,27 @@
1
+ require "saas_platform/version"
2
+ require "saas_platform/engine"
3
+
4
+ require "devise"
5
+ require "devise-two-factor"
6
+ require "pundit"
7
+ require "rolify"
8
+ require "money-rails"
9
+ require "acts_as_tenant"
10
+ require "aasm"
11
+ require "groupdate"
12
+ require "chartkick"
13
+ require "sidekiq"
14
+ require "pg_search"
15
+ require "paper_trail"
16
+ require "pagy"
17
+ require "noticed"
18
+ require "view_component"
19
+ require "tailwindcss-rails"
20
+ require "turbo-rails"
21
+ require "stimulus-rails"
22
+ require "rack/attack"
23
+ require "secure_headers"
24
+
25
+ module SaasPlatform
26
+ # Your code goes here...
27
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :saas_platform do
3
+ # # Task goes here
4
+ # end