2023-12-03 23:08:31 +00:00
# BoardWise Website
2023-11-28 17:50:13 +00:00
2023-12-03 23:08:31 +00:00
This is the repository containing both the [Phoenix ](https://www.phoenixframework.org/ )
backend and [React ](https://react.dev/ ) frontend of [boardwise.gg ](https://www.boardwise.gg ).
We use [nix ](https://nixos.org/ ) for both development and release.
2023-11-28 17:50:13 +00:00
## Quickstart
2023-12-03 23:08:31 +00:00
[direnv ](https://direnv.net/ ) can be used to launch a dev shell upon entering
this directory (refer to `.envrc` ). Otherwise run via:
```bash
$ nix develop
```
Once you have a nix development shell open, create a new Postgres cluster at
`/db` :
```bash
$ pg_ctl -D db init
```
To start the database, run the following:
2023-11-28 17:50:13 +00:00
```bash
2023-12-01 18:00:43 +00:00
$ pg_ctl -D db -l db/logfile -o --unix_socket_directories=@boardwise start
2023-11-28 17:50:13 +00:00
```
2023-12-01 18:00:43 +00:00
In the above command, `@boardwise` refers to an [abstract socket name ](https://www.postgresql.org/docs/15/runtime-config-connection.html#GUC-UNIX-SOCKET-DIRECTORIES ).
Rename to whatever is appropriate for your use case. To then connect to this
database instance, run:
2023-11-28 17:50:13 +00:00
```bash
2023-12-01 18:00:43 +00:00
$ psql -h @boardwise
2023-11-28 17:50:13 +00:00
```
2023-12-01 18:00:43 +00:00
To later shut the database down, run:
2023-11-28 17:50:13 +00:00
```bash
2023-12-01 18:00:43 +00:00
$ pg_ctl -D db stop
2023-11-28 17:50:13 +00:00
```
2023-12-03 23:08:31 +00:00
Once the database is running, you can invoke the following Phoenix setup
commands:
2023-11-28 17:50:13 +00:00
```bash
2023-12-01 18:00:43 +00:00
$ mix ecto.setup
$ mix assets.setup
2023-12-03 23:08:31 +00:00
$ cd assets & & npm install
2023-11-28 17:50:13 +00:00
```
2023-12-03 23:08:31 +00:00
Afterward start the local server:
2023-11-28 17:50:13 +00:00
```bash
2023-12-01 18:00:43 +00:00
$ mix phx.server
2023-11-28 17:50:13 +00:00
```
2023-12-03 23:08:31 +00:00
## Release
To create a new [Mix release ](https://hexdocs.pm/mix/1.12/Mix.Tasks.Release.html ),
run `nix build` (after updating dependencies as outlined in the below sections).
You can test the release is functional by running:
```bash
$ export DATABASE_URL=ecto://< username > :< password > @< host > /< db_name >
$ export SECRET_KEY_BASE=$(mix phx.gen.secret)
$ result/bin/boardwise start
```
2023-11-28 17:50:13 +00:00
2023-12-02 13:38:08 +00:00
### Backend
Mix dependencies are packaged using [mix2nix ](https://github.com/ydlr/mix2nix ).
2023-11-28 17:50:13 +00:00
After updating your `mix.lock` file, make sure to re-run the following:
```bash
2023-12-01 18:00:43 +00:00
$ mix2nix > deps.nix
2023-11-28 17:50:13 +00:00
```
As of now, `mix2nix` cannot handle git dependencies found inside the `mix.lock`
file. If you have git dependencies, add them manually or use
[FODs ](https://nixos.org/manual/nixpkgs/stable/#packaging-beam-applications ).
2023-11-29 17:01:06 +00:00
2023-12-02 13:38:08 +00:00
### Frontend
Frontend dependencies (i.e. assets found in the `/assets` folder) are packaged
using [node2nix ](https://github.com/svanderburg/node2nix ). You can generate the
relevant nix files for import using the following sequence of commands:
```bash
$ cd assets
2023-12-03 23:08:31 +00:00
$ rm -r node_modules
2023-12-02 13:38:08 +00:00
$ node2nix -l
```
In the above, we must remove `node_modules` (if it exists). Otherwise the
node packages will be included in the Nix build, influencing the outcome of
`node2nix` . The above generates three files:
* `node-packages.nix`
* Captures the packages that can be deployed (including all its required
dependencies)
* `node-env.nix`
* Contains build logic
* `default.nix`
* A composition expression allowing users to deploy the package. For an
example of this deployment, refer to `flake.nix`
NOTE: Do not update the lock version used in `assets` . `node2nix` currently only
supports lock versions 1 and 2.
2023-12-03 22:57:57 +00:00
## Development
2023-12-03 23:08:31 +00:00
It's strongly advised to use `nix develop` when performing local development.
Doing so automatically includes the following features:
2023-12-03 22:57:57 +00:00
### Language Server
2023-11-29 17:01:06 +00:00
The [elixir-ls ](https://github.com/elixir-lsp/elixir-ls ) LSP (version 0.17.10)
2023-12-02 13:38:08 +00:00
and [typescript-language-server ](https://github.com/typescript-language-server/typescript-language-server )
(version 4.1.2) is included in this flake.
2023-11-29 17:01:06 +00:00
2023-12-03 22:57:57 +00:00
### Formatting
2023-11-29 17:01:06 +00:00
2023-12-02 13:38:08 +00:00
Formatting depends on [prettier ](https://prettier.io/ ) (version 3.1.0) and the
`mix format` task. A `pre-commit` hook is included in `.githooks` that can be
used to format all `*.exs?` , `*.jsx?` , and `*.tsx?` files prior to commit.
2023-11-29 17:01:06 +00:00
Install via:
```bash
2023-12-01 18:00:43 +00:00
$ git config --local core.hooksPath .githooks/
2023-11-29 17:01:06 +00:00
```
If running [direnv ](https://direnv.net/ ), this hook is installed automatically
when entering the directory.