A browser extension (web extension) is basically a web app where all the JS and other resources are already loaded in the browser. The functional difference to an ordinary website is that a web extension has has more privileges and has access to more browser APIs.
You use the same basic techniques to build web extensions that you'd use to build a (single page) web application. The web extension will communicate through normal HTTP requests with external services. If you want to access a database, the best practice is to build a backend server that exposes an API (usually in RESTful style). If you already have a web app, the web extension can likely reuse the same backend of the web app.
Note that thanks to advancements under the umbrella term “progressive web apps”, many features that would previously have required a privileged extension are also available to ordinary web apps, e.g. notifications, background processes, or persistent offline storage.