Skip to content

Commit

Permalink
Merge pull request #2 from GenerateNU/docker-setup
Browse files Browse the repository at this point in the history
Fullstack setup
  • Loading branch information
aniamisiorek authored Jan 11, 2024
2 parents 74f38f4 + 2a2cc91 commit a569539
Show file tree
Hide file tree
Showing 16 changed files with 572 additions and 43 deletions.
17 changes: 16 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# Installing frontend dependencies
.PHONY: frontend-dep
frontend-dep:
cd frontend && yarn install

# Installing backend dependencies
.PHONY: backend-dep
backend-dep:
cd backend && go get .

# Lint backend source code
.PHONY: backend-lint
backend-lint:
Expand All @@ -6,4 +16,9 @@ backend-lint:
# Format backend source code
.PHONY: backend-format
backend-format:
cd backend && go fmt
cd backend && go fmt

# Run backend
.PHONY: backend-run
backend-run:
cd backend && go run main.go
27 changes: 24 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Fullstack application for the Algo project

## Quick Start

> TBD
```git clone [email protected]:GenerateNU/Algo.git```

## Set Up Your Development Environment
First, understand the tech stack:
Expand All @@ -17,16 +17,37 @@ Before compiling and running our application, we need to install several languag
The installation process can vary, so follow the instructions for each item below!

- [Go](https://go.dev/doc/install) - our primary backend language
- Afterwards, install all go dependencies with the command `go get .` in the root directory. This needs to be re-run if dependencies change.
- Afterwards, install all go dependencies using `make backend-dep`.
- [yarn](https://classic.yarnpkg.com/en/docs/install#mac-stable) - our package manager in the frontend
- Afterwards, install all yarn dependencies with the command `yarn --dir frontend install` in the root directory.
- Afterwards, install all yarn dependencies using `make frontend-dep`.

If everything was successful, you can now compile and run the project!

### Extra Dependencies
- go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
- go install github.com/cosmtrek/air@latest

### Tools
We will be using some tools to make development a bit easier.

- [Swagger](https://github.com/swaggo/swag) - Will allow us to visualize the API and query requests from the database.
- [Makefile](https://opensource.com/article/18/8/what-how-makefile) - Will allow us to easily run scripts by consolidating them into Makefile commands. Make sure to read up about each command and ask questions. You should know what you are running!

### Third party integrations
For this project, we will be using some third-party APIs.

- [Morgan Stanley E-Trade](https://apisb.etrade.com/docs/api/authorization/request_token.html) - Our users will be able to log into their account using SSO. This is where we will pull portfolio data and make trade orders if requested. For testing purposes, we _highly_ recommend opening an E-Trade account. However, we understand money and financial information is highly sensitive, so if you do not feel comfortable opening an account, please let us know.

## Running the project

### Docker
We will be containerizing our PostGreSQL database in Docker. Follow the steps below to add the DB to your local machine.

1. Install [Docker](https://docs.docker.com/get-docker/)
You should be able to run `docker` in your terminal if this was successful.
2. Install [Docker Desktop](https://www.docker.com/products/docker-desktop/)
3. Run `docker-compose up` from the root directory, this will spin up a postgres image.

### Backend
1. From root directory, run `make backend-run`

62 changes: 62 additions & 0 deletions backend/configurations/configuration.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package configuration

import (
"fmt"
"os"
"path/filepath"
"runtime"

"github.com/spf13/viper"
)

type Settings struct {
Database DatabaseSettings `yaml:"database"`
}

type DatabaseSettings struct {
Username string `yaml:"username"`
Password string `yaml:"password"`
Port uint16 `yaml:"port"`
Host string `yaml:"host"`
DatabaseName string `yaml:"databasename"`
RequireSSL bool `yaml:"requiressl"`
}

type Environment string

const (
EnvironmentLocal Environment = "local"
EnvironmentProduction Environment = "production"
)

var (
_, b, _, _ = runtime.Caller(0)
basepath = filepath.Dir(b)
)

func GetConfiguration() (Settings, error) {
v := viper.New()
v.SetConfigType("yaml")
v.AddConfigPath(basepath)

var settings Settings

var environment Environment
if env := os.Getenv("GITHUB_ACTIONS"); env != "" {
environment = Environment("github")
} else {
environment = "local"
}

v.SetConfigName(string(environment))

if err := v.ReadInConfig(); err != nil {
return settings, fmt.Errorf("failed to read %s configuration: %w", "local", err)
}

if err := v.Unmarshal(&settings); err != nil {
return settings, fmt.Errorf("failed to unmarshal configuration: %w", err)
}

return settings, nil
}
7 changes: 7 additions & 0 deletions backend/configurations/templates/github.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
database:
host: '172.17.0.1'
port: 5432
username: 'user'
password: 'pwd'
databasename: 'carewallet'
requiressl: false
7 changes: 7 additions & 0 deletions backend/configurations/templates/local.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
database:
host: 'localhost'
port: 5434
username: 'user'
password: 'pwd'
databasename: 'carewallet'
requiressl: false
66 changes: 58 additions & 8 deletions backend/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,83 @@ module backend

go 1.21.5

require (
github.com/gin-gonic/gin v1.9.1
github.com/jackc/pgx v3.6.2+incompatible
github.com/spf13/viper v1.18.2
github.com/swaggo/files v1.0.1
github.com/swaggo/gin-swagger v1.6.0
gorm.io/driver/postgres v1.5.4
gorm.io/gorm v1.25.5
)

require (
github.com/KyleBanks/depth v1.2.1 // indirect
github.com/PuerkitoBio/purell v1.2.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/bytedance/sonic v1.9.1 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
github.com/cockroachdb/apd v1.1.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.3 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-openapi/jsonpointer v0.20.2 // indirect
github.com/go-openapi/jsonreference v0.20.4 // indirect
github.com/go-openapi/spec v0.20.13 // indirect
github.com/go-openapi/spec v0.20.14 // indirect
github.com/go-openapi/swag v0.22.7 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.14.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/gofrs/uuid v4.4.0+incompatible // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/jackc/fake v0.0.0-20150926172116-812a484cc733 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
github.com/jackc/pgx/v5 v5.4.3 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/labstack/echo/v4 v4.11.4 // indirect
github.com/labstack/gommon v0.4.2 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/lib/pq v1.10.9 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/shopspring/decimal v1.3.1 // indirect
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/swaggo/swag v1.16.2 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.11 // indirect
github.com/urfave/cli/v2 v2.27.1 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
github.com/xrash/smetrics v0.0.0-20231213231151-1d8dd44e695e // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/net v0.19.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/arch v0.3.0 // indirect
golang.org/x/crypto v0.18.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/net v0.20.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.16.1 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
Expand Down
Loading

0 comments on commit a569539

Please sign in to comment.