-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from ryichk/build-foundation-for-client-and-api
Build foundation for Client and API
- Loading branch information
Showing
43 changed files
with
13,578 additions
and
13 deletions.
There are no files selected for viewing
This file contains 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,20 @@ | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.go] | ||
indent_style = tab | ||
indent_size = 4 | ||
|
||
[Makefile] | ||
indent_style = tab | ||
indent_size = 4 | ||
|
||
[*.{yml,yaml,toml,md}] | ||
trim_trailing_whitespace = false |
This file contains 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,14 @@ | ||
ENVIRONMENT=development | ||
|
||
CLIENT_PORT=5173 | ||
API_PORT=8080 | ||
|
||
POSTGRES_PORT=5432 | ||
POSTGRES_DB=app_db | ||
POSTGRES_ADMIN_USER=admin_user | ||
POSTGRES_ADMIN_PASSWORD=password | ||
POSTGRES_APP_USER=app_user | ||
POSTGRES_APP_PASSWORD=password | ||
|
||
AWS_REGION=ap-northeast-1 | ||
COGNITO_USER_POOL_ID= |
This file contains 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,67 @@ | ||
name: CI Pipeline | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
eslint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
- name: Set up Node.js | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: 22 | ||
- name: Install dependencies | ||
working-directory: client | ||
run: npm ci | ||
- name: Run ESLint | ||
working-directory: client | ||
run: npm run lint | ||
|
||
golangci-lint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout coe | ||
uses: actions/checkout@v4 | ||
- name: Set up Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version: '1.23.3' | ||
- name: golangci-lint | ||
uses: golangci/golangci-lint-action@v6 | ||
with: | ||
version: v1.62 | ||
working-directory: api | ||
|
||
api-test: | ||
name: API Test | ||
runs-on: ubuntu-latest | ||
services: | ||
dind: | ||
image: docker:23.0-rc-dind-rootless | ||
ports: | ||
- 2375:2375 | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- name: Set up Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version: '1.23.3' | ||
- name: Get dependencies | ||
working-directory: api | ||
run: go mod tidy | ||
- name: Build | ||
working-directory: api | ||
run: go build -v ./... | ||
- name: Test with dockertest | ||
working-directory: api | ||
run: go test -v ./... |
This file contains 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,25 +1,29 @@ | ||
# If you prefer the allow list template instead of the deny list, see community template: | ||
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore | ||
# | ||
# Binaries for programs and plugins | ||
# root | ||
.env | ||
|
||
# client | ||
node_modules | ||
|
||
/.cache | ||
/build | ||
/public/build | ||
|
||
# api | ||
## Binaries for programs and plugins | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.so | ||
*.dylib | ||
|
||
# Test binary, built with `go test -c` | ||
## Test binary, built with `go test -c` | ||
*.test | ||
|
||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
## Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out | ||
|
||
# Dependency directories (remove the comment below to include it) | ||
# vendor/ | ||
|
||
# Go workspace file | ||
## Go workspace file | ||
go.work | ||
go.work.sum | ||
|
||
# env file | ||
.env | ||
tmp |
This file contains 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,63 @@ | ||
include .env | ||
|
||
DOCKER_RUN_CLIENT=docker compose run --rm client | ||
DOCKER_RUN_API=docker compose run --rm api | ||
POSTGRESQL_ADMIN_URL=postgres://$(POSTGRES_ADMIN_USER):$(POSTGRES_ADMIN_PASSWORD)@db:$(POSTGRES_PORT)/$(POSTGRES_DB)?sslmode=disable | ||
|
||
build: | ||
docker compose build | ||
|
||
up: | ||
docker compose up -d | ||
|
||
down: | ||
docker compose down | ||
|
||
down_all: | ||
docker compose down --rmi all --volumes --remove-orphans | ||
|
||
ps: | ||
docker compose ps | ||
|
||
psql: | ||
docker compose exec db psql -U $(POSTGRES_ADMIN_USER) -d $(POSTGRES_DB) | ||
|
||
migrate_create: | ||
$(DOCKER_RUN_API) migrate create -ext sql -dir internal/db/migration -seq $(NAME) | ||
|
||
migrate_up: | ||
$(DOCKER_RUN_API) migrate -path internal/db/migration -database $(POSTGRESQL_ADMIN_URL) -verbose up | ||
|
||
migrate_down: | ||
$(DOCKER_RUN_API) migrate -path internal/db/migration -database $(POSTGRESQL_ADMIN_URL) -verbose down $(STEP) | ||
|
||
migrate_drop: | ||
$(DOCKER_RUN_API) migrate -path internal/db/migration -database $(POSTGRESQL_ADMIN_URL) -verbose drop | ||
|
||
migrate_version: | ||
$(DOCKER_RUN_API) migrate -path internal/db/migration -database $(POSTGRESQL_ADMIN_URL) version | ||
|
||
sqlc_gen: | ||
$(DOCKER_RUN_API) sqlc generate | ||
|
||
sqlc_vet: | ||
$(DOCKER_RUN_API) sqlc vet | ||
|
||
tidy: | ||
$(DOCKER_RUN_API) go mod tidy | ||
|
||
fmt: | ||
$(DOCKER_RUN_API) go fmt ./... | ||
|
||
lint: | ||
$(DOCKER_RUN_CLIENT) npm run lint:fix | ||
$(DOCKER_RUN_API) golangci-lint run | ||
|
||
lint_v: | ||
$(DOCKER_RUN_API) golangci-lint run -v | ||
|
||
test: | ||
$(DOCKER_RUN_API) go test -cover ./... | ||
|
||
test_v: | ||
$(DOCKER_RUN_API) go test -v -cover ./... |
This file contains 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,152 @@ | ||
# todolist | ||
# todolist | ||
|
||
## Summary | ||
|
||
### Frontend | ||
|
||
#### Programming Language | ||
|
||
- TypeScript | ||
|
||
#### Frameworks | ||
|
||
- [Remix](https://remix.run/) | ||
- [SPA Mode](https://remix.run/docs/en/main/guides/spa-mode) | ||
|
||
### Backend | ||
|
||
#### Programming Language | ||
|
||
- Go | ||
|
||
#### Frameworks | ||
|
||
- [Echo](https://github.com/labstack/echo) | ||
- Utilizes [air](https://github.com/air-verse/air) for Live Reload | ||
|
||
#### DB | ||
|
||
- PostgreSQL | ||
|
||
## Environment Construction | ||
|
||
### 1. Install Docker | ||
|
||
### 2. Set environment variables | ||
|
||
```sh | ||
cp .env.sample .env | ||
``` | ||
|
||
```sh | ||
cp client/.env.sample client/.env | ||
``` | ||
|
||
Set the Amazon Cognito User Pool ID and Client ID to be handled in the development environment in the environment variables of the `.env` and `client/.env` files. | ||
|
||
```.env | ||
COGNITO_USER_POOL_ID= | ||
``` | ||
|
||
```client/.env | ||
VITE_COGNITO_USER_POOL_ID= | ||
VITE_COGNITO_CLIENT_ID= | ||
``` | ||
|
||
### 3. Start the Docker Containers | ||
|
||
```sh | ||
make up | ||
``` | ||
|
||
### 4. Execute DB migration | ||
|
||
```sh | ||
make migrate_up | ||
``` | ||
|
||
## Development Procedure | ||
|
||
### Organize Dependencies of Go modules | ||
|
||
```sh | ||
make tidy | ||
``` | ||
|
||
### Code Formatting | ||
|
||
```sh | ||
make fmt | ||
``` | ||
|
||
### Static Analysis | ||
|
||
```sh | ||
make lint | ||
``` | ||
|
||
### Test Code Execution | ||
|
||
```sh | ||
make test | ||
``` | ||
|
||
### Create Migration File | ||
|
||
To make changes to the DB schema, create a file in `api/internal/db/migration` and run migration. | ||
|
||
#### Steps | ||
|
||
1. Generate migration file (you can do it manually) | ||
2. Implement DDL | ||
3. Execute migration | ||
|
||
#### Migration File Creation Command | ||
|
||
```sh | ||
make migrate_create NAME="file name" | ||
``` | ||
|
||
### Migration Execution Command | ||
|
||
```sh | ||
make migrate_up | ||
``` | ||
|
||
### Rollback Command for Migration | ||
|
||
If STEP is not passed as an argument, everything will be rolled back. | ||
|
||
```sh | ||
make migrate_down STEP=1 | ||
``` | ||
|
||
### DML Implementation | ||
|
||
Implement the query in the file `api/internal/db/query`. | ||
|
||
Reference: https://docs.sqlc.dev/en/latest/howto/select.html | ||
|
||
When adding a new model, add it to rename in `api/sqlc.yml` so that the App prefix is not attached to the model name. | ||
|
||
After implementing the query, run the `splc generate` command. | ||
|
||
```sh | ||
make sqlc_gen | ||
``` | ||
|
||
### Model Implementation | ||
|
||
the model generated by the `sqlc generate` command is placed in `api/internal/model`. | ||
|
||
The model implements business logic, etc. | ||
|
||
### Request Handler Implementation | ||
|
||
The request handler implementation is placed in `api/internal/handler`. | ||
|
||
The request handler implements request validation, etc. | ||
|
||
### Implement Request Routing | ||
|
||
Implement request routing in `api/internal/server/router.go`. |
Oops, something went wrong.