Repository: supabase/gotrue
Pull request #925 (2023-02-01 10:37:42)

feat: internalize implementation
Most of the GoTrue Go code should not be used in external imports, as it's an internal implementation. It is thus moved to an [`internal`](https://go.dev/doc/go1.4#internalpackages) package which can't be imported from the outside.

From this point on you won't be able to access implementation details by importing `github.com/netlify/gotrue/api` for example. 


Patch:
diff --git a/Makefile b/Makefile
index a251c2ae..dd6736b8 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
 .PHONY: all build deps dev-deps image migrate test vet sec format unused
 CHECK_FILES?=./...
-FLAGS?=-ldflags "-X github.com/netlify/gotrue/utilities.Version=`git describe --tags`" -buildvcs=false
+FLAGS?=-ldflags "-X github.com/netlify/gotrue/internal/utilities.Version=`git describe --tags`" -buildvcs=false
 DEV_DOCKER_COMPOSE:=docker-compose-dev.yml
 
 help: ## Show this help.
diff --git a/cmd/admin_cmd.go b/cmd/admin_cmd.go
index 2dc65dcc..0782a416 100644
--- a/cmd/admin_cmd.go
+++ b/cmd/admin_cmd.go
@@ -2,9 +2,9 @@ package cmd
 
 import (
 	"github.com/gofrs/uuid"
-	"github.com/netlify/gotrue/conf"
-	"github.com/netlify/gotrue/models"
-	"github.com/netlify/gotrue/storage"
+	"github.com/netlify/gotrue/internal/conf"
+	"github.com/netlify/gotrue/internal/models"
+	"github.com/netlify/gotrue/internal/storage"
 	"github.com/sirupsen/logrus"
 	"github.com/spf13/cobra"
 )
diff --git a/cmd/root_cmd.go b/cmd/root_cmd.go
index 71810089..9e6ab987 100644
--- a/cmd/root_cmd.go
+++ b/cmd/root_cmd.go
@@ -3,8 +3,8 @@ package cmd
 import (
 	"context"
 
-	"github.com/netlify/gotrue/conf"
-	"github.com/netlify/gotrue/observability"
+	"github.com/netlify/gotrue/internal/conf"
+	"github.com/netlify/gotrue/internal/observability"
 	"github.com/sirupsen/logrus"
 	"github.com/spf13/cobra"
 )
diff --git a/cmd/serve_cmd.go b/cmd/serve_cmd.go
index 448c15ab..9a5025d6 100644
--- a/cmd/serve_cmd.go
+++ b/cmd/serve_cmd.go
@@ -4,10 +4,10 @@ import (
 	"context"
 	"net"
 
-	"github.com/netlify/gotrue/api"
-	"github.com/netlify/gotrue/conf"
-	"github.com/netlify/gotrue/storage"
-	"github.com/netlify/gotrue/utilities"
+	"github.com/netlify/gotrue/internal/api"
+	"github.com/netlify/gotrue/internal/conf"
+	"github.com/netlify/gotrue/internal/storage"
+	"github.com/netlify/gotrue/internal/utilities"
 	"github.com/sirupsen/logrus"
 	"github.com/spf13/cobra"
 )
diff --git a/cmd/version_cmd.go b/cmd/version_cmd.go
index affd7f9f..17e51d3e 100644
--- a/cmd/version_cmd.go
+++ b/cmd/version_cmd.go
@@ -3,7 +3,7 @@ package cmd
 import (
 	"fmt"
 
-	"github.com/netlify/gotrue/utilities"
+	"github.com/netlify/gotrue/internal/utilities"
 	"github.com/spf13/cobra"
 )
 
diff --git a/docs/admin.go b/docs/admin.go
index 5fdabff0..9c87b1e1 100644
--- a/docs/admin.go
+++ b/docs/admin.go
@@ -2,7 +2,7 @@
 package docs
 
 import (
-	"github.com/netlify/gotrue/api"
+	"github.com/netlify/gotrue/internal/api"
 )
 
 // swagger:route GET /admin/users admin admin-list-users
diff --git a/docs/health.go b/docs/health.go
index 08c2fcc3..a09a4cf1 100644
--- a/docs/health.go
+++ b/docs/health.go
@@ -1,7 +1,7 @@
 //lint:file-ignore U1000 ignore go-swagger template
 package docs
 
-import "github.com/netlify/gotrue/api"
+import "github.com/netlify/gotrue/internal/api"
 
 // swagger:route GET /health health health
 // The healthcheck endpoint for gotrue. Returns the current gotrue version.
diff --git a/docs/invite.go b/docs/invite.go
index fb6b93e3..96795866 100644
--- a/docs/invite.go
+++ b/docs/invite.go
@@ -1,7 +1,7 @@
 //lint:file-ignore U1000 ignore go-swagger template
 package docs
 
-import "github.com/netlify/gotrue/api"
+import "github.com/netlify/gotrue/internal/api"
 
 // swagger:route POST /invite invite invite
 // Sends an invite link to the user.
diff --git a/docs/otp.go b/docs/otp.go
index 3998900d..24afde0f 100644
--- a/docs/otp.go
+++ b/docs/otp.go
@@ -1,7 +1,7 @@
 //lint:file-ignore U1000 ignore go-swagger template
 package docs
 
-import "github.com/netlify/gotrue/api"
+import "github.com/netlify/gotrue/internal/api"
 
 // swagger:route POST /otp otp otp
 // Passwordless sign-in method for email or phone.
diff --git a/docs/recover.go b/docs/recover.go
index d3d39cb0..365a3e07 100644
--- a/docs/recover.go
+++ b/docs/recover.go
@@ -1,7 +1,7 @@
 //lint:file-ignore U1000 ignore go-swagger template
 package docs
 
-import "github.com/netlify/gotrue/api"
+import "github.com/netlify/gotrue/internal/api"
 
 // swagger:route POST /recover recovery recovery
 // Sends a password recovery email link to the user's email.
diff --git a/docs/settings.go b/docs/settings.go
index 56c95171..944407a9 100644
--- a/docs/settings.go
+++ b/docs/settings.go
@@ -1,7 +1,7 @@
 //lint:file-ignore U1000 ignore go-swagger template
 package docs
 
-import "github.com/netlify/gotrue/api"
+import "github.com/netlify/gotrue/internal/api"
 
 // swagger:route GET /settings settings settings
 // Returns the configuration settings for the gotrue server.
diff --git a/docs/signup.go b/docs/signup.go
index d8022c4f..c42f9518 100644
--- a/docs/signup.go
+++ b/docs/signup.go
@@ -2,7 +2,7 @@
 package docs
 
 import (
-	"github.com/netlify/gotrue/api"
+	"github.com/netlify/gotrue/internal/api"
 )
 
 // swagger:route POST /signup signup signup
diff --git a/docs/token.go b/docs/token.go
index fdf5fa60..f36d20f0 100644
--- a/docs/token.go
+++ b/docs/token.go
@@ -2,7 +2,7 @@
 package docs
 
 import (
-	"github.com/netlify/gotrue/api"
+	"github.com/netlify/gotrue/internal/api"
 )
 
 // swagger:route POST /token?grant_type=password token token-password
diff --git a/docs/user.go b/docs/user.go
index 02cddf4c..f75c7259 100644
--- a/docs/user.go
+++ b/docs/user.go
@@ -2,8 +2,8 @@
 package docs
 
 import (
-	"github.com/netlify/gotrue/api"
-	"github.com/netlify/gotrue/models"
+	"github.com/netlify/gotrue/internal/api"
+	"github.com/netlify/gotrue/internal/models"
 )
 
 // swagger:route GET /user user user-get
diff --git a/docs/verify.go b/docs/verify.go
index fad723f5..4a403e88 100644
--- a/docs/verify.go
+++ b/docs/verify.go
@@ -2,7 +2,7 @@
 package docs
 
 import (
-	"github.com/netlify/gotrue/api"
+	"github.com/netlify/gotrue/internal/api"
 )
 
 // swagger:route GET /verify verify verify-get
diff --git a/api/admin.go b/internal/api/admin.go
similarity index 99%
rename from api/admin.go
rename to internal/api/admin.go
index d143a25a..a28cbca5 100644
--- a/api/admin.go
+++ b/internal/api/admin.go
@@ -10,9 +10,9 @@ import (
 
 	"github.com/go-chi/chi"
 	"github.com/gofrs/uuid"
-	"github.com/netlify/gotrue/models"
-	"github.com/netlify/gotrue/observability"
-	"github.com/netlify/gotrue/storage"
+	"github.com/netlify/gotrue/internal/models"
+	"github.com/netlify/gotrue/internal/observability"
+	"github.com/netlify/gotrue/internal/storage"
 	"github.com/sethvargo/go-password/password"
 )
 
diff --git a/api/api.go b/internal/api/api.go
similarity index 97%
rename from api/api.go
rename to internal/api/api.go
index b93cd60f..69d9e512 100644
--- a/api/api.go
+++ b/internal/api/api.go
@@ -9,10 +9,10 @@ import (
 	"github.com/didip/tollbooth/v5"
 	"github.com/didip/tollbooth/v5/limiter"
 	"github.com/go-chi/chi"
-	"github.com/netlify/gotrue/conf"
-	"github.com/netlify/gotrue/mailer"
-	"github.com/netlify/gotrue/observability"
-	"github.com/netlify/gotrue/storage"
+	"github.com/netlify/gotrue/internal/conf"
+	"github.com/netlify/gotrue/internal/mailer"
+	"github.com/netlify/gotrue/internal/observability"
+	"github.com/netlify/gotrue/internal/storage"
 	"github.com/rs/cors"
 	"github.com/sebest/xff"
 	"github.com/sirupsen/logrus"
diff --git a/api/audit.go b/internal/api/audit.go
similarity index 95%
rename from api/audit.go
rename to internal/api/audit.go
index 8b2e84b1..b7905c67 100644
--- a/api/audit.go
+++ b/internal/api/audit.go
@@ -4,7 +4,7 @@ import (
 	"net/http"
 	"strings"
 
-	"github.com/netlify/gotrue/models"
+	"github.com/netlify/gotrue/internal/models"
 )
 
 var filterColumnMap = map[string][]string{
diff --git a/api/auth.go b/internal/api/auth.go
similarity index 97%
rename from api/auth.go
rename to internal/api/auth.go
index eeec1f0f..f2268059 100644
--- a/api/auth.go
+++ b/internal/api/auth.go
@@ -8,8 +8,8 @@ import (
 
 	"github.com/gofrs/uuid"
 	jwt "github.com/golang-jwt/jwt"
-	"github.com/netlify/gotrue/models"
-	"github.com/netlify/gotrue/storage"
+	"github.com/netlify/gotrue/internal/models"
+	"github.com/netlify/gotrue/internal/storage"
 )
 
 // requireAuthentication checks incoming requests for tokens presented using the Authorization header
diff --git a/api/cleanup.go b/internal/api/cleanup.go
similarity index 100%
rename from api/cleanup.go
rename to internal/api/cleanup.go
diff --git a/api/context.go b/internal/api/context.go
similarity index 99%
rename from api/context.go
rename to internal/api/context.go
index d7a03c5a..a13baefb 100644
--- a/api/context.go
+++ b/internal/api/context.go
@@ -4,7 +4,7 @@ import (
 	"context"
 
 	jwt "github.com/golang-jwt/jwt"
-	"github.com/netlify/gotrue/models"
+	"github.com/netlify/gotrue/internal/models"
 )
 
 type contextKey string
diff --git a/api/errors.go b/internal/api/errors.go
similarity index 98%
rename from api/errors.go
rename to internal/api/errors.go
index eddd962a..5a86f3ed 100644
--- a/api/errors.go
+++ b/internal/api/errors.go
@@ -7,9 +7,9 @@ import (
 	"os"
 	"runtime/debug"
 
-	"github.com/netlify/gotrue/conf"
-	"github.com/netlify/gotrue/observability"
-	"github.com/netlify/gotrue/utilities"
+	"github.com/netlify/gotrue/internal/conf"
+	"github.com/netlify/gotrue/internal/observability"
+	"github.com/netlify/gotrue/internal/utilities"
 	"github.com/pkg/errors"
 )
 
diff --git a/api/external.go b/internal/api/external.go
similarity index 98%
rename from api/external.go
rename to internal/api/external.go
index c1ec13d7..2e85b101 100644
--- a/api/external.go
+++ b/internal/api/external.go
@@ -12,11 +12,11 @@ import (
 	"github.com/fatih/structs"
 	"github.com/gofrs/uuid"
 	jwt "github.com/golang-jwt/jwt"
-	"github.com/netlify/gotrue/api/provider"
-	"github.com/netlify/gotrue/models"
-	"github.com/netlify/gotrue/observability"
-	"github.com/netlify/gotrue/storage"
-	"github.com/netlify/gotrue/utilities"
+	"github.com/netlify/gotrue/internal/api/provider"
+	"github.com/netlify/gotrue/internal/models"
+	"github.com/netlify/gotrue/internal/observability"
+	"github.com/netlify/gotrue/internal/storage"
+	"github.com/netlify/gotrue/internal/utilities"
 	"github.com/sirupsen/logrus"
 	"golang.org/x/oauth2"
 )
diff --git a/api/external_gitlab_test.go b/internal/api/external_gitlab_test.go
similarity index 100%
rename from api/external_gitlab_test.go
rename to internal/api/external_gitlab_test.go
diff --git a/api/external_google_test.go b/internal/api/external_google_test.go
similarity index 100%
rename from api/external_google_test.go
rename to internal/api/external_google_test.go
diff --git a/api/external_keycloak_test.go b/internal/api/external_keycloak_test.go
similarity index 100%
rename from api/external_keycloak_test.go
rename to internal/api/external_keycloak_test.go
diff --git a/api/external_linkedin_test.go b/internal/api/external_linkedin_test.go
similarity index 100%
rename from api/external_linkedin_test.go
rename to internal/api/external_linkedin_test.go
diff --git a/api/external_notion_test.go b/internal/api/external_notion_test.go
similarity index 100%
rename from api/external_notion_test.go
rename to internal/api/external_notion_test.go
diff --git a/api/external_oauth.go b/internal/api/external_oauth.go
similarity index 96%
rename from api/external_oauth.go
rename to internal/api/external_oauth.go
index 7e1ae291..cd6133ef 100644
--- a/api/external_oauth.go
+++ b/internal/api/external_oauth.go
@@ -6,9 +6,9 @@ import (
 	"net/url"
 
 	"github.com/mrjones/oauth"
-	"github.com/netlify/gotrue/api/provider"
-	"github.com/netlify/gotrue/observability"
-	"github.com/netlify/gotrue/storage"
+	"github.com/netlify/gotrue/internal/api/provider"
+	"github.com/netlify/gotrue/internal/observability"
+	"github.com/netlify/gotrue/internal/storage"
 	"github.com/sirupsen/logrus"
 )
 
diff --git a/api/external_twitch_test.go b/internal/api/external_twitch_test.go
similarity index 100%
rename from api/external_twitch_test.go
rename to internal/api/external_twitch_test.go
diff --git a/api/external_twitter_test.go b/internal/api/external_twitter_test.go
similarity index 100%
rename from api/external_twitter_test.go
rename to internal/api/external_twitter_test.go
diff --git a/api/external_workos_test.go b/internal/api/external_workos_test.go
similarity index 100%
rename from api/external_workos_test.go
rename to internal/api/external_workos_test.go
diff --git a/api/external_zoom_test.go b/internal/api/external_zoom_test.go
similarity index 100%
rename from api/external_zoom_test.go
rename to internal/api/external_zoom_test.go
diff --git a/api/helpers.go b/internal/api/helpers.go
similarity index 97%
rename from api/helpers.go
rename to internal/api/helpers.go
index 69bc803b..af5d766e 100644
--- a/api/helpers.go
+++ b/internal/api/helpers.go
@@ -10,9 +10,9 @@ import (
 	"net/url"
 
 	"github.com/gofrs/uuid"
-	"github.com/netlify/gotrue/conf"
-	"github.com/netlify/gotrue/models"
-	"github.com/netlify/gotrue/utilities"
+	"github.com/netlify/gotrue/internal/conf"
+	"github.com/netlify/gotrue/internal/models"
+	"github.com/netlify/gotrue/internal/utilities"
 	"github.com/pkg/errors"
 	"github.com/sirupsen/logrus"
 )
diff --git a/api/hooks.go b/internal/api/hooks.go
similarity index 98%
rename from api/hooks.go
rename to internal/api/hooks.go
index 66b34999..f631111c 100644
--- a/api/hooks.go
+++ b/internal/api/hooks.go
@@ -18,9 +18,9 @@ import (
 	"github.com/pkg/errors"
 	"github.com/sirupsen/logrus"
 
-	"github.com/netlify/gotrue/conf"
-	"github.com/netlify/gotrue/models"
-	"github.com/netlify/gotrue/storage"
+	"github.com/netlify/gotrue/internal/conf"
+	"github.com/netlify/gotrue/internal/models"
+	"github.com/netlify/gotrue/internal/storage"
 )
 
 type HookEvent string
diff --git a/api/invite.go b/internal/api/invite.go
similarity index 94%
rename from api/invite.go
rename to internal/api/invite.go
index ae0cebd4..12dacf07 100644
--- a/api/invite.go
+++ b/internal/api/invite.go
@@ -5,9 +5,9 @@ import (
 	"net/http"
 
 	"github.com/fatih/structs"
-	"github.com/netlify/gotrue/api/provider"
-	"github.com/netlify/gotrue/models"
-	"github.com/netlify/gotrue/storage"
+	"github.com/netlify/gotrue/internal/api/provider"
+	"github.com/netlify/gotrue/internal/models"
+	"github.com/netlify/gotrue/internal/storage"
 )
 
 // InviteParams are the parameters the Signup endpoint accepts
diff --git a/api/listener.go b/internal/api/listener.go
similarity index 100%
rename from api/listener.go
rename to internal/api/listener.go
diff --git a/api/logout.go b/internal/api/logout.go
similarity index 89%
rename from api/logout.go
rename to internal/api/logout.go
index a1eada54..e3e3509b 100644
--- a/api/logout.go
+++ b/internal/api/logout.go
@@ -3,8 +3,8 @@ package api
 import (
 	"net/http"
 
-	"github.com/netlify/gotrue/models"
-	"github.com/netlify/gotrue/storage"
+	"github.com/netlify/gotrue/internal/models"
+	"github.com/netlify/gotrue/internal/storage"
 )
 
 // Logout is the endpoint for logging out a user and thereby revoking any refresh tokens
diff --git a/api/magic_link.go b/internal/api/magic_link.go
similarity index 97%
rename from api/magic_link.go
rename to internal/api/magic_link.go
index 8dd5f6e9..cbdacb00 100644
--- a/api/magic_link.go
+++ b/internal/api/magic_link.go
@@ -8,8 +8,8 @@ import (
 	"net/http"
 	"strings"
 
-	"github.com/netlify/gotrue/models"
-	"github.com/netlify/gotrue/storage"
+	"github.com/netlify/gotrue/internal/models"
+	"github.com/netlify/gotrue/internal/storage"
 	"github.com/sethvargo/go-password/password"
 )
 
diff --git a/api/mail.go b/internal/api/mail.go
similarity index 97%
rename from api/mail.go
rename to internal/api/mail.go
index 9d1df8df..7cf333a9 100644
--- a/api/mail.go
+++ b/internal/api/mail.go
@@ -10,12 +10,12 @@ import (
 
 	"github.com/badoux/checkmail"
 	"github.com/fatih/structs"
-	"github.com/netlify/gotrue/api/provider"
-	"github.com/netlify/gotrue/conf"
-	"github.com/netlify/gotrue/crypto"
-	"github.com/netlify/gotrue/mailer"
-	"github.com/netlify/gotrue/models"
-	"github.com/netlify/gotrue/storage"
+	"github.com/netlify/gotrue/internal/api/provider"
+	"github.com/netlify/gotrue/internal/conf"
+	"github.com/netlify/gotrue/internal/crypto"
+	"github.com/netlify/gotrue/internal/mailer"
+	"github.com/netlify/gotrue/internal/models"
+	"github.com/netlify/gotrue/internal/storage"
 	"github.com/pkg/errors"
 	"github.com/sethvargo/go-password/password"
 )
diff --git a/api/mfa.go b/internal/api/mfa.go
similarity index 98%
rename from api/mfa.go
rename to internal/api/mfa.go
index ed13f6f3..396381ca 100644
--- a/api/mfa.go
+++ b/internal/api/mfa.go
@@ -12,10 +12,10 @@ import (
 	svg "github.com/ajstarks/svgo"
 	"github.com/boombuler/barcode/qr"
 	"github.com/gofrs/uuid"
-	"github.com/netlify/gotrue/metering"
-	"github.com/netlify/gotrue/models"
-	"github.com/netlify/gotrue/storage"
-	"github.com/netlify/gotrue/utilities"
+	"github.com/netlify/gotrue/internal/metering"
+	"github.com/netlify/gotrue/internal/models"
+	"github.com/netlify/gotrue/internal/storage"
+	"github.com/netlify/gotrue/internal/utilities"
 	"github.com/pquerna/otp/totp"
 )
 
diff --git a/api/middleware.go b/internal/api/middleware.go
similarity index 98%
rename from api/middleware.go
rename to internal/api/middleware.go
index b83ecef4..7c44604c 100644
--- a/api/middleware.go
+++ b/internal/api/middleware.go
@@ -7,8 +7,8 @@ import (
 	"strings"
 	"time"
 
-	"github.com/netlify/gotrue/observability"
-	"github.com/netlify/gotrue/security"
+	"github.com/netlify/gotrue/internal/observability"
+	"github.com/netlify/gotrue/internal/security"
 
 	"github.com/didip/tollbooth/v5"
 	"github.com/didip/tollbooth/v5/limiter"
diff --git a/api/otp.go b/internal/api/otp.go
similarity index 97%
rename from api/otp.go
rename to internal/api/otp.go
index 7af296bd..53143b40 100644
--- a/api/otp.go
+++ b/internal/api/otp.go
@@ -6,9 +6,9 @@ import (
 	"io"
 	"net/http"
 
-	"github.com/netlify/gotrue/api/sms_provider"
-	"github.com/netlify/gotrue/models"
-	"github.com/netlify/gotrue/storage"
+	"github.com/netlify/gotrue/internal/api/sms_provider"
+	"github.com/netlify/gotrue/internal/models"
+	"github.com/netlify/gotrue/internal/storage"
 	"github.com/sethvargo/go-password/password"
 )
 
diff --git a/api/pagination.go b/internal/api/pagination.go
similarity index 96%
rename from api/pagination.go
rename to internal/api/pagination.go
index 1c234108..049d51aa 100644
--- a/api/pagination.go
+++ b/internal/api/pagination.go
@@ -6,7 +6,7 @@ import (
 	"net/url"
 	"strconv"
 
-	"github.com/netlify/gotrue/models"
+	"github.com/netlify/gotrue/internal/models"
 )
 
 const defaultPerPage = 50
diff --git a/api/phone.go b/internal/api/phone.go
similarity index 93%
rename from api/phone.go
rename to internal/api/phone.go
index 4b684787..9bce5723 100644
--- a/api/phone.go
+++ b/internal/api/phone.go
@@ -8,10 +8,10 @@ import (
 	"strings"
 	"time"
 
-	"github.com/netlify/gotrue/api/sms_provider"
-	"github.com/netlify/gotrue/crypto"
-	"github.com/netlify/gotrue/models"
-	"github.com/netlify/gotrue/storage"
+	"github.com/netlify/gotrue/internal/api/sms_provider"
+	"github.com/netlify/gotrue/internal/crypto"
+	"github.com/netlify/gotrue/internal/models"
+	"github.com/netlify/gotrue/internal/storage"
 	"github.com/pkg/errors"
 )
 
diff --git a/api/provider/apple.go b/internal/api/provider/apple.go
similarity index 99%
rename from api/provider/apple.go
rename to internal/api/provider/apple.go
index 23398339..9176d874 100644
--- a/api/provider/apple.go
+++ b/internal/api/provider/apple.go
@@ -13,7 +13,7 @@ import (
 
 	"github.com/golang-jwt/jwt"
 	"github.com/lestrrat-go/jwx/jwk"
-	"github.com/netlify/gotrue/conf"
+	"github.com/netlify/gotrue/internal/conf"
 	"golang.org/x/oauth2"
 )
 
diff --git a/api/provider/azure.go b/internal/api/provider/azure.go
similarity index 97%
rename from api/provider/azure.go
rename to internal/api/provider/azure.go
index 7a5b3b31..9e9aafad 100644
--- a/api/provider/azure.go
+++ b/internal/api/provider/azure.go
@@ -5,7 +5,7 @@ import (
 	"errors"
 	"strings"
 
-	"github.com/netlify/gotrue/conf"
+	"github.com/netlify/gotrue/internal/conf"
 	"golang.org/x/oauth2"
 )
 
diff --git a/api/provider/bitbucket.go b/internal/api/provider/bitbucket.go
similarity index 98%
rename from api/provider/bitbucket.go
rename to internal/api/provider/bitbucket.go
index 8c9a4128..71d1e091 100644
--- a/api/provider/bitbucket.go
+++ b/internal/api/provider/bitbucket.go
@@ -4,7 +4,7 @@ import (
 	"context"
 	"errors"
 
-	"github.com/netlify/gotrue/conf"
+	"github.com/netlify/gotrue/internal/conf"
 	"golang.org/x/oauth2"
 )
 
diff --git a/api/provider/discord.go b/internal/api/provider/discord.go
similarity index 98%
rename from api/provider/discord.go
rename to internal/api/provider/discord.go
index c7e70d6c..de756dbd 100644
--- a/api/provider/discord.go
+++ b/internal/api/provider/discord.go
@@ -7,7 +7,7 @@ import (
 	"strconv"
 	"strings"
 
-	"github.com/netlify/gotrue/conf"
+	"github.com/netlify/gotrue/internal/conf"
 	"golang.org/x/oauth2"
 )
 
diff --git a/api/provider/errors.go b/internal/api/provider/errors.go
similarity index 100%
rename from api/provider/errors.go
rename to internal/api/provider/errors.go
diff --git a/api/provider/facebook.go b/internal/api/provider/facebook.go
similarity index 98%
rename from api/provider/facebook.go
rename to internal/api/provider/facebook.go
index b7ab318f..7fa226d3 100644
--- a/api/provider/facebook.go
+++ b/internal/api/provider/facebook.go
@@ -8,7 +8,7 @@ import (
 	"errors"
 	"strings"
 
-	"github.com/netlify/gotrue/conf"
+	"github.com/netlify/gotrue/internal/conf"
 	"golang.org/x/oauth2"
 )
 
diff --git a/api/provider/github.go b/internal/api/provider/github.go
similarity index 98%
rename from api/provider/github.go
rename to internal/api/provider/github.go
index f138b908..ecc465ba 100644
--- a/api/provider/github.go
+++ b/internal/api/provider/github.go
@@ -6,7 +6,7 @@ import (
 	"strconv"
 	"strings"
 
-	"github.com/netlify/gotrue/conf"
+	"github.com/netlify/gotrue/internal/conf"
 	"golang.org/x/oauth2"
 )
 
diff --git a/api/provider/gitlab.go b/internal/api/provider/gitlab.go
similarity index 98%
rename from api/provider/gitlab.go
rename to internal/api/provider/gitlab.go
index d6e3d948..cc84378d 100644
--- a/api/provider/gitlab.go
+++ b/internal/api/provider/gitlab.go
@@ -6,7 +6,7 @@ import (
 	"strconv"
 	"strings"
 
-	"github.com/netlify/gotrue/conf"
+	"github.com/netlify/gotrue/internal/conf"
 	"golang.org/x/oauth2"
 )
 
diff --git a/api/provider/google.go b/internal/api/provider/google.go
similarity index 98%
rename from api/provider/google.go
rename to internal/api/provider/google.go
index 71c0d581..2d705e32 100644
--- a/api/provider/google.go
+++ b/internal/api/provider/google.go
@@ -5,7 +5,7 @@ import (
 	"errors"
 	"strings"
 
-	"github.com/netlify/gotrue/conf"
+	"github.com/netlify/gotrue/internal/conf"
 	"golang.org/x/oauth2"
 )
 
diff --git a/api/provider/keycloak.go b/internal/api/provider/keycloak.go
similarity index 98%
rename from api/provider/keycloak.go
rename to internal/api/provider/keycloak.go
index dd380741..5f49c991 100644
--- a/api/provider/keycloak.go
+++ b/internal/api/provider/keycloak.go
@@ -5,7 +5,7 @@ import (
 	"errors"
 	"strings"
 
-	"github.com/netlify/gotrue/conf"
+	"github.com/netlify/gotrue/internal/conf"
 	"golang.org/x/oauth2"
 )
 
diff --git a/api/provider/linkedin.go b/internal/api/provider/linkedin.go
similarity index 99%
rename from api/provider/linkedin.go
rename to internal/api/provider/linkedin.go
index 374b827d..91f8d0ed 100644
--- a/api/provider/linkedin.go
+++ b/internal/api/provider/linkedin.go
@@ -5,7 +5,7 @@ import (
 	"errors"
 	"strings"
 
-	"github.com/netlify/gotrue/conf"
+	"github.com/netlify/gotrue/internal/conf"
 	"golang.org/x/oauth2"
 )
 
diff --git a/api/provider/notion.go b/internal/api/provider/notion.go
similarity index 98%
rename from api/provider/notion.go
rename to internal/api/provider/notion.go
index 1e767064..64e97212 100644
--- a/api/provider/notion.go
+++ b/internal/api/provider/notion.go
@@ -8,7 +8,7 @@ import (
 	"io"
 	"net/http"
 
-	"github.com/netlify/gotrue/conf"
+	"github.com/netlify/gotrue/internal/conf"
 	"golang.org/x/oauth2"
 )
 
diff --git a/api/provider/provider.go b/internal/api/provider/provider.go
similarity index 100%
rename from api/provider/provider.go
rename to internal/api/provider/provider.go
diff --git a/api/provider/slack.go b/internal/api/provider/slack.go
similarity index 98%
rename from api/provider/slack.go
rename to internal/api/provider/slack.go
index 2649c87a..bad20c6d 100644
--- a/api/provider/slack.go
+++ b/internal/api/provider/slack.go
@@ -5,7 +5,7 @@ import (
 	"errors"
 	"strings"
 
-	"github.com/netlify/gotrue/conf"
+	"github.com/netlify/gotrue/internal/conf"
 	"golang.org/x/oauth2"
 )
 
diff --git a/api/provider/spotify.go b/internal/api/provider/spotify.go
similarity index 98%
rename from api/provider/spotify.go
rename to internal/api/provider/spotify.go
index b2375838..00e59ac9 100644
--- a/api/provider/spotify.go
+++ b/internal/api/provider/spotify.go
@@ -5,7 +5,7 @@ import (
 	"errors"
 	"strings"
 
-	"github.com/netlify/gotrue/conf"
+	"github.com/netlify/gotrue/internal/conf"
 	"golang.org/x/oauth2"
 )
 
diff --git a/api/provider/twitch.go b/internal/api/provider/twitch.go
similarity index 98%
rename from api/provider/twitch.go
rename to internal/api/provider/twitch.go
index d7d9826d..c737b8ac 100644
--- a/api/provider/twitch.go
+++ b/internal/api/provider/twitch.go
@@ -10,7 +10,7 @@ import (
 	"strings"
 	"time"
 
-	"github.com/netlify/gotrue/conf"
+	"github.com/netlify/gotrue/internal/conf"
 	"golang.org/x/oauth2"
 )
 
diff --git a/api/provider/twitter.go b/internal/api/provider/twitter.go
similarity index 99%
rename from api/provider/twitter.go
rename to internal/api/provider/twitter.go
index 01e8d409..d96d806b 100644
--- a/api/provider/twitter.go
+++ b/internal/api/provider/twitter.go
@@ -11,7 +11,7 @@ import (
 	"strings"
 
 	"github.com/mrjones/oauth"
-	"github.com/netlify/gotrue/conf"
+	"github.com/netlify/gotrue/internal/conf"
 	"golang.org/x/oauth2"
 )
 
diff --git a/api/provider/workos.go b/internal/api/provider/workos.go
similarity index 98%
rename from api/provider/workos.go
rename to internal/api/provider/workos.go
index 31058139..ca3ef223 100644
--- a/api/provider/workos.go
+++ b/internal/api/provider/workos.go
@@ -6,7 +6,7 @@ import (
 	"strings"
 
 	"github.com/mitchellh/mapstructure"
-	"github.com/netlify/gotrue/conf"
+	"github.com/netlify/gotrue/internal/conf"
 	"golang.org/x/oauth2"
 )
 
diff --git a/api/provider/zoom.go b/internal/api/provider/zoom.go
similarity index 98%
rename from api/provider/zoom.go
rename to internal/api/provider/zoom.go
index 5c2e1acb..566993c4 100644
--- a/api/provider/zoom.go
+++ b/internal/api/provider/zoom.go
@@ -5,7 +5,7 @@ import (
 	"errors"
 	"strings"
 
-	"github.com/netlify/gotrue/conf"
+	"github.com/netlify/gotrue/internal/conf"
 	"golang.org/x/oauth2"
 )
 
diff --git a/api/reauthenticate.go b/internal/api/reauthenticate.go
similarity index 93%
rename from api/reauthenticate.go
rename to internal/api/reauthenticate.go
index 16ba7dd1..409c03c7 100644
--- a/api/reauthenticate.go
+++ b/internal/api/reauthenticate.go
@@ -6,10 +6,10 @@ import (
 	"fmt"
 	"net/http"
 
-	"github.com/netlify/gotrue/api/sms_provider"
-	"github.com/netlify/gotrue/conf"
-	"github.com/netlify/gotrue/models"
-	"github.com/netlify/gotrue/storage"
+	"github.com/netlify/gotrue/internal/api/sms_provider"
+	"github.com/netlify/gotrue/internal/conf"
+	"github.com/netlify/gotrue/internal/models"
+	"github.com/netlify/gotrue/internal/storage"
 )
 
 const InvalidNonceMessage = "Nonce has expired or is invalid"
diff --git a/api/recover.go b/internal/api/recover.go
similarity index 95%
rename from api/recover.go
rename to internal/api/recover.go
index d5c5a95b..8df3f591 100644
--- a/api/recover.go
+++ b/internal/api/recover.go
@@ -5,8 +5,8 @@ import (
 	"errors"
 	"net/http"
 
-	"github.com/netlify/gotrue/models"
-	"github.com/netlify/gotrue/storage"
+	"github.com/netlify/gotrue/internal/models"
+	"github.com/netlify/gotrue/internal/storage"
 )
 
 // RecoverParams holds the parameters for a password recovery request
diff --git a/api/samlacs.go b/internal/api/samlacs.go
similarity index 97%
rename from api/samlacs.go
rename to internal/api/samlacs.go
index d379cec9..e90b219b 100644
--- a/api/samlacs.go
+++ b/internal/api/samlacs.go
@@ -12,11 +12,11 @@ import (
 	"github.com/crewjam/saml"
 	"github.com/fatih/structs"
 	"github.com/gofrs/uuid"
-	"github.com/netlify/gotrue/api/provider"
-	"github.com/netlify/gotrue/models"
-	"github.com/netlify/gotrue/observability"
-	"github.com/netlify/gotrue/storage"
-	"github.com/netlify/gotrue/utilities"
+	"github.com/netlify/gotrue/internal/api/provider"
+	"github.com/netlify/gotrue/internal/models"
+	"github.com/netlify/gotrue/internal/observability"
+	"github.com/netlify/gotrue/internal/storage"
+	"github.com/netlify/gotrue/internal/utilities"
 )
 
 func (a *API) samlDestroyRelayState(ctx context.Context, relayState *models.SAMLRelayState) error {
diff --git a/api/samlassertion.go b/internal/api/samlassertion.go
similarity index 99%
rename from api/samlassertion.go
rename to internal/api/samlassertion.go
index 2f541c4b..fdcebb94 100644
--- a/api/samlassertion.go
+++ b/internal/api/samlassertion.go
@@ -5,7 +5,7 @@ import (
 	"time"
 
 	"github.com/crewjam/saml"
-	"github.com/netlify/gotrue/models"
+	"github.com/netlify/gotrue/internal/models"
 )
 
 type SAMLAssertion struct {
diff --git a/api/settings.go b/internal/api/settings.go
similarity index 100%
rename from api/settings.go
rename to internal/api/settings.go
diff --git a/api/settings_test.go b/internal/api/settings_test.go
similarity index 100%
rename from api/settings_test.go
rename to internal/api/settings_test.go
diff --git a/api/signup.go b/internal/api/signup.go
similarity index 97%
rename from api/signup.go
rename to internal/api/signup.go
index 8d6dbe65..76ee8210 100644
--- a/api/signup.go
+++ b/internal/api/signup.go
@@ -9,11 +9,11 @@ import (
 
 	"github.com/fatih/structs"
 	"github.com/gofrs/uuid"
-	"github.com/netlify/gotrue/api/provider"
-	"github.com/netlify/gotrue/api/sms_provider"
-	"github.com/netlify/gotrue/metering"
-	"github.com/netlify/gotrue/models"
-	"github.com/netlify/gotrue/storage"
+	"github.com/netlify/gotrue/internal/api/provider"
+	"github.com/netlify/gotrue/internal/api/sms_provider"
+	"github.com/netlify/gotrue/internal/metering"
+	"github.com/netlify/gotrue/internal/models"
+	"github.com/netlify/gotrue/internal/storage"
 	"github.com/pkg/errors"
 )
 
diff --git a/api/sms_provider/messagebird.go b/internal/api/sms_provider/messagebird.go
similarity index 98%
rename from api/sms_provider/messagebird.go
rename to internal/api/sms_provider/messagebird.go
index 19aec81a..c974f339 100644
--- a/api/sms_provider/messagebird.go
+++ b/internal/api/sms_provider/messagebird.go
@@ -7,7 +7,7 @@ import (
 	"net/url"
 	"strings"
 
-	"github.com/netlify/gotrue/conf"
+	"github.com/netlify/gotrue/internal/conf"
 )
 
 const (
diff --git a/api/sms_provider/sms_provider.go b/internal/api/sms_provider/sms_provider.go
similarity index 95%
rename from api/sms_provider/sms_provider.go
rename to internal/api/sms_provider/sms_provider.go
index 4ace1ad9..d9134428 100644
--- a/api/sms_provider/sms_provider.go
+++ b/internal/api/sms_provider/sms_provider.go
@@ -6,7 +6,7 @@ import (
 	"os"
 	"time"
 
-	"github.com/netlify/gotrue/conf"
+	"github.com/netlify/gotrue/internal/conf"
 )
 
 var defaultTimeout time.Duration = time.Second * 10
diff --git a/api/sms_provider/textlocal.go b/internal/api/sms_provider/textlocal.go
similarity index 97%
rename from api/sms_provider/textlocal.go
rename to internal/api/sms_provider/textlocal.go
index 36eb5067..0188068a 100644
--- a/api/sms_provider/textlocal.go
+++ b/internal/api/sms_provider/textlocal.go
@@ -8,7 +8,7 @@ import (
 	"net/url"
 	"strings"
 
-	"github.com/netlify/gotrue/conf"
+	"github.com/netlify/gotrue/internal/conf"
 )
 
 const (
diff --git a/api/sms_provider/twilio.go b/internal/api/sms_provider/twilio.go
similarity index 98%
rename from api/sms_provider/twilio.go
rename to internal/api/sms_provider/twilio.go
index 46c37ebc..4aad6eda 100644
--- a/api/sms_provider/twilio.go
+++ b/internal/api/sms_provider/twilio.go
@@ -7,7 +7,7 @@ import (
 	"net/url"
 	"strings"
 
-	"github.com/netlify/gotrue/conf"
+	"github.com/netlify/gotrue/internal/conf"
 )
 
 const (
diff --git a/api/sms_provider/vonage.go b/internal/api/sms_provider/vonage.go
similarity index 97%
rename from api/sms_provider/vonage.go
rename to internal/api/sms_provider/vonage.go
index 4d58bbfe..139a0fcb 100644
--- a/api/sms_provider/vonage.go
+++ b/internal/api/sms_provider/vonage.go
@@ -8,7 +8,7 @@ import (
 	"net/url"
 	"strings"
 
-	"github.com/netlify/gotrue/conf"
+	"github.com/netlify/gotrue/internal/conf"
 )
 
 const (
diff --git a/api/sorting.go b/internal/api/sorting.go
similarity index 95%
rename from api/sorting.go
rename to internal/api/sorting.go
index d3999bd9..ebbab9b1 100644
--- a/api/sorting.go
+++ b/internal/api/sorting.go
@@ -5,7 +5,7 @@ import (
 	"net/http"
 	"strings"
 
-	"github.com/netlify/gotrue/models"
+	"github.com/netlify/gotrue/internal/models"
 )
 
 func sort(r *http.Request, allowedFields map[string]bool, defaultSort []models.SortField) (*models.SortParams, error) {
diff --git a/api/sso.go b/internal/api/sso.go
similarity index 96%
rename from api/sso.go
rename to internal/api/sso.go
index f481ccea..d61a3cc5 100644
--- a/api/sso.go
+++ b/internal/api/sso.go
@@ -6,9 +6,9 @@ import (
 
 	"github.com/crewjam/saml"
 	"github.com/gofrs/uuid"
-	"github.com/netlify/gotrue/models"
-	"github.com/netlify/gotrue/storage"
-	"github.com/netlify/gotrue/utilities"
+	"github.com/netlify/gotrue/internal/models"
+	"github.com/netlify/gotrue/internal/storage"
+	"github.com/netlify/gotrue/internal/utilities"
 )
 
 type SingleSignOnParams struct {
diff --git a/api/ssoadmin.go b/internal/api/ssoadmin.go
similarity index 98%
rename from api/ssoadmin.go
rename to internal/api/ssoadmin.go
index 6155f6db..6f406cf4 100644
--- a/api/ssoadmin.go
+++ b/internal/api/ssoadmin.go
@@ -12,9 +12,9 @@ import (
 	"github.com/crewjam/saml/samlsp"
 	"github.com/go-chi/chi"
 	"github.com/gofrs/uuid"
-	"github.com/netlify/gotrue/models"
-	"github.com/netlify/gotrue/observability"
-	"github.com/netlify/gotrue/storage"
+	"github.com/netlify/gotrue/internal/models"
+	"github.com/netlify/gotrue/internal/observability"
+	"github.com/netlify/gotrue/internal/storage"
 )
 
 // loadSSOProvider looks for an idp_id parameter in the URL route and loads the SSO provider
diff --git a/api/token.go b/internal/api/token.go
similarity index 99%
rename from api/token.go
rename to internal/api/token.go
index 8965958c..2dbc0a45 100644
--- a/api/token.go
+++ b/internal/api/token.go
@@ -14,10 +14,10 @@ import (
 	"github.com/coreos/go-oidc/v3/oidc"
 	"github.com/gofrs/uuid"
 	"github.com/golang-jwt/jwt"
-	"github.com/netlify/gotrue/conf"
-	"github.com/netlify/gotrue/metering"
-	"github.com/netlify/gotrue/models"
-	"github.com/netlify/gotrue/storage"
+	"github.com/netlify/gotrue/internal/conf"
+	"github.com/netlify/gotrue/internal/metering"
+	"github.com/netlify/gotrue/internal/models"
+	"github.com/netlify/gotrue/internal/storage"
 )
 
 // GoTrueClaims is a struct thats used for JWT claims
diff --git a/api/user.go b/internal/api/user.go
similarity index 96%
rename from api/user.go
rename to internal/api/user.go
index 153ba20d..15db210b 100644
--- a/api/user.go
+++ b/internal/api/user.go
@@ -4,10 +4,10 @@ import (
 	"encoding/json"
 	"net/http"
 
-	"github.com/netlify/gotrue/api/sms_provider"
-	"github.com/netlify/gotrue/models"
-	"github.com/netlify/gotrue/observability"
-	"github.com/netlify/gotrue/storage"
+	"github.com/netlify/gotrue/internal/api/sms_provider"
+	"github.com/netlify/gotrue/internal/models"
+	"github.com/netlify/gotrue/internal/observability"
+	"github.com/netlify/gotrue/internal/storage"
 )
 
 // UserUpdateParams parameters for updating a user
diff --git a/api/verify.go b/internal/api/verify.go
similarity index 99%
rename from api/verify.go
rename to internal/api/verify.go
index b10a717c..ae9a2d0e 100644
--- a/api/verify.go
+++ b/internal/api/verify.go
@@ -12,9 +12,9 @@ import (
 	"strings"
 	"time"
 
-	"github.com/netlify/gotrue/models"
-	"github.com/netlify/gotrue/observability"
-	"github.com/netlify/gotrue/storage"
+	"github.com/netlify/gotrue/internal/models"
+	"github.com/netlify/gotrue/internal/observability"
+	"github.com/netlify/gotrue/internal/storage"
 	"github.com/sethvargo/go-password/password"
 )
 
diff --git a/conf/configuration.go b/internal/conf/configuration.go
similarity index 100%
rename from conf/configuration.go
rename to internal/conf/configuration.go
diff --git a/conf/configuration_test.go b/internal/conf/configuration_test.go
similarity index 100%
rename from conf/configuration_test.go
rename to internal/conf/configuration_test.go
diff --git a/conf/logging.go b/internal/conf/logging.go
similarity index 100%
rename from conf/logging.go
rename to internal/conf/logging.go
diff --git a/conf/metrics.go b/internal/conf/metrics.go
similarity index 100%
rename from conf/metrics.go
rename to internal/conf/metrics.go
diff --git a/conf/saml.go b/internal/conf/saml.go
similarity index 100%
rename from conf/saml.go
rename to internal/conf/saml.go
diff --git a/conf/saml_test.go b/internal/conf/saml_test.go
similarity index 100%
rename from conf/saml_test.go
rename to internal/conf/saml_test.go
diff --git a/conf/tracing.go b/internal/conf/tracing.go
similarity index 100%
rename from conf/tracing.go
rename to internal/conf/tracing.go
diff --git a/crypto/crypto.go b/internal/crypto/crypto.go
similarity index 100%
rename from crypto/crypto.go
rename to internal/crypto/crypto.go
diff --git a/crypto/password.go b/internal/crypto/password.go
similarity index 98%
rename from crypto/password.go
rename to internal/crypto/password.go
index 8f6f6446..e94f6158 100644
--- a/crypto/password.go
+++ b/internal/crypto/password.go
@@ -4,7 +4,7 @@ import (
 	"context"
 	"errors"
 
-	"github.com/netlify/gotrue/observability"
+	"github.com/netlify/gotrue/internal/observability"
 	"go.opentelemetry.io/otel/attribute"
 	metricinstrument "go.opentelemetry.io/otel/metric/instrument"
 	"golang.org/x/crypto/bcrypt"
diff --git a/mailer/mailer.go b/internal/mailer/mailer.go
similarity index 96%
rename from mailer/mailer.go
rename to internal/mailer/mailer.go
index 43d10bdb..7d487a86 100644
--- a/mailer/mailer.go
+++ b/internal/mailer/mailer.go
@@ -3,8 +3,8 @@ package mailer
 import (
 	"net/url"
 
-	"github.com/netlify/gotrue/conf"
-	"github.com/netlify/gotrue/models"
+	"github.com/netlify/gotrue/internal/conf"
+	"github.com/netlify/gotrue/internal/models"
 	"github.com/netlify/mailme"
 	"github.com/sirupsen/logrus"
 	"gopkg.in/gomail.v2"
diff --git a/mailer/mailer_test.go b/internal/mailer/mailer_test.go
similarity index 100%
rename from mailer/mailer_test.go
rename to internal/mailer/mailer_test.go
diff --git a/mailer/noop.go b/internal/mailer/noop.go
similarity index 100%
rename from mailer/noop.go
rename to internal/mailer/noop.go
diff --git a/mailer/template.go b/internal/mailer/template.go
similarity index 99%
rename from mailer/template.go
rename to internal/mailer/template.go
index 65b5fd12..e86731ef 100644
--- a/mailer/template.go
+++ b/internal/mailer/template.go
@@ -6,8 +6,8 @@ import (
 	"strings"
 
 	"github.com/badoux/checkmail"
-	"github.com/netlify/gotrue/conf"
-	"github.com/netlify/gotrue/models"
+	"github.com/netlify/gotrue/internal/conf"
+	"github.com/netlify/gotrue/internal/models"
 )
 
 type MailClient interface {
diff --git a/metering/record.go b/internal/metering/record.go
similarity index 100%
rename from metering/record.go
rename to internal/metering/record.go
diff --git a/models/amr.go b/internal/models/amr.go
similarity index 96%
rename from models/amr.go
rename to internal/models/amr.go
index f951e63a..1d26b874 100644
--- a/models/amr.go
+++ b/internal/models/amr.go
@@ -5,7 +5,7 @@ import (
 
 	"github.com/gobuffalo/pop/v5"
 	"github.com/gofrs/uuid"
-	"github.com/netlify/gotrue/storage"
+	"github.com/netlify/gotrue/internal/storage"
 	"github.com/pkg/errors"
 )
 
diff --git a/models/audit_log_entry.go b/internal/models/audit_log_entry.go
similarity index 98%
rename from models/audit_log_entry.go
rename to internal/models/audit_log_entry.go
index dfcfbfde..c0fe7066 100644
--- a/models/audit_log_entry.go
+++ b/internal/models/audit_log_entry.go
@@ -7,8 +7,8 @@ import (
 	"time"
 
 	"github.com/gofrs/uuid"
-	"github.com/netlify/gotrue/observability"
-	"github.com/netlify/gotrue/storage"
+	"github.com/netlify/gotrue/internal/observability"
+	"github.com/netlify/gotrue/internal/storage"
 	"github.com/pkg/errors"
 	"github.com/sirupsen/logrus"
 )
diff --git a/models/challenge.go b/internal/models/challenge.go
similarity index 97%
rename from models/challenge.go
rename to internal/models/challenge.go
index e6fb44be..3da8c336 100644
--- a/models/challenge.go
+++ b/internal/models/challenge.go
@@ -3,7 +3,7 @@ package models
 import (
 	"database/sql"
 	"github.com/gofrs/uuid"
-	"github.com/netlify/gotrue/storage"
+	"github.com/netlify/gotrue/internal/storage"
 	"github.com/pkg/errors"
 	"time"
 )
diff --git a/models/connection.go b/internal/models/connection.go
similarity index 96%
rename from models/connection.go
rename to internal/models/connection.go
index 1363b352..3250cd9d 100644
--- a/models/connection.go
+++ b/internal/models/connection.go
@@ -2,7 +2,7 @@ package models
 
 import (
 	"github.com/gobuffalo/pop/v5"
-	"github.com/netlify/gotrue/storage"
+	"github.com/netlify/gotrue/internal/storage"
 )
 
 type Pagination struct {
diff --git a/models/errors.go b/internal/models/errors.go
similarity index 100%
rename from models/errors.go
rename to internal/models/errors.go
diff --git a/models/factor.go b/internal/models/factor.go
similarity index 99%
rename from models/factor.go
rename to internal/models/factor.go
index 2abe912e..dcbc48a2 100644
--- a/models/factor.go
+++ b/internal/models/factor.go
@@ -6,7 +6,7 @@ import (
 
 	"github.com/gobuffalo/pop/v5"
 	"github.com/gofrs/uuid"
-	"github.com/netlify/gotrue/storage"
+	"github.com/netlify/gotrue/internal/storage"
 	"github.com/pkg/errors"
 )
 
diff --git a/models/identity.go b/internal/models/identity.go
similarity index 98%
rename from models/identity.go
rename to internal/models/identity.go
index a31152f1..3e7155dd 100644
--- a/models/identity.go
+++ b/internal/models/identity.go
@@ -7,7 +7,7 @@ import (
 
 	"github.com/gobuffalo/pop/v5"
 	"github.com/gofrs/uuid"
-	"github.com/netlify/gotrue/storage"
+	"github.com/netlify/gotrue/internal/storage"
 	"github.com/pkg/errors"
 )
 
diff --git a/models/json_map.go b/internal/models/json_map.go
similarity index 100%
rename from models/json_map.go
rename to internal/models/json_map.go
diff --git a/models/linking.go b/internal/models/linking.go
similarity index 99%
rename from models/linking.go
rename to internal/models/linking.go
index 8c501cf7..81698a13 100644
--- a/models/linking.go
+++ b/internal/models/linking.go
@@ -3,7 +3,7 @@ package models
 import (
 	"strings"
 
-	"github.com/netlify/gotrue/storage"
+	"github.com/netlify/gotrue/internal/storage"
 )
 
 // GetAccountLinkingDomain returns a string that describes the account linking
diff --git a/models/refresh_token.go b/internal/models/refresh_token.go
similarity index 98%
rename from models/refresh_token.go
rename to internal/models/refresh_token.go
index b86e5067..29783f9d 100644
--- a/models/refresh_token.go
+++ b/internal/models/refresh_token.go
@@ -7,8 +7,8 @@ import (
 
 	"github.com/gobuffalo/pop/v5"
 	"github.com/gofrs/uuid"
-	"github.com/netlify/gotrue/crypto"
-	"github.com/netlify/gotrue/storage"
+	"github.com/netlify/gotrue/internal/crypto"
+	"github.com/netlify/gotrue/internal/storage"
 	"github.com/pkg/errors"
 )
 
diff --git a/models/sessions.go b/internal/models/sessions.go
similarity index 99%
rename from models/sessions.go
rename to internal/models/sessions.go
index 29cbdc3a..23adcd6a 100644
--- a/models/sessions.go
+++ b/internal/models/sessions.go
@@ -8,7 +8,7 @@ import (
 
 	"github.com/gobuffalo/pop/v5"
 	"github.com/gofrs/uuid"
-	"github.com/netlify/gotrue/storage"
+	"github.com/netlify/gotrue/internal/storage"
 	"github.com/pkg/errors"
 )
 
diff --git a/models/sso.go b/internal/models/sso.go
similarity index 99%
rename from models/sso.go
rename to internal/models/sso.go
index 6f1e7c55..d612017a 100644
--- a/models/sso.go
+++ b/internal/models/sso.go
@@ -10,7 +10,7 @@ import (
 	"github.com/crewjam/saml"
 	"github.com/crewjam/saml/samlsp"
 	"github.com/gofrs/uuid"
-	"github.com/netlify/gotrue/storage"
+	"github.com/netlify/gotrue/internal/storage"
 	"github.com/pkg/errors"
 )
 
diff --git a/models/user.go b/internal/models/user.go
similarity index 99%
rename from models/user.go
rename to internal/models/user.go
index 0cbe7f04..291e8224 100644
--- a/models/user.go
+++ b/internal/models/user.go
@@ -10,8 +10,8 @@ import (
 
 	"github.com/gobuffalo/pop/v5"
 	"github.com/gofrs/uuid"
-	"github.com/netlify/gotrue/crypto"
-	"github.com/netlify/gotrue/storage"
+	"github.com/netlify/gotrue/internal/crypto"
+	"github.com/netlify/gotrue/internal/storage"
 	"github.com/pkg/errors"
 )
 
diff --git a/observability/cleanup.go b/internal/observability/cleanup.go
similarity index 100%
rename from observability/cleanup.go
rename to internal/observability/cleanup.go
diff --git a/observability/logging.go b/internal/observability/logging.go
similarity index 97%
rename from observability/logging.go
rename to internal/observability/logging.go
index be7598a9..71795970 100644
--- a/observability/logging.go
+++ b/internal/observability/logging.go
@@ -7,7 +7,7 @@ import (
 	"github.com/bombsimon/logrusr/v3"
 	"github.com/gobuffalo/pop/v5"
 	"github.com/gobuffalo/pop/v5/logging"
-	"github.com/netlify/gotrue/conf"
+	"github.com/netlify/gotrue/internal/conf"
 	"github.com/sirupsen/logrus"
 	"go.opentelemetry.io/otel"
 )
diff --git a/observability/metrics.go b/internal/observability/metrics.go
similarity index 99%
rename from observability/metrics.go
rename to internal/observability/metrics.go
index c3079713..a5cc81a6 100644
--- a/observability/metrics.go
+++ b/internal/observability/metrics.go
@@ -8,7 +8,7 @@ import (
 	"sync"
 	"time"
 
-	"github.com/netlify/gotrue/conf"
+	"github.com/netlify/gotrue/internal/conf"
 	"github.com/sirupsen/logrus"
 
 	"go.opentelemetry.io/otel/exporters/otlp/otlpmetric"
diff --git a/observability/request-logger.go b/internal/observability/request-logger.go
similarity index 97%
rename from observability/request-logger.go
rename to internal/observability/request-logger.go
index 573fe1fa..47f7edab 100644
--- a/observability/request-logger.go
+++ b/internal/observability/request-logger.go
@@ -6,7 +6,7 @@ import (
 	"time"
 
 	chimiddleware "github.com/go-chi/chi/middleware"
-	"github.com/netlify/gotrue/utilities"
+	"github.com/netlify/gotrue/internal/utilities"
 	"github.com/sirupsen/logrus"
 )
 
diff --git a/observability/request-tracing.go b/internal/observability/request-tracing.go
similarity index 100%
rename from observability/request-tracing.go
rename to internal/observability/request-tracing.go
diff --git a/observability/tracing.go b/internal/observability/tracing.go
similarity index 97%
rename from observability/tracing.go
rename to internal/observability/tracing.go
index 7ac3837a..056d52b3 100644
--- a/observability/tracing.go
+++ b/internal/observability/tracing.go
@@ -7,8 +7,8 @@ import (
 	"sync"
 	"time"
 
-	"github.com/netlify/gotrue/conf"
-	"github.com/netlify/gotrue/utilities"
+	"github.com/netlify/gotrue/internal/conf"
+	"github.com/netlify/gotrue/internal/utilities"
 	"github.com/sirupsen/logrus"
 
 	"github.com/opentracing/opentracing-go"
diff --git a/security/hcaptcha.go b/internal/security/hcaptcha.go
similarity index 98%
rename from security/hcaptcha.go
rename to internal/security/hcaptcha.go
index 427e762f..b9447451 100644
--- a/security/hcaptcha.go
+++ b/internal/security/hcaptcha.go
@@ -10,7 +10,7 @@ import (
 	"strings"
 	"time"
 
-	"github.com/netlify/gotrue/utilities"
+	"github.com/netlify/gotrue/internal/utilities"
 	"github.com/pkg/errors"
 )
 
diff --git a/storage/dial.go b/internal/storage/dial.go
similarity index 99%
rename from storage/dial.go
rename to internal/storage/dial.go
index 721014bb..dcc088a5 100644
--- a/storage/dial.go
+++ b/internal/storage/dial.go
@@ -11,7 +11,7 @@ import (
 	"github.com/gobuffalo/pop/v5"
 	"github.com/gobuffalo/pop/v5/columns"
 	"github.com/jmoiron/sqlx"
-	"github.com/netlify/gotrue/conf"
+	"github.com/netlify/gotrue/internal/conf"
 	"github.com/pkg/errors"
 	"github.com/sirupsen/logrus"
 )
diff --git a/utilities/postgres.go b/internal/utilities/postgres.go
similarity index 100%
rename from utilities/postgres.go
rename to internal/utilities/postgres.go
diff --git a/utilities/request.go b/internal/utilities/request.go
similarity index 100%
rename from utilities/request.go
rename to internal/utilities/request.go
diff --git a/utilities/request_test.go b/internal/utilities/request_test.go
similarity index 100%
rename from utilities/request_test.go
rename to internal/utilities/request_test.go
diff --git a/utilities/version.go b/internal/utilities/version.go
similarity index 100%
rename from utilities/version.go
rename to internal/utilities/version.go
diff --git a/main.go b/main.go
index 1c124d35..0794c35c 100644
--- a/main.go
+++ b/main.go
@@ -7,9 +7,9 @@ import (
 	"syscall"
 	"time"
 
-	"github.com/netlify/gotrue/api"
 	"github.com/netlify/gotrue/cmd"
-	"github.com/netlify/gotrue/observability"
+	"github.com/netlify/gotrue/internal/api"
+	"github.com/netlify/gotrue/internal/observability"
 	"github.com/sirupsen/logrus"
 )
 


Test patch:
diff --git a/api/admin_test.go b/internal/api/admin_test.go
similarity index 99%
rename from api/admin_test.go
rename to internal/api/admin_test.go
index 9e096434..e0355f41 100644
--- a/api/admin_test.go
+++ b/internal/api/admin_test.go
@@ -11,8 +11,8 @@ import (
 	"time"
 
 	jwt "github.com/golang-jwt/jwt"
-	"github.com/netlify/gotrue/conf"
-	"github.com/netlify/gotrue/models"
+	"github.com/netlify/gotrue/internal/conf"
+	"github.com/netlify/gotrue/internal/models"
 	"github.com/stretchr/testify/assert"
 	"github.com/stretchr/testify/require"
 	"github.com/stretchr/testify/suite"
diff --git a/api/api_test.go b/internal/api/api_test.go
similarity index 83%
rename from api/api_test.go
rename to internal/api/api_test.go
index a7b6d3c9..5dc002e0 100644
--- a/api/api_test.go
+++ b/internal/api/api_test.go
@@ -4,16 +4,16 @@ import (
 	"context"
 	"testing"
 
-	"github.com/netlify/gotrue/conf"
-	"github.com/netlify/gotrue/crypto"
-	"github.com/netlify/gotrue/storage"
-	"github.com/netlify/gotrue/storage/test"
+	"github.com/netlify/gotrue/internal/conf"
+	"github.com/netlify/gotrue/internal/crypto"
+	"github.com/netlify/gotrue/internal/storage"
+	"github.com/netlify/gotrue/internal/storage/test"
 	"github.com/stretchr/testify/require"
 )
 
 const (
 	apiTestVersion = "1"
-	apiTestConfig  = "../hack/test.env"
+	apiTestConfig  = "../../hack/test.env"
 )
 
 func init() {
diff --git a/api/audit_test.go b/internal/api/audit_test.go
similarity index 97%
rename from api/audit_test.go
rename to internal/api/audit_test.go
index ca3cc36e..1ad83ed1 100644
--- a/api/audit_test.go
+++ b/internal/api/audit_test.go
@@ -9,8 +9,8 @@ import (
 	"time"
 
 	jwt "github.com/golang-jwt/jwt"
-	"github.com/netlify/gotrue/conf"
-	"github.com/netlify/gotrue/models"
+	"github.com/netlify/gotrue/internal/conf"
+	"github.com/netlify/gotrue/internal/models"
 	"github.com/stretchr/testify/assert"
 	"github.com/stretchr/testify/require"
 	"github.com/stretchr/testify/suite"
diff --git a/api/auth_test.go b/internal/api/auth_test.go
similarity index 98%
rename from api/auth_test.go
rename to internal/api/auth_test.go
index 9d616718..8b5dc547 100644
--- a/api/auth_test.go
+++ b/internal/api/auth_test.go
@@ -7,8 +7,8 @@ import (
 
 	"github.com/gofrs/uuid"
 	jwt "github.com/golang-jwt/jwt"
-	"github.com/netlify/gotrue/conf"
-	"github.com/netlify/gotrue/models"
+	"github.com/netlify/gotrue/internal/conf"
+	"github.com/netlify/gotrue/internal/models"
 	"github.com/stretchr/testify/require"
 	"github.com/stretchr/testify/suite"
 )
diff --git a/api/external_apple_test.go b/internal/api/external_apple_test.go
similarity index 100%
rename from api/external_apple_test.go
rename to internal/api/external_apple_test.go
diff --git a/api/external_azure_test.go b/internal/api/external_azure_test.go
similarity index 100%
rename from api/external_azure_test.go
rename to internal/api/external_azure_test.go
diff --git a/api/external_bitbucket_test.go b/internal/api/external_bitbucket_test.go
similarity index 100%
rename from api/external_bitbucket_test.go
rename to internal/api/external_bitbucket_test.go
diff --git a/api/external_discord_test.go b/internal/api/external_discord_test.go
similarity index 100%
rename from api/external_discord_test.go
rename to internal/api/external_discord_test.go
diff --git a/api/external_facebook_test.go b/internal/api/external_facebook_test.go
similarity index 100%
rename from api/external_facebook_test.go
rename to internal/api/external_facebook_test.go
diff --git a/api/external_github_test.go b/internal/api/external_github_test.go
similarity index 99%
rename from api/external_github_test.go
rename to internal/api/external_github_test.go
index eda895b6..2a4d1862 100644
--- a/api/external_github_test.go
+++ b/internal/api/external_github_test.go
@@ -8,7 +8,7 @@ import (
 	"time"
 
 	jwt "github.com/golang-jwt/jwt"
-	"github.com/netlify/gotrue/models"
+	"github.com/netlify/gotrue/internal/models"
 	"github.com/stretchr/testify/require"
 )
 
diff --git a/api/external_test.go b/internal/api/external_test.go
similarity index 98%
rename from api/external_test.go
rename to internal/api/external_test.go
index c0ec4d90..4daf3e6f 100644
--- a/api/external_test.go
+++ b/internal/api/external_test.go
@@ -6,8 +6,8 @@ import (
 	"net/url"
 	"testing"
 
-	"github.com/netlify/gotrue/conf"
-	"github.com/netlify/gotrue/models"
+	"github.com/netlify/gotrue/internal/conf"
+	"github.com/netlify/gotrue/internal/models"
 	"github.com/stretchr/testify/require"
 	"github.com/stretchr/testify/suite"
 )
diff --git a/api/helpers_test.go b/internal/api/helpers_test.go
similarity index 100%
rename from api/helpers_test.go
rename to internal/api/helpers_test.go
diff --git a/api/hook_test.go b/internal/api/hook_test.go
similarity index 96%
rename from api/hook_test.go
rename to internal/api/hook_test.go
index 8311d6e2..b75d239b 100644
--- a/api/hook_test.go
+++ b/internal/api/hook_test.go
@@ -10,9 +10,9 @@ import (
 	"testing"
 	"time"
 
-	"github.com/netlify/gotrue/conf"
-	"github.com/netlify/gotrue/models"
-	"github.com/netlify/gotrue/storage/test"
+	"github.com/netlify/gotrue/internal/conf"
+	"github.com/netlify/gotrue/internal/models"
+	"github.com/netlify/gotrue/internal/storage/test"
 	"github.com/stretchr/testify/assert"
 	"github.com/stretchr/testify/require"
 )
diff --git a/api/invite_test.go b/internal/api/invite_test.go
similarity index 99%
rename from api/invite_test.go
rename to internal/api/invite_test.go
index a1a2e2b7..c9f74a5c 100644
--- a/api/invite_test.go
+++ b/internal/api/invite_test.go
@@ -12,8 +12,8 @@ import (
 	"time"
 
 	jwt "github.com/golang-jwt/jwt"
-	"github.com/netlify/gotrue/conf"
-	"github.com/netlify/gotrue/models"
+	"github.com/netlify/gotrue/internal/conf"
+	"github.com/netlify/gotrue/internal/models"
 	"github.com/stretchr/testify/assert"
 	"github.com/stretchr/testify/require"
 	"github.com/stretchr/testify/suite"
diff --git a/api/logout_test.go b/internal/api/logout_test.go
similarity index 94%
rename from api/logout_test.go
rename to internal/api/logout_test.go
index 47b6a65b..7ccab664 100644
--- a/api/logout_test.go
+++ b/internal/api/logout_test.go
@@ -7,8 +7,8 @@ import (
 	"testing"
 	"time"
 
-	"github.com/netlify/gotrue/conf"
-	"github.com/netlify/gotrue/models"
+	"github.com/netlify/gotrue/internal/conf"
+	"github.com/netlify/gotrue/internal/models"
 	"github.com/stretchr/testify/require"
 	"github.com/stretchr/testify/suite"
 )
diff --git a/api/mail_test.go b/internal/api/mail_test.go
similarity index 97%
rename from api/mail_test.go
rename to internal/api/mail_test.go
index f25fecb2..5c34bf08 100644
--- a/api/mail_test.go
+++ b/internal/api/mail_test.go
@@ -10,8 +10,8 @@ import (
 	"testing"
 
 	"github.com/golang-jwt/jwt"
-	"github.com/netlify/gotrue/conf"
-	"github.com/netlify/gotrue/models"
+	"github.com/netlify/gotrue/internal/conf"
+	"github.com/netlify/gotrue/internal/models"
 	"github.com/stretchr/testify/require"
 	"github.com/stretchr/testify/suite"
 )
diff --git a/api/mfa_test.go b/internal/api/mfa_test.go
similarity index 99%
rename from api/mfa_test.go
rename to internal/api/mfa_test.go
index 32144990..109078ad 100644
--- a/api/mfa_test.go
+++ b/internal/api/mfa_test.go
@@ -11,9 +11,9 @@ import (
 	"testing"
 	"time"
 
-	"github.com/netlify/gotrue/conf"
-	"github.com/netlify/gotrue/models"
-	"github.com/netlify/gotrue/utilities"
+	"github.com/netlify/gotrue/internal/conf"
+	"github.com/netlify/gotrue/internal/models"
+	"github.com/netlify/gotrue/internal/utilities"
 	"github.com/pquerna/otp"
 
 	"github.com/jackc/pgx/v4"
diff --git a/api/middleware_test.go b/internal/api/middleware_test.go
similarity index 99%
rename from api/middleware_test.go
rename to internal/api/middleware_test.go
index c5154319..dfd8cdfc 100644
--- a/api/middleware_test.go
+++ b/internal/api/middleware_test.go
@@ -10,7 +10,7 @@ import (
 	"testing"
 
 	jwt "github.com/golang-jwt/jwt"
-	"github.com/netlify/gotrue/conf"
+	"github.com/netlify/gotrue/internal/conf"
 	"github.com/stretchr/testify/assert"
 	"github.com/stretchr/testify/require"
 	"github.com/stretchr/testify/suite"
diff --git a/api/opentelemetry-tracer_test.go b/internal/api/opentelemetry-tracer_test.go
similarity index 96%
rename from api/opentelemetry-tracer_test.go
rename to internal/api/opentelemetry-tracer_test.go
index 35a7309d..1812f374 100644
--- a/api/opentelemetry-tracer_test.go
+++ b/internal/api/opentelemetry-tracer_test.go
@@ -5,8 +5,8 @@ import (
 	"net/http/httptest"
 	"testing"
 
-	"github.com/netlify/gotrue/conf"
-	"github.com/netlify/gotrue/storage"
+	"github.com/netlify/gotrue/internal/conf"
+	"github.com/netlify/gotrue/internal/storage"
 	"github.com/stretchr/testify/assert"
 	"github.com/stretchr/testify/require"
 	"github.com/stretchr/testify/suite"
diff --git a/api/opentracer.go b/internal/api/opentracer.go
similarity index 100%
rename from api/opentracer.go
rename to internal/api/opentracer.go
diff --git a/api/opentracer_test.go b/internal/api/opentracer_test.go
similarity index 95%
rename from api/opentracer_test.go
rename to internal/api/opentracer_test.go
index 016b20c4..afb2665e 100644
--- a/api/opentracer_test.go
+++ b/internal/api/opentracer_test.go
@@ -5,8 +5,8 @@ import (
 	"net/http/httptest"
 	"testing"
 
-	"github.com/netlify/gotrue/conf"
-	"github.com/netlify/gotrue/storage"
+	"github.com/netlify/gotrue/internal/conf"
+	"github.com/netlify/gotrue/internal/storage"
 	"github.com/opentracing/opentracing-go"
 	"github.com/opentracing/opentracing-go/mocktracer"
 	"github.com/stretchr/testify/assert"
diff --git a/api/otp_test.go b/internal/api/otp_test.go
similarity index 98%
rename from api/otp_test.go
rename to internal/api/otp_test.go
index beea22c3..6e8c426b 100644
--- a/api/otp_test.go
+++ b/internal/api/otp_test.go
@@ -7,8 +7,8 @@ import (
 	"net/http/httptest"
 	"testing"
 
-	"github.com/netlify/gotrue/conf"
-	"github.com/netlify/gotrue/models"
+	"github.com/netlify/gotrue/internal/conf"
+	"github.com/netlify/gotrue/internal/models"
 	"github.com/stretchr/testify/assert"
 	"github.com/stretchr/testify/require"
 	"github.com/stretchr/testify/suite"
diff --git a/api/phone_test.go b/internal/api/phone_test.go
similarity index 98%
rename from api/phone_test.go
rename to internal/api/phone_test.go
index 63fe361f..7efe828f 100644
--- a/api/phone_test.go
+++ b/internal/api/phone_test.go
@@ -11,8 +11,8 @@ import (
 	"testing"
 	"time"
 
-	"github.com/netlify/gotrue/conf"
-	"github.com/netlify/gotrue/models"
+	"github.com/netlify/gotrue/internal/conf"
+	"github.com/netlify/gotrue/internal/models"
 	"github.com/stretchr/testify/assert"
 	"github.com/stretchr/testify/mock"
 	"github.com/stretchr/testify/require"
diff --git a/api/recover_test.go b/internal/api/recover_test.go
similarity index 98%
rename from api/recover_test.go
rename to internal/api/recover_test.go
index a58bd7c9..e1227eb2 100644
--- a/api/recover_test.go
+++ b/internal/api/recover_test.go
@@ -8,8 +8,8 @@ import (
 	"testing"
 	"time"
 
-	"github.com/netlify/gotrue/conf"
-	"github.com/netlify/gotrue/models"
+	"github.com/netlify/gotrue/internal/conf"
+	"github.com/netlify/gotrue/internal/models"
 	"github.com/stretchr/testify/assert"
 	"github.com/stretchr/testify/require"
 	"github.com/stretchr/testify/suite"
diff --git a/api/router.go b/internal/api/router.go
similarity index 100%
rename from api/router.go
rename to internal/api/router.go
diff --git a/api/saml.go b/internal/api/saml.go
similarity index 100%
rename from api/saml.go
rename to internal/api/saml.go
diff --git a/api/saml_test.go b/internal/api/saml_test.go
similarity index 98%
rename from api/saml_test.go
rename to internal/api/saml_test.go
index af662b0b..b83ba7b6 100644
--- a/api/saml_test.go
+++ b/internal/api/saml_test.go
@@ -8,7 +8,7 @@ import (
 	"net/http/httptest"
 
 	"github.com/crewjam/saml"
-	"github.com/netlify/gotrue/conf"
+	"github.com/netlify/gotrue/internal/conf"
 	"github.com/stretchr/testify/require"
 )
 
diff --git a/api/samlassertion_test.go b/internal/api/samlassertion_test.go
similarity index 99%
rename from api/samlassertion_test.go
rename to internal/api/samlassertion_test.go
index 606c1901..56b6cf31 100644
--- a/api/samlassertion_test.go
+++ b/internal/api/samlassertion_test.go
@@ -6,7 +6,7 @@ import (
 	"encoding/xml"
 
 	"github.com/crewjam/saml"
-	"github.com/netlify/gotrue/models"
+	"github.com/netlify/gotrue/internal/models"
 	"github.com/stretchr/testify/require"
 )
 
diff --git a/api/signup_test.go b/internal/api/signup_test.go
similarity index 98%
rename from api/signup_test.go
rename to internal/api/signup_test.go
index 03d9fb75..784bf34a 100644
--- a/api/signup_test.go
+++ b/internal/api/signup_test.go
@@ -13,8 +13,8 @@ import (
 
 	"github.com/gofrs/uuid"
 	jwt "github.com/golang-jwt/jwt"
-	"github.com/netlify/gotrue/conf"
-	"github.com/netlify/gotrue/models"
+	"github.com/netlify/gotrue/internal/conf"
+	"github.com/netlify/gotrue/internal/models"
 	"github.com/stretchr/testify/assert"
 	"github.com/stretchr/testify/require"
 	"github.com/stretchr/testify/suite"
diff --git a/api/sms_provider/sms_provider_test.go b/internal/api/sms_provider/sms_provider_test.go
similarity index 99%
rename from api/sms_provider/sms_provider_test.go
rename to internal/api/sms_provider/sms_provider_test.go
index b13bd9cd..a23b995d 100644
--- a/api/sms_provider/sms_provider_test.go
+++ b/internal/api/sms_provider/sms_provider_test.go
@@ -7,7 +7,7 @@ import (
 	"net/url"
 	"testing"
 
-	"github.com/netlify/gotrue/conf"
+	"github.com/netlify/gotrue/internal/conf"
 	"github.com/stretchr/testify/mock"
 	"github.com/stretchr/testify/require"
 	"github.com/stretchr/testify/suite"
diff --git a/api/sso_test.go b/internal/api/sso_test.go
similarity index 99%
rename from api/sso_test.go
rename to internal/api/sso_test.go
index 544c890a..e2cd2527 100644
--- a/api/sso_test.go
+++ b/internal/api/sso_test.go
@@ -12,8 +12,8 @@ import (
 	"time"
 
 	jwt "github.com/golang-jwt/jwt"
-	"github.com/netlify/gotrue/conf"
-	"github.com/netlify/gotrue/models"
+	"github.com/netlify/gotrue/internal/conf"
+	"github.com/netlify/gotrue/internal/models"
 	"github.com/stretchr/testify/require"
 	"github.com/stretchr/testify/suite"
 )
diff --git a/api/token_test.go b/internal/api/token_test.go
similarity index 99%
rename from api/token_test.go
rename to internal/api/token_test.go
index acecc256..b4c12fb4 100644
--- a/api/token_test.go
+++ b/internal/api/token_test.go
@@ -9,8 +9,8 @@ import (
 	"testing"
 	"time"
 
-	"github.com/netlify/gotrue/conf"
-	"github.com/netlify/gotrue/models"
+	"github.com/netlify/gotrue/internal/conf"
+	"github.com/netlify/gotrue/internal/models"
 	"github.com/stretchr/testify/assert"
 	"github.com/stretchr/testify/require"
 	"github.com/stretchr/testify/suite"
diff --git a/api/user_test.go b/internal/api/user_test.go
similarity index 99%
rename from api/user_test.go
rename to internal/api/user_test.go
index f1a9c429..5fe27422 100644
--- a/api/user_test.go
+++ b/internal/api/user_test.go
@@ -10,8 +10,8 @@ import (
 	"testing"
 	"time"
 
-	"github.com/netlify/gotrue/conf"
-	"github.com/netlify/gotrue/models"
+	"github.com/netlify/gotrue/internal/conf"
+	"github.com/netlify/gotrue/internal/models"
 	"github.com/stretchr/testify/require"
 	"github.com/stretchr/testify/suite"
 )
diff --git a/api/verify_test.go b/internal/api/verify_test.go
similarity index 99%
rename from api/verify_test.go
rename to internal/api/verify_test.go
index ad16ed6d..1840ebd5 100644
--- a/api/verify_test.go
+++ b/internal/api/verify_test.go
@@ -12,8 +12,8 @@ import (
 	"testing"
 	"time"
 
-	"github.com/netlify/gotrue/conf"
-	"github.com/netlify/gotrue/models"
+	"github.com/netlify/gotrue/internal/conf"
+	"github.com/netlify/gotrue/internal/models"
 	"github.com/stretchr/testify/assert"
 	"github.com/stretchr/testify/require"
 	"github.com/stretchr/testify/suite"
diff --git a/models/db_test.go b/internal/models/db_test.go
similarity index 92%
rename from models/db_test.go
rename to internal/models/db_test.go
index f6d5ff46..3d50bf75 100644
--- a/models/db_test.go
+++ b/internal/models/db_test.go
@@ -4,7 +4,7 @@ import (
 	"testing"
 
 	"github.com/gobuffalo/pop/v5"
-	"github.com/netlify/gotrue/models"
+	"github.com/netlify/gotrue/internal/models"
 	"github.com/stretchr/testify/assert"
 )
 
diff --git a/models/factor_test.go b/internal/models/factor_test.go
similarity index 94%
rename from models/factor_test.go
rename to internal/models/factor_test.go
index 2d150566..ab714027 100644
--- a/models/factor_test.go
+++ b/internal/models/factor_test.go
@@ -5,9 +5,9 @@ import (
 	"testing"
 
 	"github.com/gofrs/uuid"
-	"github.com/netlify/gotrue/conf"
-	"github.com/netlify/gotrue/storage"
-	"github.com/netlify/gotrue/storage/test"
+	"github.com/netlify/gotrue/internal/conf"
+	"github.com/netlify/gotrue/internal/storage"
+	"github.com/netlify/gotrue/internal/storage/test"
 	"github.com/stretchr/testify/require"
 	"github.com/stretchr/testify/suite"
 )
diff --git a/models/identity_test.go b/internal/models/identity_test.go
similarity index 95%
rename from models/identity_test.go
rename to internal/models/identity_test.go
index 276033a5..469c80ca 100644
--- a/models/identity_test.go
+++ b/internal/models/identity_test.go
@@ -4,9 +4,9 @@ import (
 	"testing"
 
 	"github.com/gofrs/uuid"
-	"github.com/netlify/gotrue/conf"
-	"github.com/netlify/gotrue/storage"
-	"github.com/netlify/gotrue/storage/test"
+	"github.com/netlify/gotrue/internal/conf"
+	"github.com/netlify/gotrue/internal/storage"
+	"github.com/netlify/gotrue/internal/storage/test"
 	"github.com/stretchr/testify/require"
 	"github.com/stretchr/testify/suite"
 )
diff --git a/models/linking_test.go b/internal/models/linking_test.go
similarity index 97%
rename from models/linking_test.go
rename to internal/models/linking_test.go
index a24d4ece..95eb95b6 100644
--- a/models/linking_test.go
+++ b/internal/models/linking_test.go
@@ -3,9 +3,9 @@ package models
 import (
 	"testing"
 
-	"github.com/netlify/gotrue/conf"
-	"github.com/netlify/gotrue/storage"
-	"github.com/netlify/gotrue/storage/test"
+	"github.com/netlify/gotrue/internal/conf"
+	"github.com/netlify/gotrue/internal/storage"
+	"github.com/netlify/gotrue/internal/storage/test"
 	"github.com/stretchr/testify/require"
 	"github.com/stretchr/testify/suite"
 )
diff --git a/models/refresh_token_test.go b/internal/models/refresh_token_test.go
similarity index 93%
rename from models/refresh_token_test.go
rename to internal/models/refresh_token_test.go
index 4f3e6b16..9feeac76 100644
--- a/models/refresh_token_test.go
+++ b/internal/models/refresh_token_test.go
@@ -4,9 +4,9 @@ import (
 	"net/http"
 	"testing"
 
-	"github.com/netlify/gotrue/conf"
-	"github.com/netlify/gotrue/storage"
-	"github.com/netlify/gotrue/storage/test"
+	"github.com/netlify/gotrue/internal/conf"
+	"github.com/netlify/gotrue/internal/storage"
+	"github.com/netlify/gotrue/internal/storage/test"
 	"github.com/stretchr/testify/require"
 	"github.com/stretchr/testify/suite"
 )
diff --git a/models/sessions_test.go b/internal/models/sessions_test.go
similarity index 93%
rename from models/sessions_test.go
rename to internal/models/sessions_test.go
index b0991514..e07e9152 100644
--- a/models/sessions_test.go
+++ b/internal/models/sessions_test.go
@@ -1,9 +1,9 @@
 package models
 
 import (
-	"github.com/netlify/gotrue/conf"
-	"github.com/netlify/gotrue/storage"
-	"github.com/netlify/gotrue/storage/test"
+	"github.com/netlify/gotrue/internal/conf"
+	"github.com/netlify/gotrue/internal/storage"
+	"github.com/netlify/gotrue/internal/storage/test"
 	"github.com/stretchr/testify/require"
 	"github.com/stretchr/testify/suite"
 	"testing"
diff --git a/models/sso_test.go b/internal/models/sso_test.go
similarity index 97%
rename from models/sso_test.go
rename to internal/models/sso_test.go
index 16943bfc..69af3764 100644
--- a/models/sso_test.go
+++ b/internal/models/sso_test.go
@@ -3,9 +3,9 @@ package models
 import (
 	tst "testing"
 
-	"github.com/netlify/gotrue/conf"
-	"github.com/netlify/gotrue/storage"
-	"github.com/netlify/gotrue/storage/test"
+	"github.com/netlify/gotrue/internal/conf"
+	"github.com/netlify/gotrue/internal/storage"
+	"github.com/netlify/gotrue/internal/storage/test"
 	"github.com/stretchr/testify/require"
 	"github.com/stretchr/testify/suite"
 )
diff --git a/models/user_test.go b/internal/models/user_test.go
similarity index 97%
rename from models/user_test.go
rename to internal/models/user_test.go
index 66369d28..a15ffe84 100644
--- a/models/user_test.go
+++ b/internal/models/user_test.go
@@ -3,16 +3,16 @@ package models
 import (
 	"testing"
 
-	"github.com/netlify/gotrue/conf"
-	"github.com/netlify/gotrue/crypto"
-	"github.com/netlify/gotrue/storage"
-	"github.com/netlify/gotrue/storage/test"
+	"github.com/netlify/gotrue/internal/conf"
+	"github.com/netlify/gotrue/internal/crypto"
+	"github.com/netlify/gotrue/internal/storage"
+	"github.com/netlify/gotrue/internal/storage/test"
 	"github.com/stretchr/testify/assert"
 	"github.com/stretchr/testify/require"
 	"github.com/stretchr/testify/suite"
 )
 
-const modelsTestConfig = "../hack/test.env"
+const modelsTestConfig = "../../hack/test.env"
 
 func init() {
 	crypto.PasswordHashCost = crypto.QuickHashCost
diff --git a/storage/dial_test.go b/internal/storage/dial_test.go
similarity index 100%
rename from storage/dial_test.go
rename to internal/storage/dial_test.go
diff --git a/storage/helper.go b/internal/storage/helper.go
similarity index 100%
rename from storage/helper.go
rename to internal/storage/helper.go
diff --git a/storage/session.go b/internal/storage/session.go
similarity index 100%
rename from storage/session.go
rename to internal/storage/session.go
diff --git a/storage/sql.go b/internal/storage/sql.go
similarity index 100%
rename from storage/sql.go
rename to internal/storage/sql.go
diff --git a/storage/test/db_setup.go b/internal/storage/test/db_setup.go
similarity index 63%
rename from storage/test/db_setup.go
rename to internal/storage/test/db_setup.go
index 817e4627..54efefd1 100644
--- a/storage/test/db_setup.go
+++ b/internal/storage/test/db_setup.go
@@ -1,8 +1,8 @@
 package test
 
 import (
-	"github.com/netlify/gotrue/conf"
-	"github.com/netlify/gotrue/storage"
+	"github.com/netlify/gotrue/internal/conf"
+	"github.com/netlify/gotrue/internal/storage"
 )
 
 func SetupDBConnection(globalConfig *conf.GlobalConfiguration) (*storage.Connection, error) {