Documentation
Folder Structure

Folder Structure

To first get a clear overview of how this codebase is structured, let's take a look at all the folders inside.

📡 /infra

The infra folder is responsible for defining and organizing all AWS infrastructure of your application using the SST framework. SST allows you to define your AWS infrastructure as code, making it easier to manage, version, and deploy your serverless applications.

💡

Learn more about each of Blitzships pre-configured infrastructure here

📦 /packages

This directory houses all the code and business-logic that powers your SaaS application (except for the infrastructure code which is located in the infra folder). The monorepo is structured into several packages, each serving a specific purpose in the overall architecture of the application.

💡

Learn more about the packages directory here

/packages/core

The core package is the central hub for all business logic in our SaaS application. It facilitates domain-driven design and maintains a clear separation of concerns.

  • Houses all business logic
  • Separates business logic from API and Lambda functions
  • Implements all application functionalities

This package is designed to be imported across all other packages in the monorepo.

💡

Learn more about the core package here

/packages/functions

This package contains the handler code for our AWS Lambda functions, providing a clean and organized structure for serverless operations.

  • Houses Lambda function handlers
  • Implements lightweight handlers as entry points
  • Calls into core business-logic defined in packages/core

Think of the previous example where we created a lambda endpoint to handle webhooks from Stripe like this:

const api = new sst.aws.ApiGatewayV2("Api");
 
api.route(
 "POST /billing/webhooks",
 "packages/functions/src/billing/webhooks.handler"
)

Now, the webhooks.ts file exporting the handler function is located exactly in this package.

💡

Learn more about the functions package here

/packages/landing-page

This package contains a full Next.js 14 project for our landing page and documentation.

  • Utilizes Next.js 14 with app router
  • Uses Mantine as the primary component library
  • Handles Stripe integration for checkout processes
  • Includes a documentation website using the pages router and markdown
  • Includes pre-built conversion optimized components and pages
💡

Learn more about the landing page package here

/packages/main-app

This package houses the main SaaS application built with Next.js 14 and the App Router.

  • Implements Next.js 14 with App Router
  • Provides authentication using Auth.js
  • Utilizes tRPC for type-safe API interactions
  • Uses Mantine for UI components and styling
  • Includes pre-built components and pages
💡

Learn more about the main app package here

/packages/schemas

This package serves as the single source of truth for business objects and their types.

  • Centralizes schema definitions using Zod (opens in a new tab)
  • Exports TypeScript types inferred from Zod schemas
  • Ensures consistency and reduces duplication across the codebase
💡

Learn more about the schemas package here

/packages/transactional

This package contains email templates for transactional emails used throughout the application.

  • Uses React Email for custom styled email templates
  • Maintains consistency with the application's design
  • Allows easy updating and version control of email templates
  • Provides type-safe email template development
💡

Learn more about the transactional package here

Summary

By organizing our codebase into these packages, we ensure a modular, maintainable, and scalable architecture for our SaaS application.