# App Directories
# Directory Structure
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:
The app directory is the home of your application logic. Inside the app directory, you will see other directories that make up your application.
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.
The Http directory contains your controllers, middleware, and form requests. Almost all of the logic to handle requests entering your application will be placed in this directory.
The app/Http/Controller directory is used to store all your Http and WebSocket controllers. You can create your controller by using the commands below, depending on the type of controller you wan't.
ts-node maker make-controller [CONTROLLER_NAME][-r]
for websocket controller:
ts-node maker make-ws-controller [CONTROLLER_NAME]
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]
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]
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]
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.
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.
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.
The database directory contains your database migrations and seeds for SQL database.
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