Full-Stack Template
Unified template for building your Agentic SaaS with a hexagonal architecture
The Full-Stack (FS) Template provides a unified approach to building your Agentic SaaS with a clean, hexagonal architecture. This template offers everything you need to create, deploy, and monetize your own agent business.
You can find the full source code for the FS template here.
Key Benefits
- Unified Architecture: Single repository for frontend, backend, and infrastructure
- Hexagonal Design: Clear separation of concerns with ports and adapters pattern
- Simplified Agent Creation: Standardized approach to building your AI agent
- Consistent Development Experience: Unified tooling and development workflow
- Streamlined Deployment: Single deployment process for all components
- Monetization Ready: Built-in Stripe integration for immediate business launch
Project Structure
The FS template follows a monorepo structure with packages for core, functions, frontend, metadata, and utils:
The lib/ Directory
The lib/
directory contains wrappers around AWS services that provide consistent patterns and reduce boilerplate code. These wrappers offer:
- Simplified Interfaces: Clean, typed interfaces for interacting with AWS services
- Error Handling: Consistent error handling patterns across all AWS interactions
- Retry Logic: Built-in retry mechanisms for transient failures
- Logging: Standardized logging for all AWS operations
- Testing: Easier mocking for unit and integration tests
Example of the DynamoDB wrapper:
Hexagonal Architecture
The FS template implements a hexagonal architecture (also known as ports and adapters) for agent modules. This architecture separates the core business logic from external concerns, making the system more maintainable, testable, and adaptable to change.
Key Components
-
Primary Adapters (Input): Handle incoming requests and transform them into a format the use cases can process
- HTTP Request Adapters
- Event Handlers
-
Use Cases (Business Logic): Contain the core business logic independent of external systems
- Implement domain-specific rules
- Orchestrate the flow of data
-
Secondary Adapters (Output): Handle communication with external systems
- AI Provider Adapters (OpenAI, etc.)
- Database Adapters
- Third-party Service Adapters
Core Library (lib/)
The lib/
directory contains reusable factory patterns and base classes that provide standardized implementations for common functionality across the application. These components abstract away the complexity of working directly with AWS services and provide a consistent interface for your application.
Key Components in lib/
- dynamodb-repository.factory.ts: Factory for creating DynamoDB repositories with standardized CRUD operations
- lambda-adapter.factory.ts: Factory for creating Lambda adapters with consistent request handling and error management
- sqs-adapter.factory.ts: Factory for creating SQS adapters for message processing
- topic-publisher.adapter.ts: Adapter for publishing messages to SNS topics
- transaction.util.ts: Utilities for handling DynamoDB transactions
Benefits of the lib/ Abstractions
- Consistent Patterns: Standardized approach to common operations
- Reduced Boilerplate: Factories eliminate repetitive code
- Type Safety: Strong typing for all operations
- Error Handling: Consistent error handling and logging
- Testability: Easier to mock and test components
Example: Using the DynamoDB Repository Factory
Agent Implementation Pattern
When implementing your AI agent, you’ll follow this standardized directory structure:
Schema-Driven Development
The FS template uses Zod for schema validation throughout the application:
Infrastructure with SST
The FS template uses SST (Serverless Stack) v3 for infrastructure as code:
Environment Configuration
Create a .env.local
file in the project root. Note that SST uses SNAKE_CASE for environment variables as per their documentation:
Development Workflow
-
Install Dependencies:
-
Start Development Environment:
-
Deploy to Staging:
-
Deploy to Production: