Development Guide
Development practices and patterns
Development practices for contributing to 2LY.
Code Style
TypeScript
- Use strict mode
- Explicit return types
- Prefer interfaces over types
- Use const for immutable values
Formatting
npm run lint
npm run formatArchitecture Patterns
Service Pattern
Services handle business logic:
@injectable()
export class RuntimeService {
async createRuntime(data: RuntimeInput): Promise<Runtime> {
// Business logic here
}
}Repository Pattern
Repositories handle data access:
@injectable()
export class RuntimeRepository {
async findById(id: string): Promise<Runtime | null> {
// Data access here
}
}Dependency Injection
Use Inversify for DI:
container.bind<RuntimeService>(TYPES.RuntimeService)
.to(RuntimeService)
.inSingletonScope();Testing
Unit Tests
describe('RuntimeService', () => {
it('should create runtime', async () => {
// Test implementation
});
});Integration Tests
Test component integration, mock external services.
Running Tests
npm run test
npm run test:watch
npm run test:coverageAdding Features
1. Plan
- Create GitHub issue
- Discuss approach
- Get feedback
2. Implement
- Create feature branch
- Write tests first (TDD)
- Implement feature
- Update docs
3. Submit
- Create pull request
- Address review feedback
- Merge when approved
Common Tasks
Adding NATS Message
- Create message class in
packages/common/src/messages/ - Implement
serialize()anddeserialize() - Register in message registry
- Add handler in backend/runtime
Adding GraphQL Resolver
- Update schema in
packages/common/schema/apollo.schema.graphql - Generate types:
npm run generate - Implement resolver in
packages/backend/src/database/resolvers.ts - Add tests
Adding Frontend Component
- Create in
packages/frontend/src/components/ - Use Tailwind for styling
- Follow existing patterns
- Add to Storybook if reusable
Best Practices
- Keep it simple: Solve the problem, nothing more
- Write tests: Test before implementation
- Document: Code comments and README updates
- Small PRs: Easier to review and merge
- Ask questions: Better to ask than assume
See Development Setup for environment details.