Cloudrive

Architecture

Split-subdomain architecture: Go API + S3 gateway, Vite dashboard SPA, vinext marketing site, and Postgres.

The big picture

Browser (cloudrive.us.ci)     ──▶ apps/main-web (vinext, Cloudflare Workers)
Browser (app.cloudrive.us.ci) ──▶ apps/web-ui   (Vite SPA on nginx)
                                      │ cross-origin (VITE_API_URL)
                                      ▼
API (api.cloudrive.us.ci)     ──▶ :8080  REST API (Fiber, JSON)
                                    ├─ /v1/auth/*   Authula (sign-in, magic link, OAuth2, tokens)
                                    ├─ /v1/*        application routes (bearer token)
                                    └─ /health

S3 clients                    ──▶ :9000  S3 gateway (SigV4, path-style, XML)
                                      │
                                      ▼
                          Connector registry ──▶ Google Drive · Dropbox · OneDrive · S3/MinIO/R2
                                      │
Postgres ◀────────────────────────────┘  public schema (app) + authula schema (auth)
  • Split subdomains. apps/main-web serves the public landing/legal site on Cloudflare Workers, apps/web-ui serves the authenticated SPA on nginx, and apps/api serves /v1/*, /v1/auth/*, and /health on its own API subdomain.
  • Two listeners. The REST API (PORT, default 8080) and the S3 gateway (S3_API_PORT, default 9000, 0 disables it) are separate Fiber apps: the gateway speaks the S3 dialect and skips the REST middleware (CORS, rate limit, compression).
  • One database, two schemas. Application tables live in public. Authula keeps its own users, sessions and accounts in the authula schema, and a service hook mirrors every Authula user into public.users.

Request flow

Browser to API

  1. The SPA stores the access and refresh tokens as cookies on its own origin (lib/auth/token-storage.ts).
  2. Every API request goes through one axios instance that attaches Authorization: Bearer <access token>, refreshing it first when it is about to expire.
  3. middlewares.Authorization() validates the JWT with Authula's JWT service and puts the user id in the request context.
  4. Handlers check organization membership and role (requireOrgMember), call repositories, and answer with the JSON envelope ({ data, metadata } or { message }).

S3 client to storage

  1. The client signs the request (SigV4) with an access key Cloudrive issued for a workspace.
  2. The gateway verifies the signature against the encrypted secret in s3_credentials.
  3. The bucket name resolves through s3_buckets to a storage account and a prefix.
  4. The connector registry builds a connector for that account's provider protocol with its decrypted credentials and proxies the operation.

Code layout

AreaLocation
HTTP entrypointapps/api/cmd/api (main.go, server.go, routes.go, authula.go)
Migration runnerapps/api/cmd/migrate
Handlersapps/api/internal/handlers
Data layerapps/api/internal/{models,repositories,dtos}
Connectorsapps/api/internal/lib/connectors
S3 gatewayapps/api/internal/handlers/s3gateway
Provider OAuthapps/api/internal/lib/provideroauth
Marketing siteapps/main-web/app
Dashboard routesapps/web-ui/src/routes
Dashboard APIapps/web-ui/src/lib/api
Shared UI & libspackages/shared/src

On this page