Skip to content

Commit 4cef09f

Browse files
committed
refactor: improve code documentation and remove unnecessary comments
- Enhanced documentation across various files, providing clearer explanations of functions and types. - Removed redundant comment blocks that did not add value or clarity to the code. - Updated comments to reflect the purpose and functionality of specific code sections, improving maintainability. - Ensured consistency in comment style and formatting throughout the codebase.
1 parent c9d30ce commit 4cef09f

17 files changed

Lines changed: 138 additions & 531 deletions

File tree

CLAUDE.md

Lines changed: 49 additions & 340 deletions
Large diffs are not rendered by default.

next-app/src/app/(site)/docs/mcp/page.tsx

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,12 @@ const SECTIONS = [
4949
{ href: "#errors", label: "Errors" },
5050
] as const;
5151

52-
// ---------------------------------------------------------------------------
53-
// Install snippets. Kept in step with `install-tabs.tsx` by hand: that
54-
// component is the hero, this is the reference, and both get copied verbatim.
55-
// ---------------------------------------------------------------------------
56-
52+
/**
53+
* One agent's install snippet.
54+
*
55+
* Kept in step with `install-tabs.tsx` by hand: that component is the hero, this
56+
* is the reference, and both get copied verbatim.
57+
*/
5758
type InstallDef = {
5859
id: string;
5960
label: string;
@@ -133,10 +134,7 @@ bearer_token_env_var = "BUILDERS_BACKLINKS_TOKEN"`,
133134
},
134135
];
135136

136-
// ---------------------------------------------------------------------------
137-
// Tool reference. Transcribed from registerTools() in src/lib/mcp/tools.ts.
138-
// ---------------------------------------------------------------------------
139-
137+
/** One argument in the tool reference below, transcribed from `registerTools()` in `src/lib/mcp/tools.ts`. */
140138
type ToolArg = {
141139
name: string;
142140
/** The schema, written the way a caller has to satisfy it. */
@@ -345,13 +343,16 @@ const WRITE_TOOLS: readonly ToolDef[] = [
345343
},
346344
];
347345

348-
// ---------------------------------------------------------------------------
349-
// The worked example. The most valuable block on the page, so it is a real
350-
// sequence with real argument names, not a shape.
351-
// ---------------------------------------------------------------------------
352-
346+
/** One beat of the worked example. */
353347
type Step = { n: string; title: string; body: string; call: string; result?: string };
354348

349+
/**
350+
* The worked example, and the most valuable block on the page.
351+
*
352+
* A real sequence with real argument names rather than a shape: readers paste
353+
* from here, so a placeholder would be the page lying about the product.
354+
*/
355+
355356
const WALKTHROUGH: readonly Step[] = [
356357
{
357358
n: "01",
@@ -425,10 +426,6 @@ const WALKTHROUGH: readonly Step[] = [
425426
},
426427
];
427428

428-
// ---------------------------------------------------------------------------
429-
// Rendering
430-
// ---------------------------------------------------------------------------
431-
432429
const PILL = "rounded-full border px-2 py-0.5 font-mono text-[10.5px] tracking-[0.1em] whitespace-nowrap uppercase";
433430
const PILL_ACCENT = `${PILL} border-accent/40 bg-accent-soft text-accent`;
434431
const PILL_MUTED = `${PILL} border-line text-muted`;

next-app/src/app/api/cron/recheck/route.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ export async function GET(request: Request) {
8080

8181
const now = new Date();
8282

83-
// ---------------------------------------------------------------------
8483
// Expire stale matches first.
8584
//
8685
// `expiresAt` was written on every match from the day matching shipped and
@@ -95,7 +94,6 @@ export async function GET(request: Request) {
9594
// partners with a live match, and lets the digest reach the member again.
9695
// `declined` and `placed` are terminal and deliberately excluded: a placed
9796
// match has real links behind it and must never be reopened by a clock.
98-
// ---------------------------------------------------------------------
9997
// Returns both site ids and the state it expired FROM, because expiry used
10098
// to be silent: a member watched a partner disappear off the dashboard with
10199
// no message before it or after. The prior state decides the wording, since a
@@ -141,7 +139,6 @@ export async function GET(request: Request) {
141139
}
142140
}
143141

144-
// ---------------------------------------------------------------------
145142
// Re-pair the idle pool.
146143
//
147144
// Approval used to be the only thing that ever called `autoPair`, which
@@ -161,7 +158,6 @@ export async function GET(request: Request) {
161158
// one this site already has a match row with. Sites already holding an open
162159
// match are excluded before that, so the pass is idempotent over an
163160
// unchanged pool.
164-
// ---------------------------------------------------------------------
165161
const dryRun = new URL(request.url).searchParams.get("dry") === "1";
166162

167163
const idle = await db()
@@ -282,7 +278,6 @@ export async function GET(request: Request) {
282278
console.log(`recheck: re-pair batch was full at ${PAIR_BATCH}, more idle sites remain for tomorrow`);
283279
}
284280

285-
// ---------------------------------------------------------------------
286281
// Nudge agreed matches where a link is still missing.
287282
//
288283
// Nothing used to be sent between `match-agreed` and expiry, and the weekly
@@ -293,7 +288,6 @@ export async function GET(request: Request) {
293288
// Only the side that owes something is mailed. `lastNudgedAt` is the
294289
// high-water mark that stops a nightly pass from mailing nightly; with the
295290
// two windows below it lands on roughly day 3 and day 10 of an agreed match.
296-
// ---------------------------------------------------------------------
297291
let nudged = 0;
298292
if (!dryRun) {
299293
try {

next-app/src/app/api/mcp/route.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,13 @@ const handler = createMcpHandler(createServer, {
157157
onerror: (err) => console.error("mcp transport error", err),
158158
});
159159

160-
// Every method goes to the same handler: POST carries the JSON-RPC exchange,
161-
// GET opens a subscription stream, DELETE and OPTIONS are answered by the
162-
// transport itself. Next needs each one exported by name to route it here.
160+
/**
161+
* The one handler behind all four HTTP methods.
162+
*
163+
* POST carries the JSON-RPC exchange, GET opens a subscription stream, and
164+
* DELETE and OPTIONS are answered by the transport itself. Next needs each one
165+
* exported by name to route it here.
166+
*/
163167
const serve = (request: Request): Promise<Response> => handler.fetch(request);
164168

165169
export { serve as GET, serve as POST, serve as DELETE, serve as OPTIONS };

next-app/src/app/app/actions.ts

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,19 @@ import { getSessionMember } from "@/lib/session";
2626
* `revalidatePath` anywhere. The client holds enough state to update itself.
2727
*/
2828

29-
// ---------------------------------------------------------------------------
30-
// Accept or decline
31-
// ---------------------------------------------------------------------------
32-
3329
export type RespondState =
3430
| { status: "idle" }
3531
| { status: "signed_out" }
3632
| { status: "error"; matchId: string; message: string }
3733
| { status: "done"; matchId: string; accepted: boolean; revealed: boolean };
3834

35+
/**
36+
* Accepts or declines a proposed match.
37+
*
38+
* `revealed` comes back on the done arm because accepting is only half of a
39+
* reveal: identities appear when BOTH sides have accepted, so the client cannot
40+
* infer it from its own click.
41+
*/
3942
export async function respondToMatchAction(_previous: RespondState, formData: FormData): Promise<RespondState> {
4043
const member = await getSessionMember();
4144
if (!member) return { status: "signed_out" };
@@ -59,10 +62,6 @@ export async function respondToMatchAction(_previous: RespondState, formData: Fo
5962
}
6063
}
6164

62-
// ---------------------------------------------------------------------------
63-
// Link brief
64-
// ---------------------------------------------------------------------------
65-
6665
export type BriefState =
6766
| { status: "idle" }
6867
| { status: "signed_out" }
@@ -102,10 +101,6 @@ export async function getLinkBriefAction(_previous: BriefState, formData: FormDa
102101
}
103102
}
104103

105-
// ---------------------------------------------------------------------------
106-
// Mark placed
107-
// ---------------------------------------------------------------------------
108-
109104
export type PlaceState =
110105
| { status: "idle" }
111106
| { status: "signed_out" }

next-app/src/app/app/key/key-panel.tsx

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,7 @@ export function KeyPanel({ initial }: KeyPanelProps) {
9393
);
9494
}
9595

96-
// ---------------------------------------------------------------------------
97-
// No key yet
98-
// ---------------------------------------------------------------------------
99-
96+
/** The state before a member has any key: what one is for, and the button that mints it. */
10097
function Generate({ formAction, pending }: { formAction: () => void; pending: boolean }) {
10198
return (
10299
<section aria-labelledby="generate-heading" className="border-line bg-surface rounded-sm border p-6 sm:p-8">
@@ -140,10 +137,12 @@ function Generate({ formAction, pending }: { formAction: () => void; pending: bo
140137
);
141138
}
142139

143-
// ---------------------------------------------------------------------------
144-
// One-time reveal
145-
// ---------------------------------------------------------------------------
146-
140+
/**
141+
* The one screen the plaintext key is ever readable on.
142+
*
143+
* Only a hash is stored, so there is no second chance and the warning is a
144+
* `role="alert"` that cannot be scrolled past.
145+
*/
147146
function Reveal({ state, onDismiss }: { state: Extract<IssueKeyState, { status: "issued" }>; onDismiss: () => void }) {
148147
const command = claudeCommand(state.plaintext);
149148
const cursor = cursorConfig(state.plaintext);
@@ -258,10 +257,7 @@ function Snippet({
258257
);
259258
}
260259

261-
// ---------------------------------------------------------------------------
262-
// Key already exists
263-
// ---------------------------------------------------------------------------
264-
260+
/** The returning state: when the key was issued and last used, and a confirmed regenerate. */
265261
function ExistingKey({
266262
issuedAt,
267263
lastUsedAt,

next-app/src/app/submit/actions.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,7 @@ import { getSessionMember } from "@/lib/session";
3535
* server never fetched, while the tool analyzes every single one.
3636
*/
3737

38-
// ---------------------------------------------------------------------------
39-
// Step one: draft
40-
// ---------------------------------------------------------------------------
41-
42-
/** Everything the confirmation screen needs, plus the signature tying DR to this server. */
38+
/** Step one. Everything the confirmation screen needs, plus the signature tying DR to this server. */
4339
export type DraftPayload = {
4440
domain: string;
4541
/** Final URL after redirects. This, not the typed one, is what gets listed. */
@@ -124,10 +120,7 @@ function explainAnalyzeFailure(err: unknown): string {
124120
return "Something went wrong on our side. Nothing was changed. Try again in a moment.";
125121
}
126122

127-
// ---------------------------------------------------------------------------
128-
// Step two: commit
129-
// ---------------------------------------------------------------------------
130-
123+
/** Step two. What the confirmation screen shows once the listing is written. */
131124
export type CommitState =
132125
| { status: "idle" }
133126
| { status: "signed_out" }

next-app/src/app/submit/review-form.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -329,10 +329,14 @@ export function ReviewForm({ draft, onStartOver }: ReviewFormProps) {
329329

330330
const SIGNED_OUT = "Your session expired before we could save this. Sign in again and resubmit, nothing was written.";
331331

332-
// One icon, not two. This used to celebrate with a PartyPopper when the submit
333-
// call came back already matched, which cannot happen any more: nothing is
334-
// matched until review clears the listing. The celebration belongs on whatever
335-
// surface tells a member they have a match, not on the one that says "received".
332+
/**
333+
* The "received, pending review" confirmation.
334+
*
335+
* One icon, not two. This used to celebrate with a PartyPopper when the submit
336+
* call came back already matched, which cannot happen any more: nothing is
337+
* matched until review clears the listing. The celebration belongs on whatever
338+
* surface tells a member they have a match, not on the one that says "received".
339+
*/
336340
function SubmittedPanel({ state }: { state: Extract<CommitState, { status: "done" }> }) {
337341
return (
338342
<section className="border-accent/35 bg-accent-soft rounded-sm border p-6 sm:p-8" aria-live="polite">

next-app/src/components/web/install-tabs.tsx

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,7 @@ import { type TabItem, TabList, panelId, tabId } from "@/components/web/tab-list
4444

4545
const MCP_URL = "https://builders-backlinks.com/api/mcp";
4646

47-
// ---------------------------------------------------------------------------
48-
// Install snippets
49-
// ---------------------------------------------------------------------------
50-
47+
/** The agents an install snippet exists for. */
5148
type ClientId = "claude" | "cursor" | "codex" | "gemini";
5249

5350
type ClientDef = {
@@ -138,10 +135,7 @@ const CLIENT_TABS: readonly TabItem<ClientId>[] = CLIENTS.map((client) => ({
138135
label: client.label,
139136
}));
140137

141-
// ---------------------------------------------------------------------------
142-
// Transcripts
143-
// ---------------------------------------------------------------------------
144-
138+
/** How one span of transcript text is coloured. Maps to the `--term-*` custom properties. */
145139
type Tone = "plain" | "dim" | "bright" | "prompt" | "tool" | "key" | "ok" | "add" | "mask" | "warn";
146140

147141
type Segment = { text: string; tone?: Tone };
@@ -304,10 +298,6 @@ const VIEW_CAPTION: Record<ViewId, string> = {
304298
place: "This is the step every other exchange leaves to you, and the step where most trades die.",
305299
};
306300

307-
// ---------------------------------------------------------------------------
308-
// Remembering whether the demo is collapsed
309-
// ---------------------------------------------------------------------------
310-
311301
/**
312302
* Where the collapsed/expanded choice is kept.
313303
*
@@ -365,10 +355,7 @@ function writeDemoPreference(open: boolean): void {
365355
}
366356
}
367357

368-
// ---------------------------------------------------------------------------
369-
// Rendering
370-
// ---------------------------------------------------------------------------
371-
358+
/** Renders one transcript as terminal lines, tone by tone. */
372359
function TranscriptBody({ lines }: { lines: readonly Line[] }) {
373360
return (
374361
<pre className="min-w-max font-mono text-[12px] leading-[1.75] sm:text-[12.5px]">

next-app/src/lib/contracts.ts

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,8 @@
1414
import type { Category } from "@/lib/categories";
1515
import type { Placement, PlacementOffer } from "@/lib/exchange";
1616

17-
// ---------------------------------------------------------------------------
18-
// src/lib/analyze -> analyzeSite()
19-
// ---------------------------------------------------------------------------
20-
2117
/**
22-
* Everything derived from a URL at submit time.
18+
* Everything derived from a URL at submit time. Produced by `analyzeSite()` in `src/lib/analyze`.
2319
*
2420
* `description` must be identity-scrubbed: it is shown to potential partners
2521
* before either side knows who the other is, so it has to say what the site
@@ -103,12 +99,9 @@ export function analyzeFailureHint(code: AnalyzeErrorCode): string {
10399

104100
export type AnalyzeSite = (rawUrl: string) => Promise<SiteAnalysis>;
105101

106-
// ---------------------------------------------------------------------------
107-
// src/lib/verify -> verifyLink()
108-
// ---------------------------------------------------------------------------
109-
110102
/**
111-
* Result of crawling one page looking for a link to one domain.
103+
* Result of crawling one page looking for a link to one domain. Produced by `verifyLink()` in
104+
* `src/lib/verify`.
112105
*
113106
* POLICY REMINDER: this classifies, it does not judge. A `footer` placement or
114107
* a `nofollow` rel is reported plainly to both parties and still counts as a
@@ -146,11 +139,10 @@ export type VerifyLink = (input: {
146139
detectSitewide?: boolean;
147140
}) => Promise<LinkVerification>;
148141

149-
// ---------------------------------------------------------------------------
150-
// src/lib/matching -> scoreCandidate() / findBestPartner()
151-
// ---------------------------------------------------------------------------
152-
153-
/** The subset of a site the matching engine needs. Keeps it testable without Mongo. */
142+
/**
143+
* The subset of a site `scoreCandidate()` and `findBestPartner()` in `src/lib/matching` need.
144+
* Deliberately a plain object, so the matcher stays testable without a database.
145+
*/
154146
export type MatchableSite = {
155147
id: string;
156148
ownerId: string;
@@ -202,13 +194,12 @@ export type FindBestPartner = (
202194
ctx: ScoreContext,
203195
) => { candidate: MatchableSite; score: ScoreBreakdown } | null;
204196

205-
// ---------------------------------------------------------------------------
206-
// Shared view models returned to MCP tools and web routes
207-
// ---------------------------------------------------------------------------
208-
209197
/**
210198
* A site's give/get standing, counted from the links that are live right now.
211199
*
200+
* First of the shared view models: everything from here down is returned to MCP
201+
* tools and web routes alike, which is what stops the two surfaces drifting.
202+
*
212203
* Every view that shows these numbers takes them as a value rather than reading
213204
* them off a site row, because they are not a property of the site: they are a
214205
* `COUNT` over `exchange_links`, resolved by `services/standing.ts`.

0 commit comments

Comments
 (0)