Think Build Implement Repeat
London, UK +44 7367 067226
WhatsApp FOLLOW f in X
  1. Home
  2. Blog
  3. Structure That Survives Growth
Python & Django

Structure That Survives Growth

Organising a Python codebase that survives growth: separate business logic from the framework, organise by feature, and keep dependencies pointing one way.

Updated 2 min readBy SpiderHunts Technologies

Free estimateNo obligation

Get a free estimate

Tell us what you need. A senior engineer reads every enquiry.

Takes under a minute. We never share your details.

  • Free consultation
  • No commitment
  • NDA on request

Prefer to talk? Book a free 30-minute call →

Quick answer — TL;DR

Separate business logic from framework code, keep modules focused, make dependencies explicit, and decide the structure before the codebase makes it for you.

Structure emerges whether you choose it or not

A project without a deliberate structure develops one anyway, usually organised by what was written when. That structure is invariably worse than one chosen at the start.

The cost of deciding structure early is an hour. The cost of imposing it later is a refactor across the whole codebase.

Separate business logic from the framework

  • Business rules in modules that import nothing framework-specific
  • Framework code that calls into them
  • Data access behind an interface, not scattered through logic
  • Configuration passed in rather than read globally

That separation makes business logic testable without spinning up a web framework, and it means a framework change is a rewrite of the edges rather than of the system.

Organise by feature, not by type

Instead ofPrefer
models/, views/, services/orders/, invoicing/, reporting/
One large utilities moduleUtilities near what uses them
Everything importable from everywhereExplicit, limited public interfaces
Deep nestingFlat until it genuinely needs depth

Feature-based organisation means a change to one area touches one directory, which makes both work and review easier.

Keep dependencies pointing one way

Business logic should not import from the web layer. The web layer imports business logic. Circular imports are a symptom that the boundaries are wrong.

When you find yourself fighting import order, the structure is telling you something.

Consistency over correctness

There is no single right structure for a Python project. There is enormous value in a project where everything follows the same pattern, because unfamiliar code becomes readable.

Decide, document it briefly, and apply it consistently.

FAQ

Frequently asked questions

The questions readers ask us after this guide.

Still have a question?

Ask us directly — a senior engineer will get back to you.

Ask about your project

Should we use a standard project layout?

A conventional one is a reasonable starting point. Adapt it to your domain rather than following it rigidly.

How do we restructure an existing project?

Incrementally, as you touch areas. A big-bang restructure is high risk and rarely finishes.

What about very small projects?

A single module is fine until it is not. The signal is when finding things starts taking time.

Does structure affect performance?

Negligibly. It affects how long changes take, which matters considerably more.

Keep reading

More on Python & Django

Python & Django

An API Other Systems Can Depend On

Designing a Python API service others can depend on: validation at the boundary, consistent errors and status codes, early versioning and documentation.

Python & Django

Moving and Transforming Data Reliably

Building data pipelines in Python that cope with malformed input: restartable stages, quarantining failures, reconciling counts and alerting on absence.

Start here

Codebase where nobody can find anything?

Usually a structure problem rather than a size one. Happy to look at how it is organised.

  1. You tell us what you needTwo minutes on the form, or a message on WhatsApp.
  2. A senior engineer reviews itAnd comes back with questions, a realistic range and an honest view on fit.
  3. Free 30-minute scoping callWe talk through scope, options and a realistic estimate — with no obligation.
Free estimateNo obligation

Talk to someone who builds this

Send a short brief and we will come back with an honest view and a realistic range.

Takes under a minute. We never share your details.

  • Free consultation
  • No commitment
  • NDA on request

Prefer to talk? Book a free 30-minute call →