Skip to content

Commit 33d99da

Browse files
authored
Backend init (#1)
* backend + db init + docs * example endpoint and supabase setup * git ignore * env fix
1 parent 44ce717 commit 33d99da

30 files changed

Lines changed: 1190 additions & 1 deletion

.github/workflows/backend.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: backend-lint
2+
on:
3+
push:
4+
branches:
5+
- "**"
6+
paths:
7+
- "backend/**"
8+
- ".github/workflows/backend.yaml"
9+
10+
permissions:
11+
contents: read
12+
checks: write
13+
14+
jobs:
15+
backend-lint:
16+
name: backend-lint
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@v4
20+
21+
- uses: actions/setup-go@v5
22+
with:
23+
go-version: "1.22"
24+
25+
- name: golangci-lint
26+
uses: golangci/golangci-lint-action@v6
27+
with:
28+
version: latest
29+
working-directory: ./backend/
30+
args: --timeout=5m
31+
32+
backend-tests:
33+
name: Run backend-tests
34+
runs-on: ubuntu-latest
35+
steps:
36+
- uses: actions/checkout@v4
37+
38+
- uses: actions/setup-go@v5
39+
with:
40+
go-version: "1.22"
41+
42+
- name: Test Backend
43+
run: |
44+
cd backend
45+
go test ./...

.github/workflows/frontend.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: frontend
2+
on:
3+
push:
4+
branches:
5+
- "main"
6+
paths:
7+
- "frontend/**"
8+
- ".github/workflows/frontend.yaml"
9+
pull_request:
10+
branches:
11+
- "main"
12+
paths:
13+
- "frontend/**"
14+
- ".github/workflows/frontend.yaml"
15+
16+
jobs:
17+
lint:
18+
runs-on: ubuntu-latest
19+
defaults:
20+
run:
21+
working-directory: ./frontend
22+
23+
steps:
24+
- name: Checkout
25+
uses: actions/checkout@v4
26+
27+
- name: Use Node.js
28+
uses: actions/setup-node@v3
29+
with:
30+
node-version: "22"
31+
32+
- name: Install dependencies
33+
run: npm install
34+
35+
- name: Lint
36+
run: npm run lint
37+
38+
build:
39+
runs-on: ubuntu-latest
40+
defaults:
41+
run:
42+
working-directory: ./frontend
43+
44+
steps:
45+
- name: Checkout
46+
uses: actions/checkout@v4
47+
48+
- name: Use Node.js
49+
uses: actions/setup-node@v3
50+
with:
51+
node-version: "22"
52+
53+
- name: Install dependencies
54+
run: npm install
55+
56+
- name: Build
57+
run: npm run build

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.task/
2+
3+
.idea/
4+
5+
.env
6+
node_modules
7+
.vscode/
8+
9+
.DS_STORE
10+
11+
.next/

CONTRIBUTING.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,19 @@
11
# Contributing
2+
3+
## Overview
4+
5+
To submit changes, create a pull request and fill out the provided template. **Make sure that the pull request title is descriptive.**
6+
7+
## Backend PRs
8+
9+
If you're writing backend code, please include a screenshot of your endpoint(s) working (Postman, Insomnia, etc.). Please also include the URL of your endpoint and any parameters you passed in - this is super helpful for other developers looking to use your endpoint.
10+
11+
## Frontend PRs
12+
13+
If you're writing frontend code, please include a screenshot or screen recording of your new/updated pages.
14+
15+
## Review process
16+
17+
Once submitted, your pull request will require at least one of the tech leads' approval. Additionally, your code will be automatically linted and built using GitHub Actions. This is super important to keep our main branch clean and well-tested. Once the CI checks pass and an approval is given, you're free to merge your PR!
18+
19+
If your pull request is reviewed and not approved, the reviewer will leave some suggestions for changes. (Sometimes we will approve and still leave suggestions). Once you have made your changes, make sure to re-request a review and/or message one of the TLs on Slack to ensure another review.

backend/.vscode/extensions.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"recommendations": ["denoland.vscode-deno"]
3+
}

backend/.vscode/settings.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"deno.enablePaths": [
3+
"supabase/functions"
4+
],
5+
"deno.lint": true,
6+
"deno.unstable": [
7+
"bare-node-builtins",
8+
"byonm",
9+
"sloppy-imports",
10+
"unsafe-proto",
11+
"webgpu",
12+
"broadcast-channel",
13+
"worker-options",
14+
"cron",
15+
"kv",
16+
"ffi",
17+
"fs",
18+
"http",
19+
"net"
20+
],
21+
"[typescript]": {
22+
"editor.defaultFormatter": "denoland.vscode-deno"
23+
}
24+
}

backend/Dockerfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM golang:1.23-alpine
2+
3+
4+
# Set the working directory (this is /backend in Arenius)
5+
WORKDIR /app
6+
7+
# Copy only go.mod and go.sum first (to cache dependencies)
8+
COPY go.mod go.sum ./
9+
RUN go mod download
10+
11+
# Copy the entire project
12+
COPY . .
13+
14+
WORKDIR /app/cmd
15+
16+
CMD ["go", "run", "main.go"]

backend/README.md

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,49 @@
1-
# Backend README
1+
# Special Standard Backend
2+
3+
## Getting Started
4+
5+
The backend is written in [Golang](https://go.dev/learn/) and handles code dependencies with Go modules managed within go.mod and go.sum.
6+
In order to run the backend, the most straightforward way is to navigate to backend/cmd and execute **go run main.go** or
7+
**go build -o main . && ./main**.
8+
9+
Alternatively, we will use **Docker** to build and run isolated containers to ensure that environment dependencies and runtimes are consistent across our machines.
10+
11+
### Steps to use Docker
12+
13+
Install [Docker Desktop](https://docs.docker.com/get-started/get-docker/) (or just [Docker Engine](https://docs.docker.com/engine/install/)).
14+
15+
In a terminal of your choice:
16+
17+
```bash
18+
cd /specialstandard
19+
docker compose up --build --watch
20+
```
21+
22+
This will compose a cluster consisting of the backend and frontend containers.
23+
Docker Watch is utilized for hot/live reloading to make development easier. The Docker Engine
24+
watches for changes within the backend and frontend, syncs file changes from
25+
the host to the respective container, and then restarts the respective container.
26+
27+
To end development, in the terminal press ctrl+c / cmd+c OR in another terminal execute:
28+
29+
```bash
30+
docker compose down
31+
```
32+
33+
Open <http://localhost:8080/health> with your browser to see the result. Requests *should* be logged in your terminal.
34+
35+
## Postman
36+
37+
For further development and testing, install [Postman](https://www.postman.com/downloads/), which simplifies making network requests.
38+
39+
## Learn More
40+
41+
- [Go Modules](https://faun.pub/understanding-go-mod-and-go-sum-5fd7ec9bcc34) - article about go.mod and go.sum.
42+
- [Tour of Go](https://go.dev/tour/welcome/1) - guided tour of Golang.
43+
- [Go Video](https://youtu.be/8uiZC0l4Ajw?si=YJq6z9nqTN-B-c8c) - fantastic build up of data structures and syntax to write a complicated API.
44+
- [Fiber Framework](https://docs.gofiber.io/) - web framework, similar to Express, SpringBoot, Flask, FastAPI, etc.
45+
- [Docker Engine](https://docs.docker.com/engine/) - documentation for docker building and running docker containers.
46+
- [pgx](https://pkg.go.dev/github.com/jackc/pgx) - driver and toolkit for PostgreSQL which can be used to interact with Supabase.
47+
- [Supabase](https://supabase.com/docs) - database hosting service, with Auth service alongside.
48+
49+
This tech stack is totally flexible--suggestions are welcome!

backend/cmd/main.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"log"
6+
"log/slog"
7+
"os"
8+
"os/signal"
9+
"specialstandard/internal/config"
10+
"specialstandard/internal/service"
11+
"syscall"
12+
13+
"github.com/joho/godotenv"
14+
"github.com/sethvargo/go-envconfig"
15+
)
16+
17+
func main() {
18+
err := godotenv.Load("../.env")
19+
if err != nil {
20+
log.Fatalf("Error loading .env file: %v", err)
21+
return
22+
}
23+
24+
var config config.Config
25+
if err := envconfig.Process(context.Background(), &config); err != nil {
26+
log.Fatalln("Error processing .env file: ", err)
27+
}
28+
29+
app := service.InitApp(config)
30+
31+
// Pushing the closing of the database connection onto a
32+
// stack of statements to be executed when this function returns.
33+
34+
// **Uncomment after repo connection is actually made**
35+
// defer app.Repo.Close()
36+
37+
port := config.Application.Port
38+
// Listen for connections with a goroutine.
39+
go func() {
40+
if err := app.Server.Listen(":" + port); err != nil {
41+
log.Fatalf("Failed to start server: %v", err)
42+
}
43+
}()
44+
45+
quit := make(chan os.Signal, 1)
46+
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
47+
48+
// Wait for the termination signal:
49+
<-quit
50+
51+
// Then shutdown server gracefully.
52+
slog.Info("Shutting down server")
53+
if err := app.Server.Shutdown(); err != nil {
54+
slog.Error("failed to shutdown server", "error", err)
55+
}
56+
57+
slog.Info("Server shutdown")
58+
}

backend/env.sample

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
DB_USER=""
2+
DB_PASSWORD=""
3+
DB_HOST=""
4+
DB_PORT=""
5+
DB_NAME=""
6+
7+
PORT="8080"
8+
9+
SUPABASE_URL=""
10+
SUPABASE_ANON_KEY=""
11+
SUPABASE_SERVICE_ROLE_KEY=""

0 commit comments

Comments
 (0)