# codeaucafe/greenlight architecture

> Architecture diagram of the GitHub repository codeaucafe/greenlight, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/codeaucafe/greenlight
- Repository: https://github.com/codeaucafe/greenlight

## Overview

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: [`cmd/api/users.go`](https://github.com/codeaucafe/greenlight/blob/main/cmd/api/users.go) (User endpoints), [`internal/validator/validator.go`](https://github.com/codeaucafe/greenlight/blob/main/internal/validator/validator.go) (Input validation), [`cmd/api/movies.go`](https://github.com/codeaucafe/greenlight/blob/main/cmd/api/movies.go) (Movie endpoints), [`cmd/api/tokens.go`](https://github.com/codeaucafe/greenlight/blob/main/cmd/api/tokens.go) (Token endpoint)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["HTTP API"]
  node_server["HTTP server<br/>[server.go]"]
  node_middleware["Request middleware<br/>[middleware.go]"]
  node_movie_handlers["Movie endpoints<br/>[movies.go]"]
  node_user_handlers["User endpoints<br/>[users.go]"]
  node_token_handlers["Token endpoint<br/>[tokens.go]"]
  node_health["Health endpoint<br/>[healthcheck.go]"]
  node_app_start["Application startup<br/>[main.go]"]
end

subgraph group_identity["Accounts and Access"]
  node_user_data["User data access<br/>[users.go]"]
  node_token_data["Token data access<br/>[tokens.go]"]
  node_permissions["User permissions<br/>[permissions.go]"]
end

subgraph group_catalog["Movie Catalogue"]
  node_movie_data["Movie data access<br/>[movies.go]"]
  node_movie_filters["Listing filters<br/>[filters.go]"]
end

subgraph group_shared["Shared Services"]
  node_mailer["Welcome mailer<br/>[mailer.go]"]
  node_validation["Input validation<br/>[validator.go]"]
  node_jsonlog["JSON logging<br/>[jsonlog.go]"]
  node_request_helpers["Request helpers<br/>[helpers.go]"]
  node_context["User context<br/>[context.go]"]
end

node_client(("API client"))
node_postgres[("PostgreSQL")]

node_app_start -->|"starts"| node_server
node_app_start -->|"initializes"| node_jsonlog
node_client -.->|"sends requests"| node_server
node_server -.->|"dispatches through"| node_middleware
node_middleware -->|"sets user"| node_context
node_movie_handlers -->|"reads and writes"| node_movie_data
node_movie_handlers -->|"validates filters"| node_movie_filters
node_movie_handlers -->|"validates input"| node_validation
node_user_handlers -->|"creates and looks up"| node_user_data
node_user_handlers -->|"grants permission"| node_permissions
node_user_handlers -->|"creates token"| node_token_data
node_user_handlers -->|"sends welcome email"| node_mailer
node_user_handlers -->|"validates input"| node_validation
node_token_handlers -->|"looks up user"| node_user_data
node_token_handlers -->|"creates token"| node_token_data
node_token_handlers -->|"validates credentials"| node_validation
node_movie_data -->|"queries"| node_postgres
node_user_data -->|"queries"| node_postgres
node_token_data -->|"stores tokens"| node_postgres
node_request_helpers -->|"uses validator"| node_validation
node_middleware -->|"uses validator"| node_validation

click node_server "https://github.com/codeaucafe/greenlight/blob/main/cmd/api/server.go"
click node_middleware "https://github.com/codeaucafe/greenlight/blob/main/cmd/api/middleware.go"
click node_movie_handlers "https://github.com/codeaucafe/greenlight/blob/main/cmd/api/movies.go"
click node_user_handlers "https://github.com/codeaucafe/greenlight/blob/main/cmd/api/users.go"
click node_token_handlers "https://github.com/codeaucafe/greenlight/blob/main/cmd/api/tokens.go"
click node_health "https://github.com/codeaucafe/greenlight/blob/main/cmd/api/healthcheck.go"
click node_movie_data "https://github.com/codeaucafe/greenlight/blob/main/internal/data/movies.go"
click node_movie_filters "https://github.com/codeaucafe/greenlight/blob/main/internal/data/filters.go"
click node_user_data "https://github.com/codeaucafe/greenlight/blob/main/internal/data/users.go"
click node_token_data "https://github.com/codeaucafe/greenlight/blob/main/internal/data/tokens.go"
click node_permissions "https://github.com/codeaucafe/greenlight/blob/main/internal/data/permissions.go"
click node_mailer "https://github.com/codeaucafe/greenlight/blob/main/internal/mailer/mailer.go"
click node_validation "https://github.com/codeaucafe/greenlight/blob/main/internal/validator/validator.go"
click node_jsonlog "https://github.com/codeaucafe/greenlight/blob/main/internal/jsonlog/jsonlog.go"
click node_request_helpers "https://github.com/codeaucafe/greenlight/blob/main/cmd/api/helpers.go"
click node_context "https://github.com/codeaucafe/greenlight/blob/main/cmd/api/context.go"
click node_app_start "https://github.com/codeaucafe/greenlight/blob/main/cmd/api/main.go"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_server,node_middleware,node_movie_handlers,node_user_handlers,node_token_handlers,node_health,node_app_start,node_client toneBlue
class node_user_data,node_token_data,node_permissions,node_postgres toneAmber
class node_movie_data,node_movie_filters toneMint
class node_mailer,node_validation,node_jsonlog,node_request_helpers,node_context toneRose
```

## Components

### HTTP API

- [HTTP server](https://github.com/codeaucafe/greenlight/blob/main/cmd/api/server.go): `cmd/api/server.go`
- [Request middleware](https://github.com/codeaucafe/greenlight/blob/main/cmd/api/middleware.go): `cmd/api/middleware.go`
- [Movie endpoints](https://github.com/codeaucafe/greenlight/blob/main/cmd/api/movies.go): `cmd/api/movies.go`
- [User endpoints](https://github.com/codeaucafe/greenlight/blob/main/cmd/api/users.go): `cmd/api/users.go`
- [Token endpoint](https://github.com/codeaucafe/greenlight/blob/main/cmd/api/tokens.go): `cmd/api/tokens.go`
- [Health endpoint](https://github.com/codeaucafe/greenlight/blob/main/cmd/api/healthcheck.go): `cmd/api/healthcheck.go`
- [Application startup](https://github.com/codeaucafe/greenlight/blob/main/cmd/api/main.go): `cmd/api/main.go`

### Accounts and Access

- [User data access](https://github.com/codeaucafe/greenlight/blob/main/internal/data/users.go): `internal/data/users.go`
- [Token data access](https://github.com/codeaucafe/greenlight/blob/main/internal/data/tokens.go): `internal/data/tokens.go`
- [User permissions](https://github.com/codeaucafe/greenlight/blob/main/internal/data/permissions.go): `internal/data/permissions.go`

### Movie Catalogue

- [Movie data access](https://github.com/codeaucafe/greenlight/blob/main/internal/data/movies.go): `internal/data/movies.go`
- [Listing filters](https://github.com/codeaucafe/greenlight/blob/main/internal/data/filters.go): `internal/data/filters.go`

### Shared Services

- [Welcome mailer](https://github.com/codeaucafe/greenlight/blob/main/internal/mailer/mailer.go): `internal/mailer/mailer.go`
- [Input validation](https://github.com/codeaucafe/greenlight/blob/main/internal/validator/validator.go): `internal/validator/validator.go`
- [JSON logging](https://github.com/codeaucafe/greenlight/blob/main/internal/jsonlog/jsonlog.go): `internal/jsonlog/jsonlog.go`
- [Request helpers](https://github.com/codeaucafe/greenlight/blob/main/cmd/api/helpers.go): `cmd/api/helpers.go`
- [User context](https://github.com/codeaucafe/greenlight/blob/main/cmd/api/context.go): `cmd/api/context.go`

### Other components

- **API client**
- **PostgreSQL**

## Connections

- Application startup → HTTP server: starts (evidence: `cmd/api/main.go`)
- Application startup → JSON logging: initializes (evidence: `cmd/api/main.go`)
- API client → HTTP server: sends requests
- HTTP server → Request middleware: dispatches through
- Request middleware → User context: sets user (evidence: `cmd/api/middleware.go`)
- Movie endpoints → Movie data access: reads and writes (evidence: `cmd/api/movies.go`)
- Movie endpoints → Listing filters: validates filters (evidence: `cmd/api/movies.go`)
- Movie endpoints → Input validation: validates input (evidence: `cmd/api/movies.go`)
- User endpoints → User data access: creates and looks up (evidence: `cmd/api/users.go`)
- User endpoints → User permissions: grants permission (evidence: `cmd/api/users.go`)
- User endpoints → Token data access: creates token (evidence: `cmd/api/users.go`)
- User endpoints → Welcome mailer: sends welcome email (evidence: `cmd/api/users.go`)
- User endpoints → Input validation: validates input (evidence: `cmd/api/users.go`)
- Token endpoint → User data access: looks up user (evidence: `cmd/api/tokens.go`)
- Token endpoint → Token data access: creates token (evidence: `cmd/api/tokens.go`)
- Token endpoint → Input validation: validates credentials (evidence: `cmd/api/tokens.go`)
- Movie data access → PostgreSQL: queries (evidence: `internal/data/movies.go`)
- User data access → PostgreSQL: queries (evidence: `internal/data/users.go`)
- Token data access → PostgreSQL: stores tokens (evidence: `internal/data/tokens.go`)
- Request helpers → Input validation: uses validator (evidence: `cmd/api/helpers.go`)
- Request middleware → Input validation: uses validator (evidence: `cmd/api/middleware.go`)
