Skip to content

[Flask] Add route resolver #112

Description

@theDakshJaitly

Target branch: main

Dependency

The Python code-graph extractor was merged in #103 and is available on main.
This issue is not blocked by another language extractor.

Goal

Add a bounded Flask framework resolver that connects decorator-defined routes
to their handler functions.

The initial implementation should cover conventional Flask application and
Blueprint decorators whose methods and paths can be determined statically.

Scope

  • Detect Flask from declared project dependencies such as pyproject.toml
    or requirements files.
  • Recognize:
    • @app.route("/path")
    • @app.route("/path", methods=["GET", "POST"])
    • Shortcut decorators such as @app.get() and @app.post()
    • Equivalent decorators on Blueprint instances
  • Treat @app.route() without an explicit methods list as a GET route.
  • Emit a separate stable route node for each explicitly declared HTTP method.
  • Emit a function_ref from each route node to the decorated handler.
  • Resolve the reference only when the matching same-file function or method is
    unambiguous.
  • Preserve Flask path converters such as /users/<int:user_id>.
  • Leave missing or ambiguous handlers unresolved rather than guessing.

Required changes

  • Add src/graph/resolution/frameworks/flask.ts implementing
    FrameworkResolver.
  • Register and export it from
    src/graph/resolution/frameworks/index.ts.
  • Add a minimal Flask fixture under
    src/graph/__tests__/fixtures/.
  • Add focused detection, extraction, resolution, and ambiguity tests.

Acceptance criteria

  • Positive and negative Flask detection are tested.
  • Application and Blueprint route decorators are covered.
  • Default GET, explicit method lists, and shortcut decorators are tested.
  • Parameterized paths using Flask converters are preserved.
  • Both synchronous and asynchronous handlers are covered.
  • Route nodes use stable IDs and Python as their language.
  • Same-file handlers resolve only when unambiguous.
  • Missing and ambiguous handlers remain unresolved.
  • The resolver is registered in the framework registry.
  • npm run typecheck, npm test, and npm run build pass.
  • No identity, reconciliation, schema, or drift-semantics changes are included.

Out of scope

  • Composing Blueprint prefixes across register_blueprint() calls.
  • add_url_rule() and dynamically registered routes.
  • MethodView, Flask extensions, middleware, and application factories.
  • Flask's implicit HEAD and OPTIONS behavior.
  • Dynamic or computed route paths.
  • Evaluating or importing the Flask application.

Contributor references

Contributor workflow

git switch main
git pull
git switch -c feat/flask-route-resolver

Open the pull request with main as the base branch.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    code-graphWork related to the AST and Tree-sitter code graphenhancementNew feature or requesthelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions