Detect a tech stack from a GitHub repo URL
By Flavio
Updated
Tagged: Node.js
Detect a project's tech stack from a public GitHub repo without cloning. GitHub API branch lookup, parallel raw manifest fetches, and signal mapping.
When someone pastes a GitHub URL into one of my apps, I prefill its intake form with the framework, database hints, and deploy targets automatically. The whole scan runs on Cloudflare Workers over HTTP with no git binary, without needing to clone the repo, set up a GitHub App, or download a tarball.
Parse the URL safely
Before making any network requests, you need to clean up and validate whatever the user pasted. People often drop in a bare github.com/owner/repo without a protocol, or copy a clone URL ending in .git. I parse the input with the URL constructor, handle those bare paths, strip any .git suffix, and reject anything that isn’t on github.com:
function parseGitHubUrl(raw) {
const trimmed = raw.trim()
if (!trimmed) return null
let url
try {
url = new URL(trimmed.includes('://') ? trimmed : `https://${trimmed}`)
} catch {
return null
}
if (url.hostname !== 'github.com' && url.hostname !== 'www.github.com') {
return null
}
const parts = url.pathname.replace(/^\/+|\/+$/g, '').split('/')
if (parts.length < 2) return null
const owner = parts[0]
const repo = parts[1].replace(/\.git$/i, '')
if (!owner || !repo) return null
return { owner, repo }
}
You should also reject dot-only repo names, since they would break the raw file URL path later on.
Resolve the default branch
Manifest files live on a branch, and assuming main breaks on plenty of repositories that still use master or another default. One call to the GitHub REST API tells you which branch to check first:
async function resolveDefaultBranch(owner, repo) {
const res = await fetch(`https://api.github.com/repos/${owner}/${repo}`, {
headers: {
Accept: 'application/vnd.github+json',
'User-Agent': 'MyApp-RepoScan',
},
})
if (!res.ok) return null
const data = await res.json()
return data.default_branch ?? null
}
Make sure you await that resolver before building your raw URLs, so you don’t accidentally interpolate an unresolved Promise straight into the URL string:
const resolved = await resolveDefaultBranch(owner, repo)
const branches = [...new Set(
[resolved, 'main', 'master'].filter(Boolean)
)]
Once you have the candidate branches, try each one until you get files back.
Fetch manifests in parallel
Cloning a repository inside a Worker would be slow and heavy for a quick prefill. Instead, you can fetch individual files over HTTPS from raw.githubusercontent.com:
https://raw.githubusercontent.com/{owner}/{repo}/{branch}/package.json
You don’t need to inspect the whole repository either. Pick a fixed list of high-signal paths like package.json, requirements.txt, go.mod, wrangler.toml, fly.toml, Dockerfile, .yarnrc.yml, and prisma/schema.prisma. Capping the list at twelve requests is enough for most repos.
Here’s how I fetch all of them in parallel with Promise.all:
async function fetchRawManifest(owner, repo, branch, path, signal) {
const url = `https://raw.githubusercontent.com/${owner}/${repo}/${branch}/${path}`
const res = await fetch(url, { signal, headers: { Accept: 'text/plain' } })
if (!res.ok) return null
const text = await res.text()
return text.length > 0 && text.length < 512_000 ? text : null
}
const results = await Promise.all(
paths.map((path) => fetchRawManifest(owner, repo, branch, path, signal))
)
Running those requests one after another is slow on repos where most paths return a 404, whereas fetching them in parallel keeps the scan under a few seconds. Wrap each fetch in a timeout with AbortController as well. Four seconds per file is plenty.
Map files to stack signals
Turning those file contents into stack hints is plain string matching, with no LLM involved.
Start by collecting dependency names from dependencies, devDependencies, and peerDependencies in package.json, then check for packages like next, astro, hono, @prisma/client, drizzle-orm, and better-auth. Keep in mind that a Yarn 2+ repository might not have a yarn.lock, which makes .yarnrc.yml the stronger signal.
Other ecosystems work the same way. In requirements.txt, look for django, fastapi, and celery, and in go.mod, check for gin-gonic/gin. Config files also point to deploy targets: wrangler.toml means Cloudflare Workers, while fly.toml means Fly.io.
I return everything the scanner finds as a structured object:
{
language: 'JavaScript/TypeScript',
framework: 'Astro',
databases: ['PostgreSQL'],
orms: ['Drizzle'],
deployTargets: ['Cloudflare Workers'],
findings: ['Found package.json', 'Wrangler config found'],
}
From there, you can turn that object into form defaults like the app type, needs-database flags, and a short list of assumptions.
Rate limits and failures
Unauthenticated GitHub API calls are limited to sixty requests per hour per IP. A single scan uses one REST API call plus up to twelve raw fetches. Raw file URLs don’t count against the REST limit the same way, though you still shouldn’t hammer them in a loop.
If nothing comes back, tell the user the repo might be empty, private, or mistyped. Return null and let them fill out the form manually.
If you want to refine the app name from a text summary, you can add an optional LLM pass at the end, though the deterministic scan already gets you most of the way there.
Want me to talk about your product? You can sponsor this site.
Related posts about node: