Backend Application and its folder structure

priya s
YavarTechWorks
Published in
3 min readOct 29, 2022

Hi everyone, in this post, we are going to learn about what is backend application and its folder structure.

Backend Application:

A back-end application supports front-end user services and interfaces with any required resources. This may interact directly with the front end or it may be called from an intermediate program that mediates front-end and back-end activities.

The back end also known as the server side, consists of the server which provides data on request, the application that channels it, and the database which organizes the information.

API: It is a software intermediary that allows two applications to talk to each other.

Backend Application Folder Structure:

Below is the sample folder structure for the library todo application.

Index.js:

This index.js typically handles the app startup, routing, and other functions of the application.

.env:

The dotenv package is used for handling environment variables. These variables can be customized.

Package.json:

The package.json file is the heart of any Node project. It records important metadata about a project which is required before publishing to NPM and also it defines functional attributes of a project that npm uses to install dependencies, run scripts, and identify the entry point to the package.

Package-lock.json:

This is created for locking the dependency with the installed version.

Nodemon.json

It supports local and global configuration files. The file can be used to add some extra configurations to our application to allow us to monitor multiple directories, ignore files, and delay restarting amongst others.

.sequelizerc:

This is a special configuration file. This will provide a path to the config file.

Config.json:

This is the main configuration file and contains all your default environment variables.

Controllers:

The controllers are responsible for handling incoming requests and returning responses to the client. Its main purpose is to receive specific requests for the application.

For the library todo application, it can have book.controller.js, user.controller.js, and session.controller.js.

Services:

The services handle all the logic between the incoming request and returning the response. In the library todo API, the services handle the add, update, list, and deletion logic and send it to the returning response.

Exceptions:

It handles the exception errors that arise in the application. For example, session timeout errors.

Hooks:

A hook allows the programmer to insert customized programming. This allows you to listen to specific events in the application or request/response lifecycle. For example, token authentication can be done here using a prehandler. The prehandler is a hook in fastify which in invoked by any incoming request.

Models:

The models are used to communicate with the database. It is an intermediary between the database and the controllers.

Routes:

It has the call route methods and the controller to execute when it is called. It has

  1. private routes
  2. public routes.

In the public routes, anyone can access it. It does not require any authorization. But in the case of private routes, it requires authorization to visit a particular route (for example to read or update the user details).

Types:

It defines the type of the payload, request, and response parameters.

Policies:

Policies are designed to let you add common types of management capabilities to an API easily and reliably. It provides security. In this example todo application, only an admin has permission to access the books table like add, update, and delete the data from the table. The user is not allowed to access the table.

Db :

This folder defines the structures of the tables with the column names and their datatypes. It has two sub-folders.

  1. Migrations — Migrating databases automatically syncing databases in all of the environments.
  2. Seeders — Seeding a database is a process in which an initial set of data is provided to a database when it is being installed.

Thank You! Hope you find it useful.

--

--