Skip to content

Module 02 · Lesson 2.1

Components, Boundaries and Dependencies

40 minUpdated 19 Nov 2026Part of Architecture Recovery and Documentation · Existing Project Engineering
On this page
  1. What you will learn
  2. What components, boundaries and dependencies mean
  3. Worked scenario: the Tidewell import graph
  4. Finding external dependencies in code and config
  5. What reading imports cannot show
  6. Step-by-step workflow
  7. Using an AI assistant to find components
  8. Conclusion and your next step
  9. Reusable prompt
  10. Expected output
  11. Common errors and fixes
  12. Validation checklist
  13. Hands-on exercise
  14. Knowledge check
  15. Frequently asked questions
  16. References

Imagine you move into a house with no floor plan. You can walk through it and learn the rooms. But you cannot see which pipes feed which tap, or which wire runs behind which wall. A software system is the same. The folder tree shows the rooms. It does not show the pipes.

In this lesson you will find the components of a system, the boundaries between them, and the dependencies that tie them together. You will build a small import graph with a Python script. You will also look for the outside services the code needs. An AI assistant can help you read the results, but every claim must point to a file.

The example continues with the fictional Tidewell Wholesale service tidewell-orders from Writing a Codebase Orientation Guide. The company, people and data are invented.

What you will learn

  • Name the components of a service and say where each one starts and ends.
  • Build an import graph with a short script and read it for the direction of each dependency.
  • List the external dependencies of a system, with the file or setting that proves each one.
  • Explain what reading imports cannot show, and use an assistant to find candidates for you to check.

Before you start

What components, boundaries and dependencies mean

Teams use these three words all the time. They rarely say what they mean. Here they are in plain words, with a house as the comparison.

Component
A part of the system with one clear job, such as invoicing or stock. In a house, a component is a room. In a Django project, it is usually one app (a folder of related code). A background worker is a component too.
Boundary
The line around a component. It shows what is inside and what is outside. In a house, it is the walls and doors. In code, it is the functions other parts are meant to call.
Dependency
Something a component needs from another part in order to work. If the kitchen needs water from the bathroom's pipe, the kitchen depends on the bathroom. In code, it is often an import line.
External dependency
Something outside your project that the system needs, such as a database, a message queue, an email provider or another company's system. In a house, it is the electricity supplier.
Import
A line at the top of a file that says 'I use code from over there'. It is like writing a friend's phone number in your address book. It tells you who you may call.

Why does this matter for a change? Because a change in one component can break any component that depends on it. If you know the dependencies, you know where to look for trouble.

Direction matters too. If orders depends on stock, then a change to stock can hurt orders. A change to orders cannot hurt stock through that line. The arrow shows who is affected.

Worked scenario: the Tidewell import graph

You still want to add a minimum order value. Before you edit orders/services.py, you want to know who depends on orders. Your orientation guide says legacy/pricing_v1.py looks dead but is imported. That sort of surprise is what an import graph finds.

The service's components are its Django apps (api, catalogue, customers, dispatch, invoicing, legacy, orders, stock) plus the Celery workers. You will build the graph with a short script. The code below is a simplified version of the service's files, so you can run it without Django. The tree has only a few lines per file, but the import lines match the real story.

Python can read a file without running it. Its ast module (the name stands for abstract syntax tree) turns the text of a file into a tree of pieces. Think of it as a sentence diagram for code. You then ask the tree for its import lines.

Pythonimport_graph.py
import ast
import sys
from collections import defaultdict
from pathlib import Path

root = Path(sys.argv[1])
apps = {p.name for p in root.iterdir() if (p / "__init__.py").exists()}
apps.discard("tidewell")

edges = defaultdict(set)
for path in sorted(root.rglob("*.py")):
    app = path.relative_to(root).parts[0]
    if app not in apps:
        continue
    tree = ast.parse(path.read_text())
    for node in ast.walk(tree):
        if isinstance(node, ast.Import):
            names = [alias.name for alias in node.names]
        elif isinstance(node, ast.ImportFrom) and node.level == 0:
            names = [node.module]
        else:
            continue
        for name in names:
            target = name.split(".")[0]
            if target in apps and target != app:
                edges[(app, target)].add(path.relative_to(root).as_posix())

for (app, target), files in sorted(edges.items()):
    print(f"{app} -> {target}   ({', '.join(sorted(files))})")
print(f"{len(edges)} edges between {len(apps)} apps")

Lists which app imports which. Run it with the folder to scan as the only argument.

What each part does

  • apps = {...} treats every top-level folder that has an __init__.py as an app. It leaves out tidewell, which holds settings rather than business code.
  • path.relative_to(root).parts[0] takes the first folder name of each file. That is the app the file belongs to.
  • ast.parse(...) reads the file's text into a tree. Nothing in the file is run.
  • ast.Import and ast.ImportFrom are the two kinds of import line. We collect the module names from both.
  • name.split(".")[0] keeps only the first part, so orders.services becomes orders.
  • The if line keeps an edge only when it points at another app. An app importing itself is not a dependency we care about.
  • The last lines print one line per edge, with the file that proves it.
Bash
python import_graph.py tree

Run it on the synthetic tree.

Real output (run twice, identical)Captured from a real run
api -> customers   (api/views.py)
api -> orders   (api/views.py)
dispatch -> customers   (dispatch/importers.py)
dispatch -> orders   (dispatch/importers.py)
invoicing -> catalogue   (invoicing/totals.py)
invoicing -> legacy   (invoicing/totals.py)
orders -> customers   (orders/services.py)
orders -> invoicing   (orders/services.py)
orders -> stock   (orders/services.py)
9 edges between 8 apps

Read it with arrows in mind. orders -> invoicing means orders needs invoicing. Two apps depend on orders: api and dispatch. A third caller, the support replay command, lives inside orders. The graph hides it, because an app importing itself is skipped.

What the graph tells you

FindingMeaning for your change
api -> orders and dispatch -> ordersBoth the portal and the EDI importer call into orders. A rule placed in orders reaches both.
invoicing -> legacyThe legacy module is a live dependency of pricing. It is not dead code.
Nothing points at stock except ordersstock is a small, quiet component. It is only used from orders.
No arrow back from orders to api or dispatchGood sign. The core does not know who calls it.
Four things the nine edges show.

Finding external dependencies in code and config

Imports show how the parts of your project depend on each other. Outside services are found in settings, environment variables, compose files and scripts. Search for them. Do not assume them from the framework's usual setup.

Bash
git grep -nE "DATABASES|CELERY_BROKER_URL|EMAIL_HOST|EDI_API_TOKEN" -- "*.py"
git grep -nE "image:|redis|postgres" -- docker-compose.yml
ls scripts

Search tracked files for the names that usually point to outside services.

Result in the fictional repositoryIllustrative — your output will differ
tidewell/settings/base.py:48:DATABASES = {
tidewell/settings/base.py:71:CELERY_BROKER_URL = env("REDIS_URL")
tidewell/settings/production.py:15:EMAIL_HOST = env("SMTP_HOST")
dispatch/importers.py:12:EDI_API_TOKEN = "<redacted>"
docker-compose.yml:4:    image: postgres
docker-compose.yml:9:    image: redis
export_accounts.py

Each line is a fact with a place you can open. Together they give this table. The last two rows are not facts yet. They are questions.

External dependencyEvidenceStatus
PostgreSQLDATABASES in settings; db service in the compose fileVerified
RedisCELERY_BROKER_URL in settings; redis service in the compose fileVerified
Email provider (SMTP)EMAIL_HOST in production.pyVerified
EDI partners' systemsdispatch/importers.py and EDI_API_TOKENVerified
Accounts team's weekly CSV exportscripts/export_accounts.pyOpen question: is it still used? Ask the finance systems contact.
Host scheduler (nightly stock sync)Mentioned in a hand-over note onlyUnverified: no code or config found.
External dependencies, each with proof or a question.

What reading imports cannot show

An import graph is a map of what the code says it needs. It is not a record of what happens when the system runs. Some links are made by name, as text, and the script cannot see them. It is like reading a street map: it shows the roads, not the traffic.

Here is a search in the synthetic tree for four kinds of hidden link. The script found no edge from the project's own tidewell/ folder, yet it ties everything together.

Bash
grep -rnE 'include\(|autodiscover|task_routes|INSTALLED_APPS' --include="*.py" .
grep -rnE '@receiver|\.connect\(|send_task' --include="*.py" .

Look for links made by name instead of by import.

Real outputCaptured from a real run
./tidewell/celery.py:4:app.autodiscover_tasks()
./tidewell/celery.py:5:app.conf.task_routes = {"orders.tasks.*": {"queue": "emails"}}
./tidewell/settings.py:1:INSTALLED_APPS = ["api", "orders", "customers", "catalogue", "stock",
./tidewell/urls.py:3:urlpatterns = [path("api/", include("api.urls"))]

The second search found nothing, so this tree has no signals or named task calls. In a real repository it often does. Each result is a link the import graph misses.

Hidden linkPlain-words comparisonWhere to look
Settings stringsA guest list written on a card, not wired to anythingINSTALLED_APPS, middleware lists: apps are named as text
URL includesA signpost that says 'go to the api office'include("api.urls") in the project's urls.py
Celery task namesPosting a job with only a name on the envelopeautodiscover_tasks, task_routes, send_task
SignalsA bell that rings in one room and is answered in another@receiver, .connect(
Links that are made by name, not by import.

Notice the Celery lines. Nothing imports orders/tasks.py into the worker. The worker finds it by scanning. So the worker depends on orders, but no import says so.

Step-by-step workflow

  1. Step 1: List the candidate components

    Start with the Django apps in the settings list, the worker and any scripts. Write one line for each: name, folder, one-sentence job. Take the job from the code, not from the folder name.

    What you should see: A list of components, each with a folder.

  2. Step 2: Build the import graph

    Run a script like the one above, or a tool such as pydeps. Save the output with the commit hash.

    What you should see: A list of edges, each with the file that proves it.

  3. Step 3: Read the arrows

    For the component you plan to change, list who depends on it and what it depends on. Mark any surprise, such as a module that looks dead but has an incoming arrow.

    What you should see: A short list: callers, callees and surprises.

  4. Step 4: Search for the external dependencies

    Search settings, environment names, compose files and scripts for databases, queues, email, partner systems and exports. Record the file for each.

    What you should see: A table of external dependencies with evidence.

  5. Step 5: Search for links made by name

    Search for URL includes, task names, signals and settings strings. Add each link you find to the graph by hand and mark it as 'by name'.

    What you should see: A list of extra links the script could not see.

  6. Step 6: Mark what you could not confirm

    Anything you saw only in a note or a diagram stays 'unverified'. Write the question and who could answer it.

    What you should see: A list of open questions with owners (by role).

From folders to a checked dependency list
  1. Candidate components

    Apps, workers, scripts

  2. Import graph

    Script or tool

  3. Read the arrows

    Callers and surprises

  4. External services

    Settings, compose, scripts

  5. Links by name

    Includes, tasks, signals

  6. Open questions

    Unverified, with owner

Each stage adds evidence. The last stage keeps guesses visible.

Using an AI assistant to find components

An assistant is good at turning raw lists into a readable summary. It is poor at knowing what it has not seen. Give it the evidence you collected. Ask it to use only that evidence.

  • Give it: the import graph output, the search results for external services, and the settings lines. Remove secrets first.
  • Ask it for: a list of components with their jobs, the direction of each dependency, and a list of things the evidence does not show.
  • Do not ask it: to describe the architecture from the folder names alone. It will sound sure and may be wrong.
  • Then check: every component and arrow it names against your graph and files. Delete what you cannot find.

Conclusion and your next step

You can now name the parts of a system and the lines between them. You built an import graph, found the external services in code and config, and learned what imports miss. You also saw that an assistant can summarise evidence but cannot supply it.

Your next step: turn this list into pictures. Continue with Diagramming What the Code Does and draw a context diagram and a component diagram, with every box tied to a folder.

For more, see Mapping Entry Points and Data Flow for how work enters the system, and the module overview Architecture Recovery and Documentation.

Reusable prompt

Component and dependency finder

Turns your import graph and config search results into a component list and dependency table, using only your evidence.

Below is evidence I collected from a Python and Django service called tidewell-orders (fictional). Use ONLY this evidence. Do not add components or services that are not in it.

Import graph (app -> app, with the file that proves it):
api -> customers (api/views.py)
api -> orders (api/views.py)
dispatch -> customers (dispatch/importers.py)
dispatch -> orders (dispatch/importers.py)
invoicing -> catalogue (invoicing/totals.py)
invoicing -> legacy (invoicing/totals.py)
orders -> customers (orders/services.py)
orders -> invoicing (orders/services.py)
orders -> stock (orders/services.py)

Config search results:
tidewell/settings/base.py:48: DATABASES
tidewell/settings/base.py:71: CELERY_BROKER_URL = env("REDIS_URL")
tidewell/settings/production.py:15: EMAIL_HOST = env("SMTP_HOST")
dispatch/importers.py:12: EDI_API_TOKEN (value removed)
docker-compose.yml: services db (postgres) and redis
scripts/export_accounts.py exists

Please give me:
1. A table of components: name, folder, one-sentence job, and the evidence for the job.
2. A table of dependencies: who depends on whom, and which file proves it.
3. A table of external dependencies, each with its evidence.
4. A list called "Not shown by this evidence" with anything you would normally expect but cannot see here, such as links made by name (settings strings, URL includes, task names, signals).
Mark any guess as (unverified). Keep each table short.
Show the reusable template

Replace each {{placeholder}} with your own details.

Below is evidence I collected from {{system_description}}. Use ONLY this evidence. Do not add components or services that are not in it.

Import graph (app -> app, with the file that proves it):
{{import_graph_output}}

Config search results:
{{config_search_results}}

Please give me:
1. A table of components: name, folder, one-sentence job, and the evidence for the job.
2. A table of dependencies: who depends on whom, and which file proves it.
3. A table of external dependencies, each with its evidence.
4. A list called "Not shown by this evidence" with anything you would normally expect but cannot see here, such as links made by name (settings strings, URL includes, task names, signals).
Mark any guess as (unverified). Keep each table short.

Expected output and limitations

Three short tables and a list of gaps. Each row cites a file from your evidence. The assistant should say that the Celery worker, the URL includes and the settings strings cannot be seen in an import graph, and should label any guess.

Sample responseIllustrative — your output will differ
Components
| Name | Folder | Job (evidence) |
| orders | orders/ | Creates orders (create_order in orders/services.py) |
| invoicing | invoicing/ | Prices orders (price_order in invoicing/totals.py) |
| legacy | legacy/ | Contract pricing, still imported by invoicing/totals.py |

External dependencies
| PostgreSQL | DATABASES in tidewell/settings/base.py |
| Redis | CELERY_BROKER_URL in tidewell/settings/base.py |
| Email provider | EMAIL_HOST in tidewell/settings/production.py |

Not shown by this evidence
- How the Celery worker finds orders/tasks.py (no import shows it).
- Who runs scripts/export_accounts.py, and whether it is still used.
- (unverified) A nightly stock sync: nothing in the evidence mentions it.

Limitations to keep in mind

  • The assistant only reorders and names what you gave it. It has not opened the repository.
  • It may invent a component that 'usually exists', such as a cache. Check each name against your list.
  • It cannot tell whether an import line is used at runtime, or whether a script is still run.
  • The answer can look complete while the evidence is thin. A short 'not shown' list is a warning sign, not a good sign.

Common errors and how to fix them

Treating the folder tree as the architecture

Why it happens: Folder names look like components, so the picture feels finished.

Fix: Build the import graph and check the arrows. A folder with no incoming or outgoing arrows may be dead, or may be wired by name.

Reading an arrow the wrong way round

Why it happens: 'A imports B' is read as 'A is used by B'.

Fix: Write the edge as 'A needs B'. The thing that needs another is the one a change can break.

Missing the links made by name

Why it happens: The graph looks complete, so nobody searches for task names, signals or settings strings.

Fix: Run the second search for each kind of hidden link, and add what you find to the graph by hand.

Validation checklist

Tick each item once you have confirmed it.

Hands-on exercise

Build a dependency list for your own repository

Pick a repository you may study. Build its import graph, search for external dependencies and hidden links, and write one page that lists them with evidence.

You will need

  • A repository you are allowed to read, and its commit hash.
  • The script from this lesson, or a tool such as pydeps (or the equivalent for your language).
  • Your reading log from Module 1.

Acceptance criteria

Your work is done when every one of these is true.

Hints (3)
  • If your language is not Python, use a dependency tool for it, or search import lines with git grep.
  • If you have no hidden links, say which searches you ran. That is also a result.
  • If you use an assistant, give it only the evidence lists and remove secret values first.
Show a model answer

A strong answer starts with the commit hash and a table of components. It shows the graph as a list of arrows, with the file for each, and points out at least one surprise, such as a module that looks unused but has an incoming arrow. The external dependency table cites settings and compose files, never guesses. A section on hidden links shows the searches and results. Questions are specific, such as 'Is the weekly export still used? Ask the finance systems contact'. A weak answer lists folder names, states external services from memory, and has no evidence.

Knowledge check

Choose an answer, then check it. Nothing is recorded — this is for you.

  1. 1.The import graph shows orders -> stock. What does that arrow tell you?
    Show the answer and explanation

    Answer: A. The arrow means orders needs stock, so a change in stock can affect orders. The second option reverses the arrow, which is the common mistake. An import does not merge two apps into one.

  2. 2.Your graph shows no arrow into orders/tasks.py, yet the Celery worker runs it. Why?
    Show the answer and explanation

    Answer: B. Celery finds task files by scanning, not by an import line, so the script cannot see the link. Blaming the script or the worker is tempting, but both are working as designed. Search for task names and autodiscovery to find such links.

  3. 3.An assistant lists a Redis cache and a search service in your architecture. Neither is in your evidence. What do you do?
    Show the answer and explanation

    Answer: B. Only evidence from your repository can confirm a component. Common patterns are guesses, so they stay unverified. Asking the assistant to confirm repeats the guess, because it cannot see your system.

Frequently asked questions

What is the difference between a component and a module?

A module is a single code file or folder in a language. A component is a part of the system with one job, and it may be one module or several. In a Django service, a component is usually one app.

Do I need a special tool to find dependencies?

No. A short script or a search with git grep is enough to start. Tools such as pydeps and Import Linter save time on large projects. Learn the idea first, so you can check what a tool tells you.

Why can't I just ask an AI assistant to draw the architecture?

An assistant that only sees folder names will guess. The guess may sound right but be wrong. Give it evidence such as an import graph, and check its answer against the code.

What if my project is not written in Python?

The idea is the same in any language. Find the import or require lines, group them by component, and search for outside services in the config. Most languages have a tool that draws the graph.

Written by
PromptFable Editorial
Last updated 19 Nov 2026
Review
Reviewed by Waseem Nadir, Technical Reviewer
Last reviewed 27 Nov 2026

References

Primary sources for the technical details in this lesson. Vendor platforms change — check the official page if anything here looks different from what you see.

PromptFable is independent and is not affiliated with, endorsed by or sponsored by Anthropic, Google, OpenAI or any other vendor. Claude, Gemini, Google AI Studio and other product names are trademarks of their respective owners.