Prompt Details
Model
(claude-4-7-opus)
Token size
930
Example input
[PROJECT_CONTEXT]: scratch
[TECH_STACK]: Python FastAPI + SQLite
[TASK]: REST API for shortening links, with create and redirect endpoints,
[CONSTRAINTS]: (blank β defaults)
[OUTPUT_MODE]: plan
Example output
Proposed structure:
link-shortener/
βββ app/ # application code, importable as a package
β βββ main.py # FastAPI app + route wiring
β βββ db.py # SQLite connection + schema init
β βββ models.py # Pydantic request/response schemas
β βββ shortener.py # short-code generation + lookup logic
βββ tests/ # pytest tests against the API
βββ requirements.txt # pinned dependencies
Each top-level folder, one phrase: app/ holds runnable application code; tests/ keeps verification separate from shippable code; requirements.txt pins what runs.
Task restatement: Build a small FastAPI service backed by SQLite that lets a client submit a long URL and get back a short code, then resolve that short code via a redirect endpoint that sends the browser to the original URL.
Steps:
Pin dependencies (fastapi, uvicorn, pydantic) in requirements.txt β SQLite needs no package, it's in Python's stdlib.
In db.py, open a SQLite connection and create a links table (code primary key, url, created_at) if it doesn't exist.
In shortener.py, write short-code generation (base62 over a random or sequential id) and a lookup-by-code function.
In models.py, define a CreateLinkRequest (the long URL) and a CreateLinkResponse (the short code + full short URL).
In main.py, wire two routes: POST /links to create, GET /{code} to redirect.
In tests/, cover create-then-redirect and the unknown-code case.
Files to create:
requirements.txt β declares what the project runs on.
app/db.py β owns the SQLite connection and schema so other modules don't duplicate it.
app/models.py β request/response shapes, validated by Pydantic at the edge.
app/shortener.py β isolates code-generation logic so it's unit-testable without HTTP.
app/main.py β the FastAPI app and the two endpoints.
tests/test_api.py β proves create and redirect work end to end.
Assumptions / open questions that could change the approach:
ASSUMPTION: short codes are server-generated; you don't need custom vanity aliases. If you want user-chosen codes, POST /links needs a collision check and the code becomes optional input.
ASSUMPTION: a single-file SQLite DB on local disk is fine; no concurrency or multi-process deployment concern yet.
Open question: should GET /{code} return 307 (temporary) or 301 (permanent) redirect? Default below is 307 so you can change destinations later without browsers caching the old one.
Security note: the create endpoint should validate that the submitted URL is actually http/https to avoid storing javascript: or file: schemes β I'll fold that into the Pydantic model.
Approve this plan, amend any assumption, or ask a question and I'll write the code.
Next: confirm 307 vs 301 redirect and whether codes are server-generated, then re-run with OUTPUT_MODE: code.
By purchasing this prompt, you agree to our terms of service
CLAUDE-4-7-OPUS
π Turn any coding task into working software with a senior pair-programming partner. On an existing project it auto-detects your stack and conventions from the repo; on a new one it proposes a clean structure. It plans before it codes and writes real logic β never fake stubs or invented APIs. Five simple slots adapt it to your task and rules. Plan-first by default so you stay in control; switch to code mode when you're ready to ship.
...more
Added 1 day ago
