Given an existing codebase, explain how it works and its architecture/flow, then implement an additional feature from a problem statement and discuss extensions.
Asked in the live coding / codebase walkthrough stage. For the implementation portion, treat the codebase as a directed module dependency graph and return every module affected by one or more changed modules.
graph maps each module to the modules it directly imports. changed is a list of changed module names. Return all changed modules and their direct or indirect dependents, excluding unknown modules, sorted lexicographically.
Example: graph = {"app": ["auth"], "auth": ["config"], "config": []}, changed = ["config"] returns ["app", "auth", "config"].
Discuss how the design could change for streaming updates, cycles, or very large codebases.
def affected_modules(graph, changed):