How to find the entry point of a codebase
Seven reliable ways to find where code starts running: package.json fields, start scripts, framework conventions, routes, user-visible strings, tests and stack traces.
Every investigation starts with one question: where does this begin? In a small script the answer is obvious. In a framework-based app, a library or a monorepo, the real starting point is often several layers away from the file you'd guess. These techniques, roughly in order of usefulness, will find it.
1. Read package.json
For JavaScript and TypeScript projects, package.json names the entry points directly:
main,moduleandexportssay what a library exposes. Theexportsmap is the authoritative list of what users can import.binnames command-line executables.scripts.startandscripts.devshow how an application is launched, such asnode dist/server.jsornext dev.
If a script runs a framework command, the entry point is defined by that framework's conventions instead.
2. Learn the framework's conventions
Frameworks decide where your code starts:
- Next.js App Router:
app/layout.tsx, then thepage.tsxfor a route, andproxy.ts(previouslymiddleware.ts) before both. - Express: the file that calls
express(), usuallyapp.tsorserver.ts. - NestJS:
src/main.ts, thenAppModule. - Vite apps:
index.html, which loadssrc/main.tsx.
Our codebase guides list the entry points for more than 70 stacks.
3. Search for something the user sees
If you're investigating a feature, search for a string from the screen: a button label, a page title, an error message. That leads to a component, which leads to its handler, which leads to the API it calls. Error messages are especially good because they're usually unique.
4. Search for the route or command
For a backend behaviour, search for the URL path ("/api/orders" or '/orders/:id') or the command name. In frameworks with file-based routing, the path is the folder structure, so look for a folder named after the path segment.
5. Start from a test
Find the test that covers the behaviour (search the test folder for a keyword) and see what it imports and calls. Tests often call the real entry point directly, with realistic inputs.
6. Start from a stack trace
If you have an error from logs, the bottom frames of the stack trace show where execution began, such as a request handler, a job processor or a timer. Read upward from there. See tracing a bug from a stack trace.
7. Use the debugger
Set a breakpoint anywhere on the path you believe runs, trigger the behaviour, and look at the call stack panel. Every frame above is a step closer to the entry point.
Entry points that hide
- Event handlers and subscribers. Code that runs when an event fires isn't called directly; search for the event name.
- Jobs and workers. Background processors often run in a separate process with their own start script.
- Cron jobs and scheduled functions. Defined in config files or platform settings rather than code.
- Plugins and registries. Code registered by name and called through a lookup table.
Asking an AI tool
You can also ask RepoGrasp "where does a request to /api/orders start, and what runs before the handler?" and get an answer with file:line citations. It reads the source files, so it can see framework conventions and route definitions. It can't see infrastructure outside the repository, such as a load balancer rewrite, so confirm surprises.