Custom PHP

Custom PHP Backend Development, Built From a Blank Canvas

Custom PHP backend development means designing a backend from a blank canvas instead of reshaping a recycled template. I define the domain model, HTTP boundaries and persistence layer first, then add only the framework and packages each feature needs. The result is code whose dependencies point inward, whose behaviour can be tested without a browser, and whose limits are explicit on day one.

By Saif Al Jahanwebdev-saif.com

Why a blank canvas is the starting point

When a client asks for custom PHP backend development, I open an empty directory and write a composer.json before I write a feature. A blank canvas does not mean rejecting libraries; it means choosing each one for a stated reason. I pin the PHP version, set PSR-4 autoloading, add PHPUnit and PHPStan, and decide how configuration reaches the application. Starting empty also forces the hard questions early: what is the domain, what are the entry points, and which parts must survive a change of framework? Those answers become the architecture instead of being discovered during a rewrite six months later.

  • Pin the runtime (currently PHP 8.3) and commit composer.lock
  • PSR-4 autoloading with one src root and a matching tests root
  • PSR-12 style plus PHPStan at a strict level from the first commit
  • Configuration read from environment variables, never committed secrets

The layers and the direction of dependencies

My default shape is small: an HTTP layer of thin controllers, an application layer of use-case services, a domain layer of entities and value objects, and an infrastructure layer for PDO repositories, queues and external clients. The rule is one-way: infrastructure implements interfaces declared in the domain or application layer, and nothing in the domain imports a framework class. A controller validates the request, calls one service, and serialises the result. It never holds business logic, and a service never reaches for $_POST or $_GET. That separation is what makes a backend from a blank canvas readable a year later.

  • Controllers: request parsing, authentication check, status code, response shape
  • Services: one use case each, transactional where more than one store changes
  • Domain: entities, value objects and enums with no framework imports
  • Infrastructure: PDO repositories, HTTP clients, queue drivers, logger
  • Interfaces declared inward; concrete adapters injected at the composition root

Boundaries that hold under change

A boundary is a promise about what may cross it. I keep three explicit ones. The HTTP boundary accepts a validated request object and returns a consistent response shape, so a change of transport does not touch business rules. The persistence boundary speaks in domain terms — findByEmail, save — rather than exposing SQL or a query builder to services. The integration boundary wraps every third-party API behind an interface with timeouts and retries in one place. I also define what must never cross: no raw superglobals past the controller, no framework attributes in domain objects, and no vendor exceptions leaking to clients.

  • Validate at the edge; reject unknown fields instead of silently ignoring them
  • Use prepared statements through PDO for every query that takes input
  • Wrap payments, mail and storage behind interfaces with one configured timeout each
  • Map domain exceptions to HTTP status codes in a single error handler

Testability is a design constraint, not an afterthought

I decide how a feature will be tested before I implement it. If a class needs a database, a clock or an HTTP client, those are constructor dependencies with interfaces, not static calls. Unit tests cover domain rules and service orchestration with in-memory fakes; integration tests run against a real database inside transactions that roll back; a small number of end-to-end tests cover the routes that matter most. I keep tests in a namespace that mirrors src, and I run them on every change. If a test requires booting the whole framework to check one rule, that is a signal the boundary is in the wrong place.

  • Unit tests: domain rules, value objects and services with fakes
  • Integration tests: PDO repositories against a disposable database, rolled back per test
  • Contract tests: response shapes checked against the documented API spec
  • An injectable Clock and HTTP client instead of global time and direct curl calls

Why I do not recycle templates

Recycled PHP templates carry someone else's decisions into your project: a directory layout you cannot explain, a base class that hides behaviour, plugins that duplicate validation, and defaults you discover only when they break. In custom PHP backend development that debt is expensive because the client owns the result. I would rather copy a handful of small, understood patterns than inherit a scaffold I cannot defend line by line. Where a framework is genuinely useful — routing, a DI container, migrations — I use its documented components directly and keep my own domain code free of its conventions. Nothing enters the project without a reason I can state.

  • No inherited base controllers or god objects hiding request handling
  • No boilerplate plugins whose options I cannot explain to the client
  • No copied middleware that swallows exceptions or logs request secrets
  • Framework components adopted individually, with their versions pinned

Verification and handoff before launch

Before handoff I check the same things on every custom backend: the app boots from a clean checkout, migrations run in order, the test suite is green, and API responses match the documented shapes. I add a small health endpoint that reports database reachability without exposing credentials, and structured logs carrying a request id so a failure can be traced. Where a client also needs a site, I keep the backend separate from the WordPress front end where practical and expose only the data the site consumes. This is how I work at webdev-saif.com, from Mymensingh, Bangladesh.

  • Clean-checkout boot with composer install and a documented env template
  • Migrations repeatable in order, with an explicit rollback path
  • Health endpoint and request-id logging with no secret leakage
  • API contract documented beside the routes it describes

Frequently asked questions

What does custom PHP backend development from a blank canvas actually mean?

It means starting with an empty repository and defining the architecture yourself instead of adapting a pre-made scaffold. I choose the runtime, autoloading, layering and test setup deliberately, then add framework components only where they solve a named problem. The client receives code whose structure I can explain and maintain.

When is a framework the right choice for a custom PHP backend?

Use a framework when routing, dependency injection, migrations or authentication save real work and you accept its conventions. Keep business rules in your own classes so a framework upgrade does not rewrite the domain. On small, well-defined APIs I sometimes use a minimal router and plain PHP classes instead.

How do you make a PHP backend testable?

By removing hidden dependencies. Time, database access and external HTTP calls become injected interfaces, so services can be exercised with fakes in unit tests. I then confirm the real adapters with integration tests against a disposable database. If a test needs the full framework booted to check a business rule, the boundary is in the wrong place.

Why not reuse a PHP boilerplate to save time?

Boilerplate saves setup time but transfers someone else's assumptions: base classes you cannot trace, duplicated validation, and defaults that surface late. A blank canvas costs a few extra hours at the start and removes those surprises. I reuse small, understood patterns instead of a whole scaffold, and keep every dependency justified.

Where do you draw the line between the backend and WordPress?

If a client needs both, I keep the custom PHP backend as a separate service with its own schema and expose a documented API. WordPress handles presentation and content editing. Coupling the two through shared tables makes deployment and testing harder, so I connect them only through explicit, versioned endpoints.

Written by Saif Al Jahan, webdev-saif.com · Mymensingh, Bangladesh. Last updated .