> For the complete documentation index, see [llms.txt](https://zapit.gitbook.io/user-guide/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://zapit.gitbook.io/user-guide/developer-notes/project-structure.md).

# Project Structure

This page describes how the code is laid out and also provides links to concepts as needed.&#x20;

### Overall Layout

* Code is laid out in [packages ](https://uk.mathworks.com/help/matlab/matlab_oop/scoping-classes-with-packages.html)(the directories starting with a `+` denote a package in MATLAB).
* The bulk of the code is in [classes](https://uk.mathworks.com/help/matlab/matlab_oop/create-a-simple-class.html): it is [object-oriented](https://uk.mathworks.com/products/matlab/object-oriented-programming.html).
* [start\_zapit ](https://github.com/Zapit-Optostim/zapit/blob/main/zapit/start_zapit.m)is used to neatly start up the GUI in a user-friendly way.&#x20;
* The main gui is structured in a similar way to a [model/view/controller](https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller) layout:
  * The "model", [zapit.pointer](https://github.com/Zapit-Optostim/zapit/tree/main/zapit/%2Bzapit/%40pointer), handles the underlying logic and is independent of the GUI as possible. This class is sometimes referred to at the [API ](https://en.wikipedia.org/wiki/API)in the documentation, is it is the interface used to integrate the photostimulation into custom behavior code.&#x20;
  * The "view", [zapit.gui.main.view](https://github.com/Zapit-Optostim/zapit/blob/main/zapit/%2Bzapit/%2Bgui/%2Bmain/view.m), builds the UI elements of the GUI itself and contains no logic. It was built using [AppDesigner ](https://uk.mathworks.com/products/matlab/app-designer.html)and must never be edited by hand.&#x20;
  * The "controller", [zapit.gui.main.controller](https://github.com/Zapit-Optostim/zapit/tree/main/zapit/%2Bzapit/%2Bgui/%2Bmain/%40controller), is a class that [inherits ](https://uk.mathworks.com/help/simscape/lang/subclassing-and-inheritance.html)`zapit.gui.main.view` and so when it is instantiated (i.e. created at the command line or in `start_zapit`) the GUI appears. The `controller` class is what provides the logic to make the GUI run: it defines [callback functions](https://uk.mathworks.com/help/matlab/creating_plots/create-callbacks-for-graphics-objects.html), [listeners](https://uk.mathworks.com/help/matlab/matlab_oop/learning-to-use-events-and-listeners.html), etc. The `controller` is a composite class, since it has a `model` [property](https://uk.mathworks.com/help/matlab/properties-storing-data-and-state.html) that contains an instance of `zapit.pointer` this enables the `controller` to interact with the model. For example, to initiate the galvo calibration routine or to present stimuli.
* The class[ zapit.pointer](https://github.com/Zapit-Optostim/zapit/tree/main/zapit/%2Bzapit/%40pointer) implements the bulk of the logic and does the heavy lifting.&#x20;

### Concepts

* In most classes contain some[ observable properties](https://uk.mathworks.com/help/matlab/matlab_oop/class-to-observe-property-changes.html), meaning that changes to the values of those properties will drive a [callback function](https://uk.mathworks.com/help/matlab/creating_plots/create-callbacks-for-graphics-objects.html) to run via a [listener](https://uk.mathworks.com/help/matlab/matlab_oop/learning-to-use-events-and-listeners.html). For example, the `experimentPath` property in [zapit.pointer](https://github.com/Zapit-Optostim/zapit/tree/main/zapit/%2Bzapit/%40pointer) is observable. The [buildListeners ](https://github.com/Zapit-Optostim/zapit/blob/main/zapit/%2Bzapit/%2Bgui/%2Bmain/%40controller/buildListeners.m)method in [zapit.gui.main.controller](https://github.com/Zapit-Optostim/zapit/tree/main/zapit/%2Bzapit/%2Bgui/%2Bmain/%40controller) creates a listener that watches for changes the experiment path property. These can be made via the GUI or at the command line (`hZP.experimentPath='\some\path'`). When changes are made, the `updateExperimentPathTextArea` method of `zapit.gui.main.controller` is run to update the text of the path in a text area box found in the GUI Calibrate Scanners tab.&#x20;
