Common Patterns & Use Cases
Explore how ONDEMANDENV's core concepts are applied to solve common challenges in managing distributed systems. Note that these patterns inherently involve secure cross-account interactions, orchestrated by the platform based on contracts defined in `contractsLib`.
Pattern: Isolated Full SDLC Environments per Service Branch
Problem: Traditional development often relies on a few shared, static environments (e.g., Dev, QA, Staging) which leads to contention, configuration drift, and deployment bottlenecks. Even modern containerized approaches using ephemeral namespaces often only provide isolated runtime environments, lacking the full context of infrastructure dependencies, versioned configurations, and cross-service interactions inherent in the complete SDLC. This forces rapid merging of small changes, hindering the development of complex features in true isolation.
ONDEMANDENV Solution: ONDEMANDENV promotes a shift towards isolated, full SDLC environments for each meaningful branch of a service. By cloning a stable base Enver (representing a complete Bounded Context), developers get a high-fidelity replica encompassing not just the service's code, but its specific infrastructure definition, versioned configuration, and resolved dependencies – essentially, an entire, independent lifecycle instance. This contrasts sharply with shared static environments or simple container/namespace isolation. It enables deep, meaningful branching strategies where complex features can be developed, deployed, and tested holistically over time within their own dedicated, consistent, and fully isolated SDLC environment, preventing conflicts and providing rapid, reliable feedback loops.
Conceptual Workflow:
- Developer Creates Feature Branch: A developer starts work on a new feature or bug fix by creating a new Git branch (e.g., `feature/new-auth-flow`) from a base branch (e.g., `dev`).
- Code & Commit with Clone Command: The developer makes code changes in their branch. When ready to test within its own lifecycle, they commit the changes including the special command odmd: create@dev (or the relevant base Enver branch name) in the commit message body.
- Platform Provisions Full SDLC Clone: ONDEMANDENV detects the command upon push. It automatically:
- Creates a new dynamic Enver associated with the `feature/new-auth-flow` branch.
- Resolves dependencies based on the state of the `dev` Enver (as specified in the command).
- Deploys a full-stack SDLC clone (infrastructure, configuration, application) using the code from the `feature/new-auth-flow` branch into the designated target account/region, ensuring resource names are unique to this clone.
- Isolated SDLC Testing & Iteration: The developer receives the endpoint or access details for their dedicated clone Enver. They can perform integration tests, manual testing, or further iteration within their dedicated SDLC environment without impacting any other developer or shared environment.
- Merge & Delete Clone Environment: Once testing is complete and the feature is merged, the developer can trigger the clone environment's destruction by pushing an empty commit with odmd: delete in the message body on the feature branch. The platform cleans up all resources associated with the clone.
This pattern fundamentally changes the development dynamic, moving beyond shared bottlenecks and superficial ephemeral testing. It enables true parallel development of complex features within complete, isolated SDLC environments managed as code, allowing teams to innovate faster and more reliably.
Pattern: Enabling Advanced Deployments (Blue/Green, A/B)
Problem: Implementing Blue/Green or A/B testing often involves duplicating configurations, managing complex traffic shifting logic, and ensuring consistency across potentially different accounts or infrastructure variants.
ONDEMANDENV Solution: Leverage distinct Envers for each application version and a dedicated Routing/Traffic Management Enver to control user traffic flow.
- Application Versions as Envers:
- Blue/Green: Maintain two distinct, stable Envers (e.g., `myApp-blue` and `myApp-green`), potentially targeting different accounts or the same one. Each publishes its unique endpoint URL or service identifier as a `Product`.
- A/B Testing / Experimentation: Create `Clones` of a base Enver or define distinct feature Envers. Each variant publishes its endpoint `Product`.
- Dedicated Routing Enver: Create a separate Enver specifically to manage traffic distribution. This Enver would:
- `Consume` the endpoint `Products` published by the relevant application Envers (e.g., blue endpoint, green endpoint, variant A endpoint, variant B endpoint).
- Control the traffic shifting mechanism, such as:
- Updating weighted DNS records (e.g., Route 53 CNAME weights).
- Configuring API Gateway stages or routes.
- Modifying Load Balancer target group weights or listener rules.
- Deployments to this Routing Enver directly control the user traffic percentage split or cutover between application versions.
Pattern: AI-Assisted Development within Bounded Contexts
Problem: AI code generation tools, while powerful, often produce code that violates architectural boundaries, introduces tight coupling, or creates accidental complexity. Without proper constraints and context, AI can generate technically correct but architecturally problematic solutions that compromise long-term maintainability and system coherence. Traditional development approaches lack the structured contracts and boundaries needed to guide AI toward producing well-architected, Domain-Driven Design-compliant code.
ONDEMANDENV Solution: ONDEMANDENV provides the perfect framework for AI-assisted development by establishing clear bounded contexts, explicit contracts, and isolated testing environments. The platform's `contractsLib` serves as a specification that AI can reference to generate code that respects domain boundaries, uses correct interfaces, and integrates properly with the existing system. This approach transforms AI from a potential source of accidental complexity into a powerful tool for generating maintainable, DDD-compliant code.
AI-Guided Development Workflow:
- Define Bounded Context in contractsLib: Establish clear boundaries, responsibilities, and contracts for your domain before involving AI in code generation.
- Provide AI with Architectural Context: Share the relevant `BuildDefinition`, `Enver` definitions, and `Product`/`Consumer` contracts with your AI assistant to establish architectural constraints.
- Generate Code within Boundaries: Request AI to generate code that operates within the defined bounded context, referencing specific contracts and dependency interfaces.
- Validate in Isolated Environment: Use ONDEMANDENV's cloning capability to create an ephemeral environment for testing AI-generated code without affecting shared infrastructure.
- Iterate with Contract Evolution: If AI suggests interface changes, evolve contracts through the proper governance process in `contractsLib` before implementing.
Example: AI-Assisted Microservice Development
Consider developing a new authentication service using AI assistance within ONDEMANDENV:
1. Define the Bounded Context (`contractsLib`)
// In MyOrgContracts.ts
const authServiceBuild = new OdmdBuild(this, 'AuthServiceBuild', {
githubRepoAlias: 'auth-service-repo',
buildType: 'cdk',
});
const authServiceDev = new AuthServiceEnver(this, 'AuthServiceDev', {
build: authServiceBuild,
targetAccountAlias: 'dev-workspace-account',
// Define what this service will provide
outputsProduct: new Product(this, 'Outputs'), // JWT endpoints, user validation APIs
// Define dependencies it needs
userDbConsumer: new Consumer(this, 'UserDbOutputs', userDbEnver.outputsProduct),
auditLogConsumer: new Consumer(this, 'AuditLogOutputs', auditLogEnver.outputsProduct),
});
2. AI Code Generation with Architectural Context
Provide your AI assistant with the contract definition and request code generation:
// AI Prompt: "Generate a CDK stack for the AuthServiceEnver that:
// 1. Consumes UserDb outputs for user data access
// 2. Consumes AuditLog outputs for security logging
// 3. Publishes JWT endpoint and validation API as outputs
// 4. Follows Application-Centric Infrastructure principles
// 5. Uses the consumed database connection for user authentication"
export class AuthServiceStack extends cdk.Stack {
constructor(scope: Construct, id: string, props: cdk.StackProps) {
super(scope, id, props);
// AI-generated code respects contract boundaries
const userDbConfig = JSON.parse(OdmdEnverCdk.getSharedValue('UserDbOutputs') || '{}');
const auditConfig = JSON.parse(OdmdEnverCdk.getSharedValue('AuditLogOutputs') || '{}');
// AI generates infrastructure within bounded context
const authLambda = new lambda.Function(this, 'AuthFunction', {
// ... AI-generated Lambda configuration
environment: {
USER_DB_ENDPOINT: userDbConfig.endpoint,
AUDIT_LOG_TOPIC: auditConfig.topicArn,
}
});
// AI publishes outputs according to contract
new OdmdShareOut(this, 'Outputs', {
value: cdk.Stack.of(this).toJsonString({
jwtEndpoint: authApi.url,
validationEndpoint: `${authApi.url}/validate`,
})
});
}
}
3. Isolated Testing with Cloning
Test the AI-generated code in isolation:
git commit -m "feat: AI-generated auth service implementation
odmd: create@AuthServiceDev"
This creates a temporary environment where the AI-generated authentication service can be tested without affecting other services or shared infrastructure.
4. Contract Evolution and Governance
If AI suggests adding new outputs or changing interfaces, update `contractsLib` through proper governance:
// AI suggests adding password reset capability
// Update contract in contractsLib through PR process
const authServiceDev = new AuthServiceEnver(this, 'AuthServiceDev', {
// ... existing configuration
outputsProduct: new Product(this, 'Outputs'), // Now includes password reset endpoints
// AI identifies need for email service
emailServiceConsumer: new Consumer(this, 'EmailServiceOutputs', emailServiceEnver.outputsProduct),
});
Benefits of AI + ONDEMANDENV + DDD
- Architectural Compliance: AI generates code that automatically respects bounded contexts and domain boundaries
- Contract Adherence: Explicit interfaces prevent AI from creating inappropriate dependencies or tight coupling
- Safe Experimentation: Cloned environments allow rapid iteration with AI-generated code without risk
- Governance Integration: Changes to system architecture follow established processes, even when AI-suggested
- Maintainable Output: AI-generated code follows consistent patterns and integrates properly with the platform
- Accelerated Development: Developers can leverage AI while maintaining architectural integrity and system coherence
This pattern demonstrates how ONDEMANDENV transforms AI from a potential source of technical debt into a powerful ally for building maintainable, well-architected systems that follow Domain-Driven Design principles.