# Lifecycle

We'll first go through a simplified version of the lifecycle of a request, assuming we're building a website application and our client is a web browser.

When a Cherrycake application receives a request, it first loads some initial modules like [Output](https://cherrycake.tin.cat/version-0.x/reference/core-modules/output), [Errors](https://cherrycake.tin.cat/version-0.x/reference/core-modules/errors) and [Actions](https://cherrycake.tin.cat/version-0.x/reference/core-modules/actions-1/actions). These are the modules that Cherrycake needs to determine what to do next:

![](https://2662762529-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M4n-IY_g0gEMb9S1Gaa-3385184398%2Fuploads%2Fgit-blob-fc1ec66e1664210f965aba46bc8a49465ef66a9d%2FCherrycakeDiagramLifecycle1.svg?alt=media)

Cherrycake now asks the [Actions](https://cherrycake.tin.cat/version-0.x/reference/core-modules/actions-1/actions) module to attend the received request:

![](https://2662762529-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M4n-IY_g0gEMb9S1Gaa-3385184398%2Fuploads%2Fgit-blob-4617628de069a606c946c271eb0b7534a71f1e32%2FCherrycakeDiagramLifecycle2.svg?alt=media)

To do so, [Actions](https://cherrycake.tin.cat/version-0.x/reference/core-modules/actions-1/actions) checks the requested route to see which modules have mapped an action. If it founds a mapped action that matches the current request, loads and runs the module who mapped it.

Let's say the browser requested the home of our website by requesting the `/` route, and that this route has been mapped by a module we called *Home*. Cherrycake loads this module and runs it:

![](https://2662762529-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M4n-IY_g0gEMb9S1Gaa-3385184398%2Fuploads%2Fgit-blob-49d327423ae57d1e47d483892c285f797517bd3b%2FCherrycakeDiagramLifecycle3.svg?alt=media)

*Home* is an app module (as opposed to a core module), and is in charge of showing the home page of the website. To do so, *Home* uses the [Patterns](https://cherrycake.tin.cat/version-0.x/reference/core-modules/patterns) core module to load an HTML file from disk and then send it to the browser. Since the [Patterns](https://cherrycake.tin.cat/version-0.x/architecture/patterns) module has not been loaded yet, Cherrycake loads it automatically:

![](https://2662762529-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M4n-IY_g0gEMb9S1Gaa-3385184398%2Fuploads%2Fgit-blob-a364eeafa509517974cd4679d85cd161f446f592%2FCherrycakeDiagramLifecycle4.svg?alt=media)

Since all output is handled by the [Output](https://cherrycake.tin.cat/version-0.x/reference/core-modules/output) core module, [Patterns](https://cherrycake.tin.cat/version-0.x/reference/core-modules/patterns) reads the requested HTML file and uses [Output](https://cherrycake.tin.cat/version-0.x/reference/core-modules/output) to send back the response to the Browser, and the request lifecycle concludes.

![](https://2662762529-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M4n-IY_g0gEMb9S1Gaa-3385184398%2Fuploads%2Fgit-blob-5e9548e7c8d57c0a89f9bdbfeacb49e36f336a0c%2FCherrycakeDiagramLifecycle5.svg?alt=media)

Now let's take a deeper look at how all this happens with some code, in the [Deep lifecycle](https://cherrycake.tin.cat/version-0.x/architecture/lifecycle/deep-lifecycle) section.
