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-webserves the public landing/legal site on Cloudflare Workers,apps/web-uiserves the authenticated SPA on nginx, andapps/apiserves/v1/*,/v1/auth/*, and/healthon its own API subdomain. - Two listeners. The REST API (
PORT, default 8080) and the S3 gateway (S3_API_PORT, default 9000,0disables 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 theauthulaschema, and a service hook mirrors every Authula user intopublic.users.
Request flow
Browser to API
- The SPA stores the access and refresh tokens as cookies on its own origin
(
lib/auth/token-storage.ts). - Every API request goes through one axios instance that attaches
Authorization: Bearer <access token>, refreshing it first when it is about to expire. middlewares.Authorization()validates the JWT with Authula's JWT service and puts the user id in the request context.- Handlers check organization membership and role (
requireOrgMember), call repositories, and answer with the JSON envelope ({ data, metadata }or{ message }).
S3 client to storage
- The client signs the request (SigV4) with an access key Cloudrive issued for a workspace.
- The gateway verifies the signature against the encrypted secret in
s3_credentials. - The bucket name resolves through
s3_bucketsto a storage account and a prefix. - The connector registry builds a connector for that account's provider protocol with its decrypted credentials and proxies the operation.
Code layout
| Area | Location |
|---|---|
| HTTP entrypoint | apps/api/cmd/api (main.go, server.go, routes.go, authula.go) |
| Migration runner | apps/api/cmd/migrate |
| Handlers | apps/api/internal/handlers |
| Data layer | apps/api/internal/{models,repositories,dtos} |
| Connectors | apps/api/internal/lib/connectors |
| S3 gateway | apps/api/internal/handlers/s3gateway |
| Provider OAuth | apps/api/internal/lib/provideroauth |
| Marketing site | apps/main-web/app |
| Dashboard routes | apps/web-ui/src/routes |
| Dashboard API | apps/web-ui/src/lib/api |
| Shared UI & libs | packages/shared/src |