Skip to main content

Develop Phase Recipes

Essential patterns and templates for AI-assisted development using the GISE methodology. These recipes help you implement robust, tested, and maintainable code efficiently.

Vibe Coding Patterns

AI-Assisted Development Workflow

Service Layer Pattern

// Service Layer Template
import { injectable, inject } from 'inversify';
import { Repository } from '../repositories/Repository';
import { Logger } from '../utils/Logger';
import { ValidationError, NotFoundError } from '../errors';

@injectable()
export class EntityService {
constructor(
@inject('Repository') private repository: Repository,
@inject('Logger') private logger: Logger
) {}

async create(data: CreateDto): Promise<Entity> {
this.logger.info('Creating entity', { data });

this.validateInput(data);

try {
const entity = await this.repository.create(data);
this.logger.info('Entity created', { id: entity.id });
return entity;
} catch (error) {
this.logger.error('Failed to create entity', { error, data });
throw error;
}
}

private validateInput(data: CreateDto): void {
if (!data.name?.trim()) {
throw new ValidationError('Name is required');
}
}
}

Testing Patterns

Unit Test Template

// Unit Test Pattern
import { describe, beforeEach, it, expect, jest } from '@jest/globals';
import { EntityService } from '../EntityService';
import { mockRepository, mockLogger, mockEntity } from '../fixtures';

describe('EntityService', () => {
let service: EntityService;
let mockRepo: jest.Mocked<Repository>;

beforeEach(() => {
mockRepo = mockRepository();
service = new EntityService(mockRepo, mockLogger());
});

describe('create', () => {
it('should create entity successfully', async () => {
// Arrange
const createData = { name: 'Test Entity' };
const expectedEntity = mockEntity(createData);
mockRepo.create.mockResolvedValue(expectedEntity);

// Act
const result = await service.create(createData);

// Assert
expect(result).toEqual(expectedEntity);
expect(mockRepo.create).toHaveBeenCalledWith(createData);
});

it('should throw ValidationError for invalid input', async () => {
// Arrange
const invalidData = { name: '' };

// Act & Assert
await expect(service.create(invalidData))
.rejects.toThrow(ValidationError);

expect(mockRepo.create).not.toHaveBeenCalled();
});
});
});

Code Quality Patterns

ESLint Configuration

// .eslintrc.js
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 2021,
sourceType: 'module',
project: './tsconfig.json'
},
plugins: ['@typescript-eslint', 'security'],
extends: [
'eslint:recommended',
'@typescript-eslint/recommended',
'plugin:security/recommended',
'prettier'
],
rules: {
'@typescript-eslint/no-unused-vars': 'error',
'@typescript-eslint/explicit-function-return-type': 'warn',
'@typescript-eslint/no-explicit-any': 'error',
'security/detect-object-injection': 'error',
'no-console': 'warn'
}
};

AI Integration Patterns

AI Prompt Templates

# Code Generation Prompt
You are an expert TypeScript developer. Generate code following these patterns:
- Use dependency injection with inversify
- Include comprehensive error handling
- Add proper logging with context
- Follow clean architecture principles
- Include JSDoc documentation

Context: [INSERT CONTEXT]
Requirements: [INSERT REQUIREMENTS]

Performance Optimization

Caching Pattern

// Redis Caching Service
import { Redis } from 'ioredis';
import { injectable, inject } from 'inversify';

@injectable()
export class CacheService {
constructor(@inject('Redis') private redis: Redis) {}

async get<T>(key: string): Promise<T | null> {
const cached = await this.redis.get(key);
return cached ? JSON.parse(cached) : null;
}

async set<T>(key: string, value: T, ttl: number = 3600): Promise<void> {
await this.redis.setex(key, ttl, JSON.stringify(value));
}

async invalidate(pattern: string): Promise<void> {
const keys = await this.redis.keys(pattern);
if (keys.length > 0) {
await this.redis.del(...keys);
}
}
}

CI/CD Pipeline Patterns

GitHub Actions Workflow

# .github/workflows/ci.yml
name: CI/CD Pipeline

on:
push:
branches: [main, develop]
pull_request:
branches: [main, develop]

jobs:
quality:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'npm'

- run: npm ci
- run: npm run lint
- run: npm run type-check
- run: npm run test:coverage
- run: npm run security-audit

- name: Upload coverage
uses: codecov/codecov-action@v3

Security Patterns

Input Validation Middleware

// Validation Middleware Pattern
import { Request, Response, NextFunction } from 'express';
import { validate } from 'class-validator';
import { plainToClass } from 'class-transformer';

export function validateBody<T>(dtoClass: new () => T) {
return async (req: Request, res: Response, next: NextFunction) => {
try {
const dto = plainToClass(dtoClass, req.body);
const errors = await validate(dto);

if (errors.length > 0) {
return res.status(400).json({
error: 'Validation failed',
details: errors.map(err => ({
property: err.property,
constraints: err.constraints
}))
});
}

req.body = dto;
next();
} catch (error) {
next(error);
}
};
}

Documentation Patterns

API Documentation Template

/**
* Creates a new project
* @route POST /api/v1/projects
* @group Projects - Project management operations
* @param {CreateProjectDto} request.body.required - Project creation data
* @returns {Project.model} 201 - Created project
* @returns {Error} 400 - Validation error
* @returns {Error} 401 - Unauthorized
* @security Bearer
*/
export async function createProject(
req: Request<{}, Project, CreateProjectDto>,
res: Response<Project>
): Promise<void> {
// Implementation
}

Related Resources:

These patterns provide proven approaches to common development challenges. Use AI assistance to implement them while maintaining human oversight for quality and architecture decisions.