saga-sm is a tRPC API service that provides schedule management functionality for Saga Connect, built with saga-soa infrastructure.
saga-soa is our shared infrastructure framework for building consistent APIs across different protocols:
- Multi-protocol support: REST endpoints, tRPC procedures, and TypeGraphQL resolvers
- Common patterns: Dependency injection, logging, database connections, and PubSub events
- Developer experience: Hot reloading, type safety, and consistent project structure
- Business logic organization: Sector-based architecture for domain separation
This project provides:
- Schedule CRUD operations: Create, read, update, delete schedules
- Real-time updates: PubSub events for schedule changes
- Type-safe API: Full TypeScript support from API to client
- Interactive testing: Web client for endpoint exploration and testing
saga-sm/
βββ apps/
β βββ api/ # tRPC API service (port 3000)
β β βββ src/
β β β βββ sectors/ # Business logic by domain
β β β β βββ schedule/ # Schedule management
β β β β βββ pubsub/ # Event definitions
β β β βββ main.ts # API bootstrap
β β β βββ inversify.config.ts
β β βββ package.json
β βββ web-client/ # Next.js test client (port 3001)
β βββ app/ # Testing interfaces
β β βββ endpoints/ # Interactive endpoint testing
β β βββ api-test/ # Connection testing
β β βββ schedule-demo/ # Live demo interface
β β βββ page.tsx # Home page
β βββ src/services/ # tRPC client integration
β βββ package.json
βββ scripts/ # Development setup automation
βββ package.json # Workspace orchestration
- Node.js >= 18
- pnpm >= 8
- MongoDB (local or remote)
- saga-soa repository (must be cloned alongside this project)
dev/
βββ saga-soa/ # Shared infrastructure (clone first)
βββ saga-sm/ # This project
1. Clone both repositories:
cd dev/
git clone [saga-soa-repo-url] saga-soa
git clone [saga-sm-repo-url] saga-sm2. Link saga-sm to saga-soa for concurrent development:
cd saga-sm
# Option A: pnpm link (recommended for active saga-soa development)
./scripts/setup-local-dev.sh
# Option B: file protocol (simpler, automatic updates)
./scripts/setup-file-protocol.sh3. Configure environment:
# Copy and customize API configuration
cp apps/api/.env.example apps/api/.env
# Update MongoDB URI and other settings as needed4. Start development servers:
# Terminal 1: Start saga-soa packages (if using pnpm link)
cd ../saga-soa && turbo run dev --filter='@saga-soa/*'
# Terminal 2: Start saga-sm applications
cd saga-sm && pnpm dev-
API Server: http://localhost:3000
- tRPC endpoints:
/trpc - Health check:
/health - PubSub port: 3002
- tRPC endpoints:
-
Web Client: http://localhost:3001
- Interactive endpoint testing
- Live schedule management demo
- Connection diagnostics
pnpm dev # Run both API and web client
pnpm build # Build all applications
pnpm test # Run all tests
pnpm check # Full validation (build + test + lint + typecheck)
pnpm lint # Lint all code
pnpm typecheck # TypeScript validation# API only
pnpm --filter @saga-sm/api dev
pnpm --filter @saga-sm/api test
# Web client only
pnpm --filter @saga-sm/web-client dev
pnpm --filter @saga-sm/web-client testFollowing saga-soa patterns:
- Sector-based organization - Business logic organized by domain
- Dependency injection - Using Inversify for service management
- tRPC API - Type-safe API endpoints
- PubSub events - Real-time event system
- 4-space indentation - Code style consistency
Next.js 15 application with App Router providing:
- Interactive Endpoint Testing - Full tRPC and HTTP testing interface
- Live Demo Interface - Schedule management with real-time updates
- Connection Diagnostics - API health monitoring
- Code Generation - Both tRPC client and cURL examples
- Dual Service Support - tRPC client and HTTP-based access
Pages:
/- Navigation hub with application overview/endpoints- Interactive API endpoint explorer/api-test- Connection testing and diagnostics/schedule-demo- Live schedule management interface
The tRPC API provides these schedule management endpoints:
schedule.getSchedules- Retrieve all schedulesschedule.getScheduleById- Get specific schedule by IDschedule.createSchedule- Create new scheduleschedule.updateSchedule- Update existing scheduleschedule.deleteSchedule- Remove schedule
Real-time events for schedule changes:
schedule:created- New schedule createdschedule:updated- Schedule modifiedschedule:deleted- Schedule removedschedule:started- Schedule execution beganschedule:completed- Schedule execution finished
pnpm test # All tests across workspace
pnpm --filter @saga-sm/api test # API tests only
pnpm --filter @saga-sm/web-client test # Client tests only- Unit tests: Individual function/class testing
- Integration tests: API endpoint and database testing
- Type checking: TypeScript validation across codebase
- saga-soa packages rebuild automatically when changed
- API server restarts on code changes
- Web client has instant hot reload
The web client provides comprehensive testing tools:
- Endpoint Explorer - Interactive forms for all API endpoints
- Dual Approach - Switch between tRPC client and HTTP calls
- Code Generation - Copy-ready code examples
- Response Inspection - Detailed API response analysis
- Real-time Updates - Live PubSub event monitoring
- Full TypeScript support throughout
- Shared type definitions (when available)
- End-to-end type safety from API to client
"saga-soa packages not found"
- Ensure saga-soa is cloned in the correct directory structure
- Re-run the setup script:
./scripts/setup-local-dev.sh
"Database connection failed"
- Check MongoDB is running locally or update
MONGODB_URIinapps/api/.env - Verify network connectivity to remote MongoDB instance
"Port already in use"
- API (3000), Web Client (3001), or PubSub (3002) ports are occupied
- Stop other services or update port configuration
"Hot reloading not working"
- Restart both terminal sessions
- Verify saga-soa packages are building with
turbo run dev
When ready for production:
- Update saga-soa dependencies to published npm packages
- Build applications:
pnpm build - Deploy API and web client independently
- Configure environment variables for production
- Explore the codebase: Start with
apps/api/src/sectors/schedule/ - Test the API: Use the web client to understand available endpoints
- Read saga-soa docs: Understand the underlying infrastructure patterns
- Make your first change: Add a new endpoint or modify existing logic