// docs/architecture/sruja-development-workflow.sruja
// Development, validation, release, and deployment workflow for the current repo

person = kind "Person"
system = kind "System"
container = kind "Container"
component = kind "Component"

Contributor = person "Contributor" {
  description "Builds features, updates docs, and validates architecture changes locally"
}

Maintainer = person "Maintainer" {
  description "Owns releases, extension publishing, and production deployments"
}

GitHub = system "GitHub" {
  description "Hosts source control, pull requests, releases, and workflow triggers"
}

OpenVSX = system "Open VSX Registry" {
  description "Primary public registry for the Sruja VS Code extension"
}

VSCodeMarketplace = system "VS Code Marketplace" {
  description "Optional distribution channel for the Sruja VS Code extension"
}

StagingWebsite = system "Staging Website" {
  description "Staging deployment target for the mdBook site and bundled WASM assets"
}

ProductionWebsite = system "Production Website" {
  description "Production deployment target for the mdBook site served at sruja.ai"
}

SrujaDevelopment = system "Sruja Development Workflow" {
  description "How contributors build, validate, release, and deploy Sruja today"

  LocalDevelopment = container "Local Development" {
    technology "cargo, npm, Makefile, mdBook"
    description "Local workflow for code changes, docs updates, and validation"

    RustToolchain = component "Rust Toolchain" {
      description "Runs cargo build, cargo test, cargo fmt, and cargo clippy across the Rust workspace"
    }

    ExtensionToolchain = component "Extension Toolchain" {
      description "Compiles the VS Code extension, runs Jest and VS Code tests, and packages VSIX artifacts"
    }

    BookAndWasm = component "Book and WASM Toolchain" {
      description "Builds mdBook content, copies WASM assets, and serves the docs site locally"
    }

    SmokeChecks = component "CLI and Example Smoke Checks" {
      description "Runs smoke checks for documented commands, examples, and architecture files before review"
    }
  }

  ContinuousIntegration = container "Continuous Integration" {
    technology "GitHub Actions, cargo, wasm-pack, sruja-cli"
    description "Automated validation that protects branches and release candidates"

    RustCI = component "Rust CI" {
      description "Runs cargo build, cargo test, cargo fmt --check, and cargo clippy in CI"
    }

    WasmCI = component "WASM CI" {
      description "Runs wasm-pack tests for the Node target used by docs and extension flows"
    }

    ArchitectureCI = component "Architecture CI" {
      description "Lints all .sruja files and validates architecture docs against language rules"
    }

    SkillCI = component "Skill CI" {
      description "Validates skill markdown, links, cross-references, and example snippets"
    }

    SecurityCI = component "Security CI" {
      description "Runs cargo audit, dependency review, and secret scanning workflows"
    }

    VersionConsistency = component "Version Consistency" {
      description "Checks Cargo workspace, extension package files, and release metadata stay aligned"
    }
  }

  ReleaseAutomation = container "Release Automation" {
    technology "GitHub Actions, release-please, cargo, npm"
    description "Automated release and deployment flows for the CLI, extension, and docs site"

    ReleasePlease = component "Release Please" {
      description "Creates release PRs and changelog updates from conventional commits"
    }

    CLIRelease = component "CLI Release" {
      description "Builds cross-platform CLI archives and attaches them to GitHub Releases"
    }

    ExtensionRelease = component "Extension Release" {
      description "Builds and publishes the VS Code extension to Open VSX and optionally Visual Studio Marketplace"
    }

    StagingDeploy = component "Staging Deploy" {
      description "Builds mdBook plus WASM assets and deploys the site to the staging website"
    }

    ProductionDeploy = component "Production Deploy" {
      description "Promotes the mdBook site from main to the production website"
    }
  }
}

SrujaDevelopment.LocalDevelopment -> SrujaDevelopment.ContinuousIntegration "Local validation mirrors CI"
SrujaDevelopment.ContinuousIntegration -> SrujaDevelopment.ReleaseAutomation "Validated changes can ship"

SrujaDevelopment.LocalDevelopment.RustToolchain -> SrujaDevelopment.LocalDevelopment.ExtensionToolchain "Provides CLI and WASM artifacts"
SrujaDevelopment.LocalDevelopment.RustToolchain -> SrujaDevelopment.LocalDevelopment.BookAndWasm "Builds shared Rust and WASM outputs"
SrujaDevelopment.LocalDevelopment.ExtensionToolchain -> SrujaDevelopment.ReleaseAutomation.ExtensionRelease "Mirrors release packaging"
SrujaDevelopment.LocalDevelopment.BookAndWasm -> SrujaDevelopment.ReleaseAutomation.StagingDeploy "Mirrors deploy build"
SrujaDevelopment.LocalDevelopment.SmokeChecks -> SrujaDevelopment.ContinuousIntegration.ArchitectureCI "Exercises documented command flows"

Contributor -> SrujaDevelopment.LocalDevelopment.RustToolchain "Runs locally"
Contributor -> SrujaDevelopment.LocalDevelopment.ExtensionToolchain "Runs locally"
Contributor -> SrujaDevelopment.LocalDevelopment.BookAndWasm "Runs locally"
Contributor -> SrujaDevelopment.LocalDevelopment.SmokeChecks "Runs locally"
Contributor -> SrujaDevelopment "Contributes through this workflow"
Contributor -> GitHub "Pushes branches and opens pull requests"

GitHub -> SrujaDevelopment.ContinuousIntegration.RustCI "Triggers on push and pull request"
GitHub -> SrujaDevelopment.ContinuousIntegration.WasmCI "Triggers on push and pull request"
GitHub -> SrujaDevelopment.ContinuousIntegration.ArchitectureCI "Triggers on push and pull request"
GitHub -> SrujaDevelopment.ContinuousIntegration.SkillCI "Triggers on push and pull request"
GitHub -> SrujaDevelopment.ContinuousIntegration.SecurityCI "Triggers on push, pull request, and schedule"
GitHub -> SrujaDevelopment.ContinuousIntegration.VersionConsistency "Triggers on push and pull request"

SrujaDevelopment.ContinuousIntegration.WasmCI -> SrujaDevelopment.ReleaseAutomation.StagingDeploy "Verifies docs and extension WASM"

GitHub -> SrujaDevelopment.ReleaseAutomation.ReleasePlease "Triggers on main commits"
SrujaDevelopment.ReleaseAutomation.CLIRelease -> GitHub "Attaches CLI binaries to releases"
SrujaDevelopment.ReleaseAutomation.ExtensionRelease -> OpenVSX "Publishes extension"
SrujaDevelopment.ReleaseAutomation.ExtensionRelease -> VSCodeMarketplace "Publishes extension"
SrujaDevelopment.ReleaseAutomation.StagingDeploy -> StagingWebsite "Deploys mdBook site"
SrujaDevelopment.ReleaseAutomation.ProductionDeploy -> ProductionWebsite "Deploys mdBook site"

Maintainer -> SrujaDevelopment.ReleaseAutomation.ReleasePlease "Reviews and merges release PRs"
Maintainer -> SrujaDevelopment.ReleaseAutomation.CLIRelease "Oversees release assets"
Maintainer -> SrujaDevelopment.ReleaseAutomation.ExtensionRelease "Oversees extension publishing"
Maintainer -> SrujaDevelopment.ReleaseAutomation.StagingDeploy "Checks staging"
Maintainer -> SrujaDevelopment.ReleaseAutomation.ProductionDeploy "Promotes production"
Maintainer -> SrujaDevelopment "Operates this workflow"

view index {
  title "Development Workflow"
  include *
}

view ci {
  title "Continuous Integration"
  include "Contributor GitHub SrujaDevelopment.ContinuousIntegration SrujaDevelopment.ReleaseAutomation.ReleasePlease"
}

view release {
  title "Release and Deployment"
  include "Maintainer GitHub OpenVSX VSCodeMarketplace StagingWebsite ProductionWebsite SrujaDevelopment.ReleaseAutomation"
}
