Skip to content

Commit

Permalink
Merge pull request #36 from expressots/refactor/doc-oct-1
Browse files Browse the repository at this point in the history
feat: review all doc for v2.5
  • Loading branch information
rsaz committed Oct 9, 2023
2 parents 9ddc860 + d9dbb31 commit c7e4340
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 84 deletions.
26 changes: 20 additions & 6 deletions docs/hello.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,39 @@ If you think about it, every programming language feature or framework is built
As a community-driven project, we want you to be part of this journey with us. Your feedback, ideas, and contributions will help us build a better developer experience for everyone.

Thanks for joining us in this challenge. Happy coding! 🚀
Thanks for joining us in this challenge. Happy coding! 🐎

---

## How to Read this Documentation

The documentation is divided into several sections, each one covering a different topic. You can navigate through the documentation using the sidebar on the left side of the page.

- **Overview**: General information about the project resources, concepts, its goals, and how to get started.
- **Code By Example**: A collection of examples that demonstrate how to use the project resources in a more practical way.
- **CLI**: Information about the command-line interface and how to use it.
- **Providers**: Information about the providers and how to use them.
- **Tutorial**: A step-by-step guide explaining how to perform a specific task.
- **Roadmap**: A list of features that are planned for future releases.
- **Governance**: Information about the project governance and how to contribute.

---

## Alert Types

- **[links](./overview/intro.md)**: Bold text denotes a link to other pages of the documentation or external locations.
- `code`: Emphasized code snippets and commands, or key technical terms.
- Alerts: Are used to highlight important information.

:::note Used to express general information
:::note ( note ) Used to express general information
:::
:::tip This is a tip
:::tip ( tip ) This is a tip
:::
:::info Extra information that is not vital
:::info ( info ) Extra information that is not vital
:::
:::caution Used to indicate spoilers
:::caution ( caution ) Used to indicate spoilers
:::
:::warning Used to indicate when something could go wrong
:::warning ( warning ) Used to indicate when something could go wrong
:::

---
Expand Down
73 changes: 49 additions & 24 deletions docs/overview/application.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ ExpressoTS will prevent you from initializing the Application without a controll

The AppExpress class offers a way to create and configure the server, passing **[Express.js middlewares](https://expressjs.com/en/guide/writing-middleware.html)** or other middleware upon server creation.

To create an ExpressoTS application instance, we use the `AppFactory` class, which is responsible for creating the application instance and initializing the container, modules, and controllers. The `create()` function returns an IApplicationExpress which provides a set of methods to configure the server, including the `listen()` method, which starts the server and listens for incoming requests.
To create an ExpressoTS application instance, we use the `AppFactory` class, which is responsible for creating the application instance and initializing the container, modules, and controllers. The `create()` function returns an IApplicationExpress which provides a set of methods to configure the server, including the `listen()` method, which starts the server and listens for incoming requests and `setEngine()`.

### AppExpress Class Definition

Expand All @@ -70,16 +70,17 @@ class AppExpress {
*/
protected serverShutdown(): void {}

public async create(
container: Container,
middlewares: Array<express.RequestHandler> = []
): Promise<ApplicationExpress> {}
public async create() {}

public async listen(
port: number,
environment: ServerEnvironment,
consoleMessage?: IApplicationMessageToConsole
): Promise<void> {}
public async listen() {}
}
```

Also, in the application provider that inherits from AppExpress user can perform conditional logic based on the server environment mechanic provided `isDevelopment()`.

```typescript
if (this.isDevelopment()) {
// your logic here
}
```

Expand Down Expand Up @@ -120,28 +121,22 @@ app.listen(3000, ServerEnvironment.Development, {
The name and version of your app can be configured via either the .env file or package.json file. In the opinionated template, we use the package.json file to retrieve the app name and version.
:::

### Application Server Environment

This is an enum that defines the server environment. Currently supported environments are development and production. Upon server initialization, the underlying framework will look for the NODE_ENV environment variable and set the server environment accordingly. If the NODE_ENV environment variable is not set, the server environment will be set to development by default.
### Server Environment Enum

Also, in the application provider user can perform conditional logic based on the server environment.

```typescript
if (this.isDevelopment()) {
// your logic here
}
```
This is an enum that defines the server environment. Currently supported environments are `development` and `production`. Upon server initialization, the underlying framework will look for the NODE_ENV environment variable and set the server environment accordingly. If the NODE_ENV environment variable is not set, the server environment will be set to development by default.

Here are the enum values available for server environments:

```typescript
ServerEnvironment.Development;
ServerEnvironment.Production;
{
ServerEnvironment.Development;
ServerEnvironment.Production;
}
```

## App Class Provider

The App class provider is the heart of the opinionated template application. It is responsible for initializing the application and provide functionalities to be configured in the server bootstrapping process. You can make use of the built-in middlewares and providers to configure your application.
The App class provider is the heart of the `opinionated template` application. It is responsible for initializing the application and provide functionalities to be configured in the server bootstrapping process. You can make use of the built-in middlewares and providers to configure your application.

```typescript
class App extends AppExpress {
Expand Down Expand Up @@ -169,7 +164,37 @@ class App extends AppExpress {
}
```

The App class provider offers a set of out-of-the-box middlewares and providers that can be used to configure your application. Explore the `IMiddleware` and `IProvider` interfaces to see what is available.
The App class provider offers a set of out-of-the-box middlewares and providers that can be used to configure your application. Here is a list of the available middlewares and providers:

### Middlewares

Here are some of the middlewares available:

| Middleware Name | Description |
| ---------------- | ------------------------------------------------- |
| addBodyParser | Add body parser middleware to the application. |
| addCompression | Add compression middleware to the application. |
| addCors | Add cors middleware to the application. |
| addHelmet | Add helmet middleware to the application. |
| addCookieParser | Add cookie parser middleware to the application. |
| addCookieSession | Add cookie session middleware to the application. |
| addSession | Add session middleware to the application. |
| addServerStatic | Add static middleware to the application. |
| addRateLimit | Add rate limit middleware to the application. |
| addMorgan | Add morgan middleware to the application. |
| addPassport | Add passport middleware to the application. |
| setMulter | Add multer middleware to the application. |
| addServeFavicon | Add serve favicon middleware to the application. |
| setErrorHandler | Add error handler middleware to the application. |

### Providers

Here are some of the providers available:

| Provider Name | Description |
| ------------- | ----------------------------------- |
| envValidator | Validate the environment variables. |
| logger | Add logger to the application. |

## App Class Lifecycle Hooks

Expand Down
82 changes: 34 additions & 48 deletions docs/overview/first-steps.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ In this section, you will delve into the core concepts of ExpressoTS to familiar

## The technology

We believe in the power of strongly typed languages, and **[TypeScript](https://www.typescriptlang.org/)** is essential when it comes to structuring or building large-scale applications in **[NodeJS](https://nodejs.org/)**. In the following example we will mostly use TypeScript, and here are the reasons why we use TypeScript:
We believe in the power of strongly typed languages, and **[TypeScript](https://www.typescriptlang.org/)** is essential when it comes to structuring or building large-scale applications in **[NodeJS](https://nodejs.org/)**. In the following example we will mostly use TypeScript.

## Why TypeScript?

- Improved code quality: Strong typing helps to catch errors and bugs at compile time, rather than at runtime, which helps to improve the overall quality of the code. This can lead to fewer crashes and issues with the code in production.

Expand Down Expand Up @@ -199,37 +201,43 @@ To bootstrap an ExpressoTS application, there are two ways:

- Non-opinionated template using the AppFactory to creates an instance of the default ExpressoTS adapter which is the Express.js. User can directly pass an array of middleware to the `AppFactory.create` method, which will be responsible for creating an Expressjs application with the provided middleware. This method of creating an ExpressoTS application exposes the Expressjs application instance, which can be used to add additional middleware or to configure the Expressjs application.

```typescript
async function bootstrap() {
const app = await AppFactory.create(container, [cors(), helmet()]);
await app.listen(3000, ServerEnvironment.Development);
}

bootstrap();
```

- Opinionated template using the AppFactory to create an AppExpress application. By using the App (AppExpress) class, you can take advantage of its built-in mechanisms for controlling the **[application life cycle hooks](application.md#application-lifecycle-hooks)**, such as injecting and executing services before, after, and during application shutdown.

```typescript
async function bootstrap() {
const app = await AppFactory.create(container, App);
await app.listen(3000, ServerEnvironment.Development);
}

bootstrap();
```

## The container

In ExpressoTS, creating an application server to listen to inbound HTTP requests is not enough. The framework requires the creation of a container that organizes all application modules into a cohesive unit. Typically, this container is created in the `app.container.ts` file. The container is responsible for managing the application's dependencies. Read more about the `app.container` in the **[App Container](app-container.md)** section.

### Application uses the container

After the container is created in the `app.container` file, the application can be created by passing the container as a parameter to the `AppFactory.create(container)` method.
After the container is created in the `app.container` file, the application can be created by passing the container as a parameter to the `AppFactory.create` method:

```typescript
AppFactory.create(container);
```

### Injecting modules in the container

Once the container is created, modules can be injected into the application. These modules are the building blocks of an ExpressoTS application and are responsible for organizing the application's business logic into layers, as a module is a group of functionalities or endpoints also called `controllers`.
Read more about the modules in the **[Modules](module.md)** section.

### Injecting controllers in the modules

The controller layer handles incoming requests and returns appropriate responses, they are the entry point of the application for each endpoint. Read more about the controllers in the **[Controllers](controller.md)** section. In order to make a controller functional, it must be injected into a module. This can be done by passing the controller as a parameter to the `CreateModule` method.

### Fully hooked-up application flow

After creating a module, the module can be added in the container, and after creating controllers, controllers can be injected into the module, resulting in a fully hooked-up application flow. The following code snippet demonstrates this process:

#### Application creation

```typescript
const app = await AppFactory.create(container);
```

#### Module injection

```typescript
const appContainer = new AppContainer();

Expand All @@ -239,15 +247,21 @@ const container: Container = appContainer.create([
]);
```

#### Controller injection
### Injecting controllers in the modules

The controller layer handles incoming requests and returns appropriate responses, they are the entry point of the application for each endpoint. Read more about the controllers in the **[Controllers](controller.md)** section. In order to make a controller functional, it must be injected into a module. This can be done by passing the controller as a parameter to any module. As an example, the following code snippet demonstrates how to inject a controller into AppModule:

```typescript
const appModule: ContainerModule = CreateModule([
const AppModule: ContainerModule = CreateModule([
// Add your controllers here
AppController,
]);
```

### Fully hooked-up application flow

After creating a module, the module can be added in the container, and after creating controllers, controllers can be injected into the module, resulting in a fully hooked-up application flow.

:::info
It is worth noting that a project created with the ExpressoTS CLI comes with an initial project structure that promotes adherence to a specific convention set by the framework. This ensures that each module has its own dedicated directory, helping developers maintain consistency throughout their codebase.
:::
Expand Down Expand Up @@ -278,34 +292,6 @@ npm run prod
Once the application is up and running, you can access it by navigating to `http://localhost:3000/`.
:::

## Deprecated features

:::warning Deprecation warning
The following features are valid until version `1.9.0` as they were deprecated in favor of the new `@expressots/core` package version `2.0.0`.
:::

### Opinionated Application Bootstrap (deprecated)

```typescript
// Using opinionated start project where App extends @expressots/core Application class
async function bootstrap() {
const app = App.create(container);
app.listen(3000, ServerEnvironment.Production);
}
```

### Non opinionated Application Bootstrap (deprecated)

```typescript
// Using the non-opinionated starter project where AppInstance is an instance of the Application class from @expressots/core
async function bootstrap() {
const app = AppInstance.create(container);
app.listen(3000, ServerEnvironment.Development);
}

bootstrap();
```

## Note

ExpressoTS is a versatile framework that is not bound to any specific platform or technology. Leveraging popular Node.js libraries like InversifyJS and Express.js, it is designed to be lightweight, modular, customizable, and easy to use. Developers can expand the framework's capabilities by creating new providers that can be incorporated into their applications.
Expand Down
12 changes: 6 additions & 6 deletions docs/overview/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ The framework provides a level of abstraction on top of a common HTTP server fra

## Philosophy

ExpressoTS is a developer-friendly framework designed to streamline the process of building server-side applications. With a focus on readability, maintainability, and scalability, ExpressoTS aims to simplify the development process by providing a clear and concise structure.
ExpressoTS is a developer-friendly framework designed to streamline the process of building server-side applications. It aims to simplify the development process by providing a clear and concise structure.

Gone are the days of tedious setup tasks such as configuring logging systems, handling authentication, and connecting to databases. With ExpressoTS, developers can focus on what really matters - writing code. The framework takes care of the repetitive and time-consuming aspects of development, allowing developers to work more efficiently.
With ExpressoTS, developers can focus on what really matters - writing code. The framework takes care of the repetitive and time-consuming aspects of development, allowing developers to work more efficiently.

One of the key features of ExpressoTS is its flexible and extensible architecture. The framework provides a robust **[Dependency Injection](di.md)** system that enables developers to extend its functionality by creating and adding providers with their specific binding scope such as `Transient, Scoped, Singleton`. This allows developers to integrate new features throughout the application without having to worry about the complexities of integration and coupling.

Expand All @@ -27,24 +27,24 @@ npm i -g @expressots/cli

## Creating a New Project

To create a project using the CLI, run the following commands. The CLI will prompt you with a few questions and then create a new project directory with the name you provide, along with the @expressots/core package and a starter project structure.
To create a project using the CLI, run the following commands.

```bash
expressots new <project-name>
```

Or you can create projects without the CLI questions by passing the template name (`opinionated` or `non-opinionated`) and the package manager (`npm`, `yarn` or `pnpm`) as arguments.
The CLI will prompt you with a few questions and then create a new project directory with the name you provide, along with the @expressots/core package and a starter project structure. Or you can create projects without the CLI questions by passing the template name (`opinionated` or `non-opinionated`) and the package manager (`npm`, `yarn` or `pnpm`) as arguments.

```bash
expressots new <project-name> -t <template-name> -p <package-manager>
```

:::tip
## Project Types or Templates

ExpressoTS offers two starter project templates: `opinionated` and `non-opinionated`.

- Use the `non-opinionated` starter project template when you need flexibility on your project structure.
- Choose the `opinionated` starter project template for more complex projects with a complete starting point.
:::

### Accessing Your Project

Expand Down

0 comments on commit c7e4340

Please sign in to comment.