Skip to content

feat: auto-register template creator as referrer via echo.json#739

Open
pannous wants to merge 2 commits intoMerit-Systems:masterfrom
pannous:feature/template-referral-system
Open

feat: auto-register template creator as referrer via echo.json#739
pannous wants to merge 2 commits intoMerit-Systems:masterfrom
pannous:feature/template-referral-system

Conversation

@pannous
Copy link

@pannous pannous commented Mar 15, 2026

Summary

Closes #612

When a user scaffolds an app from an external GitHub template via echo-start, the CLI now automatically registers the template creator as the referrer for the new app — if the template contains an echo.json with a referralCode.

Changes

  • packages/sdk/echo-start/src/index.ts — Added readEchoTemplateConfig() and registerTemplateReferral() functions. After cloning an external template, if echo.json contains a referralCode, the CLI calls POST /api/v1/apps/template-referral to register the referral, then removes echo.json from the scaffolded project.
  • packages/app/control/prisma/schema.prisma — Added templateReferrerCodeId and templateReferrerCode fields to the EchoApp model, plus a templateReferredApps reverse relation on ReferralCode.
  • packages/app/control/docs/money/referrals.mdx — Added documentation section explaining how template creators can embed referral codes.

How it works

  1. Template creator adds echo.json with { "referralCode": "THEIR_CODE" } to their template repo
  2. User runs npx echo-start -t https://github.com/creator/template
  3. echo-start clones the template, detects echo.json, calls the template-referral API
  4. echo.json is cleaned up from the scaffolded project

The existing POST /api/v1/apps/template-referral endpoint handles the backend logic.

Test plan

  • Verify echo-start correctly reads echo.json from a cloned external template
  • Verify the referral API is called with the correct appId and referralCode
  • Verify echo.json is removed after referral registration
  • Verify graceful handling when echo.json is missing or malformed
  • Verify Prisma schema migration runs cleanly

When scaffolding from an external GitHub template that contains an
echo.json with a referralCode, echo-start now automatically registers
the template creator as the referrer for the new app via the
template-referral API. The echo.json file is cleaned up after
registration to keep the scaffolded project tidy.

Closes Merit-Systems#612
Copilot AI review requested due to automatic review settings March 15, 2026 08:27
@vercel
Copy link
Contributor

vercel bot commented Mar 15, 2026

@pannous is attempting to deploy a commit to the Merit Systems Team on Vercel.

A member of the Team first needs to authorize it.

@vercel vercel bot temporarily deployed to Preview – component-registry March 15, 2026 08:27 Inactive
@vercel
Copy link
Contributor

vercel bot commented Mar 15, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
component-registry Skipped Skipped Mar 16, 2026 9:38am

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds support for “template referrals” so that when users scaffold from an external GitHub template, echo-start can read an echo.json referral code and register the template creator as the referrer for the newly created app.

Changes:

  • Extend echo-start to detect echo.json in external templates and call a template-referral API, then clean up the file.
  • Update Prisma schema to persist a template-referrer referral code relationship on EchoApp and add the reverse relation on ReferralCode.
  • Document how template creators can embed referral codes in echo.json.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.

File Description
packages/sdk/echo-start/src/index.ts Reads echo.json, calls POST /api/v1/apps/template-referral, and removes echo.json after scaffolding.
packages/app/control/prisma/schema.prisma Adds templateReferrerCodeId / templateReferrerCode to EchoApp and reverse relation on ReferralCode.
packages/app/control/docs/money/referrals.mdx Documents template referral setup and behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +187 to +193
5. The `echo.json` file is removed from the scaffolded project automatically

### Important Notes

- Template referrals are separate from user-to-user referrals
- Only the first referral code registered per app is kept
- The referral code must be valid and not expired
const configPath = path.join(projectPath, 'echo.json');
if (!existsSync(configPath)) return null;
try {
return JSON.parse(readFileSync(configPath, 'utf-8'));
Comment on lines +459 to +476
// Register template referral for external templates
if (isExternal) {
const echoConfig = readEchoTemplateConfig(absoluteProjectPath);
if (echoConfig?.referralCode) {
const registered = await registerTemplateReferral(
appId!,
echoConfig.referralCode
);
if (registered) {
log.message('Template creator registered as referrer');
}
// Remove echo.json from the scaffolded project — it's only for referral tracking
const echoConfigPath = path.join(absoluteProjectPath, 'echo.json');
if (existsSync(echoConfigPath)) {
unlinkSync(echoConfigPath);
}
}
}
// Remove echo.json from the scaffolded project — it's only for referral tracking
const echoConfigPath = path.join(absoluteProjectPath, 'echo.json');
if (existsSync(echoConfigPath)) {
unlinkSync(echoConfigPath);
Comment on lines +208 to +214
const response = await fetch(
`${ECHO_CONTROL_URL}/api/v1/apps/template-referral`,
{
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ echoAppId: appId, referralCode }),
}
Comment on lines +109 to +110
templateReferrerCodeId String? @db.Uuid // Referral code of the external template creator
templateReferrerCode ReferralCode? @relation("TemplateReferrer", fields: [templateReferrerCodeId], references: [id])
- Validate parsed JSON shape and referralCode type in readEchoTemplateConfig
- Always remove echo.json for external templates regardless of parse outcome
- Wrap unlinkSync in try/catch to avoid aborting scaffolding on cleanup failure
- Add missing API route for /api/v1/apps/template-referral
- Add Prisma migration for templateReferrerCodeId column
@vercel vercel bot temporarily deployed to Preview – component-registry March 16, 2026 09:38 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Template referral system

2 participants