Architecture Expert

The Architecture Expert agent specializes in software architecture, system design, code organization, design patterns, and building scalable, maintainable applications.

Expertise Areas#

  • Next.js App Router Structure - Route groups, layouts, loading states
  • Feature-Based Architecture - Organizing code by domain features
  • Service Layer Pattern - Business logic separation and encapsulation
  • Repository Pattern - Data access abstraction
  • Dependency Injection - Loosely coupled, testable code
  • Event-Driven Architecture - Decoupled system communication
  • Clean Architecture Layers - Separation of concerns
  • Error Handling Strategy - Consistent error management

Usage Examples#

App Router Structure#

Use the architecture-expert agent to design a Next.js App Router structure for a SaaS application with: - Marketing pages - Dashboard with sidebar - Settings with nested routes - API routes with webhooks

Response includes:

  • Complete folder structure
  • Route group organization
  • Layout component hierarchy
  • API route patterns

Feature-Based Architecture#

Use the architecture-expert agent to organize a React application using feature-based architecture.

Response includes:

  • Feature folder structure
  • Component organization
  • Hooks and actions placement
  • Type definitions

Service Layer#

Use the architecture-expert agent to implement a service layer pattern for a project management system.

Response includes:

  • Service class structure
  • Repository integration
  • Error handling
  • Transaction management

Best Practices Applied#

1. Clean Architecture#

  • Inner layers don't depend on outer layers
  • Dependencies flow inward
  • Domain layer has no external dependencies

2. Separation of Concerns#

  • Business logic in services
  • Database access through repositories
  • Presentation in components
  • Validation in dedicated schemas

3. Scalability#

  • Feature-based organization
  • Modular code structure
  • Clear dependency management
  • Environment configuration

4. Maintainability#

  • Consistent naming conventions
  • Type safety throughout
  • Comprehensive error handling
  • Logging and monitoring

Common Patterns#

Service Layer Pattern#

1// services/project-service.ts 2import { prisma } from '@/lib/db'; 3import { CreateProjectInput, UpdateProjectInput } from '@/types'; 4import { NotFoundError, UnauthorizedError } from '@/lib/errors'; 5 6export class ProjectService { 7 async getAll(userId: string) { 8 return prisma.project.findMany({ 9 where: { 10 OR: [ 11 { ownerId: userId }, 12 { members: { some: { userId } } }, 13 ], 14 }, 15 include: { 16 owner: { select: { id: true, name: true, avatar: true } }, 17 _count: { select: { tasks: true, members: true } }, 18 }, 19 orderBy: { updatedAt: 'desc' }, 20 }); 21 } 22 23 async create(data: CreateProjectInput, userId: string) { 24 return prisma.project.create({ 25 data: { 26 ...data, 27 ownerId: userId, 28 members: { 29 create: { userId, role: 'owner' }, 30 }, 31 }, 32 }); 33 } 34}

Repository Pattern#

1// repositories/base-repository.ts 2import { PrismaClient } from '@prisma/client'; 3 4export abstract class BaseRepository<T> { 5 constructor(protected prisma: PrismaClient) {} 6 7 abstract findById(id: string): Promise<T | null>; 8 abstract findAll(): Promise<T[]>; 9 abstract create(data: Partial<T>): Promise<T>; 10 abstract update(id: string, data: Partial<T>): Promise<T>; 11 abstract delete(id: string): Promise<void>; 12}

Error Handling#

1// lib/errors.ts 2export class AppError extends Error { 3 constructor( 4 message: string, 5 public code: string, 6 public statusCode: number = 400, 7 public isOperational: boolean = true 8 ) { 9 super(message); 10 Error.captureStackTrace(this, this.constructor); 11 } 12} 13 14export class NotFoundError extends AppError { 15 constructor(resource: string) { 16 super(`${resource} not found`, 'NOT_FOUND', 404); 17 } 18} 19 20export class UnauthorizedError extends AppError { 21 constructor(message = 'Unauthorized') { 22 super(message, 'UNAUTHORIZED', 401); 23 } 24}

Sample Prompts#

TaskPrompt
Project structure"Design a folder structure for a Next.js SaaS application"
Service layer"Implement a service layer for user management"
Feature organization"Organize authentication as a feature module"
Error handling"Create a comprehensive error handling strategy"
Dependency injection"Set up a dependency injection container"

Configuration#

1// bootspring.config.js 2module.exports = { 3 agents: { 4 customInstructions: { 5 'architecture-expert': ` 6 - Use Next.js App Router conventions 7 - Follow clean architecture principles 8 - Implement service layer pattern 9 - Include proper error handling 10 - Design for scalability 11 `, 12 }, 13 }, 14 stack: { 15 framework: 'nextjs', 16 patterns: ['service-layer', 'repository'], 17 }, 18};