# macs-labo/macs architecture

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

- Interactive diagram: https://gitdiagram.com/macs-labo/macs
- Repository: https://github.com/macs-labo/macs

## Overview

MacsDB combines scheduled FAMIC data refresh with SQLite-based pesticide search, plus the separately published MACS and ACFinderBE applications. The principal user workflow enters MACS, selects a chemical, crop, or pest search, and gets results from the database. The README documents the refresh and search capabilities; sampled source confirms MACS dispatch and database access, and parts of the update code. Several ACFinder and API internals are not shown, so their detailed interactions are omitted.

Main entry points: [`macs/index.php`](https://github.com/macs-labo/macs/blob/dev/macs/index.php) (Search entry), [`cron/inc.acis.php`](https://github.com/macs-labo/macs/blob/dev/cron/inc.acis.php) (Refresh coordinator), [`cron/inc.sqlite.php`](https://github.com/macs-labo/macs/blob/dev/cron/inc.sqlite.php) (SQLite refresh access), [`cron/inc.acis.sakumotsu.php`](https://github.com/macs-labo/macs/blob/dev/cron/inc.acis.sakumotsu.php) (Crop data shaping)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_refresh["Database refresh"]
  node_refreshcore["Refresh coordinator<br/>[inc.acis.php]"]
  node_refreshcommon["Refresh utilities<br/>[inc.common.php]"]
  node_refreshdb["SQLite refresh access<br/>[inc.sqlite.php]"]
  node_cropimport["Crop data shaping"]
  node_pestimport["Pest data shaping"]
  node_xls["XLS parsing<br/>[SimpleXLS.php]"]
  node_xlsx["XLSX parsing<br/>[SimpleXLSX.php]"]
end

subgraph group_search["MACS search"]
  node_macsentry["Search entry<br/>[index.php]"]
  node_searchcommon["Search session<br/>[inc.common.php]"]
  node_searchsetup["Search configuration<br/>[inc.setup.php]"]
  node_searchdb["SQLite search access<br/>[inc.sqlite.php]"]
  node_template["Page rendering<br/>[inc.template.php]"]
  node_chemsearch["Chemical search<br/>[chem3.php]"]
  node_cropsearch["Crop search<br/>[crop2.php]"]
  node_pestsearch["Pest search<br/>[pest4.php]"]
  node_macsdb[("MacsDB")]
end

subgraph group_acfinder["ACFinderBE"]
  node_acchem["Chemical lookup UI<br/>[chem.js]"]
  node_accrop["Crop lookup UI<br/>[crop.js]"]
  node_acpest["Pest lookup UI<br/>[pest.js]"]
  node_acloader["Data loading<br/>[loader.js]"]
  node_actable["Results tables<br/>[table.js]"]
  node_acpreview["Record previews<br/>[preview.js]"]
  node_acfiles["File handling<br/>[filer.js]"]
  node_acheader["Application header<br/>[header.js]"]
  node_actheme["Themes<br/>[theme.js]"]
  node_acworker["Offline worker<br/>[sw.js]"]
end

subgraph group_services["Supporting services"]
  node_subscribe["Subscription endpoint<br/>[subscribe.js]"]
  node_apiindex["API entry<br/>[index.php]"]
end

node_schedule(("Scheduled checks"))
node_famic{{"FAMIC data"}}

node_schedule -->|"triggers"| node_refreshcore
node_famic -->|"supplies data"| node_refreshcore
node_refreshcore -->|"uses"| node_refreshdb
node_refreshcore -->|"uses"| node_refreshcommon
node_refreshcore -.->|"invokes"| node_cropimport
node_refreshcore -.->|"invokes"| node_pestimport
node_cropimport -->|"updates"| node_refreshdb
node_pestimport -.->|"updates"| node_refreshdb
node_macsentry -->|"loads"| node_searchcommon
node_macsentry -->|"loads"| node_searchsetup
node_macsentry -->|"loads"| node_searchdb
node_macsentry -->|"loads"| node_template
node_macsentry -->|"dispatches"| node_chemsearch
node_macsentry -->|"dispatches"| node_cropsearch
node_macsentry -->|"dispatches"| node_pestsearch
node_cropsearch -->|"uses filters"| node_searchcommon
node_searchdb -.->|"queries"| node_macsdb
node_refreshdb -.->|"writes"| node_macsdb

click node_refreshcore "https://github.com/macs-labo/macs/blob/dev/cron/inc.acis.php"
click node_refreshcommon "https://github.com/macs-labo/macs/blob/dev/cron/inc.common.php"
click node_refreshdb "https://github.com/macs-labo/macs/blob/dev/cron/inc.sqlite.php"
click node_cropimport "https://github.com/macs-labo/macs/blob/dev/cron/inc.acis.sakumotsu.php"
click node_pestimport "https://github.com/macs-labo/macs/blob/dev/cron/inc.acis.byochu.php"
click node_xls "https://github.com/macs-labo/macs/blob/dev/cron/Excel/SimpleXLS.php"
click node_xlsx "https://github.com/macs-labo/macs/blob/dev/cron/Excel/SimpleXLSX.php"
click node_macsentry "https://github.com/macs-labo/macs/blob/dev/macs/index.php"
click node_searchcommon "https://github.com/macs-labo/macs/blob/dev/macs/inc.common.php"
click node_searchsetup "https://github.com/macs-labo/macs/blob/dev/macs/inc.setup.php"
click node_searchdb "https://github.com/macs-labo/macs/blob/dev/macs/inc.sqlite.php"
click node_template "https://github.com/macs-labo/macs/blob/dev/macs/inc.template.php"
click node_chemsearch "https://github.com/macs-labo/macs/blob/dev/macs/chem3.php"
click node_cropsearch "https://github.com/macs-labo/macs/blob/dev/macs/crop2.php"
click node_pestsearch "https://github.com/macs-labo/macs/blob/dev/macs/pest4.php"
click node_acchem "https://github.com/macs-labo/macs/blob/dev/acfinder/chem.js"
click node_accrop "https://github.com/macs-labo/macs/blob/dev/acfinder/crop.js"
click node_acpest "https://github.com/macs-labo/macs/blob/dev/acfinder/pest.js"
click node_acloader "https://github.com/macs-labo/macs/blob/dev/acfinder/loader.js"
click node_actable "https://github.com/macs-labo/macs/blob/dev/acfinder/table.js"
click node_acpreview "https://github.com/macs-labo/macs/blob/dev/acfinder/previews/preview.js"
click node_acfiles "https://github.com/macs-labo/macs/blob/dev/acfinder/filer.js"
click node_acheader "https://github.com/macs-labo/macs/blob/dev/acfinder/header.js"
click node_actheme "https://github.com/macs-labo/macs/blob/dev/acfinder/theme.js"
click node_acworker "https://github.com/macs-labo/macs/blob/dev/acfinder/sw.js"
click node_subscribe "https://github.com/macs-labo/macs/blob/dev/api/subscribe.js"
click node_apiindex "https://github.com/macs-labo/macs/blob/dev/api/index.php"

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_refreshcore,node_refreshcommon,node_refreshdb,node_cropimport,node_pestimport,node_xls,node_xlsx toneBlue
class node_macsentry,node_searchcommon,node_searchsetup,node_searchdb,node_template,node_chemsearch,node_cropsearch,node_pestsearch,node_macsdb toneAmber
class node_acchem,node_accrop,node_acpest,node_acloader,node_actable,node_acpreview,node_acfiles,node_acheader,node_actheme,node_acworker toneMint
class node_subscribe,node_apiindex toneRose
class node_schedule,node_famic toneIndigo
```

## Components

### Database refresh

- [Refresh coordinator](https://github.com/macs-labo/macs/blob/dev/cron/inc.acis.php): `cron/inc.acis.php`
- [Refresh utilities](https://github.com/macs-labo/macs/blob/dev/cron/inc.common.php): `cron/inc.common.php`
- [SQLite refresh access](https://github.com/macs-labo/macs/blob/dev/cron/inc.sqlite.php): `cron/inc.sqlite.php`
- [Crop data shaping](https://github.com/macs-labo/macs/blob/dev/cron/inc.acis.sakumotsu.php): `cron/inc.acis.sakumotsu.php`
- [Pest data shaping](https://github.com/macs-labo/macs/blob/dev/cron/inc.acis.byochu.php): `cron/inc.acis.byochu.php`
- [XLS parsing](https://github.com/macs-labo/macs/blob/dev/cron/Excel/SimpleXLS.php): `cron/Excel/SimpleXLS.php`
- [XLSX parsing](https://github.com/macs-labo/macs/blob/dev/cron/Excel/SimpleXLSX.php): `cron/Excel/SimpleXLSX.php`

### MACS search

- [Search entry](https://github.com/macs-labo/macs/blob/dev/macs/index.php): `macs/index.php`
- [Search session](https://github.com/macs-labo/macs/blob/dev/macs/inc.common.php): `macs/inc.common.php`
- [Search configuration](https://github.com/macs-labo/macs/blob/dev/macs/inc.setup.php): `macs/inc.setup.php`
- [SQLite search access](https://github.com/macs-labo/macs/blob/dev/macs/inc.sqlite.php): `macs/inc.sqlite.php`
- [Page rendering](https://github.com/macs-labo/macs/blob/dev/macs/inc.template.php): `macs/inc.template.php`
- [Chemical search](https://github.com/macs-labo/macs/blob/dev/macs/chem3.php): `macs/chem3.php`
- [Crop search](https://github.com/macs-labo/macs/blob/dev/macs/crop2.php): `macs/crop2.php`
- [Pest search](https://github.com/macs-labo/macs/blob/dev/macs/pest4.php): `macs/pest4.php`
- **MacsDB**

### ACFinderBE

- [Chemical lookup UI](https://github.com/macs-labo/macs/blob/dev/acfinder/chem.js): `acfinder/chem.js`
- [Crop lookup UI](https://github.com/macs-labo/macs/blob/dev/acfinder/crop.js): `acfinder/crop.js`
- [Pest lookup UI](https://github.com/macs-labo/macs/blob/dev/acfinder/pest.js): `acfinder/pest.js`
- [Data loading](https://github.com/macs-labo/macs/blob/dev/acfinder/loader.js): `acfinder/loader.js`
- [Results tables](https://github.com/macs-labo/macs/blob/dev/acfinder/table.js): `acfinder/table.js`
- [Record previews](https://github.com/macs-labo/macs/blob/dev/acfinder/previews/preview.js): `acfinder/previews/preview.js`
- [File handling](https://github.com/macs-labo/macs/blob/dev/acfinder/filer.js): `acfinder/filer.js`
- [Application header](https://github.com/macs-labo/macs/blob/dev/acfinder/header.js): `acfinder/header.js`
- [Themes](https://github.com/macs-labo/macs/blob/dev/acfinder/theme.js): `acfinder/theme.js`
- [Offline worker](https://github.com/macs-labo/macs/blob/dev/acfinder/sw.js): `acfinder/sw.js`

### Supporting services

- [Subscription endpoint](https://github.com/macs-labo/macs/blob/dev/api/subscribe.js): `api/subscribe.js`
- [API entry](https://github.com/macs-labo/macs/blob/dev/api/index.php): `api/index.php`

### Other components

- **Scheduled checks**
- **FAMIC data**

## Connections

- Scheduled checks → Refresh coordinator: triggers
- FAMIC data → Refresh coordinator: supplies data
- Refresh coordinator → SQLite refresh access: uses (evidence: `cron/inc.acis.php`)
- Refresh coordinator → Refresh utilities: uses (evidence: `cron/inc.common.php`)
- Refresh coordinator → Crop data shaping: invokes
- Refresh coordinator → Pest data shaping: invokes
- Crop data shaping → SQLite refresh access: updates (evidence: `cron/inc.acis.sakumotsu.php`)
- Pest data shaping → SQLite refresh access: updates
- Search entry → Search session: loads (evidence: `macs/index.php`)
- Search entry → Search configuration: loads (evidence: `macs/index.php`)
- Search entry → SQLite search access: loads (evidence: `macs/index.php`)
- Search entry → Page rendering: loads (evidence: `macs/index.php`)
- Search entry → Chemical search: dispatches (evidence: `macs/index.php`)
- Search entry → Crop search: dispatches (evidence: `macs/index.php`)
- Search entry → Pest search: dispatches (evidence: `macs/index.php`)
- Crop search → Search session: uses filters (evidence: `macs/crop2.php`)
- SQLite search access → MacsDB: queries
- SQLite refresh access → MacsDB: writes
