Skip to content

Best Practices โ€‹

Production-ready patterns, security guidelines, and optimization strategies for building robust Ignis applications. These best practices are distilled from real-world experience building enterprise applications.

Learning Path โ€‹

1

Foundation

Architecture โ†’ Decisions Guide โ†’ Code Standards

Understand patterns and establish coding conventions
2

Data Layer

Data Modeling โ†’ API Patterns โ†’ Error Handling

Design your data layer and handle edge cases
3

Quality Assurance

Testing โ†’ Avoid Pitfalls โ†’ Troubleshooting

Write tests and prevent common mistakes
4

Production Ready

Security โ†’ Performance โ†’ Deployment

Secure, optimize, and deploy your application

Quick Reference โ€‹

Essential Patterns โ€‹

typescript
// โœ… Layered Architecture
Controller โ†’ Service โ†’ Repository โ†’ DataSource

// โœ… Dependency Injection
@inject({ key: BindingKeys.build({ namespace: BindingNamespaces.SERVICE, key: UserService.name }) })

// โœ… Error Handling
throw getError({ statusCode: 404, message: 'User not found' });

// โœ… Input Validation
request: { body: jsonContent({ schema: z.object({ email: z.string().email() }) }) }

Anti-Patterns to Avoid โ€‹

typescript
// โŒ Business logic in controllers
@get({ configs: RouteConfigs.GET_USER })
async getUser(c: Context) {
  const user = await this.userRepo.findById(id);
  if (user.lastLogin < cutoff) await this.sendReminder(user); // Move to service!
  return c.json(user);
}

// โŒ Catching all errors silently
try { await riskyOperation(); } catch (e) { /* swallowed */ }

// โŒ Using `any` type
const data: any = await fetchData(); // Use proper types!

Security Checklist โ€‹

CheckAction
SecretsStore in environment variables, never in code
InputValidate with Zod schemas at API boundaries
AuthProtect routes with authStrategies: [Authentication.STRATEGY_JWT]
Sensitive dataUse hiddenProperties in model settings
File uploadsUse sanitizeFilename() for all user-provided filenames
CORSConfigure allowed origins explicitly

Performance Checklist โ€‹

CheckAction
QueriesUse fields to select only needed columns
PaginationAlways set limit on find operations
RelationsLimit include depth to 2 levels max
Connection poolConfigure pool size based on load
Background jobsOffload CPU-intensive tasks to workers
CachingCache expensive queries with Redis

All Best Practices โ€‹

Architecture & Design โ€‹

GuideDescription
Architectural PatternsLayered architecture, DI, components, mixins
Architecture DecisionsWhen to use services, repositories, components

Development โ€‹

GuideDescription
Code Style StandardsNaming conventions, types, ESLint, Prettier
Data ModelingSchema design, enrichers, relations, migrations
API Usage ExamplesRouting, repositories, middleware, services

Quality โ€‹

GuideDescription
Testing StrategiesUnit tests, integration tests, mocking, E2E
Error HandlingError patterns, structured errors, logging
Common PitfallsMistakes to avoid and how to fix them
Troubleshooting TipsDebug common issues quickly

Production โ€‹

GuideDescription
Security GuidelinesAuthentication, validation, secrets, CORS
Performance OptimizationQuery optimization, caching, connection pooling
Deployment StrategiesDocker, Kubernetes, cloud platforms, CI/CD

Contributing โ€‹

GuideDescription
Contribution WorkflowGit workflow, PR guidelines, code review

New to Ignis?

Start with the Getting Started Guide for tutorials, then return here for production-ready patterns.

Production Deployment?

Before deploying, review the Security Guidelines and Deployment Strategies thoroughly.

See Also โ€‹