Repository navigation
Commerza Admin Wiki
This wiki documents the full admin folder architecture, API responsibilities, security controls, and operational workflows for performance-safe and secure maintenance.
Root: admin/. APIs are grouped by domain under admin/backend/api/<domain>/, and auth lives in admin/backend/auth/auth.php.
-
backend/: Auth + admin APIs. -
frontend/: Admin pages + UI assets.
-
auth.php: Admin auth/session/CSRF helpers, permission checks, 2FA helpers, shared admin API rate-limit guard, shared admin action security-event logger. -
orders_api.php: Orders, customers, refunds data API; order status updates; bulk delete actions; refund status updates. -
products_sync_api.php: Full section/product sync read/write for panel product data. -
coupons_api.php: Coupon CRUD + coupon email campaign actions. -
reviews_api.php: Review moderation CRUD, visibility updates, stats. -
security_api.php: Security settings updates (email/password/reset key) + security events listing. -
viewers_api.php: Live viewer analytics mode/settings and snapshot. -
website_api.php: Branding/contact/social/ticker/slider/feature video settings. -
media_api.php: Secure admin media upload endpoint by target type.
-
admin-panel.php: Main admin dashboard with all tabpanes. -
admin-login.php: Admin login + CAPTCHA + 2FA challenge issue. -
admin-verify-2fa.php: 2FA verification and resend flow. -
admin-forgot-password.php: Password reset code and reset flow. -
admin-forgot-email.php: Admin email recovery/update flow.
-
css/style.css: Modular CSS entrypoint. -
css/modules/01-base.cssto05-responsive.css: Theme, layout, component styling, utilities, responsive behavior. -
js/script.js: Main admin-panel logic (all tabpane behavior + API integration). -
js/admin-config.js: Admin branding/meta adaptations from runtime settings. -
js/pages/*: Auth page-specific scripts.
All admin APIs are protected by:
admin_require_login_api($con)admin_require_permission_api($admin, '<domain>.manage')
Mutating endpoints require X-CSRF-Token or posted csrf_token, validated via admin_validate_csrf_token().
Admin APIs now apply action-scoped limits through:
-
admin_api_rate_limit_guard()inadmin/backend/auth.php - Scope pattern:
admin_<api>.<action>
This is enforced in:
orders_api.phpproducts_sync_api.phpcoupons_api.phpreviews_api.phpsecurity_api.phpviewers_api.phpwebsite_api.phpmedia_api.php
Sensitive admin actions log via:
-
admin_api_log_security_event()(wrapper) - shared backend logger
commerza_security_log_event()
New/strengthened logging includes:
- Order status changes
- Bulk order/customer deletion
- Refund status updates
- Coupon create/update/delete/campaign sends
- Review visibility/update/delete/upsert
- Media uploads
- Website settings writes
- Security settings writes (email/password/reset key)
- Viewer settings writes
orders_api.php now uses a transaction + row lock (FOR UPDATE) for update-status.
Benefits:
- Prevents concurrent stale writes on rapid click bursts.
- Guarantees consistent old/new status transitions per order row.
update-status supports refresh_mode: minimal to return:
- patched order state
- refreshed metrics only
This avoids expensive full summary payload rebuilds for every status click.
admin/frontend/assets/js/script.js now uses per-order lock set (ORDER_STATUS_LOCKS) to:
- Block duplicate clicks while request is active.
- Disable status/logistics buttons during update.
- Prevent accidental race requests from UI.
05-responsive.css improvements:
- Constrained tab content height on mobile for smoother scrolling.
- Better horizontal scrolling for dense tables.
- Mobile-safe padding refinements.
- Analytics chart container sizing by breakpoint.
Notification dropdown now supports:
- actionable entries that jump to relevant tab
- clear notifications action
- resume notifications action
admin-panel.php includes a new chart card:
#analyticsProfitLossChart- title: Profit vs Loss Trend (7 Days)
orders_api_fetch_metrics() now exposes:
-
refundLoss(30-day accepted refund loss total) -
netRevenue(totalRevenue - refundLoss) - weekly entries include
lossandnet
script.js now renders a mixed chart:
- Revenue (bar)
- Loss (bar)
- Net Progress (line)
Admin pages now consistently include canonical + OG tags while keeping noindex, nofollow:
admin-panel.phpadmin-login.phpadmin-forgot-password.phpadmin-forgot-email.phpadmin-verify-2fa.php
URLs/images are generated with admin_public_url(...) for deployment-safe absolute links.
-
summary(GET) -
refund-summary(GET) -
update-status(POST) -
delete-orders(POST) -
delete-customers(POST) -
update-refund-status(POST)
-
list(GET) -
save-coupon(POST) -
delete-coupon(POST) -
send-coupon-email(POST)
-
list(GET) -
set-visibility(POST) -
update-review(POST) -
delete-review(POST) -
add-review(POST)
-
list-events(GET/POST) -
update-email(POST) -
update-password(POST) -
update-reset-key(POST)
-
get(GET) -
save-brand(POST) -
save-contact(POST) -
save-social(POST) -
delete-social(POST) -
save-ticker(POST) -
save-slider(POST) -
delete-slider(POST) -
save-feature-videos(POST)
-
get(GET) -
save(POST)
- Upload by target (POST)
Use explicit XAMPP PHP binary in this repo environment:
C:\xampp\php\php.exe -l admin\backend\auth.php
C:\xampp\php\php.exe -l admin\backend\orders_api.php
C:\xampp\php\php.exe -l admin\backend\coupons_api.php
C:\xampp\php\php.exe -l admin\backend\reviews_api.php
C:\xampp\php\php.exe -l admin\backend\security_api.php
C:\xampp\php\php.exe -l admin\backend\viewers_api.php
C:\xampp\php\php.exe -l admin\backend\website_api.php
C:\xampp\php\php.exe -l admin\backend\products_sync_api.php
C:\xampp\php\php.exe -l admin\backend\media_api.php
C:\xampp\php\php.exe -l admin\frontend\admin-panel.php- Always add new admin API endpoints behind login + permission + CSRF + action-scoped rate limit.
- Log all sensitive admin writes (especially deletes, credential/security updates, or financial state changes).
- Prefer minimal payload returns for high-frequency UI actions.
- Keep frontend optimistic updates bounded and rollback-safe.
- Preserve response shape compatibility for existing tabpane renderers.
Commerza · MIT License · © Syed Ahmer Shah · ahmershah.dev · support@ahmershah.dev