Open kucherenko opened 1 year ago
feature-7-blog-backend
Implement task #7 - Make backend for the blog.
To develop a secure web app backend for the blog, I have chosen to use Nest.js, a powerful and scalable framework that follows the principles of modular design and dependency injection. Nest.js provides a solid foundation for building robust and secure applications.
For the database, I decided to use SQLite, a lightweight and file-based database system that is easy to set up and works well for small to medium-sized applications. It offers good performance and is suitable for the needs of the blog backend.
To interact with the database, I selected TypeORM, an Object-Relational Mapping (ORM) library that simplifies database access and provides a clear and intuitive syntax for performing CRUD operations. TypeORM abstracts the underlying database and ensures data integrity and security.
For API documentation and testing, I opted for Swagger, an open-source software framework that helps generate interactive API documentation. Swagger makes it easier for developers to work with the API and allows for easy testing of endpoints before integration into client applications.
Here is the list of files and their content:
backend/app.module.ts
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
@Module({
imports: [],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
backend/app.controller.ts
import { Controller, Get } from '@nestjs/common';
import { AppService } from './app.service';
@Controller()
export class AppController {
constructor(private readonly appService: AppService) {}
@Get()
getHello(): string {
return this.appService.getHello();
}
}
backend/app.service.ts
import { Injectable } from '@nestjs/common';
@Injectable()
export class AppService {
getHello(): string {
return 'Hello World!';
}
}
backend/main.ts
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
await app.listen(3000);
}
bootstrap();
backend/package.json
{
"name": "blog-backend",
"version": "1.0.0",
"description": "Backend for the blog",
"scripts": {
"start": "node dist/main.js"
},
"dependencies": {
"@nestjs/common": "latest",
"@nestjs/core": "latest",
"reflect-metadata": "latest",
"rxjs": "latest",
"typeorm": "latest"
},
"devDependencies": {
"@nestjs/cli": "latest",
"@types/node": "latest",
"sqlite3": "latest",
"swagger-ui-express": "latest",
"ts-node": "latest",
"typescript": "latest"
}
}
backend/tsconfig.json
{
"compilerOptions": {
"target": "es2015",
"module": "commonjs",
"declaration": true,
"removeComments": true,
"strictPropertyInitialization": false,
"esModuleInterop": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true
}
}
backend/swagger.ts
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
import { AppModule } from './app.module';
import { INestApplication } from '@nestjs/common';
export const setupSwagger = (app: INestApplication) => {
const options = new DocumentBuilder()
.setTitle('Blog Backend API')
.setDescription('API documentation for the blog backend')
.setVersion('1.0.0')
.build();
const document = SwaggerModule.createDocument(app, options);
SwaggerModule.setup('api', app, document);
};
decompose:
To implement the backend for the blog using Nest.js, SQLite database, TypeORM, and Swagger, I suggest the following technical subtasks:
estimate:
Make estimation like junior developer
Considering the given requirements, I estimate the task size as M (Medium).
The task involves setting up a new Nest.js application for a blog backend. Here are the reasons why I consider the task to be of medium size:
Setting up Nest.js: Setting up a new Nest.js application requires initializing a project, installing dependencies, and configuring the basic folder structure. This initial setup may take some time, but it is relatively straightforward and can be achieved using the Nest CLI. This step adds moderate complexity to the task.
Integrating SQLite Database: The requirement specifies the use of SQLite as the database. Integrating SQLite with Nest.js involves installing the necessary dependencies, configuring the database connection, creating entities, and setting up migrations. While SQLite is relatively easy to set up, some additional effort is required for database-related configuration and migrations. This adds moderate complexity to the task.
Using TypeORM: TypeORM is a powerful Object Relational Mapping (ORM) library compatible with Nest.js. Integrating TypeORM requires installing the library, configuring the connection, defining entities, and writing queries. This step adds complexity to the task but provides benefits like easier database management and query abstraction.
Swagger Integration: The requirement also specifies the integration of Swagger, which provides an interface for documenting and testing APIs. Integrating Swagger requires installing the swagger module, configuring it with the Nest.js application, and writing API documentation. While this step is not highly complex, it adds some additional work to the task.
Considering the overall integration and configuration required for setting up the Nest.js backend with SQLite, TypeORM, and Swagger, I believe the task falls into the medium size category (M).
restart:
Restarted tasks: estimate
For the given task of creating a backend for a blog using Nest.js, SQLite database, TypeORM, and Swagger, I would estimate the task size as M (Medium).
Create
backend/
directory with files to start a new nest.js application. The backend should use SQLite database, use Typeorm, and swagger.