Skip to content

Commit

Permalink
Merge pull request #225 from AthennaIO/develop
Browse files Browse the repository at this point in the history
Athenna V5
  • Loading branch information
jlenon7 committed Sep 1, 2024
2 parents 5322f27 + f858683 commit f5ddbdf
Show file tree
Hide file tree
Showing 48 changed files with 3,580 additions and 1,831 deletions.
25 changes: 13 additions & 12 deletions docs/architecture-concepts/application-lifecycle.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ sidebar_position: 1
description: Understand each one of the Athenna applications lifecycles.
---

import Path from '@site/src/components/path'
import ThemedImage from '@theme/ThemedImage'

# Application Lifecycle
Expand Down Expand Up @@ -32,7 +33,7 @@ application you are using. Meaning that no matter what is the type of
application you are using to build your solution, the explanation bellow
is valid for all of them.

The entry point of an Athenna application is the `Path.bootstrap('main.ts')`.
The entry point of an Athenna application is the <Path father="bin" child="main.ts" />.
The first action taken by Athenna itself is to create an instance of the
application and then boot it.

Expand Down Expand Up @@ -78,7 +79,7 @@ configuration documentation section](/docs/getting-started/configuration#environ
#### Configuration files

Afterwards Athenna will load all the configuration files found inside
the path returned by the `Path.config` method. You can learn more about
the path returned by the <Path father="config" /> method. You can learn more about
what is and how to configure your configuration files in
[the configuration files documentation section](/docs/getting-started/configuration#configuration-files).

Expand Down Expand Up @@ -115,7 +116,7 @@ in the `.athennarc.json` in the `preloads` array.
:::note

The process of firing the Athenna foundation is triggered by the
`Ignite::fire()` static method. But if you check your `Path.bootstrap('main.ts')`
`Ignite::fire()` static method. But if you check your <Path father="bin" child="main.ts" />
entrypoint file, you will see that this method is not called directly.
The reason for this is that this method is called internally depending
on the type of application you are using. Let's cover some examples
Expand All @@ -138,7 +139,7 @@ the foundation will be fired before executing your command.
### Kernel

The Kernel class is responsible by defining some bootstraps that will
be run before reading your `Path.routes('http.ts')` file. These bootstraps
be run before reading your <Path father="routes" child="http.ts" /> file. These bootstraps
configure error handling for requests, tracing and logging, detect the
application environment, and perform other tasks that need to be done
before the request is actually handled. Typically, these classes handle
Expand Down Expand Up @@ -166,27 +167,27 @@ implementation code.

:::

Then, you can register your `CustomKernel` in your `Path.bootstrap('main.ts')`
Then, you can register your `CustomKernel` in your <Path father="bin" child="main.ts" />
file:

```typescript
import { Ignite } from '@athenna/core'

const ignite = await new Ignite().load(import.meta.url)

await ignite.httpServer({ kernelPath: '#app/http/CustomKernel' })
await ignite.httpServer({ kernelPath: '#src/http/CustomKernel' })
```

### Routes

The `Path.routes('http.ts')` file is the entrypoint for all your http requests.
The <Path father="routes" child="http.ts" /> file is the entrypoint for all your http requests.
This file is responsible to create a contract between your client and
your application. It Is in here that we define all our routes and the
handlers/controllers who will handle the client request.

One of the most important service providers in your application is the
`HttpRouteProvider`. This service provider adds in the container the
`Route` class instance used inside `Path.routes('http.ts')` file.
`Route` class instance used inside <Path father="routes" child="http.ts" /> file.

When the client request arrives, the server first executes all your
global middlewares, then it will execute all your route middlewares.
Expand Down Expand Up @@ -274,7 +275,7 @@ kernel implementation taking a look at [ConsoleKernel](https://github.com/Athenn
:::

Then, you can register your `CustomKernel` in your
`Path.bootstrap('main.ts')` or `Path.bootstrap('artisan.ts')` file:
<Path father="bin" child="main.ts" /> or <Path father="bin" child="artisan.ts" /> file:

```typescript
import { Ignite } from '@athenna/core'
Expand All @@ -284,13 +285,13 @@ const ignite = await new Ignite().load(import.meta.url, {
})

await ignite.console(process.argv, {
kernelPath: '#app/http/CustomKernel'
kernelPath: '#src/http/CustomKernel'
})
```

### Execution

The `Path.routes('console.ts')` and the `commands` property of
The <Path father="routes" child="console.ts" /> and the `commands` property of
`.athennarc.json` file is where that we define all ours commands
and the handlers who will handle the terminal arguments.

Expand All @@ -302,7 +303,7 @@ executed the `hello` command defined in our `.athennarc.json` file:
{
"commands": {
"hello": {
"path": "#app/console/commands/HelloCommand",
"path": "#src/console/commands/HelloCommand",
"env": "local",
"loadApp": false,
"stayAlive": false,
Expand Down
8 changes: 4 additions & 4 deletions docs/architecture-concepts/facades.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ node artisan make:provider HelperProvider
Now let's register all of our helpers inside the `register()` method:

```typescript
import { File } from '#app/helpers/File'
import { String } from '#app/helpers/String'
import { File } from '#src/helpers/File'
import { String } from '#src/helpers/String'
import { ServiceProvider } from '@athenna/ioc'

export class HelperProvider extends ServiceProvider {
Expand Down Expand Up @@ -172,7 +172,7 @@ generic type:

```typescript
import { Facade } from '@athenna/ioc'
import { String as StringImpl } from '#app/helpers/String'
import { String as StringImpl } from '#src/helpers/String'

export const String = Facade.createFor<StringImpl>('App/Helpers/String')
```
Expand All @@ -181,7 +181,7 @@ Now we can start using our new `String` facade:

```typescript
import { Route } from '@athenna/http' // Route Facade
import { String } from '#providers/facades/String' // String Facade
import { String } from '#src/facades/String' // String Facade
Route.get('/welcome', ({ response }) => {
return response
Expand Down
26 changes: 14 additions & 12 deletions docs/architecture-concepts/service-container.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ sidebar_position: 2
description: Understand the purpose and how to use the Athenna service container.
---

import Path from '@site/src/components/path'

# Service Container

Understand the purpose and how to use the Athenna service container.
Expand All @@ -19,7 +21,7 @@ Let's look at a simple example:

```typescript
import { Controller, type Context } from '@athenna/http'
import { WelcomeService } from '#app/services/WelcomeService'
import { WelcomeService } from '#src/services/WelcomeService'

@Controller()
export class WelcomeController {
Expand Down Expand Up @@ -50,7 +52,7 @@ itself.

## Simple resolution

You may place the following code in your `Path.routes('http.ts')`
You may place the following code in your <Path father="routes" child="http.ts" />
file:

```typescript
Expand Down Expand Up @@ -108,7 +110,7 @@ the container to write this code, it is managing the injection of their
dependencies behind the scenes.

```typescript
import { AppService } from '#app/services/AppService'
import { AppService } from '#src/services/AppService'
import { Controller, type Context } from '@athenna/http'

@Controller()
Expand Down Expand Up @@ -142,7 +144,7 @@ global property. We can register a binding using the `bind` method, passing the
alias name that we wish to register along with our dependency:

```typescript
import { StringNormalizer } from '#app/helpers/StringNormalizer'
import { StringNormalizer } from '#src/helpers/StringNormalizer'

ioc.bind('App/Helpers/StringNormalizer', StringNormalizer)
```
Expand All @@ -155,7 +157,7 @@ resolved, a new object instance will be returned on subsequent calls into the
container:

```typescript
import { StringNormalizer } from '#app/helpers/StringNormalizer'
import { StringNormalizer } from '#src/helpers/StringNormalizer'

ioc.transient('App/Helpers/StringNormalizer', StringNormalizer)
```
Expand All @@ -174,7 +176,7 @@ resolved one time. Once a singleton binding is resolved, the same object
instance will be returned on subsequent calls into the container:

```typescript
import { StringNormalizer } from '#app/helpers/StringNormalizer'
import { StringNormalizer } from '#src/helpers/StringNormalizer'

ioc.singleton('App/Helpers/StringNormalizer', StringNormalizer)
```
Expand All @@ -186,7 +188,7 @@ You may also bind an existing object instance into the container using the
calls into the container:

```typescript
import { StringNormalizer } from '#app/helpers/StringNormalizer'
import { StringNormalizer } from '#src/helpers/StringNormalizer'

ioc.instance('App/Helpers/StringNormalizer', new StringNormalizer())
```
Expand All @@ -204,7 +206,7 @@ Let's create a simple service to understand how this annotation works:
node artisan make:service StringNormalizer
```

The command above will create the `Path.services('StringNormalizer.ts')`
The command above will create the <Path father="services" child="StringNormalizer.ts" />
file and will automatically register the service in the `services` property
of the `.athennarc.json` file.

Expand Down Expand Up @@ -254,7 +256,7 @@ resolve a class instance from the container. The use method accepts the alias
of the dependency you wish to resolve:

```typescript
import { StringNormalizer } from '#app/helpers/StringNormalizer'
import { StringNormalizer } from '#src/helpers/StringNormalizer'

const sn = ioc.use<StringNormalizer>('App/Helpers/StringNormalizer')
```
Expand All @@ -275,7 +277,7 @@ constructor. The service will automatically be resolved and injected into the
class:

```typescript
import { AppService } from '#app/services/AppService'
import { AppService } from '#src/services/AppService'
import { Controller, type Context } from '@athenna/http'

@Controller()
Expand All @@ -298,7 +300,7 @@ camelCase name of your dependency as the property name to be resolved properly:

```typescript
import { Inject } from '@athenna/ioc'
import { AppService } from '#app/services/AppService'
import { AppService } from '#src/services/AppService'
import { Controller, type Context } from '@athenna/http'

@Controller()
Expand All @@ -319,7 +321,7 @@ specific alias to be resolved in the container:

```typescript
import { Inject } from '@athenna/ioc'
import { AppService } from '#app/services/AppService'
import { AppService } from '#src/services/AppService'
import { Controller, type Context } from '@athenna/http'

@Controller()
Expand Down
11 changes: 7 additions & 4 deletions docs/architecture-concepts/service-providers.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ sidebar_position: 3
description: Understand the purpose and how to use the Athenna service providers.
---

import Path from '@site/src/components/path'

# Service Providers

Understand the purpose and how to use the Athenna service providers.
Expand Down Expand Up @@ -60,7 +62,7 @@ which provides access to the service container:

```typescript
import { ServiceProvider } from '@athenna/ioc'
import { AppHelper } from '#app/helpers/AppHelper'
import { AppHelper } from '#src/helpers/AppHelper'

export default class AppProvider extends ServiceProvider {
public register() {
Expand All @@ -83,7 +85,7 @@ the framework:

```typescript
import { ServiceProvider } from '@athenna/ioc'
import { AppHelper } from '#app/helpers/AppHelper'
import { AppHelper } from '#src/helpers/AppHelper'

export default class AppProvider extends ServiceProvider {
public boot() {
Expand Down Expand Up @@ -135,7 +137,7 @@ might need to register it manually, just add the path to it to the array:
"providers": [
// Other service providers...

"#providers/AppProvider"
"#src/providers/AppProvider"
]
}
```
Expand Down Expand Up @@ -169,8 +171,9 @@ The following environments are available by default in Athenna at this moment:
- http
- repl
- console
- cron

You could also create your own environments. In your `Path.bootstrap('main.ts')` file
You could also create your own environments. In your <Path father="bin" child="main.ts" /> file
you can add an `environments` option when calling `Ignite.load()` method:

```typescript
Expand Down
Loading

0 comments on commit f5ddbdf

Please sign in to comment.