@startuml
!define RECTANGLE rectangle
!define COMPONENT component

skinparam component {
  BackgroundColor<<External>> #E6F3FF
  BackgroundColor<<Internal>> #F0F0F0
  BackgroundColor<<User>> #E8F5E8
  BorderColor #333333
  ArrowColor #333333
  FontSize 12
}

title SmartTools Registry Architecture

package "Users" <<User>> {
  actor "CLI User" as cli_user
  actor "Web User" as web_user
}

package "Client Interfaces" <<User>> {
  component "smarttools CLI" as cli
  note right of cli
    • registry search
    • registry install
    • registry publish
    • registry browse (TUI)
  end note
  
  component "Web UI (future)" as web_ui
  note right of web_ui
    • Browse tools
    • Search
    • View tool details
  end note
}

component "REGISTRY API SERVER" as api_server <<Internal>> {
  rectangle "Flask/FastAPI" as server
  note right of server
    Hosted at: registry.smarttools.dev
    (or gitea.brrd.tech/api/registry)
  end note
  
  rectangle "Endpoints" as endpoints
  endpoints : GET  /tools                    // list all tools
  endpoints : GET  /tools/search?q=...       // search tools
  endpoints : GET  /tools/{name}             // get tool details
  endpoints : GET  /tools/{name}/download    // download tool config
  endpoints : POST /tools                    // submit new tool (creates PR)
  endpoints : GET  /categories               // list categories
  endpoints : GET  /stats                    // download counts, popular tools
  
  rectangle "Internal" as internal
  internal : POST /webhook/gitea    // receives push/merge events
  internal : Sync job               // pulls repo, updates DB
}

component "SQLite Database" as database <<Internal>> {
  rectangle "Database Schema" as db_schema
  db_schema : tools table
  db_schema : categories
  db_schema : download_stats
  db_schema : search_index
}

component "Gitea Repository" as gitea_repo <<External>> {
  rectangle "Repository Structure" as repo_structure
  repo_structure : gitea.brrd.tech/rob/SmartTools-Registry
  repo_structure : /tools/
  repo_structure :   ├── summarize.yaml
  repo_structure :   ├── translate.yaml
  repo_structure :   └── code-review.yaml
  repo_structure : /index.json  (auto-generated)
  repo_structure : /categories.json
}

actor "Tool Publisher" as tool_publisher <<User>> {
  note right of tool_publisher
    Gitea account required
  end note
}

' Connections
cli_user --> cli : uses
web_user --> web_ui : uses

cli --> api_server : HTTPS
web_ui --> api_server : HTTPS

api_server --> database : reads/writes
api_server --> gitea_repo : syncs with

tool_publisher --> gitea_repo : submits PR
gitea_repo --> api_server : webhook events

@enduml