Wikimedia Commons stores alt text in the form of WikibaseMediaInfo claims (see {T166094}). We don't want clients to access that directly because
# the Wikibase APIs are complex and not that developer-friendly;
# we want to provide stability guarantees for APIs and community-owned ontology makes that difficult;
# as much as possible we want to hide ontology changes and keep the API the same (e.g. if a migration happens because of {T325944});
# we want to make alt-text features available on developer setups and third-party MediaWiki setups without forcing a Wikibase / WikibaseMediaInfo dependency.
So, there should be an internal PHP API (presumably a core hook or service, maybe along the lines of the [[https://mediawiki.org/wiki/Manual:Hooks/GetExtendedMetadata|GetExtendedMetadata]] hook) that WikibaseMediaInfo implements by looking up the relevant Wikibase property, but other extensions can implement in different ways; and there should probably also be a web API exposing the same functionality.
Because of {T325949}, there are two orthogonal directions of abstraction here:
* how the alt text is stored (Wikibase property, or inside wikitext, or something else)
* whether it is stored on this wiki, or another wiki in the same database cluster, or another wiki only accessible via API.
Some other considerations:
* there should be a way to get the alt text for a specific file in a specific language (probably with language fallback?)
* there should be a way to get the alt text for all files on a page and/or a batch of images (for the [[https://www.mediawiki.org/wiki/InstantCommons|InstantCommons]] use case)
* is there a use case for getting all languages for a file?
* the web API should probably be cacheable for a short time