docs: fix DX for new contributors
- Fix port mismatch: Dockerfile EXPOSE 8000, .env.example PORT=8000, compose.yml gets explicit PORT=8000 - Add thoughts-frontend/.env.example with all required vars - Document NEXT_PUBLIC_FEDIVERSE_DOMAIN in README - Document private cargo registry (k-ap on Gitea) - Add local dev workflow: make dev-infra → cargo run → bun dev - Split make targets: test-unit (no DB), test-integration, up
This commit is contained in:
@@ -9,7 +9,7 @@ BASE_URL=http://localhost:3000
|
|||||||
|
|
||||||
# Optional
|
# Optional
|
||||||
HOST=0.0.0.0
|
HOST=0.0.0.0
|
||||||
PORT=3000
|
PORT=8000
|
||||||
|
|
||||||
# CORS — comma-separated allowed origins, or * for permissive (default: *)
|
# CORS — comma-separated allowed origins, or * for permissive (default: *)
|
||||||
CORS_ORIGINS=*
|
CORS_ORIGINS=*
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ WORKDIR /app
|
|||||||
COPY --from=builder /build/target/release/thoughts ./thoughts
|
COPY --from=builder /build/target/release/thoughts ./thoughts
|
||||||
COPY --from=builder /build/target/release/thoughts-worker ./thoughts-worker
|
COPY --from=builder /build/target/release/thoughts-worker ./thoughts-worker
|
||||||
|
|
||||||
EXPOSE 3000
|
EXPOSE 8000
|
||||||
|
|
||||||
ENV RUST_LOG=info
|
ENV RUST_LOG=info
|
||||||
|
|
||||||
|
|||||||
24
Makefile
24
Makefile
@@ -16,13 +16,33 @@ fmt-check:
|
|||||||
clippy:
|
clippy:
|
||||||
cargo clippy -- -D warnings
|
cargo clippy -- -D warnings
|
||||||
|
|
||||||
# Run the test suite.
|
# Run the full test suite (requires DATABASE_URL).
|
||||||
test:
|
test:
|
||||||
cargo 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.
|
# Apply fmt + clippy auto-fixes in one shot.
|
||||||
fix:
|
fix:
|
||||||
cargo fmt
|
cargo fmt
|
||||||
cargo clippy --fix --allow-dirty --allow-staged
|
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
|
||||||
|
|||||||
59
README.md
59
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+)
|
- Rust stable (1.80+)
|
||||||
- PostgreSQL 15+
|
- PostgreSQL 15+
|
||||||
- NATS with JetStream (optional — see [Without NATS](#without-nats))
|
- 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
|
## 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_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 |
|
| `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
|
## 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
|
```bash
|
||||||
# API server (runs migrations automatically on startup)
|
# API server (runs migrations automatically on startup)
|
||||||
cargo run -p bootstrap
|
cargo run -p bootstrap
|
||||||
@@ -136,14 +175,20 @@ Both processes share the same PostgreSQL database. The worker is optional but re
|
|||||||
## Test
|
## Test
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Unit tests — no database required
|
# Unit tests only — no database required
|
||||||
cargo test -p application
|
make test-unit
|
||||||
|
|
||||||
# Full workspace (requires DATABASE_URL pointing to a running PostgreSQL)
|
# Integration tests — requires DATABASE_URL pointing to a running PostgreSQL
|
||||||
cargo test --workspace
|
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
|
## API
|
||||||
|
|
||||||
@@ -203,12 +248,12 @@ docker build -t thoughts-frontend \
|
|||||||
docker run -p 3000:3000 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.
|
`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
|
```bash
|
||||||
docker compose up
|
make up # or: docker compose up --build
|
||||||
```
|
```
|
||||||
|
|
||||||
Services:
|
Services:
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ services:
|
|||||||
DATABASE_URL: postgres://postgres:postgres@postgres:5432/thoughts
|
DATABASE_URL: postgres://postgres:postgres@postgres:5432/thoughts
|
||||||
JWT_SECRET: change-me-in-production
|
JWT_SECRET: change-me-in-production
|
||||||
BASE_URL: http://localhost:8000
|
BASE_URL: http://localhost:8000
|
||||||
|
PORT: 8000
|
||||||
NATS_URL: nats://nats:4222
|
NATS_URL: nats://nats:4222
|
||||||
RUST_LOG: info
|
RUST_LOG: info
|
||||||
STORAGE_BACKEND: local
|
STORAGE_BACKEND: local
|
||||||
|
|||||||
6
thoughts-frontend/.env.example
Normal file
6
thoughts-frontend/.env.example
Normal file
@@ -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
|
||||||
1
thoughts-frontend/.gitignore
vendored
1
thoughts-frontend/.gitignore
vendored
@@ -32,6 +32,7 @@ yarn-error.log*
|
|||||||
|
|
||||||
# env files (can opt-in for committing if needed)
|
# env files (can opt-in for committing if needed)
|
||||||
.env*
|
.env*
|
||||||
|
!.env.example
|
||||||
|
|
||||||
# vercel
|
# vercel
|
||||||
.vercel
|
.vercel
|
||||||
|
|||||||
Reference in New Issue
Block a user