main.gostarts the Gin server, wiringbackend/AI providers,service/translation logic, andapi/HTTP handlers.backend/holds AI adapters (openai.go,cohere_ai.go) and translation context logic.service/wraps business rules and tokens used by the API layer;mock_babel.gosupports tests.api/exposes endpoints (/api/translate/*), session/CSRF/rate-limit middleware, and static serving fromfrontend/dist.frontend/is a Vite + React + TypeScript SPA (src/App.tsx,api.ts,styles.css); build output lives infrontend/dist.
- Go server:
go run main.go(requires backend env vars below). - Go tests:
go test ./...from repo root coversbackend/andapi/packages. - Frontend dev:
cd frontend && npm install && npm run devfor hot-reload. - Frontend build:
cd frontend && npm run build(runstsc -bthen Vite). - Frontend tests:
cd frontend && npm test(Vitest + JSDOM). - Docker:
docker build -t babelbridge .thendocker run -p 8080:8080 --env-file .env babelbridge.
- Go: run
gofmtbefore committing; use idiomatic error returns (if err != nil { ... }) and keep handlers small. Package names are lower_snake (backend,service,api); exported types/functions use CamelCase. - Frontend: TypeScript + React functional components; prefer hooks,
PascalCasefor components,camelCasefor props/handlers, and keep styles instyles.css. - Keep API paths explicit (
/api/translate/start|improve|preview|identify) and align request/response shapes withapi/models.go.
- Favor unit tests alongside code:
backend/backend_test.go,api/server_test.goillustrate patterns (mocks viaservice/mock_babel.go). - Name Go tests
TestThingand keep table-driven where possible. For frontend, colocate tests near components if added. - Run
go test ./...andcd frontend && npm testbefore PRs; add focused cases for regressions (session/CSRF, rate limits, language identification, component interaction).
- Use concise, imperative commits (e.g.,
backend: tighten language parsing,frontend: add chain mode test). - PRs should describe behavior change, linked issue, and include local test results/commands run. For UI changes, attach before/after screenshots or GIFs.
- Call out env/config impacts (ENGINE choice, model names, cookies/CSRF) and any new dependencies.
- Required env:
ENGINE(openaiorcohere), model vars, and API keys (OPENAI_API_KEYoptional,COHERE_API_KEYrequired).SECRET_KEYseeds sessions/CSRF; omit it to autogenerate for dev only. - CSRF tokens are cookie + header (
X-CSRF-Token); session cookie issession_token. Keep TLS offload andcookieSecurealigned in production.