How elyseemb/relay-compiler works
Project Type and Purpose
• This is a full-stack web application using Preact+Relay on the client and Go (gqlgen) on the server, backed by PostgreSQL.
• The front end fetches data from a GraphQL API implemented in Go; the API layer lives under pkg/server/api/console/v1.
File Structure Analysis
• assets/…: Preact source (App.tsx, components, hooks), Relay artifacts (__generated__), Vite config.
• cmd/relay-compiler/: custom Go binary to run Relay codegen.
• pkg/server/: Go HTTP server split into
• public/…: compiled static assets (Vite output) served to the browser
• web/: page handlers (templates/Layout.templ)
• api/console/v1/: GraphQL schema, resolver, sign-up handler
• pkg/services, pkg/coredata, pkg/db, pkg/crypto, pkg/usrmgr: service layer, data layer (entities, migrations), DB connection, password hashing, tenant/user management.
• compose/: Docker Compose definitions for Postgres, Prometheus, Grafana, Tempo.
• internal/tools: build-time tools (e.g., gqlgen).
README Insights
• Confirms Preact+Relay front end consuming a GraphQL API built in Go with gqlgen.
Main Components
a. Client (Browser):
• Preact app compiled by Vite, uses Relay to fetch queries/mutations.
b. API Gateway (Go HTTP Server):
• Static file handler (serves assets)
• GraphQL HTTP endpoint (/console/v1) implemented via gqlgen
• Web handlers for server-side templates
c. Business Logic Layer (Services):
• pkg/services, pkg/usrmgr orchestrate operations (create user, manage sessions)
d. Data Access Layer:
• pkg/coredata: entity definitions and migrations
• pkg/db: connection pooling, configuration
e. Persistence:
• PostgreSQL
f. Security Middleware:
• pkg/crypto/passwdhash, pkg/secureCookie for password hashing and cookie management
g. Observability Stack (Docker Compose):
• Prometheus (metrics scraping)
• Grafana (dashboards)
• Tempo (distributed tracing)
Relationships and Data Flow
• The browser sends Relay GraphQL requests → Go HTTP server.
• GraphQL resolver delegates to service layer → data layer → DB.
• Responses bubble back through resolver → Relay → Preact UI.
• Static assets are served directly from Go public/ or via Vite in dev.
• Observability agents within the Go server emit metrics/traces to Prometheus/Tempo; Grafana queries Prometheus.
Architectural Patterns & Principles
• Layered architecture: Presentation (assets + GraphQL client) → API/Handler → Service → Data → DB.
• Separation of concerns:
• Codegen tools (gqlgen, Relay compiler) isolated in cmd/ and config files.
• Database migrations kept under pkg/coredata/migrations.
• Infrastructure as code: Docker Compose for spinning up dependencies.