Skip to content

Commit

Permalink
refactor: change project layout
Browse files Browse the repository at this point in the history
  • Loading branch information
enisdenjo committed Nov 23, 2023
1 parent 960831b commit 98d2e85
Show file tree
Hide file tree
Showing 67 changed files with 48 additions and 47 deletions.
5 changes: 3 additions & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
# Allow files and directories
!go.mod
!go.sum
!/cmd/**
!/pkg/**
!/database/**
!/graphql/**
!/server/**
!/internal/**
!/app/**

# Ignore unnecessary files inside allowed directories
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/graphql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:

defaults:
run:
working-directory: cmd/graphql
working-directory: graphql

jobs:
type-check:
Expand All @@ -28,7 +28,7 @@ jobs:
- name: Cache
uses: actions/cache@v2
with:
path: cmd/graphql/.yarn/cache
path: graphql/.yarn/cache
key: ${{ runner.os }}-graphql-yarn-cache-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-graphql-yarn-cache-
Expand All @@ -50,7 +50,7 @@ jobs:
- name: Cache
uses: actions/cache@v2
with:
path: cmd/graphql/.yarn/cache
path: graphql/.yarn/cache
key: ${{ runner.os }}-graphql-yarn-cache-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-graphql-yarn-cache-
Expand Down
2 changes: 1 addition & 1 deletion app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
"packageManager": "[email protected]",
"scripts": {
"get-schema-enums": "yarn relay-enum-generator --schema ../cmd/graphql/schema.graphql --path ./src --name enums.graphql.ts && echo \"/* tslint:disable */\n/* eslint-disable */\n// @ts-nocheck\n\n$(cat src/enums.graphql.ts)\" > src/enums.graphql.ts",
"get-schema-enums": "yarn relay-enum-generator --schema ../graphql/schema.graphql --path ./src --name enums.graphql.ts && echo \"/* tslint:disable */\n/* eslint-disable */\n// @ts-nocheck\n\n$(cat src/enums.graphql.ts)\" > src/enums.graphql.ts",
"relay": "relay-compiler",
"relay:clean": "rimraf $(find . -type d -name __generated__)",
"lint": "eslint 'src/**/*.{js,jsx,ts,tsx}'",
Expand Down
2 changes: 1 addition & 1 deletion app/relay.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
language: 'typescript',
schema: '../cmd/graphql/schema.graphql',
schema: '../graphql/schema.graphql',
src: './src',
eagerEsModules: true,
noFutureProofEnums: true,
Expand Down
1 change: 0 additions & 1 deletion cmd/graphql/.env

This file was deleted.

2 changes: 1 addition & 1 deletion database/schema/public/file.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ create index file_created_by_idx on public.file (created_by);
create function public.file_link(
file public.file
) returns text as $$
-- matches the route specified in cmd/server/routes/routes.go
-- matches the route specified in server/routes/routes.go
select '/api/file/' || file.id::text
$$ language sql stable strict;
comment on function public.file_link is '@notNull';
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.override.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ services:
- ./database:/docker-entrypoint-initdb.d
graphql:
volumes:
- ./cmd/graphql/schema.graphql:/opt/graphql/dist/schema.graphql
- ./graphql/schema.graphql:/opt/graphql/dist/schema.graphql
ports:
- ${GRAPHQL_PORT}:${GRAPHQL_PORT}
server:
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ services:
image: ghcr.io/bhidapa/heltin-graphql
build:
context: .
dockerfile: ./cmd/graphql/Dockerfile
dockerfile: ./graphql/Dockerfile
networks:
- local
environment:
Expand All @@ -65,7 +65,7 @@ services:
image: ghcr.io/bhidapa/heltin-server
build:
context: .
dockerfile: ./cmd/server/Dockerfile
dockerfile: ./server/Dockerfile
networks:
- local
environment:
Expand Down
1 change: 1 addition & 0 deletions graphql/.env
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
14 changes: 7 additions & 7 deletions cmd/graphql/Dockerfile → graphql/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ LABEL org.opencontainers.image.source https://github.com/bhidapa/heltin
WORKDIR /graphql

# yarn setup
COPY cmd/graphql/.yarn/releases ./.yarn/releases
COPY cmd/graphql/.yarn/plugins ./.yarn/plugins
COPY cmd/graphql/.yarnrc.yml .
COPY graphql/.yarn/releases ./.yarn/releases
COPY graphql/.yarn/plugins ./.yarn/plugins
COPY graphql/.yarnrc.yml .

# install deps
COPY cmd/graphql/yarn.lock .
COPY cmd/graphql/package.json .
COPY graphql/yarn.lock .
COPY graphql/package.json .
RUN yarn install --immutable

# build
COPY cmd/graphql/tsconfig.json .
COPY cmd/graphql/src .
COPY graphql/tsconfig.json .
COPY graphql/src .
RUN yarn build

FROM node:18-bullseye-slim
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion cmd/graphql/src/index.ts → graphql/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const session = createSession({
secret: config.sessionSecret,
trustProxy: true,
cookie: {
name: 'heltin.sid', // synchronised with pkg/session
name: 'heltin.sid', // synchronised with internal/session
secure: config.sessionSecure,
sameSite: 'lax',
httpOnly: true,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion pkg/file/config.go → internal/file/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package file
import (
_ "embed"

"github.com/bhidapa/heltin/pkg/env"
"github.com/bhidapa/heltin/internal/env"
rootlog "github.com/domonda/golog/log"
"github.com/ungerik/go-fs"
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/file/delete.go → internal/file/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package file
import (
"context"

"github.com/bhidapa/heltin/pkg/session"
"github.com/bhidapa/heltin/internal/session"
"github.com/domonda/go-errs"
"github.com/domonda/go-sqldb/db"
"github.com/domonda/go-types/uu"
Expand Down
2 changes: 1 addition & 1 deletion pkg/file/download.go → internal/file/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"fmt"
"net/http"

"github.com/bhidapa/heltin/pkg/session"
"github.com/bhidapa/heltin/internal/session"
"github.com/domonda/go-errs"
"github.com/domonda/go-sqldb/db"
"github.com/domonda/go-types/uu"
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion pkg/file/upload.go → internal/file/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"net/http"
"strings"

"github.com/bhidapa/heltin/pkg/session"
"github.com/bhidapa/heltin/internal/session"
"github.com/ungerik/go-fs"
"github.com/ungerik/go-fs/multipartfs"
"github.com/ungerik/go-httpx/httperr"
Expand Down
2 changes: 1 addition & 1 deletion pkg/pdf/config.go → internal/pdf/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package pdf
import (
"fmt"

"github.com/bhidapa/heltin/pkg/env"
"github.com/bhidapa/heltin/internal/env"
rootlog "github.com/domonda/golog/log"
)

Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion pkg/postgres/connect.go → internal/postgres/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"time"

"github.com/bhidapa/heltin/pkg/env"
"github.com/bhidapa/heltin/internal/env"
"github.com/domonda/go-sqldb"
"github.com/domonda/go-sqldb/db"
"github.com/domonda/go-sqldb/pqconn"
Expand Down
File renamed without changes
File renamed without changes
8 changes: 4 additions & 4 deletions pkg/reports/conclusion.go → internal/reports/conclusion.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (
"errors"
"time"

"github.com/bhidapa/heltin/pkg/casestudy"
"github.com/bhidapa/heltin/pkg/file"
"github.com/bhidapa/heltin/pkg/pdf"
"github.com/bhidapa/heltin/pkg/session"
"github.com/bhidapa/heltin/internal/casestudy"
"github.com/bhidapa/heltin/internal/file"
"github.com/bhidapa/heltin/internal/pdf"
"github.com/bhidapa/heltin/internal/session"
"github.com/domonda/go-errs"
"github.com/domonda/go-sqldb"
"github.com/domonda/go-sqldb/db"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions pkg/reports/treatment.go → internal/reports/treatment.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"errors"
"time"

"github.com/bhidapa/heltin/pkg/file"
"github.com/bhidapa/heltin/pkg/pdf"
"github.com/bhidapa/heltin/pkg/session"
"github.com/bhidapa/heltin/internal/file"
"github.com/bhidapa/heltin/internal/pdf"
"github.com/bhidapa/heltin/internal/session"
"github.com/domonda/go-errs"
"github.com/domonda/go-sqldb"
"github.com/domonda/go-sqldb/db"
Expand Down
4 changes: 2 additions & 2 deletions pkg/session/config.go → internal/session/config.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package session

import (
"github.com/bhidapa/heltin/pkg/env"
"github.com/bhidapa/heltin/internal/env"
rootlog "github.com/domonda/golog/log"
)

Expand All @@ -13,7 +13,7 @@ var (
}
)

const cookieName = "heltin.sid" // synchronised with cmd/graphql/index.ts
const cookieName = "heltin.sid" // synchronised with graphql/index.ts

func init() {
err := env.Parse(&config)
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion pkg/session/session.go → internal/session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ type Session struct {
CreatedAt time.Time `db:"created_at"`
}

// SessionCookie is the session cookie and it matches the SessionCookie in cmd/graphql/src/session.ts@SessionCookie
// SessionCookie is the session cookie and it matches the SessionCookie in graphql/src/session.ts@SessionCookie
type SessionCookie struct {
Domain string `json:"domain"`
Path string `json:"path"`
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions cmd/server/Dockerfile → server/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ COPY go.mod .
COPY go.sum .
RUN go mod download -x

COPY pkg ./pkg
COPY cmd/server ./cmd/server
COPY internal ./internal
COPY server ./server
RUN set -eux; \
cd cmd/server; \
cd server; \
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 \
go build -v -o /heltin-server

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions cmd/server/routes/routes.go → server/routes/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"fmt"
"net/http"

"github.com/bhidapa/heltin/pkg/file"
"github.com/bhidapa/heltin/pkg/session"
"github.com/bhidapa/heltin/internal/file"
"github.com/bhidapa/heltin/internal/session"
"github.com/gorilla/mux"

"github.com/domonda/go-function"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"encoding/json"
"reflect"

"github.com/bhidapa/heltin/pkg/file"
"github.com/bhidapa/heltin/pkg/reports"
"github.com/bhidapa/heltin/internal/file"
"github.com/bhidapa/heltin/internal/reports"

"github.com/domonda/go-function"
"github.com/domonda/go-types/uu"
Expand Down
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions cmd/server/server.go → server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (
"net/http"
"time"

"github.com/bhidapa/heltin/cmd/server/routes"
"github.com/bhidapa/heltin/pkg/env"
"github.com/bhidapa/heltin/pkg/postgres"
"github.com/bhidapa/heltin/pkg/session"
"github.com/bhidapa/heltin/internal/env"
"github.com/bhidapa/heltin/internal/postgres"
"github.com/bhidapa/heltin/internal/session"
"github.com/bhidapa/heltin/server/routes"
"github.com/domonda/go-errs"
"github.com/domonda/go-sqldb/db"
"github.com/domonda/golog/log"
Expand Down

0 comments on commit 98d2e85

Please sign in to comment.