A TypeScript package for type-safe services with Result pattern, ORM-agnostic repositories, and framework-flexible API handlers.
npm install @ignix/core---
---
---
IService with CRUD operations, customizable DTOs (Create, Update, Response), and extensible error types. Includes BaseService implementation.IRepository interface with base implementations for TypeORM, Prisma, and more, allowing easy extension.IAPIHandler with adapters for NestJS (controllers) and Express-like (routes), supporting multiple request/response patterns.LegacyService wrapper for promise-based APIs if Result pattern isn't desired.---
---
``mermaid
graph LR
A[Client] --> B[API Layer]
B --> C[Service Layer]
C --> D[Repository Layer]
D --> E[(Database)]
subgraph "API Layer"
F[IAPIHandler] --> G[Adapters: NestJS, Express]
end
subgraph "Service Layer"
H[IService
J[BaseService] --> H
K[LegacyService] --> H
end
subgraph "Repository Layer"
L[IRepository
end
`
- Service Layer: Core business logic with Result pattern for error handling. BaseService provides a ready-to-use implementation.BaseRepository
- Repository Layer: Abstract data access, with as extensible base class.
- API Layer: Handlers that map HTTP requests to services, with adapters for different frameworks.
- Key Decisions: Generics for type safety, discriminated unions for errors, and interfaces for extensibility.
---
`bash`
npm install @ignix/core
Or with yarn:
`bash`
yarn add @ignix/core
---
typescript
import { BaseService, IRepository, BaseRepository } from '@ignix/core';// Define your entity
interface User {
id: number;
name: string;
email: string;
}
// Implement repository (extend BaseRepository for your ORM)
class UserRepository extends BaseRepository {
constructor(ormClient: any) {
super(ormClient);
}
// Implement abstract methods for your ORM
}
// Create service
const repo = new UserRepository(ormClient);
const service = new BaseService(repo);
// Use service
const result = await service.findAll();
if (result.type === 'success') {
console.log(result.data);
} else {
console.error(result.error.message);
}
`$3
`typescript
import { IService, Result, BaseService } from '@ignix/core';type CreateUserDto = Omit;
type UpdateUserDto = Partial;
type UserResponseDto = Pick;
class UserService extends BaseService {
// Override methods if needed
async mapToResponse(entity: User): Promise {
return { id: entity.id, name: entity.name };
}
}
`$3
`typescript
import { LegacyService } from '@ignix/core';const legacyService = new LegacyService(service);
try {
const users = await legacyService.findAll();
console.log(users);
} catch (error) {
console.error(error.message);
}
`$3
`typescript
import { IAPIHandler, BaseAPIHandler } from '@ignix/core';class UserAPIHandler extends BaseAPIHandler {}
const handler = new UserAPIHandler(service);
// Use with Express adapter (when implemented)
`See the
/examples folder for full implementations.---
Roadmap
We have exciting plans for future versions to enhance DX and functionality:- Validation Helpers: Integrate schema validation (e.g., with Zod) for DTOs, returning Result-based errors.
- Pagination & Filtering: Add utilities for paginated queries and advanced filtering options.
- Caching Layer: Implement a caching interface with adapters (Redis, In-Memory) and decorators.
- Event System: Introduce an event bus for decoupling and event-driven architectures (towards CQRS).
- Auth Helpers: Provide lightweight helpers for JWT and role-based access.
- CLI Tool: Create a CLI for code generation (services, repositories).
- More Adapters: Expand ORM and framework support (Sequelize, Koa, etc.).
- CQRS Support: Full CQRS implementation in v2 with commands and queries.
Stay tuned! Contributions welcome for these features.
---
Contributing
We welcome contributions! To get started:
1. Fork the repo and clone it.
2. Install dependencies:
npm install.
3. Run tests: npm test.
4. Create a feature branch: git checkout -b feature/your-amazing-your-feature.
5. Follow our coding standards: Use TypeScript strict mode, add tests for new features, and ensure Result pattern for error handling.
6. Submit a PR with a clear description.- Bug Fixes: Open an issue first.
- Features: Discuss in issues before implementing (e.g., new ORM adapters).
- Style: Follow ESLint config; prefer functional patterns over classes where possible.
- Publishing: The package is scoped as
@ignix/core`; ensure compatibility when adding features.---
This project is licensed under the MIT License - see the LICENSE file for details.
---
- Maintainer: Johny (Senior Architect, GDE, MVP)
- Email: johny@example.com (placeholder)
- GitHub Issues: For bugs or features
- Discord: Join our community at discord.gg/ignix (placeholder)
---
Made with ❤️ for passionate developers who hate mediocrity.