Skip to content
beginner Phase 14 · Application Structure

Magento Entry Points

Different entry points - pub/index.php (frontend), pub/admin.php (admin), rest/V1 (API), crontab (cron). How each routes differently

45m
0 problems
Topic Progress 0%

Web Entry Points

Frontend Entry Point: pub/index.php

// pub/index.php — Serves the storefront
$bootstrap = Bootstrap::create(BP, []);
$bootstrap->run(
    new Magento\Framework\App\Http(
        $bootstrap->getObjectManager()
    )
);

// Area code: 'frontend'
// Routes: etc/frontend/routes.xml
// Theme: app/design/frontend/Vendor/theme/
// Cache: Full-page cache active

URL pattern: https://store.com/catalog/product/view/id/1

Admin Entry Point: pub/admin.php

// pub/admin.php — Serves the admin panel
$bootstrap = Bootstrap::create(BP, []);
$bootstrap->run(
    new Magento\Framework\App\Adminhtml(
        $bootstrap->getObjectManager()
    )
);

// Area code: 'adminhtml'
// Routes: etc/adminhtml/routes.xml
// Theme: app/design/adminhtml/Vendor/theme/
// Auth: Admin login required
// URL: typically /admin/ with custom admin path

URL pattern: https://store.com/admin/dashboard

Comparison

Entry Point Area Auth Required Theme
pub/index.php frontend No (guest allowed) frontend theme
pub/admin.php adminhtml Yes (admin login) adminhtml theme

The admin path is configurable:

// app/etc/env.php
'backend' => [
    'frontName' => 'admin_abc123' // Custom admin URL
],

Never use default /admin/ in production.

API Entry Points

REST API: pub/index.php (same entry point, different routing)

// REST API uses the same pub/index.php
// But routes differently via Accept header

// Request:
GET /rest/V1/products/SKU-123
Accept: application/json

// Area code: 'api'
// Routes: etc/webapi.xml (not frontend/routes.xml)
// No theme rendering
// Returns JSON response

REST URL pattern: /rest/{storeCode}/V1/{resource}

// REST endpoints defined in etc/webapi.xml
<routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:Magento:module:Magento_Webapi:etc/webapi.xsd">

    <!-- GET request -->
    <route url="/V1/products/:sku" method="GET">
        <service class="Magento\Catalog\Api\ProductRepositoryInterface" method="get"/>
        <resources>
            <resource ref="Magento_Catalog::products"/>
        </resources>
    </route>

    <!-- POST request -->
    <route url="/V1/products" method="POST">
        <service class="Magento\Catalog\Api\ProductRepositoryInterface" method="save"/>
        <resources>
            <resource ref="Magento_Catalog::products"/>
        </resources>
    </route>
</routes>

GraphQL API: pub/index.php (via GraphQL endpoint)

# Request:
POST /graphql
Content-Type: application/json

{
  products(filter: { sku: { eq: "SKU-123" } }) {
    items {
      name
      price {
        regularPrice { amount { value } }
      }
    }
  }
}

# Area code: 'api_graphql'
# Schema: defined in Schema.graphql files per module
# Response: JSON matching query structure

SOAP API (Legacy)

# URL: /soap/V1/?wsdl
# Area code: 'api'
# WSDL auto-generated from service contracts
# Less common, REST preferred

Cron and CLI Entry Points

Cron Entry Point

// pub/cron.php — Executes scheduled tasks
require __DIR__ . '/../app/autoload.php';

$bootstrap = Magento\Framework\App\Bootstrap::create(
    BP,
    []
);

$bootstrap->run(
    new Magento\Framework\App\Cron(
        $bootstrap->getObjectManager()
    )
);

// Area code: 'crontab'
// Routes: crontab.xml per module
// No HTTP request needed
// Run via system cron: * * * * * php /var/www/html/pub/cron.php

crontab.xml

<!-- app/code/Vendor/Module/etc/crontab.xml -->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Cron:etc/crontab.xsd">
    <group id="default">
        <job name="vendor_module_sync" instance="Vendor\Module\Cron\Sync" method="execute">
            <schedule>*/5 * * * *</schedule> <!-- Every 5 minutes -->
        </job>
    </group>
    <group id="index">
        <job name="vendor_module_reindex" instance="Vendor\Module\Cron\Reindex" method="execute">
            <schedule>0 2 * * *</schedule> <!-- Daily at 2 AM -->
        </job>
    </group>
</config>

CLI Entry Point: bin/magento

# bin/magento — Command-line interface
#!/usr/bin/env php
<?php
require __DIR__ . '/../app/autoload.php';

$bootstrap = Magento\Framework\App\Bootstrap::create(
    BP,
    ['mode' => 'developer']
);

$cli = new Magento\Framework\Console\Cli(
    $bootstrap->getObjectManager()
);

$cli->run();

# Usage:
bin/magento setup:install
bin/magento cache:clean
bin/magento catalog:product:reindex
bin/magento module:enable Vendor_Module
bin/magento setup:di:compile
bin/magento cron:run

Entry Point Summary

Entry Point Area Purpose Auth
pub/index.php frontend Storefront Optional
pub/admin.php adminhtml Admin panel Required
/rest/V1/* api REST API Token/Session
/graphql api_graphql GraphQL Optional
pub/cron.php crontab Scheduled tasks None
bin/magento cli CLI commands None

Quiz

1. What area code does the admin panel use?

Question 1 options

2. The REST API uses which entry point?

Question 2 options

3. Cron jobs are defined in which file?

Question 3 options

Flashcards

Question

What are Magento's entry points?

Answer

pub/index.php (frontend), pub/admin.php (admin), /rest/V1 (API), pub/cron.php (cron), bin/magento (CLI)

Question

Which area code for REST API?

Answer

api (uses same index.php, routes via Accept header)

Question

Where are cron jobs defined?

Answer

etc/crontab.xml with schedule, instance, method

Question

What is the admin URL configurable?

Answer

app/etc/env.php → backend.frontName (never use default /admin/)

Revision Notes

Key Takeaways

  • 1. Frontend: pub/index.php (area: frontend, no auth required)
  • 2. Admin: pub/admin.php (area: adminhtml, login required, configurable URL)
  • 3. REST API: pub/index.php via Accept header (area: api)
  • 4. GraphQL: pub/index.php via /graphql endpoint (area: api_graphql)
  • 5. Cron: pub/cron.php (area: crontab, scheduled tasks)
  • 6. CLI: bin/magento (console commands, setup, maintenance)

Interview Tips

  • List all entry points and their area codes
  • Explain how REST API reuses pub/index.php
  • Discuss why the admin URL should be customized

Cheat Sheet

Entry Points:
  pub/index.php   → frontend (storefront)
  pub/admin.php   → adminhtml (admin panel, login required)
  /rest/V1/*      → api (REST API)
  /graphql         → api_graphql (GraphQL API)
  pub/cron.php    → crontab (scheduled tasks)
  bin/magento     → CLI (commands, setup)

Area Codes:
  frontend, adminhtml, api, api_graphql, crontab

Admin URL: app/etc/env.php → backend.frontName
Cron: etc/crontab.xml → <job name="..." schedule="..."/>