# configuroweb/farmacia architecture

> Architecture diagram of the GitHub repository configuroweb/farmacia, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-08). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/configuroweb/farmacia
- Repository: https://github.com/configuroweb/farmacia

## Overview

1. This is a classic PHP/MySQL admin system for pharmacy management, not a framework-based app. The server renders pages directly with PHP, and the browser uses JavaScript for most CRUD interactions.

2. The main business areas are:
   - Providers/brands
   - Categories
   - Products/medicines
   - Orders/invoices
   - Users/admin accounts
   - Sales and product reports, including expired products

3. The application is split into two clear layers:
   - Page layer: top-level PHP files like `dashboard.php`, `product.php`, `categories.php`, `orders`/`report` pages, plus `add-*` and `edit*` forms.
   - Action layer: `php_action/*` scripts that perform create/read/update/delete operations and return data for tables, forms, and AJAX requests.

4. The primary data flow is browser → page → JavaScript → `php_action` endpoint → MySQL → response back to the page. Most listing screens are likely driven by AJAX rather than full page reloads, especially for products, brands, categories, orders, and users.

5. Database access is centralized through connection files in `constant/connect.php`, `constant/connect1.php`, and `php_action/db_connect.php`. There is no ORM; the architecture is direct PHP-to-MySQL.

6. Authentication and account management are handled separately from the main inventory flow:
   - `login.php`, `constant/logout.php`
   - `app/changepassword.php`, `php_action/changePassword.php`, `php_action/changeUsername.php`
   - `constant/forgot_password.php`
   - `email_config.php` suggests password reset or notification email support

7. Presentation is organized around reusable layout fragments in `constant/layout/`:
   - `head.php`, `header.php`, `sidebar.php`, `footer.php`
   These provide the shared admin shell for all management pages.

8. Frontend behavior is mostly in `custom/js/*.js`, with one script per domain area:
   - `brand.js`, `categories.js`, `product.js`, `order.js`, `report.js`, `user.js`, `setting.js`, `import.js`
   These scripts coordinate forms, tables, validation, modals, and AJAX calls into `php_action`.

9. The UI stack is heavily vendor-based and dashboard-oriented:
   - Bootstrap and jQuery for structure and interaction
   - DataTables for searchable/sortable lists
   - SweetAlert and Toastr for user feedback
   - Chart libraries like Chart.js, Morris, Google Charts, Highcharts, ECharts, and amCharts for dashboard/report visualizations

10. Inventory and catalog management are the core bounded contexts:
   - Brands/proveedores: `brand.php`, `add-brand.php`, `editbrand.php`, `php_action/createBrand.php`, `php_action/removeBrand.php`
   - Categories: `categories.php`, `add-category.php`, `editcategory.php`
   - Products: `product.php`, `add-product.php`, `editproduct.php`, image handling via `php_action/editProductImage.php`

11. Order/invoice processing is another distinct flow:
   - `add-order.php`, `editorder.php`, `Order.php`, `invoiceprint.php`
   - Endpoint scripts such as `php_action/order.php`, `fetchOrder.php`, `fetchOrderData.php`, `editOrder.php`, `editPayment.php`, `printOrder.php`
   This indicates order creation, payment update, listing, and printable invoice output.

12. Reporting is separated from transactional editing:
   - `report.php`, `sales_report.php`, `salesreport.php`, `productreport.php`, `expreport.php`, `getproductreport.php`
   - Backend report endpoints like `php_action/getsalereport.php`, `php_action/getOrderReport.php`, `php_action/getexpproduct.php`
   Reports likely aggregate by date range and category/product status.

13. There is also a small import path:
   - `assets/import/proveedores.xlsx`
   - `custom/js/import.js`
   - `php_action/createBrandImport.php`
   This suggests bulk loading of providers/brands from Excel into the catalog.

14. Static assets are fully bundled inside the repo under `assets/`, including images, icons, CSS, JS plugins, and uploaded files under `assets/uploadImage/`. That makes the project self-contained and deployable as a PHP site with local asset hosting.

15. Overall, the architecture is a monolithic admin application with:
   - shared PHP layout templates
   - domain-specific CRUD pages
   - AJAX-backed action scripts
   - direct MySQL persistence
   - client-side dashboard widgets and reporting charts
   This is the key structure to capture in an architecture diagram.

Main entry points: [`php_action/db_connect.php`](https://github.com/configuroweb/farmacia/blob/master/php_action/db_connect.php) (DB connect), [`constant/layout/header.php`](https://github.com/configuroweb/farmacia/blob/master/constant/layout/header.php) (Layout shell), [`product.php`](https://github.com/configuroweb/farmacia/blob/master/product.php) (Catalog pages), [`custom/js/product.js`](https://github.com/configuroweb/farmacia/blob/master/custom/js/product.js) (Catalog JS)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["Page layer"]
  node_index["Home<br/>entry page<br/>[index.php]"]
  node_dashboard["Dashboard<br/>admin page<br/>[dashboard.php]"]
  node_catalog_pages["Catalog pages<br/>CRUD pages<br/>[product.php]"]
  node_order_pages["Order pages<br/>transaction pages<br/>[add-order.php]"]
  node_report_pages["Report pages<br/>[report.php]"]
  node_user_pages["User pages<br/>account pages<br/>[login.php]"]
end

subgraph group_actions["Action layer"]
  node_brand_actions["Brand actions<br/>CRUD endpoints<br/>[createBrand.php]"]
  node_category_actions["Category actions<br/>CRUD endpoints"]
  node_product_actions["Product actions<br/>CRUD endpoints<br/>[createProduct.php]"]
  node_order_actions["Order actions<br/>transaction endpoints<br/>[order.php]"]
  node_report_actions["Report actions<br/>report endpoints<br/>[getsalereport.php]"]
  node_user_actions["User actions<br/>account endpoints<br/>[createUser.php]"]
end

subgraph group_shared["Shared runtime"]
  node_layout_shell["Layout shell<br/>PHP templates<br/>[header.php]"]
  node_auth_config["Auth & config<br/>session helpers<br/>[check.php]"]
  node_db_connect[("DB connect<br/>mysql connection<br/>[db_connect.php]")]
end

subgraph group_frontend["Client scripts"]
  node_brand_js["Brand JS<br/>domain script<br/>[brand.js]"]
  node_catalog_js["Catalog JS<br/>domain script<br/>[product.js]"]
  node_order_js["Order JS<br/>domain script<br/>[order.js]"]
  node_report_js["Report JS<br/>domain script<br/>[report.js]"]
  node_user_js["User JS<br/>domain script<br/>[user.js]"]
end

subgraph group_domain["Business areas"]
end

subgraph group_assets["Bundled assets"]
  node_web_assets["UI assets<br/>static bundle<br/>[style.css]"]
end

node_index -->|"login gate"| node_auth_config
node_dashboard -->|"renders with"| node_layout_shell
node_catalog_pages -->|"renders with"| node_layout_shell
node_order_pages -->|"renders with"| node_layout_shell
node_report_pages -->|"renders with"| node_layout_shell
node_user_pages -->|"renders with"| node_layout_shell
node_dashboard -->|"loads"| node_web_assets
node_catalog_pages -->|"drives"| node_brand_js
node_catalog_pages -->|"drives"| node_catalog_js
node_order_pages -->|"drives"| node_order_js
node_report_pages -->|"drives"| node_report_js
node_user_pages -->|"drives"| node_user_js
node_brand_js -->|"AJAX"| node_brand_actions
node_catalog_js -->|"AJAX"| node_category_actions
node_catalog_js -->|"AJAX"| node_product_actions
node_order_js -->|"AJAX"| node_order_actions
node_report_js -->|"AJAX"| node_report_actions
node_user_js -->|"AJAX"| node_user_actions
node_brand_actions -->|"SQL"| node_db_connect
node_category_actions -->|"SQL"| node_db_connect
node_product_actions -->|"SQL"| node_db_connect
node_order_actions -->|"SQL"| node_db_connect
node_report_actions -->|"SQL"| node_db_connect
node_user_actions -->|"SQL"| node_db_connect
node_auth_config -->|"SQL"| node_db_connect

click node_index "https://github.com/configuroweb/farmacia/blob/master/index.php"
click node_dashboard "https://github.com/configuroweb/farmacia/blob/master/dashboard.php"
click node_catalog_pages "https://github.com/configuroweb/farmacia/blob/master/product.php"
click node_order_pages "https://github.com/configuroweb/farmacia/blob/master/add-order.php"
click node_report_pages "https://github.com/configuroweb/farmacia/blob/master/report.php"
click node_user_pages "https://github.com/configuroweb/farmacia/blob/master/login.php"
click node_layout_shell "https://github.com/configuroweb/farmacia/blob/master/constant/layout/header.php"
click node_auth_config "https://github.com/configuroweb/farmacia/blob/master/constant/check.php"
click node_db_connect "https://github.com/configuroweb/farmacia/blob/master/php_action/db_connect.php"
click node_brand_actions "https://github.com/configuroweb/farmacia/blob/master/php_action/createBrand.php"
click node_category_actions "https://github.com/configuroweb/farmacia/blob/master/php_action/createCategories.php"
click node_product_actions "https://github.com/configuroweb/farmacia/blob/master/php_action/createProduct.php"
click node_order_actions "https://github.com/configuroweb/farmacia/blob/master/php_action/order.php"
click node_report_actions "https://github.com/configuroweb/farmacia/blob/master/php_action/getsalereport.php"
click node_user_actions "https://github.com/configuroweb/farmacia/blob/master/php_action/createUser.php"
click node_brand_js "https://github.com/configuroweb/farmacia/blob/master/custom/js/brand.js"
click node_catalog_js "https://github.com/configuroweb/farmacia/blob/master/custom/js/product.js"
click node_order_js "https://github.com/configuroweb/farmacia/blob/master/custom/js/order.js"
click node_report_js "https://github.com/configuroweb/farmacia/blob/master/custom/js/report.js"
click node_user_js "https://github.com/configuroweb/farmacia/blob/master/custom/js/user.js"
click node_web_assets "https://github.com/configuroweb/farmacia/blob/master/assets/css/style.css"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_index,node_dashboard,node_catalog_pages,node_order_pages,node_report_pages,node_user_pages toneBlue
class node_brand_actions,node_category_actions,node_product_actions,node_order_actions,node_report_actions,node_user_actions toneAmber
class node_layout_shell,node_auth_config,node_db_connect toneMint
class node_brand_js,node_catalog_js,node_order_js,node_report_js,node_user_js toneRose
class node_web_assets toneTeal
```

## Components

### Page layer

Top-level PHP pages that render the admin UI and host forms, dashboards, and listings.

- [Home](https://github.com/configuroweb/farmacia/blob/master/index.php): entry page · Entry point that routes into the admin application. · `index.php`
- [Dashboard](https://github.com/configuroweb/farmacia/blob/master/dashboard.php): admin page · Main overview screen with widgets and charts. · `dashboard.php`
- [Catalog pages](https://github.com/configuroweb/farmacia/blob/master/product.php): CRUD pages · Brand, category, and product screens plus add/edit forms. · `product.php`
- [Order pages](https://github.com/configuroweb/farmacia/blob/master/add-order.php): transaction pages · Order entry, edit, and invoice-printing screens. · `add-order.php`
- [Report pages](https://github.com/configuroweb/farmacia/blob/master/report.php): report pages · Sales, product, and expired-product reporting screens. · `report.php`
- [User pages](https://github.com/configuroweb/farmacia/blob/master/login.php): account pages · Login and user-management screens for admin accounts. · `login.php`

### Action layer

PHP endpoints that handle CRUD, fetch data, and process AJAX requests.

- [Brand actions](https://github.com/configuroweb/farmacia/blob/master/php_action/createBrand.php): CRUD endpoints · Create, fetch, edit, remove, and import provider/brand data. · `php_action/createBrand.php`
- [Category actions](https://github.com/configuroweb/farmacia/blob/master/php_action/createCategories.php): CRUD endpoints · Create, fetch, edit, and remove categories. · `php_action/createCategories.php`
- [Product actions](https://github.com/configuroweb/farmacia/blob/master/php_action/createProduct.php): CRUD endpoints · Create, fetch, edit, image update, and remove medicines/products. · `php_action/createProduct.php`
- [Order actions](https://github.com/configuroweb/farmacia/blob/master/php_action/order.php): transaction endpoints · Order creation, fetch, payment edit, printing, and removal endpoints. · `php_action/order.php`
- [Report actions](https://github.com/configuroweb/farmacia/blob/master/php_action/getsalereport.php): report endpoints · Sales, order, and expired-product aggregation endpoints. · `php_action/getsalereport.php`
- [User actions](https://github.com/configuroweb/farmacia/blob/master/php_action/createUser.php): account endpoints · User creation, fetch, edit, remove, and credential update endpoints. · `php_action/createUser.php`

### Shared runtime

Authentication, layout fragments, and database connection files reused across pages.

- [Layout shell](https://github.com/configuroweb/farmacia/blob/master/constant/layout/header.php): PHP templates · Shared head, header, sidebar, and footer fragments for the admin UI. · `constant/layout/header.php`
- [Auth & config](https://github.com/configuroweb/farmacia/blob/master/constant/check.php): session helpers · Login, logout, password recovery, and account-change helpers. · `constant/check.php`
- [DB connect](https://github.com/configuroweb/farmacia/blob/master/php_action/db_connect.php): mysql connection · Central direct PHP-to-MySQL connection files. · `php_action/db_connect.php`

### Client scripts

Domain JavaScript that drives tables, forms, validation, and AJAX calls.

- [Brand JS](https://github.com/configuroweb/farmacia/blob/master/custom/js/brand.js): domain script · Client logic for brand CRUD, tables, and AJAX calls. · `custom/js/brand.js`
- [Catalog JS](https://github.com/configuroweb/farmacia/blob/master/custom/js/product.js): domain script · Client logic for categories and products. · `custom/js/product.js`
- [Order JS](https://github.com/configuroweb/farmacia/blob/master/custom/js/order.js): domain script · Client logic for order entry, payment updates, and invoice interactions. · `custom/js/order.js`
- [Report JS](https://github.com/configuroweb/farmacia/blob/master/custom/js/report.js): domain script · Client logic for report filtering and dashboard/report charts. · `custom/js/report.js`
- [User JS](https://github.com/configuroweb/farmacia/blob/master/custom/js/user.js): domain script · Client logic for user administration and settings. · `custom/js/user.js`

### Bundled assets

Static CSS/JS libraries and uploads shipped with the application.

- [UI assets](https://github.com/configuroweb/farmacia/blob/master/assets/css/style.css): static bundle · Bundled CSS, JS libraries, icons, and uploads used by the admin UI. · `assets/css/style.css`

## Connections

- Home → Auth & config: login gate · Entry pages pass through authentication checks.
- Dashboard → Layout shell: renders with · Admin pages share the common shell.
- Catalog pages → Layout shell: renders with · Catalog screens use shared templates.
- Order pages → Layout shell: renders with · Order screens use shared templates.
- Report pages → Layout shell: renders with · Report screens use shared templates.
- User pages → Layout shell: renders with · Account screens use shared templates.
- Dashboard → UI assets: loads · Dashboard UI depends on bundled CSS, JS, and chart libraries.
- Catalog pages → Brand JS: drives · Brand screens are coordinated by client-side scripts.
- Catalog pages → Catalog JS: drives · Category and product screens are coordinated by client-side scripts.
- Order pages → Order JS: drives · Order screens are coordinated by client-side scripts.
- Report pages → Report JS: drives · Report screens are coordinated by client-side scripts.
- User pages → User JS: drives · User screens are coordinated by client-side scripts.
- Brand JS → Brand actions: AJAX · Brand operations call action endpoints.
- Catalog JS → Category actions: AJAX · Category operations call action endpoints.
- Catalog JS → Product actions: AJAX · Product operations call action endpoints.
- Order JS → Order actions: AJAX · Order operations call action endpoints.
- Report JS → Report actions: AJAX · Reporting screens request aggregated data.
- User JS → User actions: AJAX · User management operations call action endpoints.
- Brand actions → DB connect: SQL · Brand CRUD persists directly to MySQL.
- Category actions → DB connect: SQL · Category CRUD persists directly to MySQL.
- Product actions → DB connect: SQL · Product CRUD and image updates persist directly to MySQL.
- Order actions → DB connect: SQL · Order processing and invoice data persist directly to MySQL.
- Report actions → DB connect: SQL · Reports read aggregated data from MySQL.
- User actions → DB connect: SQL · Account management persists directly to MySQL.
- Auth & config → DB connect: SQL · Authentication and password flows use the shared connection.
