Some checks are pending
Bidi Control Character Guard / bidi-control-guard (push) Waiting to run
Circular Dependency Check / Check for new circular dependencies (push) Waiting to run
Citus Migration Smoke / Combined migrations on single-node Citus (push) Waiting to run
E2E Fresh Install Tests / fresh-install-e2e (push) Waiting to run
ext-v2 guardrails / Run ext-v2 guard and ESLint (push) Waiting to run
Integration Tests / Check for relevant changes (push) Waiting to run
Integration Tests / ${{ (github.event_name == 'schedule' || github.event.inputs.suite == 'full') && 'Full integration suite' || 'Tier-1 integration subset' }} (push) Blocked by required conditions
Mobile checks / Mobile lint + typecheck (push) Waiting to run
Mobile checks / Mobile unit tests (push) Waiting to run
Mobile checks / Mobile dependency audit (report) (push) Waiting to run
Mobile checks / Mobile reproducibility checks (push) Waiting to run
Secrets guard (env backups) / Ensure no tracked env backup files (push) Waiting to run
Temporal Readiness / fast-readiness (push) Waiting to run
Temporal Readiness / docker-parity (push) Waiting to run
TypeScript Type Check / Nx affected typecheck (push) Waiting to run
Unit Tests / Skipped-test budget (push) Waiting to run
Unit Tests / Nx affected unit tests (push) Waiting to run
Unit Tests / Server unit coverage (informational) (push) Waiting to run
Validate Tenant Management Schema / Check for relevant changes (push) Waiting to run
Validate Tenant Management Schema / Validate Tenant Management Schema (push) Blocked by required conditions
EE Workflows Build Guard / ee-workflows-build-guard (push) Waiting to run
Excluded: .git, node_modules, secrets/, compose.env, assemblyscript tgz Source: /opt/alga-psa on psa.joliet.tech
3.9 KiB
3.9 KiB
AI Coding Assistant Guide
This document provides guidance for AI coding assistants working with the Alga PSA codebase.
Prerequisites
- Node.js 20.0.0 or higher is required for this project
- Understanding of TypeScript, Next.js 14, and PostgreSQL
- Familiarity with REST API design patterns
Key Architectural Patterns
1. V2 Controller Pattern
All new APIs should use the V2 controller pattern located in /src/lib/api/controllers/. This pattern:
- Handles authentication inline to avoid circular dependencies
- Uses Zod schemas for validation
- Implements consistent error handling
- Supports tenant isolation
Example structure:
export class ApiXxxControllerV2 extends ApiBaseControllerV2 {
constructor() {
super(xxxService, {
resource: 'xxx',
createSchema: createXxxSchema,
updateSchema: updateXxxSchema,
querySchema: xxxListQuerySchema,
permissions: {
create: 'create',
read: 'read',
update: 'update',
delete: 'delete',
list: 'read'
}
});
}
}
2. Service Layer Pattern
Business logic should be in service files located in /src/lib/services/:
- Keep controllers thin
- Services handle database operations
- Use transactions for data consistency
- Implement proper error handling
3. Database Patterns
- Use Knex.js for database queries
- Always include tenant isolation (
tenant_id) - Use migrations for schema changes
- Follow naming conventions (snake_case for DB, camelCase for JS)
4. Testing Requirements
All new features must include:
- E2E tests in
/src/test/e2e/ - Test factories for data generation
- Both positive and negative test cases
- Authentication and authorization tests
Common Tasks
Adding a New API Endpoint
- Create the V2 controller in
/src/lib/api/controllers/ - Define Zod schemas in
/src/lib/schemas/ - Update route files in
/src/app/api/v1/ - Write E2E tests
- Update documentation
Modifying Database Schema
- Create a migration file:
npm run migrate:make <name> - Write up and down migrations
- Run migrations:
npm run migrate - Update TypeScript interfaces
- Update affected services and controllers
Working with Authentication
- REST APIs use API keys (X-API-KEY header)
- Web interface uses session-based auth
- Always verify tenant context
- Check permissions before operations
Code Quality Standards
TypeScript
- Use strict mode
- Define proper interfaces
- Avoid
anytypes - Use type guards where needed
Error Handling
- Use consistent error classes
- Return appropriate HTTP status codes
- Include helpful error messages
- Log errors appropriately
Performance
- Use database indexes appropriately
- Implement pagination for list endpoints
- Cache frequently accessed data
- Optimize N+1 queries
Important Files and Directories
/src/lib/api/controllers/- V2 API controllers/src/lib/services/- Business logic services/src/lib/schemas/- Zod validation schemas/src/app/api/v1/- API route definitions/src/test/e2e/- End-to-end tests/migrations/- Database migrations/docs/- Project documentation
Debugging Tips
- Check logs in
/logs/directory - Use
npm run test:watchfor TDD - Verify tenant context in all queries
- Check API key permissions
- Review error responses for clues
Common Pitfalls to Avoid
- Circular Dependencies: Use inline authentication in V2 controllers
- Missing Tenant Context: Always include tenant_id in queries
- Inadequate Validation: Use Zod schemas for all inputs
- Poor Error Messages: Provide clear, actionable error messages
- Skipping Tests: Always write E2E tests for new features
Getting Help
- Review existing V2 controllers for examples
- Check
/docs/api-migration-summary.mdfor patterns - Look at test files for usage examples
- Follow established conventions in the codebase