From 505c9b39686fa8311fe9ed1397d4cca1a5e13783 Mon Sep 17 00:00:00 2001 From: Oscar Roche Date: Tue, 16 Sep 2025 15:20:51 +0200 Subject: [PATCH 1/5] :construction_worker: add dockerfiles / docker-compose --- .env.example | 2 +- backend/Dockerfile | 17 +++++++++++++++++ docker-compose.yml | 43 +++++++++++++++++++++++++++++++++++++++++++ frontend/Dockerfile | 15 +++++++++++++++ 4 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 backend/Dockerfile create mode 100644 docker-compose.yml create mode 100644 frontend/Dockerfile diff --git a/.env.example b/.env.example index e934082..422a1df 100644 --- a/.env.example +++ b/.env.example @@ -1,5 +1,5 @@ # Database -DATABASE_URL=postgres://guild_user:guild_password@localhost:5432/guild_genesis +DATABASE_URL=postgres://guild_user:guild_password@postgres:5432/guild_genesis # Frontend PUBLIC_WALLET_CONNECT_PROJECT_ID=your_project_id_here diff --git a/backend/Dockerfile b/backend/Dockerfile new file mode 100644 index 0000000..d915913 --- /dev/null +++ b/backend/Dockerfile @@ -0,0 +1,17 @@ +FROM rust:latest AS build +WORKDIR /app +COPY . . +RUN cargo build --release + +FROM debian:bookworm-slim +RUN apt-get update && apt-get install -y --no-install-recommends \ + netcat-openbsd \ + && rm -rf /var/lib/apt/lists/* +RUN useradd -m appuser +WORKDIR /app +COPY --from=build /app/target/release/guild-backend /app/app +ENV RUST_LOG=info PORT=3001 +EXPOSE 3001 +USER appuser +CMD ["/app/app"] + diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..4301ba5 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,43 @@ +version: "3.9" + +services: + postgres: + image: postgres:16 + environment: + POSTGRES_USER: guild_user + POSTGRES_PASSWORD: guild_password + POSTGRES_DB: guild_genesis + ports: + - "5432:5432" + volumes: + - pg_data:/var/lib/postgresql/data + + backend: + build: ./backend + command: ["/app/app"] + environment: + RUST_LOG: debug + RUST_BACKTRACE: 1 + PORT: 3001 + env_file: + - .env + ports: + - "3001:3001" + depends_on: + - postgres + + frontend: + build: ./frontend + command: npm run dev -- --host 0.0.0.0 --port 4321 + ports: + - "4321:4321" + environment: + HOST: 0.0.0.0 + PORT: 4321 + PUBLIC_WALLET_CONNECT_PROJECT_ID: ${PUBLIC_WALLET_CONNECT_PROJECT_ID} + PUBLIC_API_URL: ${PUBLIC_API_URL} + depends_on: + - backend + +volumes: + pg_data: diff --git a/frontend/Dockerfile b/frontend/Dockerfile new file mode 100644 index 0000000..faca66e --- /dev/null +++ b/frontend/Dockerfile @@ -0,0 +1,15 @@ +FROM node:20-alpine AS build +WORKDIR /app +RUN apk add --no-cache python3 make g++ +COPY package*.json ./ +RUN npm ci +COPY . . +RUN npm run build + +FROM node:20-alpine +WORKDIR /app +ENV NODE_ENV=production +COPY --from=build /app ./ +ENV PORT=8080 +EXPOSE 8080 +CMD ["node", "server.js"] From ee480caeb5822d24f94445655b6c6a15f5d69fa9 Mon Sep 17 00:00:00 2001 From: Oscar Roche Date: Wed, 17 Sep 2025 13:08:51 +0200 Subject: [PATCH 2/5] :wrench: update frontend build script --- frontend/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/package.json b/frontend/package.json index a311baa..db57557 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -4,7 +4,7 @@ "version": "0.0.1", "scripts": { "dev": "astro dev", - "build": "astro build && node dist/server/entry.mjs", + "build": "astro build", "preview": "astro preview", "astro": "astro", "test": "vitest", From 68432bb702cab7e535e5ef94410d66cebf92ecc7 Mon Sep 17 00:00:00 2001 From: Oscar Roche Date: Wed, 17 Sep 2025 13:09:08 +0200 Subject: [PATCH 3/5] :memo: update readme --- README.md | 86 ++++++------------------------------------------------- 1 file changed, 8 insertions(+), 78 deletions(-) diff --git a/README.md b/README.md index 35dbea7..345bd35 100644 --- a/README.md +++ b/README.md @@ -38,40 +38,21 @@ This is a monorepo containing: ## Quick Start ### Prerequisites -- [Nix](https://nixos.org/download.html) with flakes enabled -- [direnv](https://direnv.net/) (optional, for automatic environment loading) -- [just](https://github.com/casey/just) (command runner) +- [Docker](https://www.docker.com/) - [Foundry](https://book.getfoundry.sh/getting-started/installation) (for smart contracts) -### Setup - -1. **Clone and enter the development environment:** - ```bash - git clone - cd TheGuildGenesis - - # If using direnv (recommended) - direnv allow - - # Or manually enter the Nix shell - nix develop - ``` - -2. **Install dependencies:** - ```bash - just install-all - ``` - ### Development Workflow #### Quick Start ```bash -# Set up the database -just db-setup +cd backend +cargo install sqlx-cli --no-default-features --features rustls,postgres +cargo sqlx prepare -- --bin guild-backend +``` -# Start both frontend and backend -just dev +```bash +docker-compose up -d ``` **Access the applications:** @@ -79,35 +60,6 @@ just dev - Backend API: http://localhost:3001 - PostgreSQL: localhost:5432 -#### Individual Services - -```bash -# Start database only -just db-start - -# Start frontend only -just dev-frontend - -# Start backend only -just dev-backend - -# Stop database -just db-stop -``` - -#### Database Management - -```bash -# Set up database with migrations -just db-setup - -# Reset database completely -just db-reset - -# Stop database -just db-stop -``` - #### Smart Contracts Development ```bash @@ -132,17 +84,6 @@ forge script script/TheGuildBadgeRegistry.s.sol:TheGuildBadgeRegistryScript --rp forge script script/TheGuildBadgeRegistry.s.sol:TheGuildBadgeRegistryScript --rpc-url --private-key --broadcast ``` -### Available Commands - -Run `just help` to see all available commands: - -- **Development:** `just dev`, `just dev-frontend`, `just dev-backend` -- **Database:** `just db-start`, `just db-stop`, `just db-setup`, `just db-reset` -- **Build:** `just build`, `just build-frontend`, `just build-backend` -- **Testing:** `just test`, `just test-frontend`, `just test-backend` -- **Code Quality:** `just lint`, `just format` -- **Utilities:** `just clean`, `just help` - ## Smart Contracts The `the-guild-smart-contracts/` directory contains our Solidity smart contracts built with Foundry. @@ -203,27 +144,16 @@ event BadgeCreated(bytes32 indexed name, bytes32 description, address indexed cr ## Development Philosophy -- **Nix-first development** - Reproducible environments without Docker overhead - **Simple first, complex later** - Start with MVP, iterate - **Non-profit, member-driven** - Community ownership - **Horizontal governance** - Flat organization structure - **Action over endless talk** - Build and ship - **We use what we build** - Dogfooding our own tools -### Why Nix? - -This project uses Nix for development instead of Docker because: - -- **Reproducible environments** - Everyone gets identical toolchains -- **No container overhead** - Direct process execution, faster builds -- **Simpler setup** - One command (`nix develop`) gets you everything -- **Better performance** - No Docker daemon, faster file system access -- **True reproducibility** - Nix ensures exact same versions across all systems - ## Contributing This is a community-driven project. Join our [Discord](https://discord.gg/pg4UgaTr) to discuss features, propose changes, and contribute to the codebase. ## License -See [LICENSE](LICENSE) file for details. \ No newline at end of file +See [LICENSE](LICENSE) file for details. From c83ea9285ceca92b520a532891c1cb89819f5a82 Mon Sep 17 00:00:00 2001 From: Oscar Roche Date: Wed, 17 Sep 2025 13:09:18 +0200 Subject: [PATCH 4/5] :wrench: add sqlx files for docker build --- ...4a4956cb9189f2baed776e733f138fb7ccb3e.json | 50 ++++++++++++++++++ ...4b22a58f6b0ffa6f32d51a61a83bab2e74959.json | 19 +++++++ ...9f7fb50a0497388efd4fefff42391278f7fc9.json | 52 +++++++++++++++++++ ...8225baff0216a62ab2bc7a4a5dc2324ecf067.json | 14 +++++ ...169e252a1f7395ecf242f366fe44817fe11c7.json | 18 +++++++ 5 files changed, 153 insertions(+) create mode 100644 backend/.sqlx/query-14af4de80324b022defcc022ae84a4956cb9189f2baed776e733f138fb7ccb3e.json create mode 100644 backend/.sqlx/query-25dd1d31b19c5826968a9729d064b22a58f6b0ffa6f32d51a61a83bab2e74959.json create mode 100644 backend/.sqlx/query-8310e232b4c89fdd962e21fcf659f7fb50a0497388efd4fefff42391278f7fc9.json create mode 100644 backend/.sqlx/query-a478268fcaba59a09995733f4058225baff0216a62ab2bc7a4a5dc2324ecf067.json create mode 100644 backend/.sqlx/query-c70becfbfc2934ce1a453e9f1ef169e252a1f7395ecf242f366fe44817fe11c7.json diff --git a/backend/.sqlx/query-14af4de80324b022defcc022ae84a4956cb9189f2baed776e733f138fb7ccb3e.json b/backend/.sqlx/query-14af4de80324b022defcc022ae84a4956cb9189f2baed776e733f138fb7ccb3e.json new file mode 100644 index 0000000..3aa4dcf --- /dev/null +++ b/backend/.sqlx/query-14af4de80324b022defcc022ae84a4956cb9189f2baed776e733f138fb7ccb3e.json @@ -0,0 +1,50 @@ +{ + "db_name": "PostgreSQL", + "query": "\n SELECT address, name, description, avatar_url, created_at, updated_at\n FROM profiles\n ", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "address", + "type_info": "Varchar" + }, + { + "ordinal": 1, + "name": "name", + "type_info": "Varchar" + }, + { + "ordinal": 2, + "name": "description", + "type_info": "Text" + }, + { + "ordinal": 3, + "name": "avatar_url", + "type_info": "Text" + }, + { + "ordinal": 4, + "name": "created_at", + "type_info": "Timestamptz" + }, + { + "ordinal": 5, + "name": "updated_at", + "type_info": "Timestamptz" + } + ], + "parameters": { + "Left": [] + }, + "nullable": [ + false, + true, + true, + true, + true, + true + ] + }, + "hash": "14af4de80324b022defcc022ae84a4956cb9189f2baed776e733f138fb7ccb3e" +} diff --git a/backend/.sqlx/query-25dd1d31b19c5826968a9729d064b22a58f6b0ffa6f32d51a61a83bab2e74959.json b/backend/.sqlx/query-25dd1d31b19c5826968a9729d064b22a58f6b0ffa6f32d51a61a83bab2e74959.json new file mode 100644 index 0000000..801da35 --- /dev/null +++ b/backend/.sqlx/query-25dd1d31b19c5826968a9729d064b22a58f6b0ffa6f32d51a61a83bab2e74959.json @@ -0,0 +1,19 @@ +{ + "db_name": "PostgreSQL", + "query": "\n INSERT INTO profiles (address, name, description, avatar_url, created_at, updated_at)\n VALUES ($1, $2, $3, $4, $5, $6)\n ", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Varchar", + "Varchar", + "Text", + "Text", + "Timestamptz", + "Timestamptz" + ] + }, + "nullable": [] + }, + "hash": "25dd1d31b19c5826968a9729d064b22a58f6b0ffa6f32d51a61a83bab2e74959" +} diff --git a/backend/.sqlx/query-8310e232b4c89fdd962e21fcf659f7fb50a0497388efd4fefff42391278f7fc9.json b/backend/.sqlx/query-8310e232b4c89fdd962e21fcf659f7fb50a0497388efd4fefff42391278f7fc9.json new file mode 100644 index 0000000..f45800b --- /dev/null +++ b/backend/.sqlx/query-8310e232b4c89fdd962e21fcf659f7fb50a0497388efd4fefff42391278f7fc9.json @@ -0,0 +1,52 @@ +{ + "db_name": "PostgreSQL", + "query": "\n SELECT address, name, description, avatar_url, created_at, updated_at\n FROM profiles\n WHERE address = $1\n ", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "address", + "type_info": "Varchar" + }, + { + "ordinal": 1, + "name": "name", + "type_info": "Varchar" + }, + { + "ordinal": 2, + "name": "description", + "type_info": "Text" + }, + { + "ordinal": 3, + "name": "avatar_url", + "type_info": "Text" + }, + { + "ordinal": 4, + "name": "created_at", + "type_info": "Timestamptz" + }, + { + "ordinal": 5, + "name": "updated_at", + "type_info": "Timestamptz" + } + ], + "parameters": { + "Left": [ + "Text" + ] + }, + "nullable": [ + false, + true, + true, + true, + true, + true + ] + }, + "hash": "8310e232b4c89fdd962e21fcf659f7fb50a0497388efd4fefff42391278f7fc9" +} diff --git a/backend/.sqlx/query-a478268fcaba59a09995733f4058225baff0216a62ab2bc7a4a5dc2324ecf067.json b/backend/.sqlx/query-a478268fcaba59a09995733f4058225baff0216a62ab2bc7a4a5dc2324ecf067.json new file mode 100644 index 0000000..0ac2746 --- /dev/null +++ b/backend/.sqlx/query-a478268fcaba59a09995733f4058225baff0216a62ab2bc7a4a5dc2324ecf067.json @@ -0,0 +1,14 @@ +{ + "db_name": "PostgreSQL", + "query": "\n DELETE FROM profiles\n WHERE address = $1\n ", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Text" + ] + }, + "nullable": [] + }, + "hash": "a478268fcaba59a09995733f4058225baff0216a62ab2bc7a4a5dc2324ecf067" +} diff --git a/backend/.sqlx/query-c70becfbfc2934ce1a453e9f1ef169e252a1f7395ecf242f366fe44817fe11c7.json b/backend/.sqlx/query-c70becfbfc2934ce1a453e9f1ef169e252a1f7395ecf242f366fe44817fe11c7.json new file mode 100644 index 0000000..2fb7630 --- /dev/null +++ b/backend/.sqlx/query-c70becfbfc2934ce1a453e9f1ef169e252a1f7395ecf242f366fe44817fe11c7.json @@ -0,0 +1,18 @@ +{ + "db_name": "PostgreSQL", + "query": "\n UPDATE profiles\n SET name = $2, description = $3, avatar_url = $4, updated_at = $5\n WHERE address = $1\n ", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Text", + "Varchar", + "Text", + "Text", + "Timestamptz" + ] + }, + "nullable": [] + }, + "hash": "c70becfbfc2934ce1a453e9f1ef169e252a1f7395ecf242f366fe44817fe11c7" +} From ed17721270dd2e209b649628060c9009ed52627f Mon Sep 17 00:00:00 2001 From: Oscar Roche Date: Wed, 17 Sep 2025 13:12:37 +0200 Subject: [PATCH 5/5] :fire: remove justfile --- justfile | 138 ------------------------------------------------------- 1 file changed, 138 deletions(-) delete mode 100644 justfile diff --git a/justfile b/justfile deleted file mode 100644 index d8ac461..0000000 --- a/justfile +++ /dev/null @@ -1,138 +0,0 @@ -# The Guild Genesis - Development Commands - -# Start both frontend and backend in development mode -dev: - @echo "๐Ÿš€ Starting The Guild Genesis development servers..." - @echo "Starting frontend and backend in parallel..." - @just dev-frontend & - @just dev-backend & - @wait - -# Start frontend development server -dev-frontend: - @echo "๐ŸŽจ Starting Astro frontend..." - cd frontend && npm run dev - -# Start backend development server -dev-backend: - @echo "๐Ÿฆ€ Starting Rust backend..." - cd backend && cargo run --bin guild-backend - -# Install all dependencies -install-all: - @echo "๐Ÿ“ฆ Installing dependencies..." - cd frontend && npm install - cd backend && cargo build - -# Database commands using Nix PostgreSQL -db-start: - @echo "๐Ÿ—„๏ธ Starting PostgreSQL database..." - @if [ ! -d ".postgres" ]; then \ - echo "Initializing PostgreSQL database..."; \ - initdb -D .postgres; \ - fi - @echo "Starting PostgreSQL server..." - pg_ctl -D .postgres -l .postgres/postgres.log start - @echo "โœ… PostgreSQL started on localhost:5432" - -db-stop: - @echo "๐Ÿ›‘ Stopping PostgreSQL database..." - pg_ctl -D .postgres stop - @echo "โœ… PostgreSQL stopped" - -db-setup: - @echo "๐Ÿ—„๏ธ Setting up database..." - @just db-start - @echo "Creating database and user..." - createdb guild_genesis || true - psql -d guild_genesis -c "CREATE USER guild_user WITH PASSWORD 'guild_password';" || true - psql -d guild_genesis -c "GRANT ALL PRIVILEGES ON DATABASE guild_genesis TO guild_user;" || true - @echo "Running migrations..." - cd backend && cargo run --bin migrate - @echo "โœ… Database setup complete" - -db-reset: - @echo "๐Ÿ”„ Resetting database..." - @just db-stop - @just db-setup - -# Build commands -build: - @echo "๐Ÿ”จ Building all services..." - cd frontend && npm run build - cd backend && cargo build --release - -build-frontend: - @echo "๐ŸŽจ Building frontend..." - cd frontend && npm run build - -build-backend: - @echo "๐Ÿฆ€ Building backend..." - cd backend && cargo build --release - -# Testing -test: - @echo "๐Ÿงช Running tests..." - cd frontend && npm run test:run - cd backend && cargo test --test simple_tests - -test-frontend: - @echo "๐Ÿงช Running frontend tests..." - cd frontend && npm run test:run - -test-backend: - @echo "๐Ÿงช Running backend tests..." - cd backend && cargo test --test simple_tests - -# Linting and formatting -lint: - @echo "๐Ÿ” Linting code..." - cd frontend && npm run lint - cd backend && cargo clippy - -format: - @echo "โœจ Formatting code..." - cd frontend && npm run format - cd backend && cargo fmt - -# Clean up -clean: - @echo "๐Ÿงน Cleaning up..." - cd frontend && rm -rf dist node_modules/.cache - cd backend && cargo clean - @just db-stop - rm -rf .postgres - -# Help -help: - @echo "The Guild Genesis - Available Commands:" - @echo "" - @echo "Development:" - @echo " dev Start both frontend and backend" - @echo " dev-frontend Start frontend only" - @echo " dev-backend Start backend only" - @echo " install-all Install all dependencies" - @echo "" - @echo "Database:" - @echo " db-start Start PostgreSQL database" - @echo " db-stop Stop PostgreSQL database" - @echo " db-setup Set up database with migrations" - @echo " db-reset Reset database completely" - @echo "" - @echo "Build:" - @echo " build Build all services" - @echo " build-frontend Build frontend only" - @echo " build-backend Build backend only" - @echo "" - @echo "Testing:" - @echo " test Run all tests" - @echo " test-frontend Run frontend tests" - @echo " test-backend Run backend tests" - @echo "" - @echo "Code Quality:" - @echo " lint Lint all code" - @echo " format Format all code" - @echo "" - @echo "Utilities:" - @echo " clean Clean up build artifacts" - @echo " help Show this help message" \ No newline at end of file