diff --git a/doc/development.md b/doc/development.md new file mode 100644 index 00000000..15408ea7 --- /dev/null +++ b/doc/development.md @@ -0,0 +1,291 @@ +# Doing Development on Friendly Feud + +## Table of Contents +1. [Project Structure](#project-structure) +2. [Dependencies](#dependencies) +3. [Setup Instructions](#setup-instructions) +4. [Quick Start](#quick-start) +5. [Running Development](#running-development) +6. [End-to-End Testing](#end-to-end-testing) +7. [Frontend Overview](#frontend-overview) +8. [Backend Overview](#backend-overview) +9. [Troubleshooting](#troubleshooting) +10. [Contributing Guidelines](#contributing-guidelines) + +## Project Structure +```plaintext +├── backend/ # Golang backend +│ ├── api/ # Backend API and websocket logic +│ ├── Dockerfile # Backend Dockerfile +│ ├── main.go # Entry point for backend server +├── docker/ # Docker and nginx configuration files +│ ├── allinone/ # All-in-one Docker configuration +│ ├── nginx/ # Nginx configuration +│ └── docker-compose*.yaml # Docker compose files +├── doc/ # Documentation and development guide +├── e2e/ # End-to-end tests using Playwright +├── games/ # Pre-built game files in JSON format +├── i18n/ # Localization and translation files +├── public/ # Static assets (images, fonts, etc.) +├── scripts/ # Utility scripts for game creation +├── Dockerfile # Frontend dockerfile +├── Dockerfile.allinone # All-in-one dockerfile +├── src/ # Next.js frontend +│ ├── components/ # React components +│ ├── lib/ # Utility functions +│ ├── pages/ # Next.js page components +``` + + +## Dependencies + +### System Requirements + +- [Docker](https://docs.docker.com/engine/install/) +- [Docker Compose](https://docs.docker.com/compose/install/) +- [Node.js](https://nodejs.org/) (version specified in `.nvmrc`) +- [Go](https://go.dev/doc/install) +- [Make](https://www.gnu.org/software/make/) + +> Note: Required versions are not updated, but newest versions should work 😅 + +## Setup Instructions + +### Windows Setup + +For Windows users, we recommend using WSL. + +You might need to configure Windows firewall to allow WSL network access: +```powershell +# Add outbound rules +netsh advfirewall firewall add rule name="WSL2 HTTPS Out" dir=out action=allow protocol=TCP localport=443 +netsh advfirewall firewall add rule name="WSL2 HTTP Out" dir=out action=allow protocol=TCP localport=80 +# Add inbound rules +netsh advfirewall firewall add rule name="WSL2 HTTPS" dir=in action=allow protocol=TCP localport=443 +netsh advfirewall firewall add rule name="WSL2 HTTP" dir=in action=allow protocol=TCP localport=80 +``` + +### Linux Setup + +Install dependencies + +## Quick Start +1. Install dependencies +2. Clone the repository +3. Start development environment: + ```bash + make dev + ``` +4. Access the application at [localhost](https://localhost/) + +## Running development +The stack consists of: + +- `frontend`: Next.js +- `backend`: Golang +- `proxy`: Nginx as the entry point + +The development environment is managed through a Makefile. Key commands include: + +- `make dev`: Builds and starts the development stack +- `make dev-background`: Same as `make dev`, but detaches +- `make dev-down`: Stops/removes the development stack + +Access the application at [localhost/](https://localhost/) + +The compose files should automatically be selected by the Makefile, but you can: +- check out the [Linux version](../docker/docker-compose.yaml) if on Linux or Macos +- check out the [WSL version](../docker/docker-compose-dev-wsl.yaml) if on Windows + +## End-to-End Testing + +`make e2e-ui` will launch [playwright](https://playwright.dev/) + +The e2e tests are located in the [e2e](../e2e/) folder. + +Tests are marked with their `*.spec.js` file name + +## Frontend Overview +The frontend is using `Next.js` as its way to serve pages. + +[Next.js Project Structure](https://nextjs.org/docs/app/getting-started/project-structure) + +Code is arranged in the [./src](../src/) folder with [./src/pages/index.jsx](../src/pages/index.jsx) being the entry point + +From there you can expect the usual React functionality. + +The `frontend` connects back to the `backend` via the `nginx` proxy to setup a WebSocket connection that will control its behavior when data comes in. + +We store a cookie to keep the user's session in the game as they refresh the page. + +### Working with styles + +You can use anything from [TailwindCSS](https://tailwindcss.com/) as long as the colors you use match the colors found in [tailwind.config.js](../tailwind.config.js) + +```js +// .... +success: { + 900: "#14532D", + 700: "#15803D", + 500: "#22C55E", + 300: "#86EFAC", + 200: "#BBF7D0", +}, +secondary: { + 900: "#A1A1AA", + 700: "#D4D4D8", + 500: "#E4E4E7", + 300: "#F4F4F5", + 200: "#FAFAFA", +}, +// .... +``` + +This looks like + +```html +