Skip to content

Commit c51a4cc

Browse files
authored
Merge pull request #7 from sumon-ohid/backend-restucture
Backend restucture
2 parents 48016c0 + 058aa76 commit c51a4cc

69 files changed

Lines changed: 3951 additions & 3416 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CONTRIBUTING.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ go run .
5656
```
5757
The API server will listen on `http://localhost:8080` by default.
5858

59+
For a quick map of backend files and responsibilities, see
60+
[`backend/docs/architecture.md`](backend/docs/architecture.md).
61+
5962
### 3. Run the Frontend
6063
The frontend is a Next.js single-page application.
6164
```bash

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ WORKDIR /src
44
COPY backend/go.mod backend/go.sum ./
55
RUN go mod download
66
COPY backend/ ./
7-
RUN CGO_ENABLED=0 go build -ldflags "-X main.version=docker" -o better-paas-backend .
7+
RUN CGO_ENABLED=0 go build -ldflags "-X paas/internal/paas.version=docker" -o better-paas-backend .
88

99
# Stage 2: Build the Next.js Frontend
1010
FROM node:20-alpine AS frontend-builder

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ git tag v1.3.0
197197
git push origin v1.3.0 # builds and publishes the release
198198
```
199199

200-
Each release cross-compiles the Go backend for `linux/amd64`, `linux/arm64`, `darwin/amd64`, and `darwin/arm64`, embeds the version tag via `-ldflags "-X main.version=<tag>"`, and attaches the compiled binaries along with a `SHA256SUMS` verification manifest to the GitHub Release.
200+
Each release cross-compiles the Go backend for `linux/amd64`, `linux/arm64`, `darwin/amd64`, and `darwin/arm64`, embeds the version tag via `-ldflags "-X paas/internal/paas.version=<tag>"`, and attaches the compiled binaries along with a `SHA256SUMS` verification manifest to the GitHub Release.
201201

202202
### How the In-App Updater Works
203203
1. **Version Checking**: The current running version is baked into the server binary. Updates check the GitHub Releases API for the repository slug defined in `UPDATE_REPO` (resolved from environment, database, or git remote origin).

backend/docs/architecture.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+
```

backend/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module baas
1+
module paas
22

33
go 1.25.0
44

0 commit comments

Comments
 (0)