Skip to content

Core Backend Server

Allen Shibu edited this page Sep 27, 2023 · 1 revision

Overview

The backend for the application is an express server written in TypeScript. The code for the backend server is available in the apps/core folder.

We tried to apply some concepts from the controller service pattern just enough to make the codebase manageable, but not too much to take away the ease of coding in JavaScript/TypeScript.

All the files have a ..ts where layer refers to the whether the file is a controller, service, etc.

Folder Structure

src

Contains the source files

controllers

Contains all the controllers that accept the HTTP requests and forward them to the appropriate services.

middlewares

Contains all the middleware which sits in between the HTTP requests and services.

routes

Contains the configuration for all the route configurations. This folder acts as API documentation for the time being.

services

Contains all the services file which contains the business logic of the application.

test

Contains test files written using Mocha and Chai.

Architecture

The backend code is split mainly into two layers - controllers and services. Each entity/function gets its own file in each layer.

Controllers

Controllers act as the bridge between the HTTP request and the service layer. This layer makes sure that the user is authenticated, all the required request parameters are present and sends appropriate responses. This layer then calls the service layer which does its job and sends its output which the controller layer sends back as an HTTP response.

Services

Services are the business layer of the application. This layer does all the computations. The service layer also accesses the database right now, but we plan to introduce a repository layer in the future to further decouple the data access layer from the service layer. The service layer is not concerned with the details of the HTTP requests and solely focuses on the business logic. The controller layer must make sure that it calls the correct service functions and that all the function parameters that it forwards from the HTTP requests are valid.