Code Structure Analyzer

How to use 4 steps
  1. Pick the Language.
  2. Paste under Paste your code and press Analyze Code.
  3. Read the breakdown, then Copy it if you need it.
  4. Optional: add a free AI key for stronger results.
Structural analysis

This tool runs entirely in your browser and produces an estimate from the text or file you supply. It does not query an external database or index, and nothing you enter is uploaded.

How this tool works

Offline this measures your snippet rather than reading it. It counts total, code, comment and blank lines, tracks the deepest nesting level, finds the longest line, works out whether you indent with tabs or spaces, and detects function, class and method declarations by pattern. That is lexical analysis: your code is never executed, and nothing here judges whether it is correct.

Add a free AI key and a language model explains the logic instead — what the code does overall, what each significant part is for, and what it cannot tell from the snippet alone. It is instructed to say when behaviour depends on code you have not pasted, rather than guessing at it.

Getting a useful explanation

  • Paste complete units: a whole function explains far better than a fragment of one. Cut at function boundaries, not at line counts.
  • Include the imports: the top of the file often determines what the rest of the code actually does.
  • Set the language correctly: the declaration patterns and comment syntax differ per language, and a wrong setting produces wrong line counts.
  • Do not paste secrets: with a key your code goes to the provider you chose. Strip API keys, tokens, passwords and connection strings first.

Two ways to understand unfamiliar code

When you open a file you did not write, you are doing two separate things. You are working out its shape — how big, how deep, how many moving parts — and you are working out its intent, which is what it was trying to achieve and why.

Shape can be measured. Intent cannot, and anything that claims to tell you a function's purpose is inferring it from names and patterns, which is exactly how confident wrong answers get produced.

The [msm_tool slug="code-explainer"] keeps those apart. Offline it measures: line counts, nesting depth, longest line, indentation style, and function, class and method declarations found by pattern. Your code is never executed and nothing judges whether it is correct. With an AI key a model explains the logic instead, and is instructed to say when behaviour depends on code you have not pasted rather than inventing it.

What the measurements actually tell you

  • Nesting depth is the most honest single number. Four levels of indentation inside one function usually means several responsibilities are tangled together, and it correlates with how hard the code is to change safely far better than length does.
  • Code versus comment lines shows the documentation balance. Almost no comments in intricate logic is a warning. A very high comment ratio often means comments explaining what a line does rather than why, which rots the moment the line changes.
  • Longest line flags the chained expression or the condition with five clauses in it. Those are where misreadings happen.
  • Declaration count against total lines tells you whether you are looking at many small units or a few large ones.
  • Indentation style matters when a file mixes tabs and spaces, which in some languages is a bug and in all of them is a diff that will fight you.

None of these is a verdict. A long, flat, well-named function can be perfectly clear, and a short deeply nested one can be dreadful. The numbers tell you where to look, not what you will find.

Reading a file you have never seen

  1. Find the entry points first. What calls into this? A route, a handler, an event, a command. Everything else is downstream of that.
  2. Read the signatures, skip the bodies. One pass over the declarations gives you the vocabulary before you try to follow any logic.
  3. Follow the data, not the control flow. Where does a value come in, what changes it, where does it get written or returned. Most bugs live on that path.
  4. Go to the deepest nesting. The most tangled block is usually where the real business rules were bolted on, and it is where the surprises are.
  5. Read the tests if there are any. Tests are the only documentation that fails when it becomes untrue.

The limits of explaining a snippet

A fragment cannot tell you what a fragment does. A function calling process(order) is opaque unless you know what process is, and no amount of analysis of the calling code will reveal it. This is not a tool limitation; it is what a snippet is.

The same applies to anything shaped by things outside the paste: framework conventions that make a bare method name meaningful, dependency injection, decorators, environment variables, database state, and side effects in code you did not include. A model asked to explain such a snippet may describe what it usually means in code like this, which is a reasonable guess presented in the same tone as a fact.

So paste complete units rather than fragments, include the imports, and set the language correctly — the same syntax means different things in different languages, and the pattern matching is language-aware.

Do not paste secrets

Real code carries credentials more often than people expect: connection strings, API keys, internal hostnames, S3 bucket names, staging URLs, customer identifiers in test fixtures. A comment naming an internal system is itself information.

Offline analysis runs entirely in your browser and nothing leaves the page. With an AI key it does leave — from your browser straight to the provider you chose, under their terms, which for free tiers often include using submitted text. Neither route passes through this site, and this site stores nothing, but the second route is a decision worth making deliberately.

Strip the values before pasting. Replacing a key with REDACTED costs nothing and changes no structural measurement.

Where explanations are most and least reliable

Most reliable on self-contained algorithmic code: a sort, a parser, a date calculation, a regular expression. The logic is entirely present and a good explanation of a dense regex saves genuine time.

Least reliable on framework glue, configuration and anything whose behaviour comes from convention rather than code on the screen. There the honest answer is often this depends on things you have not shown me, and an explanation that never says so is telling you less than it appears to.

Frequently Asked Questions

Specific to the Code Structure Analyzer. Broader questions about this category are answered on the category page.

No. Offline it is analysed as text in your browser and never runs. With a key it is sent as text to the provider you chose so a model can read it, and it does not run there either. Neither path executes anything.
Because measurement cannot answer that. Nesting depth and line counts are facts; whether the code is correct or well designed is a judgement that needs to understand intent. Rating code on metrics alone produces confident nonsense, so the offline mode reports what it measured and stops there.
Not reliably, and it should not be relied on for either. With a key it will flag unhandled edge cases and unclear logic it can see in the snippet, which is useful during review. It is not a linter, not a static analyser and not a security audit.
Depth is counted from brace and block structure across the whole snippet, so an object literal, a long chain of callbacks or a switch statement all add levels. In languages where blocks are not brace-delimited, the count is an approximation.
The offline analysis handles JavaScript, PHP, Python, Java, CSS, HTML and SQL, each with its own comment and declaration patterns. With a key the model will read most languages regardless of the selector, though the measurements shown alongside still follow the language you picked.

Subscribe to receive notifications about new tools, features, and productivity tips.