# Code Farm The Code Farm is a cooperative idle game. Each member owns a farm of plots, plants software projects that build over real time, harvests them for coins and XP, upgrades their CI tier for faster builds, and waters other members' growing builds to speed them up and earn coins. Refactoring (prestige) costs a dynamic coin fee that grows with prestige and current wealth; the fees fill a community treasury from which active low-balance farms can claim a weekly grant. All endpoints negotiate HTML or JSON. POST bodies are form encoded (`application/x-www-form-urlencoded`). Every own-farm action returns `{"ok": true, "farm": {...}}` - the full updated farm state - so a client can refresh without a second request; the two neighbour actions (water, steal) return the neighbour's farm as `{"farm": {...}}`, and a successful steal adds `stole_coins`. An invalid action (not enough coins, wrong plot state, a protected harvest, an active cooldown) returns HTTP 400 as `{"error": {"status": 400, "message": "..."}}`; an unknown farm username is 404. Reading your own farm state also runs lazy owner effects: the CI Bot legacy upgrade auto-harvests ready builds, and any due Defense upkeep is charged. The complete rules, formulas, and an automated client are on the [Code Farm guide](/docs/code-farm.html).
GET /game Minimal role: Member

Code Farm page

The player's own farm: HUD, plot grid, shop, and leaderboard.

GET /game/state Minimal role: Member

Farm state

The signed-in player's full farm state as JSON. Reading it auto-collects ready builds (with the CI Bot legacy upgrade, reported as auto_harvested/auto_harvest_coins/auto_harvest_xp) and charges any due Defense upkeep.

GET /game/leaderboard Minimal role: Public

Farm leaderboard

Top 25 farmers on a chosen board: score (default), prestige, harvests (this week), raids (avg coins per successful raid over 30 days, min 3 raids), time_to_kernel, fair_play, or era (current Era only, empty when none is running). Cached about 15 seconds.

GET /game/farm/{username} Minimal role: Public

View a farm

Another player's farm, with per-plot can_water/can_steal flags computed for the viewer.

POST /game/plant Minimal role: Member

Plant a crop

Plant a crop in an empty plot. Costs the crop's live coin price (the cost field in the farm state's crops list).

POST /game/harvest Minimal role: Member

Harvest a build

Harvest a finished (state ready) build for coins and XP.

POST /game/buy-plot Minimal role: Member

Buy a plot

Unlock a new plot (up to 12). Cost starts at 100 coins and doubles per extra plot; the exact price is the farm state's next_plot_cost.

POST /game/upgrade Minimal role: Member

Upgrade CI

Upgrade the farm CI tier for faster builds (up to tier 5); the exact price is the farm state's ci_next_cost.

POST /game/farm/{username}/water Minimal role: Member

Water a build

Water another player's growing build to cut 8% off its build time; pays the visitor 6 coins scaled by their own prestige and Tech Debt Payoff multiplier, plus 3 XP. Once per visitor per build, 3 waterings per build total.

POST /game/farm/{username}/steal Minimal role: Member

Steal a build

Raid another player's ready build once its protection window has passed. You take a share of the build's realized coin value (half by default, less against defended owners - the plot's steal_coins field is the exact payout) and the owner keeps and can still harvest the remainder; the plot records the share taken as raided_fraction. Limited to once per hour per neighbour and 3 raids per victim per day; a fully stripped build reports steal_reason stripped, and Security Fortress builds are immune.

POST /game/fertilize Minimal role: Member

Fertilize a build

Spend coins to halve a growing build's remaining time (the plot's fertilize_cost field is the exact price). The price is computed from the exact value this build will pay out - including the golden multiplier and any active contract, Underdog, or Canary upside - so fertilizing is a pure time-skip and never a profit, on any build, at any prestige, with any combination of boosts.

POST /game/daily Minimal role: Member

Claim daily bonus

Claim the once-per-UTC-day coin bonus; consecutive days grow a streak (20 coins on day one up to 92 from day seven on), scaled by your own prestige and Tech Debt Payoff multiplier. A lapsed streak resets to day one - the farm state's daily_streak_reset flag and daily_reward already reflect that.

POST /game/perk Minimal role: Member

Upgrade a perk

Upgrade a permanent perk with coins: yield (+5% harvest coins), growth (+4% build speed), discount (-3% planting cost), or xp (+5% harvest XP) per level. Perks reset on refactor.

POST /game/quests/claim Minimal role: Member

Claim a quest

Claim a completed daily quest by its kind, or (with scope=weekly, requires the Legacy Contracts Mastery upgrade) the weekly contract, which pays Stars plus a 48-hour +20% coin boost instead of coins.

POST /game/prestige Minimal role: Member

Refactor (prestige)

Reset the farm at level 10+ for a permanent +25% coin bonus and earn Stars to spend on Legacy upgrades. Refactoring costs a coin fee that scales with prestige and current wealth (the farm state's refactor_cost); the fee funds the community treasury and a fraction of the remaining coins (10% base, up to 35% with the Golden Parachute Legacy upgrade) carries over. From prestige 50 onward, every 10 more prestige also earns a permanent Mastery point.

POST /game/grant Minimal role: Member

Claim the community grant

Claim the weekly community grant, paid from the treasury filled by refactor fees and divided between everyone currently eligible (capped at 2500 coins, suppressed below 250). Eligible farms are active (5+ harvests this week), below 10000 coins, and at most prestige 5.

POST /game/legacy Minimal role: Member

Buy a Legacy upgrade

Spend Stars on a permanent Legacy upgrade that survives every refactor: autoharvest (CI Bot), multiplier (+10% coins/level), speed (+5% build speed/level), plots (+1 starting plot/level), defense (+30s grace, -5% steal loss/level), or carryover (Golden Parachute, +5% refactor carry-over/level).

POST /game/mastery Minimal role: Member

Buy a Mastery upgrade

Spend Mastery points (earned at prestige 50 and every 5 prestige after) on a permanent Mastery upgrade: autoreplant (Continuous Delivery, 3 points), analytics (Farm Analytics, 2 points), or contracts (Legacy Contracts, 4 points).

POST /game/infrastructure/buy Minimal role: Member

Buy Infrastructure

Buy a permanent, expensive, prestige-gated Infrastructure building: registry (Rust/Compiler/Kernel build 15% faster; 3M coins, prestige 3), canary (12% chance to double a harvest, 6% to only refund its planting cost; 6M, prestige 8), or observability (caps what any raider can take from you at 20% of a build's value; 15M, prestige 15).

POST /game/defense/upgrade Minimal role: Member

Upgrade Defense

Buy the next Defense tier (Firewall through Zero Trust Mesh; the farm state's defense_next_cost is the exact price). Each tier multiplicatively reduces what a raider takes from you and adds steal grace, but adds an ongoing daily coin upkeep of max(tier minimum, 0.2% of your balance). If you cannot pay, the tier decays by one level and only what you can afford is taken - your balance is never emptied.

POST /game/defense/downgrade Minimal role: Member

Downgrade Defense

Drop your Defense down one tier to escape its daily upkeep. There is no refund. Available whenever defense_downgrade_available is true in the farm state.

POST /game/cosmetics/buy Minimal role: Member

Buy a cosmetic

Buy a purely cosmetic title or plot skin with coins. No gameplay effect. The farm state's cosmetics list carries each key, cost, and an owned flag.

POST /game/cosmetics/equip Minimal role: Member

Equip a title

Equip an owned title cosmetic so its display name shows next to your name on the leaderboard.