# 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-1.x-beta/reference/core-modules/output), [Errors](https://cherrycake.tin.cat/version-1.x-beta/reference/core-modules/errors) and [Actions](https://cherrycake.tin.cat/version-1.x-beta/reference/core-modules/actions-1/actions). These are the modules that Cherrycake needs to determine what to do next:

![](https://870459776-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4n-IY_g0gEMb9S1Gaa%2F-M4t4Y56_r9y4MudgPt3%2F-M4tFkH9Hx4qJrI-UTnc%2FCherrycakeDiagramLifecycle1.svg?alt=media\&token=53ddf827-7d05-4486-b16a-632a717e9374)

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

![](https://870459776-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4n-IY_g0gEMb9S1Gaa%2F-M4t4Y56_r9y4MudgPt3%2F-M4tFmqfDblyjsG0DiYA%2FCherrycakeDiagramLifecycle2.svg?alt=media\&token=03a6e54d-5cd4-49dc-82cf-150b5cab8e67)

To do so, [Actions](https://cherrycake.tin.cat/version-1.x-beta/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://870459776-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4n-IY_g0gEMb9S1Gaa%2F-M4t4Y56_r9y4MudgPt3%2F-M4tFpKC9HXSFJxnqbyy%2FCherrycakeDiagramLifecycle3.svg?alt=media\&token=4e52fee8-10f9-4aed-a470-b424c5de4455)

*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-1.x-beta/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-1.x-beta/architecture/patterns) module has not been loaded yet, Cherrycake loads it automatically:

![](https://870459776-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4n-IY_g0gEMb9S1Gaa%2F-M4t4Y56_r9y4MudgPt3%2F-M4tFsUD3O4DOko20OEU%2FCherrycakeDiagramLifecycle4.svg?alt=media\&token=aef02414-eac5-432f-951f-fdc92112c79a)

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

![](https://870459776-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4n-IY_g0gEMb9S1Gaa%2F-M4tG-3UgDxJxaD9aMd_%2F-M4tGJeQo1neqRGv84KB%2FCherrycakeDiagramLifecycle5.svg?alt=media\&token=aef38325-0800-4a76-b886-c8f32913cfcb)

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