Building a custom Magento Open Source module

A custom module makes sense when a required behavior is specific to your business and no extension fits without heavy patching. This page covers when to build, how to structure and package the module with Composer, and the review points that keep it upgradable.

On this page

When a custom Magento Open Source module beats an off-the-shelf extension

A custom module is justified when the behavior you need is specific to your business, will be owned by your team, and must survive patch cycles. If a marketplace extension already does the job with an acceptable maintenance record, buy it. If the logic is a competitive differentiator, touches pricing, fulfillment or back-office rules that no vendor shares, or would require you to fork a vendor's code to get it, build it. Store owners and CTOs usually meet this decision when the catalog cannot express a rule such as a region-specific bundle price or a custom approval step before order submission.

Magento Open Source extends through three component types: modules, themes and language packages. Custom functionality lives in modules, which follow a PSR-4 compliant structure, so the namespace, directory layout and autoloading are predictable for any developer who knows the platform. Adobe's upgrade guide names customizations, extension count, third-party integrations and coding practices as the main drivers of upgrade effort. Each custom module adds code you must retest on every patch, so the question is not only whether you can build it but whether your team will keep it compatible across 2.4.x releases.

Before you commission a build, ask the developer to show how the module hooks into core, which core classes it touches, and how it will be tested after each patch. Confirm which Magento Open Source release line you are on and its end of support date, because that date sets how long the module must stay compatible. Ask for ownership of the source code and a written list of every core extension point used, so the decision to buy or build can be revisited later with real information.

Build a custom module or buy an extension: the decision factors

This table compares four routes for a requirement the core store does not cover: configuring core features, buying a Marketplace extension, adapting a community distribution's extension set, and building a custom module. Read each row against your own requirement, upgrade calendar and vendor risk. The main takeaway is that every route moves upgrade work somewhere, and the question is who owns that work and who reviews it.

FactorConfigure core or buy a Marketplace extensionAdapt a community distribution's extension setBuild a custom module
Fit for the requirementGood when the need is common and the core settings cannot express it. Confirm the extension covers your exact workflow, not a similar one.Fit depends on whether the extensions you need already exist in that distribution's set. Check each one against your requirement before choosing it.Best for logic that is specific to your business or integrations that no product covers. Requires a written spec before any code is written.
Ownership of upgrade workThe vendor usually updates the extension, but your team or partner still tests it against each Magento patch and minor release.Upgrade work is shared with the distribution's maintainers. Confirm how fast they port Adobe security patches and how they handle breaking changes.Your team or partner owns every upgrade, including code changes when core APIs change. Plan this as ongoing work, not a one-off project.
Vendor dependencyDepends on the vendor's continued support, license terms and release cadence. Ask what happens if the vendor is acquired or stops updating.Depends on the distribution project's governance and release process. Mage-OS is upstream compatible with Magento 2 extensions, which is one factor to weigh, not a recommendation.Low vendor dependency, but high dependency on the people who wrote the module. Keep documentation, tests and source control access with your organization.
Extension count and third-party codeEach added extension adds upgrade effort and conflict risk. Count what you already run before adding another.Adopting a full extension set can bring in many modules you do not need. Audit the set before you inherit it.Adds only code you have reviewed, but it still interacts with every other module. Test it alongside the extensions you already run.
What must be reviewedMarketplace review scope, vendor security practices, license terms, compatibility with your Magento version and any PCI DSS impact on payment flows.Each module's code, compatibility with the Magento version you run, maintenance activity and the license of each included component.Coding standard results, plugin and observer choices, database changes, dependency licenses, security review of input handling and test coverage.
Cost patternUsually a license or subscription that recurs, plus integration and testing effort. Ask the vendor for renewal terms in writing.Recurring effort to keep the adapted set working. The base software cost is typically zero, but integration and maintenance are not.Mostly one-time build effort, followed by recurring maintenance for each Magento upgrade. Ask any partner to price upgrades separately from the build.

How a Magento module is structured for PSR-4 autoloading

A Magento module is a self-contained directory with a fixed set of files that Magento looks for at registration time, and the first decision is whether your change really needs one. Adobe's developer documentation describes modules, themes and language packages as the component types used to extend Magento Open Source, and a custom module is the only one of the three that carries new business logic, data structures and service configuration. Confirm the exact file layout against the Adobe Commerce PHP development overview for your release line before you scaffold anything, because the expected files and their conventions are documented per version.

Two small files anchor every module. registration.php calls the component registrar to declare the module's name and directory, so Magento can find it. etc/module.xml declares the module name and its setup_version and lists sequence dependencies on other modules, which controls load order and is the place where a missing dependency shows up as a failed setup. Keep the module name in module.xml aligned with the vendor and module names in composer.json, since mismatches are a common source of install-time confusion that is easy to avoid at scaffold time.

Autoloading follows the PSR-4 rule: the namespace prefix in composer.json under autoload.psr-4 maps to the module directory, so a class in Vendor\Module\Model\Thing must live at a path that mirrors its namespace. Use the folders to separate responsibilities. etc holds configuration such as di.xml, events.xml and routes, Model holds business logic and resource models, Block holds view-layer classes, Controller holds request handlers, and Setup holds schema and data patches. Agree this split in the design review, because a reviewer who can see logic leaking into Block or Controller can spot maintenance risk before it reaches an upgrade.

How to build and package the module with Composer

This sequence takes a custom module from a written requirement to a Composer package that installs, upgrades and disables cleanly on a supported Magento Open Source release. Each step ends with a check the team can record before moving on.

  1. Define the requirement and extension points

    The lead developer and the business owner write down the behavior the module must add or change, the store workflows it touches, and the Magento extension points it will use: plugins, observers, preferences or new routes and controllers. Each point is chosen for a reason, and any change to a core class is flagged for review because it raises upgrade effort. The output is a short design note listing the target release line, for example 2.4.9 or 2.4.8-p5, and the extension points with their owners. Done means the reviewer can point to a requirement for every class the module will ship.

  2. Scaffold the module with the correct namespace

    A developer creates the module directory using the vendor namespace the organization will own and a module name that describes its business purpose. The module follows the PSR-4 layout Adobe documents for modules, with registration.php and etc/module.xml at the root and source code under the vendor namespace. Avoid names that imitate Magento's own vendor namespaces. Done means the module is recognized by the framework and the namespace in module.xml matches the directory and the autoload mapping.

  3. Declare the package in composer.json

    The developer writes composer.json with the package name, type set to magento2-module, a PSR-4 autoload entry and a require block that lists the Magento Open Source packages the module depends on, with version constraints that match the release line under test. The constraint should name the target line, not an open range, so builds do not silently pick up a different release. Done means composer validate passes with no errors, and the team has recorded the constraint it chose for each release line it supports.

  4. Install into a development environment on supported versions

    The developer builds a clean development environment on the stack Adobe lists for the target release. For 2.4.9 that is PHP 8.5, MySQL 8.4 or MariaDB 12.3 or 11.8, OpenSearch 3, Redis or Valkey 9, RabbitMQ 4.3, Composer 2.10 and nginx 1.30 on Linux x86-64. For 2.4.8-p5 the listed PHP versions are 8.4 and 8.3, with Varnish 8 also listed. Adobe supports only the listed combinations, so the team records the exact versions and does not mix them. The module is added through a path or private repository and installed with Composer. Done means Composer resolves the dependency tree without conflicts and the versions in use are written into the project's readme or build notes.

  5. Run setup:upgrade and cache checks

    The developer runs bin/magento module:enable for the new module, then bin/magento setup:upgrade, followed by bin/magento setup:di:compile and cache cleaning. Errors in dependency injection, declarative schema or missing classes surface here, so the output of each command is saved. The team then checks the module list with bin/magento module:status and confirms the storefront and admin load without errors in the logs. Done means every command exits cleanly, the module appears as enabled, and the logs show no new errors after a cache flush.

  6. Verify the module enables and disables cleanly

    The tester disables the module with bin/magento module:disable, runs setup:upgrade again and confirms the store still works without it. Then the module is re-enabled and the same checks are repeated. This shows that the module does not leave hard dependencies in core configuration, layouts or templates that break the store when it is removed. Any data the module stores should be reviewed at this point for how it behaves on removal. Done means the store runs in both states and the results are recorded against the release line under test.

  7. Record the package and confirm the upgrade path

    The team tags the package version, commits the lock file or the dependency constraints used for the build, and records the PHP, Composer and service versions in the release notes. It also confirms with the Upgrade Compatibility Tool and the lifecycle dates in Adobe's documentation which release lines the package must support next. Patch-cycle upgrades should be scheduled against the module's checks. Done means the package can be rebuilt from the repository, and the team knows which release lines it has been tested on.

Review points that keep a custom module maintainable

A custom module is judged less by how it works today than by how much it costs to move to the next patch and minor release. The gates below are the places where reviewers can catch design choices that make upgrades expensive, before the code reaches production.

Extend through plugins and observers

Check that the module changes core behavior with plugins or observers rather than by overriding classes. A class override replaces the whole file, so every upstream fix to that class is silently lost at the next patch. Plugins wrap only the methods they name, which keeps the change visible and easier to reason about. Ask the developer to list every preference and override in the module, with a reason for each one.

PHP development docs

Declare database changes with declarative schema

Review that every table and column change is declared in the module's schema file and applied through the standard setup process, not through hand-written SQL run on a live database. Declared schema lets the platform compare the target state with the current database and apply only the differences on each upgrade. Ask for the list of tables the module adds, and confirm that none of them duplicate core data.

Run the coding standard in CI

Require the Magento coding standard checks to pass in the build pipeline before any merge. Findings that surface late tend to be fixed by hand under deadline pressure, which is where undocumented workarounds start. Treat the check results as acceptance criteria in the statement of work, so the vendor or internal team knows the bar before development begins.

Keep third-party calls behind configuration

Check that endpoints, API keys, timeouts and retry settings for payment, ERP or shipping services live in admin configuration or environment settings, not in code. Hard-coded values force a code release every time a vendor changes a URL or a certificate, and they expose secrets in the repository. Ask where each credential is stored and who can read it.

Avoid edits to core files

Reject any change inside the core code tree or the vendor directory. Edits to core files are overwritten by the next Composer update, and they make it impossible to tell which behavior belongs to the store and which belongs to Adobe. Any gap that seems to require a core edit should be raised as a design question, with a plugin or configuration option proposed as the alternative.

Write tests that run each patch cycle

Require automated tests for checkout, pricing and each integration point, and run them against every patch release before the store is updated. Tests catch regressions in the module after a core patch, which is when upgrade effort is most likely to grow. Ask the team to show the test run against the latest patch of the release line the store uses.

How the module, Composer package and upgrade cycle fit together

The path starts with a documented requirement and a decision on the extension point: a plugin for around or after a public method, an observer for a dispatched event, or a preference only when no other mechanism fits. The module code then moves into a Composer package, through a private repository or build pipeline, onto a staging store. There it is checked against the patch cycle with the Upgrade Compatibility Tool before the review gate lets it reach production. Check each hand-off: the decision record, the built artifact and the staging test result.

Requirement to production path for a custom module, with decision points and the review gate.

Security and operational risks in custom module code

Custom modules run inside the store's trust boundary, so a weakness in one controller or stored credential can expose the whole platform. The cards below cover the risks that recur in custom Magento code and the checks to put in the build and handover.

Input handling in controllers and APIs

Every controller action, REST endpoint and GraphQL resolver in a custom module receives data from browsers, integrations or admin users. Validate types and lengths on the server, never trust values that the storefront JavaScript already checked, and use Magento's own resource models and query builders so values are bound rather than concatenated into SQL. Ask the build partner to show the input rules for each endpoint and to test them with malformed and oversized payloads before acceptance.

Credential storage for integrations

ERP, payment and shipping integrations usually need API keys, tokens or passwords. These should never be written into module source, committed to Git or placed in shared configuration files. Confirm where each secret is stored, who can read it in the admin and in the environment, and how it is rotated when a person or vendor changes. Write down the rotation procedure as part of the handover, not as an afterthought.

Inline scripts and CSP compatibility

A module that adds inline JavaScript or inline event handlers can break under the Content Security Policy headers that Magento supports, and enforcement is stricter on payment pages in recent releases. Keep scripts in module files loaded through the standard asset pipeline, and test every storefront and admin page the module touches. Confirm the exact policy behavior for your release against Adobe's CSP documentation before the module reaches production.

CSP documentation

Logging without personal data

Custom code often logs request payloads or integration responses while debugging, and those logs then contain names, addresses, email addresses or card-related identifiers. Define which fields a module may log, mask or drop the rest, and set a retention period for log files. Review the log output from a test order before go-live, and confirm that the log destinations are inside the same access controls as the store itself.

Module ownership after handover

A custom module is only maintainable if the client holds the source code, the Composer package, the tests and the documentation. Confirm in the written scope who owns the repository, where the package is hosted, who holds the deployment credentials, and which internal engineer can review changes. Ask for a list of third-party libraries the module pulls in, since each one adds upgrade and security work after the partner leaves.

Upgrade and patch readiness

Adobe recommends applying patches every cycle, and extension count and custom code are named as drivers of upgrade effort. A custom module should therefore have automated tests, a documented list of the core classes it overrides or plugs into, and a compatibility check run against each new release line before the store moves. Ask the partner which checks run in CI and which must be repeated by your team on upgrade.

Upgrade guide

What to confirm before committing to a custom module

Which Magento Open Source release line and PHP version does the store run?

Confirm the exact 2.4.x release line and PHP version in use before writing any module code, because the module must match what Adobe supports for that line. Adobe's system requirements for 2.4.9 list PHP 8.5, MySQL 8.4 or MariaDB 12.3 (recommended) or 11.8, OpenSearch 3, Redis or Valkey 9, RabbitMQ 4.3, Composer 2.10 and nginx 1.30 on Linux x86-64, and Adobe supports only the listed combinations. Check the system requirements for the line you run. If the store sits on a line near end of regular support, the module may need rework during the next upgrade, so factor that into the quote.

Does a Marketplace extension already cover the requirement?

Check the Marketplace and your existing extension list before deciding to build, because a maintained extension can be cheaper to adopt than a custom module you must maintain. Write the requirement as a list of business rules, then compare each rule against the extension's documented features, version compatibility and vendor support terms. A custom module makes sense when the rules are specific to your processes, when no extension meets them without heavy changes, or when the extension would add more code paths than you want to own. Ask the vendor for the supported release lines and their upgrade history.

Is the chosen front end (Luma, Blank or Hyvä) supported by the module?

Confirm which storefront theme is in production and whether the module's templates, layout XML and JavaScript work with it. Luma and Blank use the standard Magento frontend stack, while Hyvä uses a different frontend approach, so a module that renders storefront output can need a separate compatibility layer. Ask the team to state the front end in the scope document, list every storefront template the module touches, and decide whether a Hyvä-specific version or a headless approach is in scope. Without this answer, frontend work tends to grow late in the project.

How will the team run the Upgrade Compatibility Tool against the module?

Decide who runs the Upgrade Compatibility Tool, on which target release, and how the results are acted on before the module is accepted. Adobe's upgrade guide references the tool and names customizations, extension count, third-party integrations and coding practices as drivers of upgrade effort. Ask for a written process: the tool run in a staging copy of the store, a log of findings, a named owner for each finding and a rerun after fixes. Also confirm that the team plans to apply each patch cycle, since Adobe's guide recommends upgrading every patch cycle to stay secure and PCI compliant.

Who owns the module code and its automated test suite after handover?

Settle ownership in writing before development starts: who holds the repository, the license to internal code, the test suite and the documentation. Ask whether the module will be published to a private Composer repository or kept in your own Git system, and who holds the credentials. Confirm that the test suite is part of the deliverable, including unit and integration tests, and that a named internal engineer can run it after handover. Ownership gaps are one of the most common reasons a custom module becomes a blocker at the next upgrade.

What recurring work will the module add to the upgrade cycle?

Each custom module adds code that must be retested at every core patch and every release line change, so ask for an estimate of that recurring work in the quote. Recurring costs come from patch testing, compatibility fixes after core changes, dependency updates and support for any third-party services the module calls. One-time costs cover the design, build, tests and first release. Ask the partner to separate these two groups and to state who pays for each upgrade cycle, whether internal staff or a retainer covers it.

Could the module expose payment or customer data and need a PCI DSS scope review?

Confirm early whether the module touches cardholder data, payment flows, customer personal data or admin access, because those areas bring compliance and security review. Ask the team to map each data flow, to confirm which controls on the store already apply, and to identify any Content Security Policy or payment page rules the module must respect. A custom module that changes checkout or payment pages can change PCI DSS scope, so get the scope decision recorded before build. DeployOpen prepares systems and evidence for compliance assessments, but independent auditors issue any attestation.

How DeployOpen scopes and delivers a custom Magento module

DeployOpen plans, builds and supports custom Magento Open Source modules inside the client's own infrastructure, as a Chainscore Labs company that handles self-hosted open-source platforms end to end. For a custom module, the work usually starts with a written scope that names the business behavior to add, the Magento components it touches (plugins, observers, preferences, declarative schema, layout and configuration), the target Magento Open Source release line, and the environments where the module will be deployed. Most engagements are fixed-scope, so scope, deliverables and timelines are agreed in writing before any code is written. Ask for that document to list the acceptance criteria, the coding standard checks that will run, the packaging format (a Composer package with the module's PSR-4 namespace), and who owns the repository and the release process after handover.

Ongoing work is priced separately from the build. A custom module is a recurring maintenance item because every Adobe patch cycle may change core classes it depends on. Adobe's upgrade guide names customizations, extension count, third-party integrations and coding practices as the drivers of upgrade effort, so the module's share of that effort should be estimated during scoping, not discovered later. DeployOpen offers ongoing upgrades, testing and support as retainers, and the quote should state what a retainer covers: which release lines, how often compatibility is retested, and who fixes a regression caused by a core patch. Confirm these terms in the written scope rather than assuming them.

DeployOpen prepares the evidence a compliance or security assessment will ask for, including the code review record, test results, change history and deployment configuration for the module. It does not issue audit reports, attestations or certifications, and that work stays with your assessor or certification body. Ask DeployOpen to name the artifacts it will hand over at each milestone and where they will be stored, so your security and compliance teams can review the module without relying on the build team's memory.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.