# App Directories

# Introduction

The Expresswebjs directory structure may feel overwhelming at first glance since there are a handful of pre-configured directories.

Gradually you’ll understand the benefit of separating your entities into multiple directories, keeping your code maintainable and easy to search.

A standard Expresswebjs installation looks something like so:


📁 App/
        📁 Console/
        📁 Http/
        📁 Model/
        📁 Events/
        📁 Listeners/
        📁 Exceptions/
        📁 Providers/  
        📁 Repository/
        📁 Service/
📁 Command/
📁 Config/
        📘 app.ts
        📘 auth.ts
        📘 bodyParser.ts
        📘 cors.ts
        📘 database.ts
        📘 filesystems.ts
        📘 hashing.ts
        📘 logging.ts
        📘 queue.ts
        📘 socket.ts
📁 Database/
        📁 Migrations
        📁 Seeds
📁 Logs/
        🔖 systemLog.log
📁 Routes/
        📘 api.ts
        📘 sockets.ts
📁 Storage/
📁 Utils/
📘 app.ts
⚙️ .env
📘 maker.ts

The app directory is the home of your application logic. Inside the app directory, you will see other directories that make up your application.

# App/Console

The Console directory contains all of the custom Maker commands for your application. These commands may be generated using the make-command command. This directory also houses your console kernel, which is where your custom Maker commands are registered and your scheduled tasks are defined.

# App/Http

The Http directory contains your controllers, middleware, and validations. All of the logic to handle requests entering your application will be placed in this directory.

# App/Events

The Events directory is used to store your application events classes .This directory does not exist by default, but will be created for you by the make-event followed by event name.Events may be used to alert other parts of your application that a given action has occurred, providing a great deal of flexibility and decoupling.

 ts-node maker make-event [EVENT_NAME]

# App/Listeners

The Listeners directory contains the classes that handle your events.This directory does not exist by default, but will be created for you by the make-listener [ListerName] maker command. Event listeners receive an event name and maybe a params and perform logic in response to the event being fired.

ts-node maker make-listener [LISTENER_NAME]

# App/Model

The Models directory contains all of your database model class. Each database table has a corresponding "Model" which is used to interact with that table. Models allow you to query for data in your tables, as well as insert new records into the table. To create a NoSql model, use the maker command make-nosql-model [ModelName] where [ModelName] will be the name of your model. The same goes for SQL models make-sql-model [ModelName]. To generate Sql model with migration, you can add the -m flag like so make-sql-model [ModelName] -m

   ts-node maker make-nosql-model [MODEL_NAME]

OR

ts-node maker make-sql-model [MODEL_NAME][-m]

where –m or –migration is for creating a migration file with make-sql-model

Expresswebjs provides a beautiful, simple ActiveRecord implementation for working with your sql database. Each database table has a corresponding “Model” which is used to interact with that table. Models allow you to query for data in your tables, as well as insert new records into the table.

Before getting started, be sure to configure a database connection in .env file.

# App/Providers

The Providers directory contains the AppServiceProvider.js file and RouteServiceProvider.js for your application. AppServiceProvider.js file bootstrap your application by binding services in the service container. You are free to add your own services into the service container.

# App/Exceptions

The Exceptions directory contains your application's exception handler and is also a good place to place any exceptions thrown by your application. If you would like to customize how your exceptions are logged or rendered, you should modify the Handler class in this directory.

# App/Repository

The Repository directory contains your application's repository files and its a good place to write your data queries.

# App/Service

The Service directory contains your application's service files and its a good place to write your services.

# Config

The config directory is used to define the configuration of your application. Expresswebjs ships with a number of config files. It will be nice to familiarize yourself with all of the options available to you.

# Database

The database directory contains your database migrations and seeds for SQL database.

# Routing

The routes directory contains all of the route definitions for your application. Several route files are included By default to ExpressWebJs: api.js and socket.js