This guide covers development workflows, best practices, and common tasks when working with the PSA platform.
- Docker Engine 24.0.0+
- Docker Compose v2.20.0+
- Node.js 18+
- Git
- VS Code (recommended)
- Clone and setup:
git clone https://github.com/your-org/alga-psa.git
cd alga-psa
cp .env.example .env.development
- Create development secrets:
mkdir -p secrets
# Create development secrets with dummy values
echo "dev-password" > secrets/db_password_server
echo "dev-password" > secrets/db_password_hocuspocus
# ... create other required secrets
chmod 600 secrets/*
- Start development environment:
# For Community Edition
docker compose -f docker-compose.base.yaml -f docker-compose.ce.yaml up
# For Enterprise Edition
docker compose -f docker-compose.base.yaml -f docker-compose.ee.yaml up
alga-psa/
├── server/ # Main application server
│ ├── src/ # Source code
│ ├── migrations/ # Database migrations
│ └── tests/ # Test files
├── hocuspocus/ # Real-time collaboration
├── redis/ # Redis configuration
└── setup/ # Setup and initialization
main
: Production-ready codedevelop
: Integration branchfeature/*
: New featuresfix/*
: Bug fixesrelease/*
: Release preparation
- Create feature branch:
git checkout -b feature/your-feature
- Start development environment:
docker compose -f docker-compose.base.yaml -f docker-compose.ce.yaml up
- Make changes and test
- Commit changes:
git add .
git commit -m "feat: description"
- Push and create PR:
git push origin feature/your-feature
- Create new migration:
cd server
npm run migrate:make your_migration_name
- Run migrations:
npm run migrate:latest
- Rollback:
npm run migrate:rollback
- Run all tests:
npm test
- Run specific tests:
npm test -- path/to/test
- Watch mode:
npm test -- --watch
- Rebuild specific service:
docker compose build server
- View logs:
docker compose logs -f [service]
- Restart service:
docker compose restart [service]
- Clean up:
docker compose down -v
- Follow ESLint configuration
- Use TypeScript for type safety
- Follow existing patterns
- Document complex logic
- Write meaningful commit messages
- Write tests for new features
- Maintain test coverage
- Use meaningful test descriptions
- Test edge cases
- Mock external dependencies
- Keep images minimal
- Use multi-stage builds
- Don't store secrets in images
- Use proper cache busting
- Tag images appropriately
- Never commit secrets
- Use environment variables
- Validate user input
- Follow OWASP guidelines
- Regular dependency updates
- Enable debug logs:
docker compose up -f docker-compose.base.yaml -f docker-compose.ce.yaml -e DEBUG=true
- Use VS Code debugger:
- Launch configuration provided
- Breakpoints supported
- Variable inspection
- Call stack tracking
- Connect to database:
docker compose exec postgres psql -U psa_user psa_db
- View logs:
docker compose logs postgres
- Redis CLI:
docker compose exec redis redis-cli
- Monitor all Redis events:
docker compose exec redis redis-cli monitor
- Monitor event streams:
# Monitor all events
docker compose exec redis redis-cli psubscribe "alga-psa:event:*"
# Monitor specific event type
docker compose exec redis redis-cli psubscribe "alga-psa:event:TICKET_UPDATED"
- View event bus subscribers:
docker compose exec redis redis-cli pubsub channels "alga-psa:event:*"
- Debug event bus configuration:
# Check Redis connection
docker compose exec redis redis-cli ping
# View event bus channels
docker compose exec redis redis-cli pubsub channels
# Check channel subscribers
docker compose exec redis redis-cli pubsub numsub channel_name
The event bus system uses Redis for event streaming. Configure through environment variables:
# Redis Configuration
REDIS_URL=redis://localhost:6379
REDIS_PREFIX=alga-psa:
REDIS_EVENT_PREFIX=event:
REDIS_RECONNECT_RETRIES=10
REDIS_RECONNECT_INITIAL_DELAY=100
REDIS_RECONNECT_MAX_DELAY=3000
- Create new event types:
// In server/src/lib/eventBus/events.ts
export const EventTypeEnum = z.enum([
'YOUR_NEW_EVENT',
// ... other events
]);
export const YourEventPayloadSchema = BasePayloadSchema.extend({
// Define your event payload schema
// BasePayloadSchema already includes tenantId
});
// Add to EventPayloadSchemas
export const EventPayloadSchemas = {
YOUR_NEW_EVENT: YourEventPayloadSchema,
// ... other schemas
};
- Create event subscriber:
// In server/src/lib/eventBus/subscribers/yourSubscriber.ts
import { eventBus } from '../index';
import { YourEvent, EventType } from '../events';
async function handleYourEvent(event: YourEvent): Promise<void> {
const { tenantId } = event.payload;
// Handle the event
}
export async function registerYourSubscriber(): Promise<void> {
await eventBus.subscribe(
'YOUR_NEW_EVENT',
handleYourEvent
);
}
- Publish events:
import { eventBus } from 'lib/eventBus';
await eventBus.publish({
eventType: 'YOUR_NEW_EVENT',
payload: {
tenantId: 'tenant-id',
// Your event data
},
});
- Create event bus mocks:
// In your test file
jest.mock('lib/eventBus', () => ({
eventBus: {
publish: jest.fn(),
subscribe: jest.fn(),
},
}));
- Test event publishing:
test('should publish event', async () => {
const event = {
eventType: 'YOUR_NEW_EVENT',
payload: {
tenantId: 'test-tenant',
// ... other payload data
},
};
await yourFunction();
expect(eventBus.publish).toHaveBeenCalledWith(
expect.objectContaining(event)
);
});
- Test event handling:
test('should handle event', async () => {
const event = {
id: 'test-id',
eventType: 'YOUR_NEW_EVENT',
timestamp: new Date().toISOString(),
payload: {
tenantId: 'test-tenant',
// ... other payload data
},
};
await handleYourEvent(event);
// Assert expected behavior
});
- Index frequently queried fields
- Optimize complex queries
- Regular VACUUM
- Monitor query performance
- Use caching effectively
- Optimize API responses
- Implement pagination
- Profile memory usage
- Optimize image sizes
- Use volume mounts
- Configure resource limits
- Monitor container stats
-
Database Connection Issues
- Check credentials
- Verify host/port
- Check network connectivity
-
Redis Connection Issues
- Verify password
- Check persistence config
- Monitor memory usage
-
Build Issues
- Clear Docker cache
- Update dependencies
- Check Dockerfile syntax
# Check service status
docker compose ps
# View service logs
docker compose logs [service]
# Check network
docker network inspect alga-psa_default
# Container shell access
docker compose exec [service] sh
- Docker
- ESLint
- Prettier
- TypeScript
- GitLens
- REST Client
- Development setup:
./scripts/dev-setup.sh
- Test data generation:
./scripts/generate-test-data.sh
- Dependency updates:
./scripts/update-deps.sh