How codeaucafe/greenlight works
Greenlight is a Go HTTP API for movie-catalogue management and user accounts. The principal workflow is a client request entering the API, passing middleware and endpoint handling, then reading or changing movie data and returning JSON. Account workflows cover registration, activation, authentication tokens, and permissions; registration can also send a welcome email. Source excerpts show the movie and account model calls, but route wiring and several middleware details are not shown, so those links are left unasserted.
Main entry points: users.go User endpoints · validator.go Input validation · movies.go Movie endpoints · tokens.go Token endpoint
Components 19
HTTP API
- HTTP server
cmd/api/server.go - Request middleware
cmd/api/middleware.go - Movie endpoints
cmd/api/movies.go - User endpoints
cmd/api/users.go - Token endpoint
cmd/api/tokens.go - Health endpoint
cmd/api/healthcheck.go - Application startup
cmd/api/main.go
Accounts and Access
- User data access
internal/data/users.go - Token data access
internal/data/tokens.go - User permissions
internal/data/permissions.go
Movie Catalogue
- Movie data access
internal/data/movies.go - Listing filters
internal/data/filters.go
Shared Services
- Welcome mailer
internal/mailer/mailer.go - Input validation
internal/validator/validator.go - JSON logging
internal/jsonlog/jsonlog.go - Request helpers
cmd/api/helpers.go - User context
cmd/api/context.go
Other components
- API client
- PostgreSQL
Connections 21
- Application startup → HTTP server: starts
cmd/api/main.go - Application startup → JSON logging: initializes
cmd/api/main.go - API client → HTTP server: sends requests
- HTTP server → Request middleware: dispatches through
- Request middleware → User context: sets user
cmd/api/middleware.go - Movie endpoints → Movie data access: reads and writes
cmd/api/movies.go - Movie endpoints → Listing filters: validates filters
cmd/api/movies.go - Movie endpoints → Input validation: validates input
cmd/api/movies.go - User endpoints → User data access: creates and looks up
cmd/api/users.go - User endpoints → User permissions: grants permission
cmd/api/users.go - User endpoints → Token data access: creates token
cmd/api/users.go - User endpoints → Welcome mailer: sends welcome email
cmd/api/users.go - User endpoints → Input validation: validates input
cmd/api/users.go - Token endpoint → User data access: looks up user
cmd/api/tokens.go - Token endpoint → Token data access: creates token
cmd/api/tokens.go - Token endpoint → Input validation: validates credentials
cmd/api/tokens.go - Movie data access → PostgreSQL: queries
internal/data/movies.go - User data access → PostgreSQL: queries
internal/data/users.go - Token data access → PostgreSQL: stores tokens
internal/data/tokens.go - Request helpers → Input validation: uses validator
cmd/api/helpers.go - Request middleware → Input validation: uses validator
cmd/api/middleware.go