How megabre/stokmasterpro works
1. High-level shape
- This is a server-rendered PHP inventory/ERP-style application built around a modular admin interface.
- The codebase is organized into shared infrastructure (core/, config/, includes/) plus feature areas under modules/ and JSON/AJAX endpoints under api/.
2. Primary entrypoints and request flow
- index.php is the main authenticated landing point, typically driving the dashboard.
- login.php and logout.php handle session start/end.
- reset-admin.php is a maintenance/bootstrap script for restoring admin access.
- Most browser requests flow: browser → PHP page/controller → core services → MySQL/MariaDB → HTML response.
3. Core application services
- core/Database.php and config/database.php define the database layer, using PDO against MySQL/MariaDB.
- core/Authentication.php, core/Session.php, and core/Security.php enforce login state, role checks, CSRF/XSS protection, and input handling.
- core/Cache.php, core/Language.php, and core/DynamicFields.php provide caching, localization, and extensible entity schemas.
- Shared utility functions live in core/functions.php and core/helpers.php.
4. Feature modules as the main domain boundary
- Each domain is isolated under modules/<domain>/ and usually contains CRUD screens plus special actions.
- Key domains are dashboard, products, categories, customers, stock, orders, transactions, profile, settings, tools, and activity.
- The module layout is mostly page-based rather than service-based: index.php, add.php, edit.php, delete.php, view.php, etc.
5. Data-heavy business subsystems
- Products, categories, customers, and stock are the core inventory entities and are tightly connected through dynamic fields and import/export templates.
- Orders manage lifecycle/state transitions and include dedicated print and status-update pages.
- Transactions cover payments, debts, expenses, and cash summaries, with customer-linked financial history.
- Dashboard aggregates counts, charts, recent activity, and widget visibility settings.
6. API/AJAX boundary
- The api/ folder exposes lightweight endpoints for asynchronous UI operations and dashboard configuration.
- Examples include dashboard settings get/save, system update, and entity-related endpoints for products, stock, orders, customers, categories, and transactions.
- This is the main boundary where the front-end JavaScript talks back to the server without full page reloads.
7. Front-end composition
- Shared layout pieces live in includes/header.php, includes/sidebar.php, and includes/footer.php.
- Static assets are in assets/, with separate CSS and JavaScript for the general app and dashboard experience.
- Notable scripts include dashboard.js, chart-utils.js, dynamic-fields.js, and main.js; the UI is built around Tabler and uses ApexCharts, with jQuery, Select2, and DataTables as supporting libraries.
8. Database and persistent data
- The canonical schema/data source is stok.sql, indicating a classic relational backend.
- backup/ contains timestamped SQL dumps, showing that backups are a first-class operational feature.
- The app also persists uploaded files in structured folders under uploads/ for company assets, products, profiles, and imported data.
9. Import/export and templates
- templates/ contains CSV/XLSX templates for bulk import/export across major entities such as products, orders, customers, stock, categories, and transactions.
- modules/tools/import-export.php and related pages likely coordinate file ingestion and generation.
- uploads/import/ stores imported source files, reinforcing that batch data loading is an important workflow.
10. Settings, administration, and operational tools
- modules/settings/ centralizes system configuration: roles, users, currencies, units, customer tags, inventory settings, and system metadata.
- modules/tools/ provides backups, cache management, optimization, calculators, and reports.
- modules/activity/ is the audit log subsystem, separate from operational data but cross-cutting across the app.
11. Cross-cutting concerns
- The repository emphasizes role-based access control, multi-language support (lang/en.php, lang/tr.php), secure file uploads, and audit logging.
- The presence of dynamic field definitions across products/categories/customers/stock suggests a schema-extensibility layer on top of the relational model.
- Security and session handling are central architectural boundaries rather than just UI features.
12. Operational/runtime context
- The app is designed for deployment on Apache or Nginx with PHP 7.4+ and MySQL/MariaDB 5.7+.
- Writable runtime directories include uploads/ and backup/, which are part of the application’s operational surface.
- assets/vendor/ indicates bundled third-party front-end dependencies rather than external CDN-only delivery.
Main entry points: tools.php API · index.php Dashboard · helpers.php Helpers · Database.php Database
Components 28
Entry & UI
Browser entrypoints and shared page chrome.
- Home · Authenticated landing page and dashboard entry.
index.php - Login · Starts an authenticated session.
login.php - Logout · Ends the user session.
logout.php - Header · Shared top-of-page chrome.
includes/header.php - Sidebar · Shared navigation and module menu.
includes/sidebar.php - Footer · Shared bottom-of-page chrome.
includes/footer.php
Core Services
Authentication, session, security, database, and shared helpers.
- Database · PDO-backed database access to MySQL/MariaDB.
core/Database.php - DB Config · Database connection configuration.
config/database.php - Auth · Login state and role checks.
core/Authentication.php - Session · Session lifecycle and persistence.
core/Session.php - Security · Input handling and request protection.
core/Security.php - Dynamic Fields · Extensible entity fields used across modules.
core/DynamicFields.php - Cache · Application caching for shared data.
core/Cache.php - Language · Locale loading and translated strings.
core/Language.php - Helpers · Shared utility and helper functions.
core/helpers.php
Domain Modules
Primary business areas implemented as page-based modules.
- Dashboard · Overview widgets, stats, and recent activity.
modules/dashboard/index.php - Products · Product catalog with dynamic fields.
modules/products/index.php - Customers · Customer records, filters, and profiles.
modules/customers/index.php - Orders · Order lifecycle, printing, and status updates.
modules/orders/index.php - Stock · Stock movements and inventory records.
modules/stock/index.php - Transactions · Payments, debts, expenses, and cash summaries.
modules/transactions/index.php - Settings · Users, roles, units, currencies, and system settings.
modules/settings/index.php - Activity · Cross-cutting audit trail and activity history.
modules/activity/index.php
API & Operations
Asynchronous endpoints, settings, tools, and runtime data.
- Tools · Backup, cache, optimization, import/export, and reports.
modules/tools/index.php - API · Lightweight endpoints for dashboard and entity actions.
api/tools.php - Uploads · Persistent uploaded company, product, profile, and import files.
uploads/import - Backups · Timestamped SQL backups created by the app.
backup/backup_2025-05-25_03-14-12.sql - Schema · Canonical relational database schema and seed data.
stok.sql
Connections 31
- Login → Session: start · Creates and maintains the logged-in session.
- Logout → Session: end · Terminates the active session.
- Home → Auth: guarded by · Main landing page requires authenticated access.
- Home → Dashboard: loads · Authenticated home routes into the dashboard module.
- Dashboard → Database: reads · Fetches counts, widgets, and recent records.
- Dashboard → Cache: uses · Caches dashboard data and shared lookups.
- Dashboard → API: refreshes via · Dashboard widgets sync through AJAX endpoints.
- Products → Dynamic Fields: extends with · Supports configurable product attributes.
- Customers → Dynamic Fields: extends with · Supports configurable customer attributes.
- Stock → Dynamic Fields: extends with · Supports configurable stock attributes.
- Orders → Products: references · Orders depend on product records.
- Orders → Customers: references · Orders depend on customer records.
- Stock → Products: tracks · Inventory movements are tied to products.
- Transactions → Customers: links to · Financial history is customer-aware.
- Settings → Auth: admin check · User and role administration is protected.
- Settings → Database: persists · Stores configuration and master data.
- Tools → Backups: creates · Backup tooling writes SQL dumps.
- Tools → Uploads: imports · Import/export workflows use uploaded files.
- API → Dashboard: serves · Provides dashboard settings and data endpoints.
- API → Products: serves · Supports asynchronous product actions.
- API → Customers: serves · Supports asynchronous customer actions.
- API → Orders: serves · Supports asynchronous order actions.
- API → Stock: serves · Supports asynchronous stock actions.
- API → Transactions: serves · Supports asynchronous transaction actions.
- Header → Helpers: shared with · Layout pieces rely on common utilities.
- Sidebar → Helpers: shared with · Navigation uses shared utilities and state.
- Footer → Helpers: shared with · Footer shares common helper functions.
- Helpers → Language: loads · Helper layer supports localized output.
- Helpers → Security: uses · Common helpers participate in input handling.
- DB Config → Database: configures · Database connection settings feed the PDO layer.
- Database → Schema: targets · Database layer persists into the SQL schema.