For the attachments like pdf you can use webdav, but for the metadata you have to use their service [1]. They have the code repos online so it's open source, but no self-hosting instructions [2]. They claimed it to be due to technical difficulties [3], though imo they have no incentives to provide this given that they host a paid service themselves.
[1]: https://www.zotero.org/support/sync
[2]: https://github.com/zotero/dataserver
[3]: https://github.com/zotero/dataserver/issues/105