Real Backend Projects
Apply OOP + DI to build scalable NestJS backends end to end.
30 minLevel 20 of 20
Project blueprint
Every Nest backend project in this academy follows the same OOP+DI spine:
1. Define domain entities & ports (interfaces) 2. Implement repositories 3. Application services (use-cases) 4. Controllers as adapters 5. Feature module wires providers 6. Tests inject fakes
Use the Architecture Builder to sketch modules.
Vertical slice
interface TaskRepo { save(title: string): { id: string; title: string }; list(): { id: string; title: string }[]; }
class MemoryTaskRepo implements TaskRepo {
private items: { id: string; title: string }[] = [];
save(title: string) {
const row = { id: String(this.items.length + 1), title };
this.items.push(row);
return row;
}
list() { return [...this.items]; }
}
class TasksService {
constructor(private repo: TaskRepo) {}
create(title: string) { return this.repo.save(title); }
list() { return this.repo.list(); }
}
class TasksController {
constructor(private tasks: TasksService) {}
create(title: string) { return this.tasks.create(title); }
list() { return this.tasks.list(); }
}
const api = new TasksController(new TasksService(new MemoryTaskRepo()));
console.log(api.create("Learn DI"));
console.log(api.list());Suggested projects
Apply the same pattern to:
- Student Management
- Library / Inventory
- Banking ledger
- Hospital appointments
- E-commerce orders
- Blog API + Auth
- Task management (above)
- CRM contacts
Each needs modules, controllers, services, repositories, and tests with DI.
Auth service sketch
interface Hash { hash(p: string): string; verify(p: string, h: string): boolean; }
class PlainHash implements Hash {
hash(p: string) { return "h:" + p; }
verify(p: string, h: string) { return this.hash(p) === h; }
}
class AuthService {
constructor(private hash: Hash) {}
register(password: string) { return this.hash.hash(password); }
}
console.log(new AuthService(new PlainHash()).register("secret"));Testing with DI
Swap MemoryTaskRepo for a mock in tests — the controller never changes. That is the payoff of everything you learned.
Fake repo
const fake = {
save: (title: string) => ({ id: "1", title }),
list: () => [{ id: "1", title: "x" }],
};
class TasksService {
constructor(private repo: { list: () => { title: string }[] }) {}
list() { return this.repo.list(); }
}
console.log(new TasksService(fake).list());Check your understanding
5 questionsQuestion 1 of 5
Score: 0
Multiple choice