I keep seeing outfits I like in films and on social media, and I never know what the pieces are, what they cost, or where to buy them. Covet is my attempt at fixing that: you upload a photo, it detects the clothing items, tags the overall style, and returns real products to buy, including cheaper alternatives.

It’s a portfolio project, so the goal is to practise real backend work in Go: API design, a proper schema, third-party integrations and async processing.

Scoping before coding

The early decisions that saved me the most time were about what not to build:

  • No custom ML. Training a clothing detector is a research project. I use existing vision models.
  • No user-generated data. Covet works from external product data, so it needs no community to be useful.
  • A search engine, not a chatbot. The output is structured: items, prices, retailers, links.
  • Cut from the MVP: exact visual matching, a separate price-estimate feature, and price-drop alerts. The pipeline looks like this:
POST /outfits -> save image, insert row (status: pending), return id background job -> detect items, find products, store them (status: complete) GET /outfits/{id}/results -> client polls until status is complete 

The stack is Go with the standard library router, Postgres in Docker through pgx, Gemini for style tags, and Lykdat for detection and product matching.

Foundations: config, a pool and context

The first milestone was boring on purpose: a server that loads config from the environment, opens a pgxpool connection pool, pings the database at startup and refuses to start if that fails. Failing fast beats discovering a bad DATABASE_URL on the first real request.

This is also where I properly learned context.Context: a cancellation and deadline signal that travels down the call chain so work stops when nobody wants the result any more. It matters again later, because the background job can’t reuse the request’s context.

Schema decisions

Five tables: users, sessions, outfit_uploads, detected_items and product_matches. A few choices I’d defend in an interview:

  • match_type as text (closest_match or budget_alternative) rather than a boolean, so a third category later doesn’t force a schema change.
  • outfit_uploads.user_id is nullable with ON DELETE SET NULL. Anonymous uploads work, and deleting an account doesn’t destroy the data.
  • NUMERIC(10,2) for prices. Never floats for money.
  • UUID primary keys for users and sessions, because they end up in cookies. ## The upload endpoint

POST /outfits does more than save a file:

  1. It caps the body at 10 MB.
  2. It detects the real content type from the first 512 bytes instead of trusting the extension, then calls Seek(0, 0) so the saved file isn’t missing those bytes.
  3. It saves the file under a UUID filename so uploads can’t collide.
  4. It inserts a row with status = 'pending' and returns 201 with the id immediately. The slow part runs in a goroutine:
go h.runDetection(uploadID, savePath) 

Inside, I use context.Background(), not r.Context(). The request context is cancelled the moment the response is written, which would kill the job mid-flight. The status column (pending, processing, complete, failed) is what lets the client poll honestly instead of hanging on a 10-second request.

Don’t trust model output

My first design asked Gemini for structured JSON describing each garment. Models drift from schemas, so I put three defences between the model and the database:

  1. Ask for JSON mode in the API call.
  2. Validate in Go before inserting anything: at least one item, no more than ten, non-empty category and description, and a length cap.
  3. Normalize known values, so “outerwear”, “coat” and “blazer” all become jacket, and style tags are lowercased and de-duplicated.
if len(result.Items) == 0 { return fmt.Errorf("no items detected in image") } 

Two smaller lessons from this stage. Model names churn: gemini-1.5-flash and then gemini-2.0-flash both returned 404 errors when I called them, so the model name belongs in config. And Go refuses to compile unused imports and variables, which annoyed me for a day and then started catching real mistakes.

The shopping search dead end

Next I turned each detected item’s description into a Google Shopping query through SerpAPI. It failed in a way that taught me the most.

Descriptions like “vibrant bright yellow cropped fleece hoodie with drawstring hood” returned nothing. SerpAPI’s response reported the results state as “Fully empty”. I shortened the queries, stripped stop words and kept only colour, one descriptor and the category. Some started returning results. Others didn’t.

One bug was entirely mine. I added debug logging that read the response body with io.ReadAll, then parsed it with json.NewDecoder(resp.Body). The body was already consumed, so every parse failed with EOF:

bodyBytes, _ := io.ReadAll(resp.Body) log.Printf("response: %s", bodyBytes) // parsing resp.Body again here returns EOF, so parse the bytes instead: json.Unmarshal(bodyBytes, &parsed) 

A response body is a stream you can read once. I also lost an evening to timeouts that turned out to be my own machine’s network, not the API.

The deeper problem was the translation layer. I was flattening a rich visual understanding into a text query for a product search that expects retailer-written titles. Simplifying queries until they return results also makes them generic. “Yellow top” is something you can type into Google yourself.

Switching to image-native matching

Lykdat’s Global Search API takes the image and returns detected items with similar products (name, brand, price, currency, URL, images and a similarity score) in one call. The free plan allows 500 image searches a month, which is plenty for development.

That changed the architecture. Lykdat became the source of truth for detection and matching, and Gemini shrank to one whole-outfit call that returns style tags like “streetwear” or “minimalist”. Running two independent detectors and aligning them afterwards by category name would have produced mismatches.

I’d believed the shopping service was an abstraction I could swap without touching the handlers. That turned out to be false. The old method took a detected item and a country, and the new one takes an image path, so runDetection had to be rewritten. An interface shaped around one provider’s paradigm leaks when the paradigm changes.

Making “budget alternative” mean something

My first rule labelled the top five results as closest matches and everything after as budget alternatives. Lykdat returned up to 50 products per item, so dozens landed in the “budget” tab purely because they ranked lower, and some cost more than the closest matches.

The fix: sort by similarity score and take the top eight as closest matches. Then label a lower-ranked product a budget alternative only if it’s cheaper than the average closest match in the same currency. The total is capped at 20 per item. Now the label is true.

The results endpoint

GET /outfits/{id}/results returns just the status until the job completes, then the full tree. A few decisions:

  • Filters are SQL, not API calls. Changing the budget bracket never calls Lykdat or Gemini again, because everything is already stored:
WHERE detected_item_id = ANY($1) AND ($2::text IS NULL OR match_type = $2) AND ($3::numeric IS NULL OR price >= $3) AND ($4::numeric IS NULL OR price <= $4) AND ($5::text IS NULL OR currency = $5) 
  • Two queries, not one per item. One fetches the items and one fetches all their matches with ANY($1), which avoids the N+1 pattern.
  • ORDER BY comes from a fixed list, never straight from user input, because it can’t be parameterized.
  • Links are built at response time. The database keeps the clean retailer URL. The response adds a shop_url, wrapped by an affiliate service that does nothing until it’s configured, so approval delays don’t block development. ## Auth, without ceremony

Cookie sessions backed by a sessions table: register, login, logout and a /auth/me endpoint. Passwords are hashed with bcrypt (capped at 72 characters, which is all bcrypt reads), and login failures return one generic message. When the email doesn’t exist, the handler still runs a dummy bcrypt comparison so response time doesn’t reveal which emails are registered.

A middleware identifies the user if a valid session exists and never rejects the request, so the app still works logged out. Owned outfits return 404, not 403, to anyone else, so ids can’t be probed.

Things that bit me

  • Docker data loss. My Postgres container kept breaking, and each recreation wiped my tables because the data lived inside the container. A named volume is the fix.
  • A key in a log line. An error that printed the full request URL leaked an API key into my terminal output. Log response bodies, not request URLs, and rotate anything that leaks.
  • Wiring renames. Swapping one provider for another touched config, constructors, main.go and the .env file, and a missed rename produced “undefined” errors in three places. ## What’s next

The remaining Phase 1 item is the frontend, built as plain HTML, CSS and JavaScript served by the Go server so there’s no CORS to deal with. After that come a landing page with smooth scrolling, an AI stylist chat grounded in each outfit’s stored results, and a virtual try-on experiment. Whether they land depends on what the data shows.

If you’re building something similar, the most useful thing I can pass on is to test the riskiest assumption first. Mine was “a text description will find the right product”, and I spent days on it before checking.