Go backend (#1555)

* Replaces old Deno server with a Go implementation
* Restructured the code base accordingly
This commit is contained in:
Zef Hemel
2025-09-19 13:23:20 +02:00
committed by GitHub
parent ff2cb27a1b
commit a524c64884
322 changed files with 3841 additions and 3228 deletions
+2 -1
View File
@@ -3,11 +3,12 @@ An attempt at documenting the changes/new features introduced in each release.
## Edge
These are changes live on the edge builds:
* New server written in Go, should be functionally equivalent to the old Deno-based backend, but is much smaller, faster and uses less memory.
* Sync engine re-architecture: see [[Architecture]] and [[Sync]]
* More configuring what to index (see [[^Library/Std/Config]] under the `index` section) for the purpose of reducing local storage size and needless CPU waste. Some useful ones:
* `config.set("index.search.enable", false)` to disable [[Full Text Search]] entirely (saves on processing and storage if you don’t use it)
* `config.set("index.paragraph.all", false)` to disable indexing all (untagged) paragraphs. This is also somewhat wasteful if you don’t query these.
* Parallel sync (5 files simultaneously)
* Parallel sync
* Disable ability to rename pages in read-only mode (by [Jelenkee](https://github.com/silverbulletmd/silverbullet/pull/1509))
* Improved docker build + health check (by [Zef](https://github.com/silverbulletmd/silverbullet/issues/1515))
* Added `templates.tagItem` template (by [Andy Costanza](https://github.com/silverbulletmd/silverbullet/commit/6d4f964a6e2a4f7dae04aa7558defcaa9f1f1a86))
+61 -17
View File
@@ -1,42 +1,86 @@
# Stack
SilverBullet is written in [TypeScript](https://www.typescriptlang.org/) and built on top of the excellent [CodeMirror 6](https://codemirror.net/) editor component. Additional UI is built using [Preact](https://preactjs.com/). [ES Build](https://esbuild.github.io) is used to build both the front-end and back-end bundles. The server backend runs as an HTTP server on [Deno](https://deno.land/) using [Hono](https://hono.dev).
SilverBullet’s client is written in [TypeScript](https://www.typescriptlang.org/) and built on top of the excellent [CodeMirror 6](https://codemirror.net/) editor component. Additional UI is built using [Preact](https://preactjs.com/). [ES Build](https://esbuild.github.io) is used to build the frontend.
[[Plugs]] are also written in TypeScript.
The SilverBullet server is written in [Go](https://go.dev/).
# Code structure
* `client/`: The SilverBullet client, implemented with TypeScript
* `server/`: The SilverBullet server, written in Go
* `plugs`: Set of built-in plugs that are distributed with SilverBullet
* `libraries`: A set of libraries (space scripts, page templates, slash templates) distributed with SilverBullet
* `plug-api/`: Useful APIs for use in plugs
* `lib/`: Useful libraries to be used in plugs
* `syscalls/`: TypeScript wrappers around syscalls
* `types/`: Various (client) types that can be references from plugs
* `bin`
* `plug_compile.ts` the plug compiler
* `scripts/`: Useful scripts
* `website/`: silverbullet.md website content
# Development
Requirements: [Deno](https://deno.land/) 2.2 or newer.
Requirements:
* [Deno](https://deno.land/) 2.4 or newer.
* [Go](https://go.dev/) 1.25 or newer
* Make
Clone the repository from GitHub:
It's convenient to also install [air](https://github.com/air-verse/air) for development, this tool will watch your code base for changes and automatically rebuild:
```shell
git clone git@github.com:silverbulletmd/silverbullet.git
cd silverbullet
go install github.com/air-verse/air@latest
```
And build it:
Make sure your `$GOPATH/bin` is in your $PATH.
To build everything and run the server using air:
```shell
deno task build
air <PATH-TO-YOUR-SPACE>
```
For convenience, replace your `silverbullet` install with the one from this repo via:
Note, that if you want to pass arguments to your SilverBullet binary like `-p` or `-L` you need to this as follows:
```shell
deno task install
air -- -L 0.0.0.0 <PATH-TO-YOUR-SPACE>
```
You can now run the server in “watch mode” (automatically restarting when you change source files) with:
Alternatively, to build the project without air:
```shell
deno task watch-server <PATH-TO-YOUR-SPACE>
make build
```
It's convenient to run three commands in parallel (in separate terminals):
To run the resulting server:
```shell
deno task watch-web
deno task watch-server <PATH-TO-YOUR-SPACE>
deno task watch-plugs
./silverbullet <PATH-TO-YOUR-SPACE>
```
All of these watch for file changes and a rebuild should trigger automatically.
### Useful development tasks
```shell
# Clean all generated files
make clean
# Typecheck and lint all code
make check
# Format all code
make fmt
# Run all tests
make test
```
### Build a docker container
Note, you do not need Deno nor Go locally installed for this to work:
```shell
docker build -t silverbullet .
```
To run:
```shell
docker run -p 3000:3000 -v <PATH-TO-YOUR-SPACE>:/space silverbullet
```
Note that there are dependencies between these builds. Any change to any of the built-in _plugs_ requires a rebuild of the web app. Any rebuild of the web app will only be picked up by the server after it restarts (which should happen automatically).
+2 -1
View File
@@ -4,6 +4,7 @@ SilverBullet is primarily configured via environment variables. This page gives
* `SB_INDEX_PAGE`: Sets the default page to load, defaults to `index`.
* `SB_SPACE_IGNORE`: Ignore certain path patterns based on a .gitignore style format, e.g. `SB_SPACE_IGNORE="IgnoreMe/*"`.
* `SB_HTTP_LOGGING`: Set to any value to enable HTTP logging
# Network
* `SB_HOSTNAME`: Set to the hostname to bind to (defaults to `127.0.0.0`, set to `0.0.0.0` to accept outside connections for the local deno setup, defaults to `0.0.0.0` for docker)
@@ -43,7 +44,7 @@ Configuration only relevant to docker deployments:
* `PGID`: Runs the server process with the specified GID (default: whatever group owns the `/space` mapped folder)\
# Web app manifest
Configure aspects of web app appearance:
Configure aspects of web app appearance as well as the authentication page:
* `SB_NAME`: Sets `name` and `short_name` members of web app manifest to whatever specified in `SB_NAME`
* `SB_DESCRIPTION`: Sets `description` member of web app manifest to whatever specified in `SB_DESCRIPTION`
+1 -1
View File
@@ -4,7 +4,7 @@ This can be used to achieve various things, such as overriding the default edito
To apply the updated styles, either reload the client or run the ${widgets.commandButton("System: Reload")} command.
Many styles can be set with [variables](https://github.com/silverbulletmd/silverbullet/blob/main/web/styles/theme.scss) but not everything is covered. You’ll have to reverse-engineer those parts, unfortunately.
Many styles can be set with [variables](https://github.com/silverbulletmd/silverbullet/blob/main/client/styles/theme.scss) but not everything is covered. You’ll have to reverse-engineer those parts, unfortunately.
# Load order
You can tweak the CSS load order style by including a `/* priority: number */` comment: