|
| 1 | +# Backend Architecture |
| 2 | + |
| 3 | +The backend is a Go module. The executable entrypoint lives at `main.go` in |
| 4 | +the backend root, while the main application package lives in `internal/paas`. |
| 5 | + |
| 6 | +## Layout |
| 7 | + |
| 8 | +- `main.go`: binary entrypoint. Keep this thin. |
| 9 | +- `internal/paas/`: API process, domain models, deployment workflows, storage, |
| 10 | + background jobs, tests, and feature handlers. |
| 11 | +- `internal/catalog/`: curated one-click app template data and template |
| 12 | + structs. Edit app catalog definitions here. |
| 13 | +- `internal/paas/app.go`: boot sequence for the API process and background workers. |
| 14 | +- `internal/paas/routes.go`: HTTP and WebSocket route registration, grouped by feature area. |
| 15 | +- `internal/paas/http_middleware.go`: auth gate, CORS, and request body protection. |
| 16 | +- `internal/paas/config.go`: environment parsing and process-level runtime configuration. |
| 17 | +- `internal/paas/models.go`: shared domain models passed between handlers, storage, and |
| 18 | + deployment code. |
| 19 | +- `internal/paas/db.go`: SQLite initialization, migrations, and persistence helpers. |
| 20 | +- `internal/paas/catalog.go`: catalog API handlers, image size fetching, and custom catalog |
| 21 | + deploy orchestration. |
| 22 | +- `internal/paas/docker.go`, `internal/paas/compose.go`, `internal/paas/caddy.go`, `internal/paas/executor.go`: deployment, |
| 23 | + container, compose, proxy, local, and SSH execution workflows. |
| 24 | +- Feature files such as `internal/paas/addons.go`, `internal/paas/backup.go`, |
| 25 | + `internal/paas/cron.go`, `internal/paas/domains.go`, |
| 26 | + `internal/paas/servers.go`, `internal/paas/terminal.go`, and |
| 27 | + `internal/paas/analytics*.go` own their API behavior. |
| 28 | + |
| 29 | +## Contributor Guidelines |
| 30 | + |
| 31 | +Prefer small, feature-named files over broad catch-all files. When a file grows |
| 32 | +large, split by responsibility first: |
| 33 | + |
| 34 | +- request handlers |
| 35 | +- storage helpers |
| 36 | +- background jobs |
| 37 | +- provider/client code |
| 38 | +- static or curated data |
| 39 | + |
| 40 | +Keep `main.go` limited to calling `paas.Run()`. This keeps the |
| 41 | +runtime path easy to test and avoids hiding behavior in the command package. |
| 42 | + |
| 43 | +Go packages are directory-scoped, so moving feature files into subdirectories |
| 44 | +also creates new packages. Prefer incremental moves into `internal/<feature>` |
| 45 | +when the code has a clean boundary, as with `internal/catalog`. Avoid moving a |
| 46 | +large file just for tidiness if it would require exporting unrelated globals or |
| 47 | +handler internals. |
| 48 | + |
| 49 | +Run backend checks from this directory: |
| 50 | + |
| 51 | +```bash |
| 52 | +go test ./... |
| 53 | +go run . |
| 54 | +``` |
0 commit comments