This tutorial focuses on implementing the backend of your capstone project.
You'll set up your project structure, create routing and controllers,
implement service layer logic, add error handling and validation, and
configure Docker for containerisation. By the end, you'll have a fully
functional backend API.
Why this matters:
The backend is the heart of your application. A well‑structured API with
robust error handling is essential for a production‑ready system.
1. Project Setup
Start by initialising your backend project. The structure depends on your
chosen framework, but the principles are the same.
Write a global exception filter that formats all error responses
consistently with a timestamp and path field.
Sample answer
@Catch()
export class AllExceptionsFilter implements ExceptionFilter {
catch(exception: unknown, host: ArgumentsHost) {
const ctx = host.switchToHttp();
const response = ctx.getResponse();
const request = ctx.getRequest();
let status = 500;
let message = 'Internal server error';
if (exception instanceof HttpException) {
status = exception.getStatus();
message = exception.message;
}
response.status(status).json({
statusCode: status,
timestamp: new Date().toISOString(),
path: request.url,
message
});
}
}
Homework
Homework 1
Implement the complete backend API for your capstone project. Include all
CRUD endpoints, validation DTOs, error handling, and Docker configuration.
Sample outline
Setup: Initialize your backend project.
Endpoints: All CRUD endpoints for each resource.
DTOs: Create and update DTOs with validation.
Services: Business logic with error handling.
Docker: Dockerfile and docker-compose.yml.
Mini‑Project
Backend Development Sprint
Implement the backend for your capstone project:
Set up your project structure
Implement all CRUD endpoints for your main entity
Add validation DTOs
Implement global error handling
Configure Docker for the backend
Write tests for your endpoints
Sample outline
Project: Create a new backend project
Database: Set up PostgreSQL with Prisma or TypeORM
Endpoints: Implement all endpoints for your main resource
Testing: Write unit and integration tests
Docker: Containerise the application
Tutorial Summary
You implemented a complete backend API for your capstone project. You
learned how to structure your project, create controllers and services,
handle errors and validation, and containerise with Docker. Your backend
is now ready to be connected to the frontend.
Key takeaway: A well‑structured backend with proper
error handling and validation is essential for a production‑ready
application. Invest time in getting these fundamentals right.