Quick Start Guide¶
Welcome to ABS Platform development! This guide will get you up and running with a local development environment in under 30 minutes.
Prerequisites¶
Before you begin, ensure you have the following installed:
Required Software¶
- Node.js 18+ - Download from nodejs.org
- npm 8+ - Comes with Node.js
- Git - Download from git-scm.com
- Docker & Docker Compose - Download from docker.com
- PostgreSQL 14+ - Download from postgresql.org (or use Docker)
Recommended Tools¶
- VS Code - Download from code.visualstudio.com
- VS Code Extensions:
- TypeScript and JavaScript Language Features
- GraphQL: Language Feature Support
- ESLint
- Prettier - Code formatter
- Docker
Project Setup¶
1. Clone the Repository¶
git clone https://github.com/OVES/abs-platform.git
cd abs-platform
2. Install Dependencies¶
# Install Node.js dependencies
npm install
# Verify installation
npm run verify
3. Environment Configuration¶
Create your local environment configuration:
# Copy environment template
cp .env.example .env.local
# Edit configuration (use your preferred editor)
code .env.local
Required Environment Variables:
# Database Configuration
DATABASE_URL=postgresql://abs_user:abs_password@localhost:5432/abs_platform
REDIS_URL=redis://localhost:6379
# MQTT Configuration
MQTT_BROKER_URL=mqtt://localhost:1883
MQTT_USERNAME=abs_platform
MQTT_PASSWORD=your_mqtt_password
# Authentication
JWT_SECRET=your_super_secret_jwt_key_here
JWT_EXPIRES_IN=24h
# External Integrations
ODOO_API_URL=http://localhost:8069
ODOO_DATABASE=abs_platform
ODOO_USERNAME=admin
ODOO_PASSWORD=admin
# Development Settings
NODE_ENV=development
LOG_LEVEL=debug
4. Start Infrastructure Services¶
Start the required infrastructure using Docker Compose:
# Start PostgreSQL, Redis, and MQTT broker
docker-compose up -d
# Verify services are running
docker-compose ps
5. Database Setup¶
Initialize the database schema and seed data:
# Run database migrations
npm run db:migrate
# Seed initial data
npm run db:seed
# Verify database setup
npm run db:verify
6. Start the Development Server¶
# Start the ABS Platform server
npm run dev
# Server should start on http://localhost:3000
7. Verify Installation¶
Open your browser and navigate to: - GraphQL Playground: http://localhost:3000/graphql - Health Check: http://localhost:3000/health - API Documentation: http://localhost:3000/docs
Development Workflow¶
Project Structure Overview¶
abs-platform/
├── src/ # Source code
│ ├── agents/ # Agent system implementation
│ ├── core/ # Core services and utilities
│ ├── fsm/ # Finite State Machine engine
│ ├── orchestrator/ # System orchestration
│ ├── resolvers/ # GraphQL resolvers
│ └── services/ # Business services
├── models/ # Business models and configurations
│ └── bss/ # Battery Swap Service model
├── schema/ # GraphQL schema definitions
├── docs/ # Documentation
├── tests/ # Test files
└── scripts/ # Utility scripts
Running Tests¶
# Run all tests
npm test
# Run tests in watch mode
npm run test:watch
# Run specific test file
npm test -- --testPathPattern=fsm
# Generate test coverage report
npm run test:coverage
Code Quality¶
# Check TypeScript compilation
npm run type-check
# Run ESLint
npm run lint
# Fix auto-fixable lint issues
npm run lint:fix
# Format code with Prettier
npm run format
# Run all quality checks
npm run quality-check
Development Commands¶
Essential Commands¶
# Development server with hot reload
npm run dev
# Build for production
npm run build
# Start production server
npm start
# Database operations
npm run db:migrate # Run migrations
npm run db:rollback # Rollback last migration
npm run db:seed # Seed test data
npm run db:reset # Reset database
# Testing
npm test # Run all tests
npm run test:unit # Run unit tests only
npm run test:integration # Run integration tests only
npm run test:e2e # Run end-to-end tests
Debugging¶
# Start server in debug mode
npm run dev:debug
# Debug with VS Code
# Use the "Launch Program" configuration in .vscode/launch.json
Working with the Codebase¶
Creating a New Agent¶
-
Create Agent File: Create a new file in
src/agents/// src/agents/my-new-agent.ts import { AgentFunction, AgentContext } from './types'; export const myNewAgent: AgentFunction = async ( request: any, servicePlan: any, context: AgentContext ) => { // Your agent logic here return { success: true, updatedState: context.state, outputs: [] }; }; -
Register Agent: Add to agent registry
// src/agents/plugin-registry.ts import { myNewAgent } from './my-new-agent'; export const agentRegistry = { // ... existing agents myNewAgent, }; -
Write Tests: Create test file
// tests/agents/my-new-agent.test.ts import { myNewAgent } from '../../src/agents/my-new-agent'; describe('myNewAgent', () => { it('should process requests correctly', async () => { // Your test implementation }); });
Creating GraphQL Resolvers¶
-
Define Schema: Add to
schema/abs.graphqltype Mutation { executeMyOperation(input: MyOperationInput!): MyOperationResult! } input MyOperationInput { servicePlanId: ID! operationData: JSON } type MyOperationResult { success: Boolean! message: String } -
Implement Resolver: Add to
src/resolvers/// src/resolvers/my-operation.ts export const myOperationResolver = async ( parent: any, args: { input: MyOperationInput }, context: GraphQLContext ) => { // Your resolver logic here return { success: true, message: "Operation completed successfully" }; };
Working with FSMs¶
- FSM Definition: Create FSM configuration in
models/*/fsm-definitions/ - Load FSM: Use the FSM engine to load and execute
import { FSMEngine } from '../src/fsm/engine'; const fsmEngine = new FSMEngine(); const result = await fsmEngine.processTransition( currentState, inputSignal, context );
Integration Testing¶
Create integration tests for complete workflows:
// tests/integration/service-workflow.test.ts
describe('Service Workflow Integration', () => {
it('should complete full service lifecycle', async () => {
// 1. Create service plan
const servicePlan = await createServicePlan(templateData);
// 2. Process service request
const result = await processServiceRequest(requestData);
// 3. Verify state transitions
expect(result.service_cycle_state).toBe('BATTERY_ISSUED');
// 4. Complete service
const completion = await completeService(servicePlan.id);
expect(completion.status).toBe('COMPLETE');
});
});
Common Development Tasks¶
Adding New Environment Variables¶
- Add to
.env.example: Document the new variable - Update Configuration: Add to
src/config/index.ts - Use in Code: Access via config object
import { config } from '../config'; const myValue = config.myNewVariable;
Database Schema Changes¶
-
Create Migration:
npm run migration:create -- --name add_new_table -
Edit Migration File: Add your schema changes
- Run Migration:
npm run db:migrate
Adding New Dependencies¶
# Add runtime dependency
npm install package-name
# Add development dependency
npm install --save-dev package-name
# Update TypeScript types if needed
npm install --save-dev @types/package-name
Troubleshooting¶
Common Issues¶
Port Already in Use¶
# Find process using port 3000
lsof -ti:3000
# Kill the process (macOS/Linux)
kill -9 $(lsof -ti:3000)
# Or use a different port
PORT=3001 npm run dev
Database Connection Issues¶
# Check if PostgreSQL is running
docker-compose ps
# Restart database
docker-compose restart postgres
# Check database logs
docker-compose logs postgres
MQTT Connection Issues¶
# Check MQTT broker status
docker-compose logs mosquitto
# Test MQTT connection
npx mqtt pub -t 'test/topic' -m 'hello world' -h localhost
Getting Help¶
- Documentation: Check
/docsfolder for detailed guides - Issues: Create GitHub issues for bugs or feature requests
- Discussions: Use GitHub Discussions for questions
- Code Review: Submit PRs for code review and feedback
Next Steps¶
Once you have the basic development environment running:
- Explore the Codebase: Review the existing agents and FSM implementations
- Run Example Workflows: Execute the example battery swap service workflows
- Read Architecture Docs: Understand the system design and patterns
- Join Development: Start contributing to the project
Recommended Learning Path¶
- Architecture Overview - Understand the system design
- FSM Engine Guide - Learn the state management patterns
- Agent Development Guide - Master the agent architecture
Happy coding! 🚀