The Service project is the backend foundation of the MagicPets multi-tenant SaaS platform, built as a serverless microservices architecture on AWS. Using the LazyMagic framework, it implements an OpenAPI-first development approach where all APIs are defined in YAML specifications and code is generated automatically. The Service provides four distinct APIs (Admin, Store, Consumer, Public) through AWS Lambda functions and generates strongly-typed client SDKs consumed by the frontend applications.
Service/
├── Schemas/ # Domain data models and repositories
│ ├── AdminSchema/ # Administrative entities
│ ├── ConsumerSchema/ # Consumer-specific entities
│ ├── SharedSchema/ # Core business entities
│ ├── StoreSchema/ # Store management entities
│ └── PublicSchema/ # Public/unauthenticated entities
├── Modules/ # Business logic implementations
│ ├── AdminModule/ # Administrative operations
│ ├── StoreModule/ # Store management operations
│ ├── ConsumerModule/ # Consumer-facing operations
│ └── PublicModule/ # Public/unauthenticated operations
├── Containers/ # Lambda function containers
│ ├── AdminLambda/ # Admin + Store + Consumer + Public APIs
│ ├── StoreLambda/ # Store + Consumer + Public APIs
│ ├── ConsumerLambda/ # Consumer + Public APIs
│ └── PublicLambda/ # Public API only
├── ClientSDKs/ # Generated client libraries
│ ├── AdminApi/ # Full-access admin client
│ ├── StoreApi/ # Store operations client
│ ├── ConsumerApi/ # Consumer operations client
│ ├── PublicApi/ # Public access client
│ └── *ModuleClientInterface/ # Module-specific interfaces
├── AWSTemplates/ # Infrastructure as Code
├── LocalWebService/ # Local development server
├── ProjectTemplates/ # Code generation templates
└── openapi.*.yaml # API specifications
Purpose: Administrative entities for system management.
Key Models:
TenantUser
: Administrative users with role-based permissionsSubtenant
: Hierarchical tenant organizationTenantUserStatus
: User lifecycle state managementGenerated Components:
Purpose: Consumer-specific entities and preferences.
Key Models:
Preferences
: User preferences including locale and theme settingsPurpose: Core business entities shared across all modules.
Key Models:
Pet
: Central pet entity with comprehensive attributesCategory
: Hierarchical pet categorizationTag
: Flexible tagging system for petsPetStatus
: Pet availability and lifecycle statesRepository Pattern:
public partial interface IPetRepo : IDocumentRepo<Pet>
{
// Auto-generated CRUD operations
// Custom query methods can be added
}
public partial class PetRepo : DYDBRepository<Pet>, IPetRepo
{
// DynamoDB-specific implementation
// Tenant-aware data access
}
Purpose: Store management and operations.
Key Models:
Order
: Order management and processingPurpose: Public/unauthenticated access entities.
Key Models:
Fingerprint
: Browser fingerprinting for analyticsBada
: Public data entities┌─────────────┬─────────────┬─────────────┬─────────────┐
│ AdminModule │ StoreModule │ ConsumerMod │ PublicModule│
├─────────────┼─────────────┼─────────────┼─────────────┤
│ │ │ │ │
│ AdminLambda │ StoreLambda │ ConsumerLam │ PublicLambda│
│ (All) │ (S+C+P) │ (C+P) │ (P) │
└─────────────┴─────────────┴─────────────┴─────────────┘
Purpose: System administration and tenant management.
Key Classes:
AdminModuleController.cs
: Custom business logic implementationAdminModuleControllerBase.g.cs
: Generated from OpenAPI specificationIAdminModuleController.g.cs
: Generated interfaceAdminModuleAuthorization.cs
: TenantAuth authentication logicAdminModuleRegistrations.g.cs
: Dependency injection setupOperations:
Purpose: Store operations and inventory management.
Key Classes:
StoreModuleController.cs
: Store-specific business logicStoreModuleAuthorization.cs
: Store employee authenticationOperations:
Purpose: Consumer-facing operations and personalization.
Key Classes:
ConsumerModuleController.g.cs
: Generated consumer operationsConsumerModuleAuthorization.g.cs
: ConsumerAuth authenticationOperations:
Purpose: Unauthenticated public access operations.
Key Classes:
PublicModuleController.cs
: Public API implementationPublicModuleAuthorization.cs
: No authentication requiredOperations:
Each container hosts a specific combination of modules based on access requirements:
Access Level: Full system access Hosted Modules: Public + Consumer + Store + Admin Authentication: TenantAuth (administrative users) Use Cases: System administration, tenant management, full backend access
Access Level: Store operations Hosted Modules: Public + Consumer + Store Authentication: TenantAuth (store employees) Use Cases: Store management, inventory operations, customer service
Access Level: Consumer operations Hosted Modules: Public + Consumer Authentication: ConsumerAuth (end consumers) Use Cases: Consumer app backend, personalization, pet browsing
Access Level: Public only Hosted Modules: Public Authentication: None required Use Cases: Anonymous access, public content, SEO
Key Generated Files:
LambdaEntryPoint.g.cs
: AWS Lambda entry point with middleware setupLocalEntryPoint.g.cs
: Local development ASP.NET Core entry pointStartup.g.cs
: Service configuration and middleware pipelineConfigureSvcs.g.cs
: Dependency injection container setupFeatures:
Generated client SDKs provide strongly-typed access to backend APIs:
// AdminApi - Full access to all modules
public partial interface IAdminApi :
IPublicModuleClient,
IConsumerModuleClient,
IStoreModuleClient,
IAdminModuleClient
{
// Generated HTTP client methods
// Full API surface area
}
// StoreApi - Store + Consumer + Public access
public partial interface IStoreApi :
IPublicModuleClient,
IConsumerModuleClient,
IStoreModuleClient
{
// Store-level operations
}
// ConsumerApi - Consumer + Public access
public partial interface IConsumerApi :
IPublicModuleClient,
IConsumerModuleClient
{
// Consumer-level operations
}
// PublicApi - Public access only
public partial interface IPublicApi :
IPublicModuleClient
{
// Unauthenticated operations
}
Purpose: Interface segregation for specific module operations.
Examples:
IAdminModuleClient
: Administrative operations onlyIStoreModuleClient
: Store operations onlyIConsumerModuleClient
: Consumer operations onlyIPublicModuleClient
: Public operations onlyBenefits:
Purpose: Local development server that emulates AWS API Gateway.
Key Features:
https://localhost:5001
/swagger
Configuration:
// launchSettings.json
{
"https": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"AWS_PROFILE": "default",
"AWS_REGION": "us-east-1"
},
"applicationUrl": "https://localhost:5001"
}
}
Service Registration:
The Service implements two separate Cognito-based authentication systems:
Purpose: Administrative and store employee authentication User Pool: Tenant-specific Cognito User Pool Consumers: AdminApi, StoreApi Features:
Purpose: End consumer authentication User Pool: Separate Cognito User Pool for consumers Consumers: ConsumerApi Features:
public class CallerInfo
{
public string UserId { get; set; }
public string TenantId { get; set; }
public string SubtenantId { get; set; }
public Dictionary<string, string> Claims { get; set; }
}
Purpose: Model-Driven Development with OpenAPI specifications.
Generation Pipeline:
Integrated Analyzers:
LazyMagic.LzItemViewModelGenerator
: Generates ViewModels from DTOsLazyMagic.DIHelper
: Auto-registers services with dependency injectionLazyMagic.FactoryGenerator
: Creates factory classes for object creationProjectTemplates: Reusable templates for new components
Benefits:
SAM Templates: Complete AWS infrastructure defined as code
Generated Infrastructure:
Client App → Client SDK → API Gateway → Lambda Container → Module → Repository → DynamoDB
↑ ↓
JSON/HTTP ← Generated Client ← HTTP Response ← Lambda Response ← Business Logic ← Data Access
OpenAPI Specs → LazyMagic Tool → Generated Code → Manual Implementation → Deployment
↓ ↓ ↓ ↓ ↓
API Def → Schema/Controller → DTOs/Models/Repos → Custom Logic → AWS Resources
Client Login → Cognito → JWT Token → API Gateway → Lambda Middleware → CallerInfo → Repository
↓ ↓ ↓
User Creds → Auth Pool → Claims/Token → Validation → User Context → Tenant Data
cd Service
dotnet build MagicPetsService.sln
cd LocalWebService
dotnet run
# Access Swagger UI at https://localhost:5001/swagger
cd AWSTemplates
sam build
sam deploy --guided
# LazyMagic tool automatically generates:
# - DTOs and Models from OpenAPI schemas
# - Controllers and repositories
# - Client SDKs
# - AWS SAM templates
The Service project represents a sophisticated, production-ready serverless backend that leverages modern cloud architecture patterns while maintaining developer productivity through extensive code generation and tooling automation.