Skip to content

🏗️ Dual SDK architecture

Composer Skills isn't one SDK — it's two packaged in the same module. They solve different problems, take different underlying paths, and have different runtime requirements. Understanding their boundaries is essential to using this project well.

🌐 vs 🛠️ Two SDKs at a glance

🌐 Packagist API SDK🛠️ Composer CLI SDK
Package pathpkg/client, pkg/repositorypkg/composer
Underlying mechanismHTTP calls to Packagist REST APIExecutes local composer binary (os/exec)
Needs PHP?❌ No (pure Go)✅ Yes (PHP 7.4+)
Needs Composer?❌ No✅ Yes (Composer 2.0+, can auto-install)
Data sourcePackagist server (remote)Local PHP project (composer.json/composer.lock)
Methods20234
Typical useSearch packages, view statistics, pull advisoriesInstall/update dependencies, local audits, manage projects

🌐 Packagist API SDK

Package path: github.com/scagogogo/composer-skills/pkg/client

It's a set of typed HTTP clients that communicate directly with Packagist servers. Return values are Go structs; it doesn't touch the local PHP environment.

go
c := client.NewComposerClient(30 * time.Second)

// Remote search
results, _ := c.SearchPackages("logging", 10, 1)

// Remote package details
pkg, _ := c.GetPackage("monolog/monolog")

// Remote security advisories (repository-wide)
advisories, _ := c.GetSecurityAdvisories()

// Site-wide statistics
stats, _ := c.GetStatistics()

pkg/repository provides higher-level repository operation wrappers on top of client, suited for building package mirrors, index downloads, and similar use cases.

When to pick it

  • Your program runs in an environment without PHP (pure Go services, CI runners, Lambda).
  • You need global Packagist data, not a specific local project's state.
  • You're only querying, not modifying (search, statistics, advisories).

🛠️ Composer CLI SDK

Package path: github.com/scagogogo/composer-skills/pkg/composer

It uses os/exec to invoke the local composer executable, wrapping all standard Composer subcommands (234 methods across 20 categories). All operations target a specific local PHP project (set via SetWorkingDir).

go
comp, _ := composer.New(composer.DefaultOptions())
comp.SetWorkingDir("/path/to/php/project")

// Local dependency management
comp.Install(false, true)
comp.RequirePackage("monolog/monolog", "^3.0", false)

// Local security audit (against the project's installed dependencies)
result, _ := comp.AuditWithJSON()

// Local package inspection
tree, _ := comp.ShowDependencyTree("symfony/console")

When to pick it

  • You're operating on a real PHP project (install, update, audit, scripts).
  • You need structured info from the local composer.json / composer.lock.
  • You're doing DevOps automation: detect environment, install Composer, run install, validate schema.

🤔 Which one to use?

A simple rule of thumb: Where does the data come from?

  • Data comes from Packagist server ("what logging packages exist in the world?", "are there new advisories for monolog?") → use 🌐 Packagist API SDK.
  • Data comes from local project ("what dependencies does this project have?", "does this project have vulnerabilities?", "install dependencies") → use 🛠️ Composer CLI SDK.

They are often used together. For example, a security scanner might:

  1. Use 🌐 client.GetSecurityAdvisories() to pull all remote advisories.
  2. Use 🛠️ comp.GetDirectDependencyNames() to get the local project's dependency list.
  3. Cross-reference them in Go and output "specific vulnerabilities affecting this project".

📊 Capability comparison cheat sheet

Capability🌐 Packagist API🛠️ Composer CLI
Search packagesSearchPackagesSearch
Package detailsGetPackageShowPackage
Security advisoriesGetSecurityAdvisories (repo-wide)AuditWithJSON (this project only)
StatisticsGetStatistics
Install/update dependenciesInstall/Update
Dependency tree / whyShowDependencyTree/WhyPackage
Outdated packagesOutdatedPackages
Create project / scriptsCreateProject/RunScript
composer.json read/writeReadComposerJSON/WriteComposerJSON

Difference in security advisories

GetSecurityAdvisories (Packagist API) returns a repository-wide advisory feed; AuditWithJSON (Composer CLI) audits only the currently installed dependencies in this project. They complement each other and are not interchangeable.

🧭 Next steps

Released under the MIT License