Skip to main content

Day 8: Codematic Hackathon: Build with Google Cloud

Mastering the NestJS

Published 3 min readMarkdown
Day 8: Codematic Hackathon: Build with Google Cloud

Day 8 was dedicated entirely to adopting the right tool for the job: NestJS. After stabilizing the CI/CD pipeline on Day 7, the focus shifted to building the core business logic—the "brain" of the application—in a structured, scalable way. NestJS, a progressive Node.js framework supporting TypeScript, is the perfect candidate for building efficient, microservices-ready servers.

Lessons Learned

The Value of Structure (and TypeScript)

  • Roadblock: Coming from a simple FastAPI microservice, diving into a full-fledged, opinionated framework like NestJS initially felt like overkill. I struggled with where certain pieces of logic should live (e.g., should database calls go in the Controller?).

  • Solution: I realized that NestJS's architectural structure—inspired by Angular—is its greatest strength. It enforces the separation of concerns needed for scalability.

    • Controllers: Only handle incoming HTTP requests and delegate tasks.

    • Providers (Services): Hold the business logic and heavy lifting (like API calls and database interactions).

    • Modules: Group related components (Controllers, Services) into feature sets. This OOP-based approach dramatically increases development speed once the pattern clicks.

Mastering the Core Concepts

I spent time learning the core building blocks of the framework:

  • Decorators (@ symbols): These are essential for mapping request handlers (@Get(), @Post()), marking classes as components (@Controller(), @Injectable()), and defining metadata.

  • DTOs (Data Transfer Objects): These classes define the exact structure of data being passed between the client and the application (e.g., when a user submits coordinates). Using DTOs with TypeScript ensures data integrity and validation—a huge boost in reliability.

  • Dependency Injection: This is the heart of NestJS. Instead of manually creating instances of classes, you rely on the framework to inject them where needed (e.g., injecting a UserService into a UserController). This makes the application highly testable and loosely coupled.

Daily Accomplishments

  • NestJS Foundation Complete: Successfully completed the introductory learning phase, covering the core concepts (Modules, Controllers, Providers).

  • Project Initialization: Created the initial NestJS project structure, ready to house the core business logic.

  • Service Design: Designed the initial architecture for the Home Hunt Service, planning out how the geocoding data from the FastAPI service will be consumed and enriched by external APIs.

Tips for Fellow Hackers

  • Deep Dive into the Docs: The NestJS Documentation (https://docs.nestjs.com/) is exceptional. Start with the "Fundamentals" section, especially the relationship between Controllers (HTTP layer) and Providers (business logic layer).

  • Video Tutorial Companion: I found the combination of the official documentation and the excellent tutorial series by Dave Gray on YouTube (https://www.youtube.com/watch?v=8_X0nSrzrCw) to be the fastest way to grasp the practical implementation.

  • TypeScript is Non-Negotiable: If you're using NestJS, embrace TypeScript wholeheartedly. The strong typing and interfaces prevent an entire class of runtime errors, which saves huge amounts of time in production debugging.

  • The Power of OOP for APIs: Don't be intimidated by the Object-Oriented Programming (OOP) focus. Thinking in terms of classes, inheritance, and modules makes your API naturally more organized and scalable than traditional monolithic Node.js setups.

Next Step

My focus now moves back to data integration and enrichment. I will be learning about the Google Maps Places API and the Vertex AI/Gemini API, and how to integrate them into the NestJS core logic. This integration will be essential for taking raw coordinate data and generating the user-centric insights needed for my personalized home hunt service.

About the author

  • Fortune Precious is a software engineer skilled in TypeScript, C++, Python, Rust, Java and C#. He has interests in products, data and research.

No comments yet. Be the first to comment.