diff --git a/.env.example b/.env.example index 849966e..ff7da9a 100644 --- a/.env.example +++ b/.env.example @@ -9,7 +9,7 @@ BASE_URL=http://localhost:3000 # Optional HOST=0.0.0.0 -PORT=3000 +PORT=8000 # CORS — comma-separated allowed origins, or * for permissive (default: *) CORS_ORIGINS=* diff --git a/Dockerfile b/Dockerfile index f53033e..348e791 100644 --- a/Dockerfile +++ b/Dockerfile @@ -52,7 +52,7 @@ WORKDIR /app COPY --from=builder /build/target/release/thoughts ./thoughts COPY --from=builder /build/target/release/thoughts-worker ./thoughts-worker -EXPOSE 3000 +EXPOSE 8000 ENV RUST_LOG=info diff --git a/Makefile b/Makefile index e2f26a7..5770f67 100644 --- a/Makefile +++ b/Makefile @@ -16,13 +16,33 @@ fmt-check: clippy: cargo clippy -- -D warnings -# Run the test suite. +# Run the full test suite (requires DATABASE_URL). test: cargo test +# Unit tests only — no database required. +test-unit: + cargo test -p domain -p application -p api-types -p activitypub + +# Integration tests only — requires DATABASE_URL. +test-integration: + cargo test -p postgres -p postgres-federation -p postgres-search -p presentation + # Apply fmt + clippy auto-fixes in one shot. fix: cargo fmt cargo clippy --fix --allow-dirty --allow-staged -.PHONY: check fmt fmt-check clippy test fix +# Start infra (Postgres + NATS) for local development. +dev-infra: + docker compose up postgres nats -d + +# Stop infra. +dev-infra-down: + docker compose down + +# Full Docker stack. +up: + docker compose up --build + +.PHONY: check fmt fmt-check clippy test test-unit test-integration fix dev-infra dev-infra-down up diff --git a/README.md b/README.md index c1c1f36..83564c1 100644 --- a/README.md +++ b/README.md @@ -85,6 +85,11 @@ Users can upload avatar and banner images via `PUT /users/me/avatar` and `PUT /u - Rust stable (1.80+) - PostgreSQL 15+ - NATS with JetStream (optional — see [Without NATS](#without-nats)) +- Docker & Docker Compose (for the easiest local setup) + +### Private cargo registry + +The `k-ap` crate (ActivityPub protocol library) is hosted on a private Gitea registry configured in `.cargo/config.toml`. To build the project you need read access to `git.gabrielkaszewski.dev`. If you're contributing and don't have access, open an issue and I'll sort it out. ## Environment Variables @@ -121,8 +126,42 @@ Copy `.env.example` to `.env` and fill in your values. | `UPLOAD_MAX_BYTES` | `5242880` | Max upload size in bytes (default 5 MiB) | | `UPLOAD_ALLOWED_TYPES` | `image/jpeg,image/png,image/gif,image/webp,image/avif` | Comma-separated allowed MIME types | +### Frontend environment + +Copy `thoughts-frontend/.env.example` to `thoughts-frontend/.env.local` and adjust: + +| Variable | Description | +|---|---| +| `NEXT_PUBLIC_API_URL` | API URL for client-side (browser) requests, e.g. `http://localhost:8000` | +| `NEXT_PUBLIC_SERVER_SIDE_API_URL` | API URL for SSR requests — same as above locally, or `http://api:8000` inside Docker | +| `NEXT_PUBLIC_FEDIVERSE_DOMAIN` | (Optional) Domain shown on profile fediverse handles, e.g. `yourinstance.example.com` | + ## Run +### Local development (recommended) + +Start only the infrastructure containers (Postgres + NATS), then run the Rust backend and Next.js frontend natively for fast iteration: + +```bash +# 1. Start Postgres + NATS +make dev-infra + +# 2. Copy and fill in env files +cp .env.example .env +cp thoughts-frontend/.env.example thoughts-frontend/.env.local + +# 3. API server (runs migrations automatically on startup) +cargo run -p bootstrap + +# 4. Event worker (separate terminal, optional) +cargo run -p worker + +# 5. Frontend (separate terminal) +cd thoughts-frontend && bun install && bun dev +``` + +### Bare metal + ```bash # API server (runs migrations automatically on startup) cargo run -p bootstrap @@ -136,14 +175,20 @@ Both processes share the same PostgreSQL database. The worker is optional but re ## Test ```bash -# Unit tests — no database required -cargo test -p application +# Unit tests only — no database required +make test-unit -# Full workspace (requires DATABASE_URL pointing to a running PostgreSQL) -cargo test --workspace +# Integration tests — requires DATABASE_URL pointing to a running PostgreSQL +make test-integration + +# Everything (unit + integration) +make test + +# Full check suite: fmt + clippy + tests +make check ``` -The `application` crate contains unit tests for all event services and use cases backed by in-memory fakes from `domain`'s `test-helpers` feature. These are the fastest feedback loop for business logic. +`make test-unit` runs domain, application, api-types, and activitypub tests using in-memory fakes — the fastest feedback loop for business logic. `make test-integration` runs the adapter crates against a live PostgreSQL. ## API @@ -203,12 +248,12 @@ docker build -t thoughts-frontend \ docker run -p 3000:3000 thoughts-frontend ``` -### Local development stack +### Full Docker stack `compose.yml` spins up the full stack: PostgreSQL, NATS (with JetStream and monitoring on port 8222), the API server, the event worker, and the frontend. ```bash -docker compose up +make up # or: docker compose up --build ``` Services: diff --git a/compose.yml b/compose.yml index f9bbc79..a6ca4d1 100644 --- a/compose.yml +++ b/compose.yml @@ -30,6 +30,7 @@ services: DATABASE_URL: postgres://postgres:postgres@postgres:5432/thoughts JWT_SECRET: change-me-in-production BASE_URL: http://localhost:8000 + PORT: 8000 NATS_URL: nats://nats:4222 RUST_LOG: info STORAGE_BACKEND: local diff --git a/thoughts-frontend/.env.example b/thoughts-frontend/.env.example new file mode 100644 index 0000000..5304ac2 --- /dev/null +++ b/thoughts-frontend/.env.example @@ -0,0 +1,6 @@ +# API endpoints +NEXT_PUBLIC_API_URL=http://localhost:8000 # client-side (browser) requests +NEXT_PUBLIC_SERVER_SIDE_API_URL=http://localhost:8000 # SSR requests (use http://api:8000 inside Docker) + +# Fediverse handle display (optional) +# NEXT_PUBLIC_FEDIVERSE_DOMAIN=yourinstance.example.com diff --git a/thoughts-frontend/.gitignore b/thoughts-frontend/.gitignore index ad20b09..708e94f 100644 --- a/thoughts-frontend/.gitignore +++ b/thoughts-frontend/.gitignore @@ -32,6 +32,7 @@ yarn-error.log* # env files (can opt-in for committing if needed) .env* +!.env.example # vercel .vercel