-
Notifications
You must be signed in to change notification settings - Fork 0
Backend init #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Backend init #1
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| name: backend-lint | ||
| on: | ||
| push: | ||
| branches: | ||
| - "**" | ||
| paths: | ||
| - "backend/**" | ||
| - ".github/workflows/backend.yaml" | ||
|
|
||
| permissions: | ||
| contents: read | ||
| checks: write | ||
|
|
||
| jobs: | ||
| backend-lint: | ||
| name: backend-lint | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - uses: actions/setup-go@v5 | ||
| with: | ||
| go-version: "1.22" | ||
|
|
||
| - name: golangci-lint | ||
| uses: golangci/golangci-lint-action@v6 | ||
| with: | ||
| version: latest | ||
| working-directory: ./backend/ | ||
| args: --timeout=5m | ||
|
|
||
| backend-tests: | ||
| name: Run backend-tests | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - uses: actions/setup-go@v5 | ||
| with: | ||
| go-version: "1.22" | ||
|
|
||
| - name: Test Backend | ||
| run: | | ||
| cd backend | ||
| go test ./... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| name: frontend | ||
| on: | ||
| push: | ||
| branches: | ||
| - "main" | ||
| paths: | ||
| - "frontend/**" | ||
| - ".github/workflows/frontend.yaml" | ||
| pull_request: | ||
| branches: | ||
| - "main" | ||
| paths: | ||
| - "frontend/**" | ||
| - ".github/workflows/frontend.yaml" | ||
|
|
||
| jobs: | ||
| lint: | ||
| runs-on: ubuntu-latest | ||
| defaults: | ||
| run: | ||
| working-directory: ./frontend | ||
|
|
||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Use Node.js | ||
| uses: actions/setup-node@v3 | ||
| with: | ||
| node-version: "22" | ||
|
|
||
| - name: Install dependencies | ||
| run: npm install | ||
|
|
||
| - name: Lint | ||
| run: npm run lint | ||
|
|
||
| build: | ||
| runs-on: ubuntu-latest | ||
| defaults: | ||
| run: | ||
| working-directory: ./frontend | ||
|
|
||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Use Node.js | ||
| uses: actions/setup-node@v3 | ||
| with: | ||
| node-version: "22" | ||
|
|
||
| - name: Install dependencies | ||
| run: npm install | ||
|
|
||
| - name: Build | ||
| run: npm run build |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| .task/ | ||
|
|
||
| .idea/ | ||
|
|
||
| .env | ||
| node_modules | ||
| .vscode/ | ||
|
|
||
| .DS_STORE | ||
|
|
||
| .next/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,19 @@ | ||
| # Contributing | ||
|
|
||
| ## Overview | ||
|
|
||
| To submit changes, create a pull request and fill out the provided template. **Make sure that the pull request title is descriptive.** | ||
|
|
||
| ## Backend PRs | ||
|
|
||
| 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. | ||
|
|
||
| ## Frontend PRs | ||
|
|
||
| If you're writing frontend code, please include a screenshot or screen recording of your new/updated pages. | ||
|
|
||
| ## Review process | ||
|
|
||
| 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! | ||
|
|
||
| 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "recommendations": ["denoland.vscode-deno"] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| { | ||
| "deno.enablePaths": [ | ||
| "supabase/functions" | ||
| ], | ||
| "deno.lint": true, | ||
| "deno.unstable": [ | ||
| "bare-node-builtins", | ||
| "byonm", | ||
| "sloppy-imports", | ||
| "unsafe-proto", | ||
| "webgpu", | ||
| "broadcast-channel", | ||
| "worker-options", | ||
| "cron", | ||
| "kv", | ||
| "ffi", | ||
| "fs", | ||
| "http", | ||
| "net" | ||
| ], | ||
| "[typescript]": { | ||
| "editor.defaultFormatter": "denoland.vscode-deno" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| FROM golang:1.23-alpine | ||
|
|
||
|
|
||
| # Set the working directory (this is /backend in Arenius) | ||
| WORKDIR /app | ||
|
|
||
| # Copy only go.mod and go.sum first (to cache dependencies) | ||
| COPY go.mod go.sum ./ | ||
| RUN go mod download | ||
|
|
||
| # Copy the entire project | ||
| COPY . . | ||
|
|
||
| WORKDIR /app/cmd | ||
|
|
||
| CMD ["go", "run", "main.go"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,49 @@ | ||
| # Backend README | ||
| # Special Standard Backend | ||
|
|
||
| ## Getting Started | ||
|
|
||
| The backend is written in [Golang](https://go.dev/learn/) and handles code dependencies with Go modules managed within go.mod and go.sum. | ||
| In order to run the backend, the most straightforward way is to navigate to backend/cmd and execute **go run main.go** or | ||
| **go build -o main . && ./main**. | ||
|
|
||
| Alternatively, we will use **Docker** to build and run isolated containers to ensure that environment dependencies and runtimes are consistent across our machines. | ||
|
|
||
| ### Steps to use Docker | ||
|
|
||
| Install [Docker Desktop](https://docs.docker.com/get-started/get-docker/) (or just [Docker Engine](https://docs.docker.com/engine/install/)). | ||
|
|
||
| In a terminal of your choice: | ||
|
|
||
| ```bash | ||
| cd /specialstandard | ||
| docker compose up --build --watch | ||
| ``` | ||
|
|
||
| This will compose a cluster consisting of the backend and frontend containers. | ||
| Docker Watch is utilized for hot/live reloading to make development easier. The Docker Engine | ||
| watches for changes within the backend and frontend, syncs file changes from | ||
| the host to the respective container, and then restarts the respective container. | ||
|
|
||
| To end development, in the terminal press ctrl+c / cmd+c OR in another terminal execute: | ||
|
|
||
| ```bash | ||
| docker compose down | ||
| ``` | ||
|
|
||
| Open <http://localhost:8080/health> with your browser to see the result. Requests *should* be logged in your terminal. | ||
|
|
||
| ## Postman | ||
|
|
||
| For further development and testing, install [Postman](https://www.postman.com/downloads/), which simplifies making network requests. | ||
|
|
||
| ## Learn More | ||
|
|
||
| - [Go Modules](https://faun.pub/understanding-go-mod-and-go-sum-5fd7ec9bcc34) - article about go.mod and go.sum. | ||
| - [Tour of Go](https://go.dev/tour/welcome/1) - guided tour of Golang. | ||
| - [Go Video](https://youtu.be/8uiZC0l4Ajw?si=YJq6z9nqTN-B-c8c) - fantastic build up of data structures and syntax to write a complicated API. | ||
| - [Fiber Framework](https://docs.gofiber.io/) - web framework, similar to Express, SpringBoot, Flask, FastAPI, etc. | ||
| - [Docker Engine](https://docs.docker.com/engine/) - documentation for docker building and running docker containers. | ||
| - [pgx](https://pkg.go.dev/github.com/jackc/pgx) - driver and toolkit for PostgreSQL which can be used to interact with Supabase. | ||
| - [Supabase](https://supabase.com/docs) - database hosting service, with Auth service alongside. | ||
|
|
||
| This tech stack is totally flexible--suggestions are welcome! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "context" | ||
| "log" | ||
| "log/slog" | ||
| "os" | ||
| "os/signal" | ||
| "specialstandard/internal/config" | ||
| "specialstandard/internal/service" | ||
| "syscall" | ||
|
|
||
| "github.com/joho/godotenv" | ||
| "github.com/sethvargo/go-envconfig" | ||
| ) | ||
|
|
||
| func main() { | ||
| err := godotenv.Load("../.env") | ||
| if err != nil { | ||
| log.Fatalf("Error loading .env file: %v", err) | ||
| return | ||
| } | ||
|
|
||
| var config config.Config | ||
| if err := envconfig.Process(context.Background(), &config); err != nil { | ||
| log.Fatalln("Error processing .env file: ", err) | ||
| } | ||
|
|
||
| app := service.InitApp(config) | ||
|
|
||
| // Pushing the closing of the database connection onto a | ||
| // stack of statements to be executed when this function returns. | ||
|
|
||
| // **Uncomment after repo connection is actually made** | ||
| // defer app.Repo.Close() | ||
|
|
||
| port := config.Application.Port | ||
| // Listen for connections with a goroutine. | ||
| go func() { | ||
| if err := app.Server.Listen(":" + port); err != nil { | ||
| log.Fatalf("Failed to start server: %v", err) | ||
| } | ||
| }() | ||
|
|
||
| quit := make(chan os.Signal, 1) | ||
| signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM) | ||
|
|
||
| // Wait for the termination signal: | ||
| <-quit | ||
|
|
||
| // Then shutdown server gracefully. | ||
| slog.Info("Shutting down server") | ||
| if err := app.Server.Shutdown(); err != nil { | ||
| slog.Error("failed to shutdown server", "error", err) | ||
| } | ||
|
|
||
| slog.Info("Server shutdown") | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| DB_USER="" | ||
| DB_PASSWORD="" | ||
| DB_HOST="" | ||
| DB_PORT="" | ||
| DB_NAME="" | ||
|
|
||
| PORT="8080" | ||
|
|
||
| SUPABASE_URL="" | ||
| SUPABASE_ANON_KEY="" | ||
| SUPABASE_SERVICE_ROLE_KEY="" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| module specialstandard | ||
|
|
||
| go 1.23.1 | ||
|
|
||
| require ( | ||
| github.com/goccy/go-json v0.10.5 | ||
| github.com/gofiber/fiber/v2 v2.52.9 | ||
| github.com/google/uuid v1.6.0 | ||
| github.com/jackc/pgx/v5 v5.7.5 | ||
| github.com/lib/pq v1.10.9 | ||
| github.com/pkg/errors v0.9.1 | ||
| ) | ||
|
|
||
| require ( | ||
| github.com/andybalholm/brotli v1.1.0 // indirect | ||
| github.com/jackc/pgpassfile v1.0.0 // indirect | ||
| github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect | ||
| github.com/jackc/puddle/v2 v2.2.2 // indirect | ||
| github.com/joho/godotenv v1.5.1 // indirect | ||
| github.com/klauspost/compress v1.17.9 // indirect | ||
| github.com/mattn/go-colorable v0.1.13 // indirect | ||
| github.com/mattn/go-isatty v0.0.20 // indirect | ||
| github.com/mattn/go-runewidth v0.0.16 // indirect | ||
| github.com/rivo/uniseg v0.2.0 // indirect | ||
| github.com/sethvargo/go-envconfig v1.3.0 // indirect | ||
| github.com/stretchr/testify v1.8.4 // indirect | ||
| github.com/valyala/bytebufferpool v1.0.0 // indirect | ||
| github.com/valyala/fasthttp v1.51.0 // indirect | ||
| github.com/valyala/tcplisten v1.0.0 // indirect | ||
| golang.org/x/crypto v0.37.0 // indirect | ||
| golang.org/x/sync v0.13.0 // indirect | ||
| golang.org/x/sys v0.32.0 // indirect | ||
| golang.org/x/text v0.24.0 // indirect | ||
| ) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should say something abt squash merge in case they are unfamiliar