# ASA Architecture Spec v0.1
# This file declares the desired architecture state for your project.
# Edit this file to match your project's actual configuration.
#
# Docs: https://github.com/janvoldan/asa-standard

asa:
  spec_version: "0.1"

app:
  name: "{{ app_name }}"
  mode: "{{ app_mode }}"
  framework: "{{ framework }}"
  runtime: "{{ runtime }}"

providers:
  auth: "{{ auth_provider }}"
  database: "{{ db_provider }}"
{% if billing_provider %}
  billing: "{{ billing_provider }}"
{% endif %}

tenancy:
  principal: "{{ tenancy_principal }}"
  tenant_key: "{{ tenant_key }}"

domains:
  foundation:
{% for domain in foundation_domains %}
    - "{{ domain }}"
{% endfor %}
  business: []
  # Add your business domains here, e.g.:
  # - "invoices"
  # - "projects"

rules:
  no_auth_in_ui: true
  no_stripe_outside_billing: true
  no_direct_db_from_ui: true
  no_supabase_admin_outside_server: true
  all_protected_routes_require_guard: true
  all_billing_state_changes_require_webhook_or_domain_service: true

auth:
  session_source: "{{ auth_provider }}"
  user_entity: "profiles"
  guard_api:
    - "requireUser"
    - "requireRole"

{% if billing_provider %}
billing:
  provider: "{{ billing_provider }}"
  webhook_source_of_truth: true
  plans:
    - key: "free"
    - key: "pro"

entitlements:
  source_of_truth: "database"
  features: []
  limits: []
  # Add your features and limits here, e.g.:
  # features:
  #   - key: "csv_export"
  #     type: "boolean"
  #     default: false
  # limits:
  #   - key: "max_invoices_per_month"
  #     type: "number"
  #     default: 5
  guard_api:
    - "requireEntitlement"
    - "requireLimit"
{% endif %}

data_access:
  rls_required: true
  ownership_model: "user-scoped"
  forbidden_imports:
    - "@supabase/supabase-js in ui"
    - "stripe in ui"

{% if app_mode == "upgrade" %}
bridge:
  legacy_patterns: []
  # Add legacy patterns to replace, e.g.:
  # - find: "user.plan === 'pro'"
  #   replace_with: "requireEntitlement('csv_export')"
{% endif %}

verification:
  block_on:
    - "auth-in-ui"
    - "stripe-outside-billing"
    - "direct-db-from-ui"
    - "inline-plan-check"
