Modular monolith over microservices
One deployable Go binary keeps operations trivial for a single maintainer, while hexagonal modules with port-only dependencies keep a future split cheap.
Technical documentation · v1.0
Trama Archive is an independent, encyclopedic platform where a community catalogs historical garments, brands and their labels. It is built API-first: a Go GraphQL backend fully decoupled from a Next.js client, so new clients can be added without touching business logic.
Trama is an archive, not a shop. The system does not process payments, carts, logistics or shipping. The current release focuses entirely on cataloging and community:
There is no monetization logic: the goal is data quality, indexing and user experience.
The trade-offs that shaped the system, and why.
One deployable Go binary keeps operations trivial for a single maintainer, while hexagonal modules with port-only dependencies keep a future split cheap.
Weighted full-text plus trigram similarity covers current volume without a 1–2 GB JVM. Elasticsearch is already implemented behind the same port and switches on with one variable.
An outbound-only Cloudflare Tunnel hides the origin, removes port forwarding and dynamic DNS, and puts WAF and DDoS protection in front of a self-hosted server.
Approvals write an event in the same transaction instead of calling the search engine directly, so a network failure can never leave the index and database out of sync.
Browsers compress images to WebP and upload them to R2 with presigned URLs, so media never consumes backend bandwidth and egress stays free.
Anonymous SSR queries share the Next.js Data Cache and are invalidated by a backend webhook, so load scales with content changes rather than traffic.
02
The main interaction flows, from passive discovery to contribution and moderation.
A trending carousel and a "featured brands" list ranked by real visits in Redis with time decay, plus a grid of the latest approved items.
Typo-tolerant full-text search with a filter drawer for category, gender, designer, SKU and taxonomies (color, material, fit, decade). Empty states suggest clearing filters or contributing the missing item.
Gallery, technical sheet, a modular wiki, contributor list, market value chart, favorites and a report flag. Authenticated users can suggest edits to any part.
Each brand has a dated archive of its sewn-in labels, filterable by decade or free year range (kept in the URL so filtered views are shareable) to help date garments.
Account & security, a tracker of submitted proposals and reports, notification preferences and GDPR account deletion with anonymization.
A unified moderation queue, side-by-side diff view for edit proposals, taxonomy merging, permanent deletion, user management and report handling.
Every new item or edit follows the same path from the guided wizard to the public catalog.
Authenticated users can report an approved item or label (counterfeit, wrong information, inappropriate content) with a description and an optional evidence link. Reports reach admins on every channel; resolving one may apply a 24-hour timeout or a permanent ban to the content's author. Submission is rate-limited and a user can only keep one open report per target.
The interface is available in Italian and English on the same URLs. The language is stored in a technical cookie (first visit follows the browser's Accept-Language), every UI string comes from typed dictionaries, and backend errors are translated per request. User content and taxonomy names are never translated.
03
Production runs on a single, fully containerized self-hosted server to keep costs low during validation, with a clear path to cloud hosting. The origin accepts no inbound connections from the Internet: all public traffic enters through Cloudflare.
| Layer | Technology | Role |
|---|---|---|
| Edge | Cloudflare | Single public entry point. Proxied DNS records hide the origin; managed WAF, DDoS mitigation, HTTPS redirect, TLS 1.2+ and an edge rate-limit rule on the API. |
| Tunnel | cloudflared | Opens an outbound connection to Cloudflare and forwards public traffic to Traefik. No port forwarding, no dynamic DNS, works behind CGNAT. |
| Router | Traefik v3 | Routes by Docker labels and terminates TLS with Let's Encrypt certificates obtained through the DNS-01 challenge (end-to-end Full (strict) TLS). |
| Public network | Docker bridge | Hosts the Next.js frontend and the Go backend, the only services Traefik can reach. |
| Internal network | Docker bridge | Isolates PostgreSQL, Redis and the optional Elasticsearch. They publish no ports and only the backend talks to them. |
/healthz (liveness, never checks dependencies) and /readyz (readiness: PostgreSQL is critical, Redis only degrades the status).SIGTERM the server stops accepting requests, stops background workers and drains the worker pool.SearchRepository port and is enabled by switching one environment variable — no business logic changes.
04
05
PostgreSQL 15 is the single source of truth, chosen for referential integrity and ACID guarantees. Schema migrations run at every start-up in a fixed order and are written to be idempotent.
users user_preferences user_tokens
brands brand_tags items item_images taxonomies item_taxonomies
item_price_history
proposed_edits contributors boards favorites
reports notifications outbox_events
search_vector (name, designer, wiki) combined with pg_trgm similarity, so a typo like margela still finds Margiela. GIN indexes keep all match conditions fast.proposed_edits and applied partially on approval, so the public record is never touched before review.06
The web client keeps server state (GraphQL cache) strictly apart from client state (Zustand), and organizes code by business domain with Feature-Sliced Design.
AuthSlice (identity and role, never the token), UIPreferencesSlice (modal visibility, cookie consent, unread badge) and ToastSlice (auto-dismissed feedback).prefers-color-scheme; pinch-zoom stays available for accessibility.07
The server is a modular monolith in Go, structured with the hexagonal (ports & adapters) pattern. Business rules depend only on interfaces; the concrete adapter for each port is chosen at start-up from environment variables.
handler.go defines its GraphQL types, queries and mutations; they validate input, check permissions and call services. No business logic.domain.go), use cases (service.go) and ports (repository.go).cmd/api.08
During the contribution wizard, WebP images are sent as Base64 with the brand name. The AIProvider adapter asks Gemini, acting as a "fashion archivist", to return strict JSON with name, category, gender, season and designer.
The parser strips Markdown fences, ignores extra keys, normalizes unknown genders to Unisex, and on malformed output the wizard simply continues with manual entry.
When an approved item is viewed and its price history is missing or older than seven days, an estimate is queued on the worker pool. A Redis cooldown prevents concurrent and repeated calls.
The engine queries brand, name and season, takes the median of the first ten valid offers and stores it in the price history. A mock provider keeps local development independent of eBay.
09
Two-step registration with an e-mailed one-time code, bcrypt-hashed passwords and limited verification attempts.
A signed JWT lives only in an HttpOnly, Secure, SameSite cookie, out of reach of JavaScript; nothing is kept in localStorage.
Guest, user and admin roles enforced in resolvers, with a protected super-admin. Banned or suspended accounts are downgraded on every request.
Edge and application rate limiting on login, verification and reports, keyed on the real client IP provided by Cloudflare.
Single-use, short-lived tokens; unknown addresses return no error to prevent user enumeration.
Parameterized SQL, no e-mail addresses, clear-text IPs or tokens in logs, e-mail never searchable by admins, and GDPR deletion through anonymization.
10