Skip to content

Commit

Permalink
Webapp: structure in directories and add READMEs
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinepouille committed Sep 25, 2024
1 parent e01065a commit 2c9e133
Show file tree
Hide file tree
Showing 94 changed files with 192 additions and 162 deletions.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ SCRIPTSSOURCE = $(wildcard $(MANSCRIPTREP)*.sh)
SCRIPTSWITNESS = $(SCRIPTSSOURCE:.sh=.witness) $(MANGENREP)version.tex
MODELS = $(wildcard $(MANKAPPAMODELSREP)*.ka)

RESOURCES_HTML=$(wildcard gui/shared/*.js) $(wildcard gui/viz/*.js) $(wildcard gui/viz/*.css) gui/favicon.ico gui/package.json
RESOURCES_HTML=$(wildcard gui/js_lib/*.js) $(wildcard gui/js_lib/viz/*.js) $(wildcard gui/resources/*.css) gui/resources/favicon.ico gui/entry_point/package.json gui/entry_point/main.js

# `APP_EXT` defines where to fetch the js libs.
# `local` is to download them from the dev website e.g. github and saving them locally.
# `cdn` uses `cdnjs.cloudfare.com` to fetch the libs
# `debian` and `deploy` are also available
APP_EXT?=cdn
INDEX_HTML=gui/use-$(APP_EXT).html
INDEX_HTML=gui/entry_point/use-$(APP_EXT).html
ifeq ($(APP_EXT),local)
SITE_EXTRAS= build/site/external build/site/external/bootstrap-$(BOOTSTRAP_VERSION)-dist build/site/external/codemirror-$(CODEMIRROR_VERSION) build/site/external/dagre-d3 build/site/external/d3 build/site/external/jquery
else
Expand Down Expand Up @@ -232,12 +232,12 @@ Kappapp.app:
+$(MAKE) clean
+$(MAKE) build/Kappapp.app

build/Info.plist: gui/Info.plist.skel $(wildcard .git/refs/heads/*)
build/Info.plist: gui/resources/Info.plist.skel $(wildcard .git/refs/heads/*)
mkdir -p build
sed -e s/'\(.*\)\".*tag: \([^,\"]*\)[,\"].*/\1\"\2\"'/g $< | \
sed -e 's/\$$Format:%D\$$'/"$$(git describe --always --dirty || echo unkown)"/ > $@

build/Kappa.iconset: gui/Kappa-Logo.png
build/Kappa.iconset: gui/resources/Kappa-Logo.png
mkdir -p build
rm -rf $@ && mkdir $@
sips -z 16 16 $< --out $@/icon_16x16.png
Expand Down
4 changes: 2 additions & 2 deletions core/simulation/dune
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
(targets resource_strings.ml)
(deps
../../dev/load_files_into_ocaml_string_vars.sh
../../gui/shared/flux.js
../../gui/viz/common.js)
../../gui/js_lib/flux.js
../../gui/js_lib/viz/common.js)
(action
(with-stdout-to
%{targets}
Expand Down
14 changes: 7 additions & 7 deletions gui/JsSim.ml
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@ let onload (_ : 'a) : bool Js.t =
let () =
Dom.appendChild main (Tyxml_js.To_dom.of_div (Panel_projects.content ()))
in
let () = Dom.appendChild main (Panel_tab.navtabs ()) in
let () = Dom.appendChild main (Panel_tab.navcontents ()) in
let () = Dom.appendChild main (Panel_tabs.navtabs ()) in
let () = Dom.appendChild main (Panel_tabs.navcontents ()) in
let () =
Dom.appendChild main (Tyxml_js.To_dom.of_div (Panel_settings.content ()))
Dom.appendChild main (Tyxml_js.To_dom.of_div (Panel_preferences.content ()))
in

let () = Panel_projects.onload () in
let () = Panel_tab.onload () in
let () = Panel_settings.onload () in
let () = Panel_tabs.onload () in
let () = Panel_preferences.onload () in

let _ =
Dom_html.window##.onresize :=
Dom_html.handler (fun _ ->
let () = Panel_projects.onresize () in
let () = Panel_tab.onresize () in
let () = Panel_settings.onresize () in
let () = Panel_tabs.onresize () in
let () = Panel_preferences.onresize () in
Js._true)
in
Js._true
Expand Down
42 changes: 27 additions & 15 deletions gui/README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,46 @@
In this dir is the code for the webapp and electron app
In this dir is the code for the _Kappapp_ webapp and electron app!

`.ml` files starting by a capital, as `KaSimWorker.ml` are executable files.
### Directory structure

TODO: revamp this as it's really imprecise and incomplete
`viz/main.js` contains the code for the main electron process
`runtime_processes.ml` setups the manager and runs the local subprocesses on electron
`JsSim.ml` defines the window DOM and its different components
- Panel_tab contains all tabs from a project, other panels manages settings, projects...
- tabs are the tabs of different tools in a given project, some are in fact subtabs in the right hand side of the editor, which is called subpanel_editor
- state_* files manages in part the logic in the given app parts
The `.ml` files in this directory , as `KaSimWorker.ml` are executable files, as indicated by their capitalization.

`JsSim.ml` defines the main executable, with the window DOM and its different components,
while the other are the different workers that can be ran as webworkers/threads in the app.

`secret_method_name` indicate a method that should be called only by inherited classes. However this was not respected thoroughly so it has not be replaced
by `inherit parent as super ... super#private_method` which fills this need in the language
`ui` contains the different panels and tabs making the interface, along with their logic. The logic tries to match in limited fashion the view and controller roles in a Control/Model/View architecture (controller for controller_* files in `ui/tab_editor`)

`_mpi` indicates the message passing interface of the different processes and web workers (threads) used
Files in `state` manages state logic from different app part, similar to a `model` in a Control/Model/View architecture.

`entry_point` contains the entry point info for the html main page of the webapp and electron app config

`lib`, `lib_no_jsoo`, `js_lib` contain libs used by the webapp. Those in `lib_no_jsoo` do not depend on js_of_ocaml. Libs in `js_lib` are written in javascript`, while the other are in ocaml.

`resources` contains resources used to build the webapp and electron app.

### Runtime
The app is divided in :
- the interface
- the agents: kasim, kamoha, kasa, kastor. Which are handling respectively the simulation, the project files, the static analysis, the analysis of traces and computation of stories

There are two different runtimes for the agents (see `state_runtime.ml`) :
- webworkers/threads for the agents (`runtime_web_workers.ml`).
There are two different runtimes for the agents (see `state/state_runtime.ml`) :
- webworkers/threads for the agents (`state/runtime_web_workers.ml`).
This is the mode ran in the browser. The app uses a matching client to communicate with each thread e.g. `kasa_client` which are writing _messages_ to the agents. The threads are spawned as _workers_ e.g. `KaSaWorker`, which use the _message passing interface_ logic e.g. `kasa_mpi`, which parses the messages and compute what is asked by the clients.
There is a special case for the kasim agent. There is an `KaSimAsEmbedded` option that run it in the main thread and not in a separated web worker thread. The logic for the agent is then not in the `_mpi` but in `kasim_runtime` as it is used in both the _worker_ and in the main thread. Mode with kasim in a separated thread is called `KasimAsWebWorker`
- processes for the agents (`runtime_processes.ml`)
- processes for the agents (`state/runtime_processes.ml`)
This is the mode ran in the electron app. The app uses clients to communicate with agent processes.
Agents processes are defined in `core/agent` with a name starting with a capital letter. `mpi` files are in in different directories of `core` .
Kamoha agent and kastor agent have names that doesn't end in agent, which can be misleading. (TODO: change this?)
The app here spawns two processes, Kastor and KappaSwitchman. The KappaSwitchman one then spawns the other agents and manages the communication between them and the app.
Kastor is not included with the others as it can be communicated to in raw, and it doesn't have an internal state.

### Misc notes

This code uses js_of_ocaml, the React lib for reactive programming, and lwt.
Some changes in the code might cause parts of the code to not be called. This happens even with the removal of the dead code elimination in js_of_ocaml. A way to fix these issues is to use the Hooked lib in `lib_no_jsoo`, that is meant to replace the React lib with hooks, which don't have this issue. Replacing `React` by `Hooked` in place, and converting the signals to Hooked and back should help if this issue arise again.
Feel free to add an implementation for needed `React` functions that are not yet implemented in `lib_no_jsoo/hooked.ml`.

`secret_method_name` indicate a method that should be called only by inherited classes. However this was not respected thoroughly so it has not be replaced
by `inherit parent as super ... super#private_method` which fills this need in the language

`_mpi` indicates the message passing interface of the different processes and web workers (threads) used

12 changes: 0 additions & 12 deletions gui/dune_js_of_ocaml_flags.inc

This file was deleted.

1 change: 1 addition & 0 deletions gui/entry_point/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
`entry_point` contains the entry point info for the html main page of the webapp and electron app config
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 9 additions & 0 deletions gui/js_lib/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
This directory contains javascript libraries.

`viz` contains js libs for vizualization from kappa tools.

`flux.js` is used by the webapp, and by the html generation in ./core/simulation

`graphlogger.js` by the webapp.

`parser.js` might be unused.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions gui/js_lib/viz/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
This directory contains js libs for vizualization from kappa tools.

Some files here are used in the webapp.

`common.js` is also included by the html generation in `core/simulation`

`Kappa.js` might be unused, and includes info for kappa language syntax highlighting.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion gui/lib/dune
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
lwt_react
js_of_ocaml-tyxml
ppx_inline_test
kappa_webapp_lib_no_js
kappa_webapp_lib_no_jsoo
kappa_parameters
kappa_kasa_type_interface)
(flags :standard -w +a
Expand Down
6 changes: 3 additions & 3 deletions gui/lib/hooked.ml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
module DebugPrint : Kappa_webapp_lib_no_js.Hooked.DebugPrint = struct
module DebugPrint : Kappa_webapp_lib_no_jsoo.Hooked.DebugPrint = struct
let debug_print s =
let () = Common.debug ~loc:__LOC__ s in
()
end

module S = Kappa_webapp_lib_no_js.Hooked.MakeS (DebugPrint)
module E = Kappa_webapp_lib_no_js.Hooked.MakeE (DebugPrint)
module S = Kappa_webapp_lib_no_jsoo.Hooked.MakeS (DebugPrint)
module E = Kappa_webapp_lib_no_jsoo.Hooked.MakeE (DebugPrint)

type 'a signal = 'a S.t
type 'a event = 'a E.t
6 changes: 3 additions & 3 deletions gui/lib/hooked.mli
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module DebugPrint : Kappa_webapp_lib_no_js.Hooked.DebugPrint
module S : Kappa_webapp_lib_no_js.Hooked.S
module E : Kappa_webapp_lib_no_js.Hooked.E
module DebugPrint : Kappa_webapp_lib_no_jsoo.Hooked.DebugPrint
module S : Kappa_webapp_lib_no_jsoo.Hooked.S
module E : Kappa_webapp_lib_no_jsoo.Hooked.E

type 'a signal = 'a S.t
type 'a event = 'a E.t
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions gui/lib_no_jsoo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Here are libs used by the webapp that don't use js_of_ocaml.

This allows to use ppx_inline_test on them.
2 changes: 1 addition & 1 deletion gui/lib_no_js/dune → gui/lib_no_jsoo/dune
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(library
(name kappa_webapp_lib_no_js)
(name kappa_webapp_lib_no_jsoo)
(inline_tests)
(preprocess
(pps
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
1 change: 1 addition & 0 deletions gui/resources/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Here are resources used to build the webapp
File renamed without changes.
3 changes: 0 additions & 3 deletions gui/shared/README.md

This file was deleted.

13 changes: 13 additions & 0 deletions gui/state/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Files in `state` manages state logic from different app part, similar to a `model` in a Control/Model/View architecture.

`state_error.ml` manages errors at the webapp level

`state_ui.ml` call _init_ and _sync_ for `state_*` files

`state_file.ml` mainly manages editor & kasa stuff, but is accessed too from settings, state_ui

`state_perturbation.ml` manages simulation perturbations, only used from panel preferences

`state_runtime.ml` defines worker runtime, used from other `states_*` + preferences + projects controller

`state_simulation.ml` sets simulation controls and functions to interact with simulation data
2 changes: 0 additions & 2 deletions gui/state/dune
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
(include ../dune_js_of_ocaml_flags.inc)

(library
(name kappa_webapp_state)
(libraries
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions gui/state/state_ui.ml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
open Lwt.Infix

let sync () : unit Lwt.t =
State_settings.sync () >>= State_runtime.sync >>= State_project.sync
State_preferences.sync () >>= State_runtime.sync >>= State_project.sync
>>= fun _ ->
State_file.sync () >>= fun _ -> Lwt.return_unit

let init () : unit Lwt.t =
Lwt.return_unit >>= State_settings.init >>= State_runtime.init
Lwt.return_unit >>= State_preferences.init >>= State_runtime.init
>>= State_project.init >>= State_file.init >>= State_simulation.init >>= sync

let onload () : unit = Common.async __LOC__ (fun () -> Lwt.return_unit >>= init)
2 changes: 1 addition & 1 deletion gui/ui/dune
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(include ../dune_js_of_ocaml_flags.inc)
(include_subdirs unqualified)

(library
(name kappa_webapp_ui)
Expand Down
Loading

0 comments on commit 2c9e133

Please sign in to comment.