Skip to content

Implement REST API Backend for ACP Mobile App #21

@jeremyeder

Description

@jeremyeder

Implement REST API Backend for ACP Mobile App

Overview

The ACP Mobile companion app requires a REST API backend with real-time updates via Server-Sent Events (SSE). This issue tracks the implementation of the backend services needed to support the mobile application.

Documentation

Implementation Plan

Phase 1: Authentication (Week 1)

  • Implement OAuth 2.0 + PKCE flow
  • Integrate with Red Hat SSO
  • Implement token refresh endpoint with automatic rotation
  • Test token expiration and refresh mechanisms

Endpoints:

  • POST /auth/login - Initiate OAuth flow, return authorization URL
  • POST /auth/token - Exchange authorization code for JWT tokens
  • POST /auth/refresh - Refresh access token using refresh token

Requirements:

  • PKCE support for mobile security
  • JWT tokens with configurable expiration (default: 1 hour)
  • Automatic token rotation on refresh
  • Red Hat SSO integration

Phase 2: Core APIs (Week 2)

  • Implement Sessions CRUD operations
  • Implement Repositories API
  • Implement User Profile & Preferences
  • Add comprehensive error handling and validation

Endpoints:

  • GET/POST /sessions - List and create AI coding sessions
  • GET/PATCH /sessions/{id} - Get and update session details
  • GET /sessions/{id}/logs - Get session execution logs
  • GET/POST/DELETE /repos - Manage connected repositories
  • GET/PATCH /user/profile - User profile management
  • GET/PATCH /user/preferences - User preferences (theme, notifications, quiet hours)

Data Models:

  • Sessions: Track AI workflow execution with status, progress, and task history
  • Repositories: User's connected GitHub repositories
  • User preferences: Theme, notification settings, quiet hours configuration

Phase 3: Real-time Updates (Week 3)

  • Implement SSE endpoint (GET /sse/sessions)
  • Send session progress events (session.progress)
  • Send session status transitions (session.status)
  • Send session updates (session.updated)
  • Test reconnection logic with exponential backoff

SSE Event Types:

  1. session.progress - Incremental progress updates (don't trigger cache invalidation)
  2. session.updated - Partial session changes (client merges into cache)
  3. session.status - Status transitions (trigger notifications if awaiting_review)
  4. notification.new - New GitHub notification (invalidates cache)
  5. notification.read - Notification marked as read (invalidates cache)

Requirements:

  • Persistent SSE connection with automatic reconnection
  • Events update client cache without full API refetch
  • Exponential backoff on reconnection (1s → 30s max)
  • Connection management for mobile (disconnect on background, reconnect on foreground)

Phase 4: GitHub Integration (Week 4)

  • Integrate GitHub API for notifications
  • Implement Notifications API
  • Add workflow suggestion logic (analyze notification type → suggest appropriate workflow)
  • Test notification flow end-to-end

Endpoints:

  • GET /notifications - List GitHub notifications with suggested workflows
  • PATCH /notifications/{id} - Mark notification as read
  • POST /notifications/{id}/mute - Mute notification thread

Workflow Suggestion Logic:

  • Pull requests → review workflow
  • Issues with "bug" label → bugfix workflow
  • Feature requests → plan workflow
  • General issues → research workflow

Phase 5: Polish & Production Readiness (Week 5)

  • Implement push token registration (POST /user/push-token)
  • Integrate Expo push notification service
  • Add comprehensive request/response validation (Zod/similar)
  • Security audit (SQL injection, XSS, auth bypass)
  • Performance testing (response times, SSE scalability)
  • Load testing with realistic mobile usage patterns

Technical Requirements

Security

  • All endpoints require authentication (except /auth/*)
  • OAuth 2.0 with PKCE for mobile security
  • JWT tokens with Bearer authentication
  • HTTPS only in production
  • Input validation on all endpoints
  • SQL injection and XSS prevention

Performance

  • Response time: <2 seconds for most endpoints
  • SSE: Streaming, indefinite connection support
  • Efficient database queries with proper indexing
  • Rate limiting on authenticated endpoints

Error Handling

  • Standard error response format:
    {
      "error": "ErrorType",
      "message": "Human-readable message",
      "details": {}
    }
  • Status codes: 200 (success), 201 (created), 204 (no content), 400 (bad request), 401 (unauthorized), 404 (not found), 500 (server error)
  • 401 responses trigger automatic client token refresh (max 1 retry)

Third-party Integrations

  1. Red Hat SSO - OAuth authentication provider
  2. GitHub API - Fetch notifications, repository metadata
  3. Expo Push Service - Send push notifications to mobile devices
  4. Claude API - Chat feature (future implementation)

Development Support

Client Mock Data

The mobile client includes comprehensive mocks for development:

  • Mock authentication (bypass OAuth)
  • Mock sessions with realistic data and SSE events
  • Mock GitHub notifications
  • Environment variable toggles for selective mocking

Environment Variables

EXPO_PUBLIC_API_BASE_URL=https://ambient-code.apps.rosa.vteam-stage.7fpc.p3.openshiftapps.com/api/v1
EXPO_PUBLIC_OAUTH_DOMAIN=sso.redhat.com
EXPO_PUBLIC_OAUTH_CLIENT_ID=acp-mobile

Reference Implementation

  • Client code: services/api/ (TypeScript API client)
  • Type definitions: types/ (data models)
  • Mock services: services/mock/ (expected behavior)

Acceptance Criteria

  • All endpoints from OpenAPI spec implemented and tested
  • OAuth 2.0 + PKCE authentication working with Red Hat SSO
  • SSE connection stable with automatic reconnection
  • GitHub notifications integration functional
  • Push notifications working via Expo Push Service
  • All endpoints validated with request/response schemas
  • Security audit completed and issues addressed
  • Performance testing shows <2s response times
  • Production deployment successful on staging environment

Contact

For questions or clarification: Jeremy Eder (jeder@redhat.com)


Related: This backend will power the ACP Mobile companion app for AI-assisted development workflows. The client is built with React Native + Expo and uses React Query for data management.

Metadata

Metadata

Assignees

No one assigned

    Labels

    apiREST API relatedbackendBackend API implementationenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions