Skip to content

Commit

Permalink
controller & handlers diagram
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoineLep committed Oct 4, 2023
1 parent b0305e6 commit 97407b9
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 9 deletions.
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ exports.myHandler = handlers.myHandler;

## Configuration

Anthill Framework uses a configuration inheritance system allowing to apply some common logic within your app, controller or handler scope.
Anthill Framework uses a configuration inheritance system allowing to apply common logics within your app, controller or handler scope.

Ex: For dealing with cors for all the REST handlers of the application, set it on Anthill app scope:

Expand All @@ -130,7 +130,7 @@ app.configure({
});
```

Ex: The following code will enable caching and require that an "Authorization" header is provided for each of the controller handlers.
Ex: The following code will enable caching and require that an `Authorization` header is provided for each of the controller handlers.
The second handler configuration will override the caching configuration to apply a shorter TTL.

```ts
Expand Down Expand Up @@ -167,8 +167,6 @@ class MyController {
}
```

Here is an example of how 3 layers of configuration can work.

> [!NOTE]
> Middleware inheritance is cumulative so the 3 layers of middleware will be applied successively.
> Through Anthill, Controller and Handler during runBefore and in reversed order during runAfter.
Expand Down Expand Up @@ -219,10 +217,12 @@ If you're still not convinced and want to map an ANY method event to a single ha

## Controllers & Handlers

Controllers are groups of handlers. They define a scope in which some common configuration is applied.
Controllers are groups of handlers defining a scope in which some common configuration is applied.
Registering a controller to Anthill with `configure()` (see [Anthill](#anthill)), makes its handlers exposeable by the Anthill `exposeHandlers()` method.

Handlers are methods that can be either instance methods or a static methods. They are the main entry points for the code implementation
Handlers are methods that can be either instance or static methods. They are the main entry points for the code implementation

![image](https://github.com/AntL4b/anthill-framework/blob/main/docs/images/controllers-handlers.drawio.png?raw=true)

To create controllers and handlers, Anthill Framework uses classes and decorators.
Two types of controllers and handlers are available: `@RestController` and `@LambdaController` going in pair with `@RestHandler` and `@LambdaHandler`
Expand All @@ -231,8 +231,9 @@ Two types of controllers and handlers are available: `@RestController` and `@Lam
> All handlers within the app MUST have different names.
> By default, the handler registration system will use the handler method name but there's a possibility this name won't be unique.
> Ex: MyController1.list() and MyController2.list() won't work.
> If two handlers located in two controllers have the same name, you will have to declare an alternative name for at least one handler.
> The `name` property of the configuration object of `@RestHandler` and `@LambdaHandler` decorators is made for that purpose.
If two handlers located in two controllers have the same name, you will have to declare an alternative name for at least one handler.
The `name` property of the configuration object of `@RestHandler` and `@LambdaHandler` decorators is made for that purpose.

### REST

Expand Down Expand Up @@ -347,7 +348,7 @@ The nominal scenario is this one:

- m1.runBefore(ev) > m2.runBefore(ev) > m3.runBefore(ev)
- handler(ev) => resp
- m3.runAfter(resp) > m2.runAfter(resp) > m1.runAfter(resp).
- m3.runAfter(resp) > m2.runAfter(resp) > m1.runAfter(resp)

`runBefore()` and `runAfter()` are called as a mirror around the handler.

Expand Down
82 changes: 82 additions & 0 deletions docs/diagrams/controllers-handlers.drawio
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<mxfile host="Electron" modified="2023-10-04T09:46:48.990Z" agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/22.0.2 Chrome/114.0.5735.289 Electron/25.8.4 Safari/537.36" etag="R_48fkrlYmqS7NbgW9MF" version="22.0.2" type="device">
<diagram id="C5RBs43oDa-KdzZeNtuy" name="Page-1">
<mxGraphModel dx="954" dy="593" grid="0" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="1169" pageHeight="827" background="none" math="0" shadow="0">
<root>
<mxCell id="WIyWlLk6GJQsqaUBKTNV-0" />
<mxCell id="WIyWlLk6GJQsqaUBKTNV-1" parent="WIyWlLk6GJQsqaUBKTNV-0" />
<mxCell id="NndLvORObzjh5Yxis3ud-40" value="" style="rounded=0;whiteSpace=wrap;html=1;sketch=1;hachureGap=4;jiggle=2;curveFitting=1;fontFamily=Architects Daughter;fontSource=https%3A%2F%2Ffonts.googleapis.com%2Fcss%3Ffamily%3DArchitects%2BDaughter;fontSize=20;" parent="WIyWlLk6GJQsqaUBKTNV-1" vertex="1">
<mxGeometry x="3" y="3" width="814" height="387" as="geometry" />
</mxCell>
<mxCell id="NndLvORObzjh5Yxis3ud-4" value="Anthill" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;fontSize=20;fontFamily=Architects Daughter;" parent="WIyWlLk6GJQsqaUBKTNV-1" vertex="1">
<mxGeometry x="305.87" y="48" width="191.25" height="30" as="geometry" />
</mxCell>
<mxCell id="NndLvORObzjh5Yxis3ud-23" value="" style="rounded=1;whiteSpace=wrap;html=1;sketch=1;hachureGap=4;jiggle=2;curveFitting=1;fontFamily=Architects Daughter;fontSource=https%3A%2F%2Ffonts.googleapis.com%2Fcss%3Ffamily%3DArchitects%2BDaughter;fontSize=20;fillColor=none;fontColor=#ffffff;strokeColor=#A50040;" parent="WIyWlLk6GJQsqaUBKTNV-1" vertex="1">
<mxGeometry x="63.5" y="192" width="328" height="167" as="geometry" />
</mxCell>
<mxCell id="NndLvORObzjh5Yxis3ud-35" value="Your code" style="rounded=1;whiteSpace=wrap;html=1;sketch=1;hachureGap=4;jiggle=2;curveFitting=1;fontFamily=Architects Daughter;fontSource=https%3A%2F%2Ffonts.googleapis.com%2Fcss%3Ffamily%3DArchitects%2BDaughter;fontSize=20;fillColor=none;fontColor=#FFFFFF;strokeColor=#CC0066;" parent="WIyWlLk6GJQsqaUBKTNV-1" vertex="1">
<mxGeometry x="245" y="248" width="120" height="70" as="geometry" />
</mxCell>
<mxCell id="NndLvORObzjh5Yxis3ud-36" value="Handler 2" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;fontSize=20;fontFamily=Architects Daughter;" parent="WIyWlLk6GJQsqaUBKTNV-1" vertex="1">
<mxGeometry x="259.5" y="325" width="91" height="30" as="geometry" />
</mxCell>
<mxCell id="NndLvORObzjh5Yxis3ud-24" value="REST Controller" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;fontSize=20;fontFamily=Architects Daughter;rotation=270;" parent="WIyWlLk6GJQsqaUBKTNV-1" vertex="1">
<mxGeometry x="-39" y="238" width="167.5" height="30" as="geometry" />
</mxCell>
<mxCell id="NndLvORObzjh5Yxis3ud-41" value="Controllers &amp;amp; Handlers" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;fontSize=20;fontFamily=Architects Daughter;" parent="WIyWlLk6GJQsqaUBKTNV-1" vertex="1">
<mxGeometry x="16" y="18" width="254" height="30" as="geometry" />
</mxCell>
<mxCell id="-vhWvSG_m3Fp0A6SvReb-0" value="Your code" style="rounded=1;whiteSpace=wrap;html=1;sketch=1;hachureGap=4;jiggle=2;curveFitting=1;fontFamily=Architects Daughter;fontSource=https%3A%2F%2Ffonts.googleapis.com%2Fcss%3Ffamily%3DArchitects%2BDaughter;fontSize=20;fillColor=none;fontColor=#FFFFFF;strokeColor=#CC0066;" parent="WIyWlLk6GJQsqaUBKTNV-1" vertex="1">
<mxGeometry x="83" y="248.5" width="120" height="67.5" as="geometry" />
</mxCell>
<mxCell id="-vhWvSG_m3Fp0A6SvReb-1" value="Handler 1" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;fontSize=20;fontFamily=Architects Daughter;" parent="WIyWlLk6GJQsqaUBKTNV-1" vertex="1">
<mxGeometry x="93" y="325" width="91" height="30" as="geometry" />
</mxCell>
<mxCell id="-vhWvSG_m3Fp0A6SvReb-2" value="" style="rounded=1;whiteSpace=wrap;html=1;sketch=1;hachureGap=4;jiggle=2;curveFitting=1;fontFamily=Architects Daughter;fontSource=https%3A%2F%2Ffonts.googleapis.com%2Fcss%3Ffamily%3DArchitects%2BDaughter;fontSize=20;fillColor=none;fontColor=#ffffff;strokeColor=#A50040;" parent="WIyWlLk6GJQsqaUBKTNV-1" vertex="1">
<mxGeometry x="425" y="193" width="328" height="170" as="geometry" />
</mxCell>
<mxCell id="-vhWvSG_m3Fp0A6SvReb-3" value="Your code" style="rounded=1;whiteSpace=wrap;html=1;sketch=1;hachureGap=4;jiggle=2;curveFitting=1;fontFamily=Architects Daughter;fontSource=https%3A%2F%2Ffonts.googleapis.com%2Fcss%3Ffamily%3DArchitects%2BDaughter;fontSize=20;fillColor=none;fontColor=#FFFFFF;strokeColor=#CC0066;" parent="WIyWlLk6GJQsqaUBKTNV-1" vertex="1">
<mxGeometry x="603" y="248.25" width="120" height="68.75" as="geometry" />
</mxCell>
<mxCell id="-vhWvSG_m3Fp0A6SvReb-4" value="Handler 2" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;fontSize=20;fontFamily=Architects Daughter;" parent="WIyWlLk6GJQsqaUBKTNV-1" vertex="1">
<mxGeometry x="617.5" y="325" width="91" height="30" as="geometry" />
</mxCell>
<mxCell id="-vhWvSG_m3Fp0A6SvReb-5" value="Lambda Controller" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;fontSize=20;fontFamily=Architects Daughter;rotation=90;" parent="WIyWlLk6GJQsqaUBKTNV-1" vertex="1">
<mxGeometry x="671" y="243" width="200" height="30" as="geometry" />
</mxCell>
<mxCell id="-vhWvSG_m3Fp0A6SvReb-6" value="Your code" style="rounded=1;whiteSpace=wrap;html=1;sketch=1;hachureGap=4;jiggle=2;curveFitting=1;fontFamily=Architects Daughter;fontSource=https%3A%2F%2Ffonts.googleapis.com%2Fcss%3Ffamily%3DArchitects%2BDaughter;fontSize=20;fillColor=none;fontColor=#FFFFFF;strokeColor=#CC0066;" parent="WIyWlLk6GJQsqaUBKTNV-1" vertex="1">
<mxGeometry x="446" y="250.25" width="120" height="66.75" as="geometry" />
</mxCell>
<mxCell id="-vhWvSG_m3Fp0A6SvReb-7" value="Handler 1" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;fontSize=20;fontFamily=Architects Daughter;" parent="WIyWlLk6GJQsqaUBKTNV-1" vertex="1">
<mxGeometry x="459" y="325" width="91" height="30" as="geometry" />
</mxCell>
<mxCell id="-vhWvSG_m3Fp0A6SvReb-8" value="options (all)" style="rounded=1;whiteSpace=wrap;html=1;sketch=1;hachureGap=4;jiggle=2;curveFitting=1;fontFamily=Architects Daughter;fontSource=https%3A%2F%2Ffonts.googleapis.com%2Fcss%3Ffamily%3DArchitects%2BDaughter;fontSize=20;fillColor=#6a00ff;fontColor=#ffffff;strokeColor=#3700CC;fillStyle=hachure;" parent="WIyWlLk6GJQsqaUBKTNV-1" vertex="1">
<mxGeometry x="322.5" y="90" width="158" height="38" as="geometry" />
</mxCell>
<mxCell id="-vhWvSG_m3Fp0A6SvReb-9" value="REST Config" style="rounded=1;whiteSpace=wrap;html=1;sketch=1;hachureGap=4;jiggle=2;curveFitting=1;fontFamily=Architects Daughter;fontSource=https%3A%2F%2Ffonts.googleapis.com%2Fcss%3Ffamily%3DArchitects%2BDaughter;fontSize=20;fillColor=#6a00ff;fontColor=#ffffff;strokeColor=#3700CC;fillStyle=hachure;" parent="WIyWlLk6GJQsqaUBKTNV-1" vertex="1">
<mxGeometry x="45" y="90" width="273" height="38" as="geometry" />
</mxCell>
<mxCell id="-vhWvSG_m3Fp0A6SvReb-10" value="Lambda Config" style="rounded=1;whiteSpace=wrap;html=1;sketch=1;hachureGap=4;jiggle=2;curveFitting=1;fontFamily=Architects Daughter;fontSource=https%3A%2F%2Ffonts.googleapis.com%2Fcss%3Ffamily%3DArchitects%2BDaughter;fontSize=20;fillColor=#6a00ff;fontColor=#ffffff;strokeColor=#3700CC;fillStyle=hachure;" parent="WIyWlLk6GJQsqaUBKTNV-1" vertex="1">
<mxGeometry x="485" y="90" width="288" height="38" as="geometry" />
</mxCell>
<mxCell id="-vhWvSG_m3Fp0A6SvReb-11" value="REST Config" style="rounded=1;whiteSpace=wrap;html=1;sketch=1;hachureGap=4;jiggle=2;curveFitting=1;fontFamily=Architects Daughter;fontSource=https%3A%2F%2Ffonts.googleapis.com%2Fcss%3Ffamily%3DArchitects%2BDaughter;fontSize=20;fillColor=#a20025;fontColor=#ffffff;strokeColor=#6F0000;fillStyle=hachure;" parent="WIyWlLk6GJQsqaUBKTNV-1" vertex="1">
<mxGeometry x="66" y="153" width="323" height="38" as="geometry" />
</mxCell>
<mxCell id="-vhWvSG_m3Fp0A6SvReb-14" value="Lambda Config" style="rounded=1;whiteSpace=wrap;html=1;sketch=1;hachureGap=4;jiggle=2;curveFitting=1;fontFamily=Architects Daughter;fontSource=https%3A%2F%2Ffonts.googleapis.com%2Fcss%3Ffamily%3DArchitects%2BDaughter;fontSize=20;fillColor=#a20025;fontColor=#ffffff;strokeColor=#6F0000;fillStyle=hachure;" parent="WIyWlLk6GJQsqaUBKTNV-1" vertex="1">
<mxGeometry x="425" y="153" width="327" height="38" as="geometry" />
</mxCell>
<mxCell id="-vhWvSG_m3Fp0A6SvReb-16" value="&lt;font style=&quot;font-size: 16px;&quot;&gt;REST Config&lt;/font&gt;" style="rounded=1;whiteSpace=wrap;html=1;sketch=1;hachureGap=4;jiggle=2;curveFitting=1;fontFamily=Architects Daughter;fontSource=https%3A%2F%2Ffonts.googleapis.com%2Fcss%3Ffamily%3DArchitects%2BDaughter;fontSize=16;fillColor=#d80073;fontColor=#ffffff;strokeColor=#A50040;fillStyle=hachure;" parent="WIyWlLk6GJQsqaUBKTNV-1" vertex="1">
<mxGeometry x="83" y="208.5" width="116.5" height="38" as="geometry" />
</mxCell>
<mxCell id="-vhWvSG_m3Fp0A6SvReb-17" value="&lt;font style=&quot;font-size: 16px;&quot;&gt;REST Config&lt;/font&gt;" style="rounded=1;whiteSpace=wrap;html=1;sketch=1;hachureGap=4;jiggle=2;curveFitting=1;fontFamily=Architects Daughter;fontSource=https%3A%2F%2Ffonts.googleapis.com%2Fcss%3Ffamily%3DArchitects%2BDaughter;fontSize=20;fillColor=#d80073;fontColor=#ffffff;strokeColor=#A50040;fillStyle=hachure;" parent="WIyWlLk6GJQsqaUBKTNV-1" vertex="1">
<mxGeometry x="248.5" y="208.5" width="116.5" height="38" as="geometry" />
</mxCell>
<mxCell id="-vhWvSG_m3Fp0A6SvReb-18" value="&lt;font style=&quot;font-size: 16px;&quot;&gt;Lambda Config&lt;/font&gt;" style="rounded=1;whiteSpace=wrap;html=1;sketch=1;hachureGap=4;jiggle=2;curveFitting=1;fontFamily=Architects Daughter;fontSource=https%3A%2F%2Ffonts.googleapis.com%2Fcss%3Ffamily%3DArchitects%2BDaughter;fontSize=20;fillColor=#d80073;fontColor=#ffffff;strokeColor=#A50040;fillStyle=hachure;" parent="WIyWlLk6GJQsqaUBKTNV-1" vertex="1">
<mxGeometry x="446" y="208.25" width="117" height="38" as="geometry" />
</mxCell>
<mxCell id="-vhWvSG_m3Fp0A6SvReb-19" value="&lt;font style=&quot;font-size: 16px;&quot;&gt;Lambda Config&lt;/font&gt;" style="rounded=1;whiteSpace=wrap;html=1;sketch=1;hachureGap=4;jiggle=2;curveFitting=1;fontFamily=Architects Daughter;fontSource=https%3A%2F%2Ffonts.googleapis.com%2Fcss%3Ffamily%3DArchitects%2BDaughter;fontSize=20;fillColor=#d80073;fontColor=#ffffff;strokeColor=#A50040;fillStyle=hachure;" parent="WIyWlLk6GJQsqaUBKTNV-1" vertex="1">
<mxGeometry x="604.5" y="208.25" width="117" height="38" as="geometry" />
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>
Binary file added docs/images/controllers-handlers.drawio.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 97407b9

Please sign in to comment.