Skip to content

Migrate Azure Functions to NextJS Server Actions following architecture standards#2

Merged
mlynam merged 8 commits into
mainfrom
copilot/refactor-azure-functions-actions
Feb 4, 2026
Merged

Migrate Azure Functions to NextJS Server Actions following architecture standards#2
mlynam merged 8 commits into
mainfrom
copilot/refactor-azure-functions-actions

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 4, 2026

Refactors 47 Azure Functions into NextJS App Router server actions following the Netsurit architecture guidelines and existing migration guide. Organizes functions into type-based service domains with proper authentication, error handling, and database integration.

Service Architecture

10 domains, 47 server actions:

  • users/ (10) - Profile management, team assignments, file uploads
  • teams/ (9) - Metrics, meetings, coach management
  • weeks/ (6) - Current/past weeks, rollover, archiving
  • prompts/ (5) - AI prompt management and history
  • dreams/ (4) - Dream book, year vision, images
  • items/ (4) - Deprecated item CRUD operations
  • scoring/ (3) - Performance scoring across years
  • connects/ (3) - Connection record management
  • ai/ (2) - Image/vision generation stubs (require OpenAI integration)
  • admin/ (2) - Coaching alerts, health checks

Each domain has barrel exports for clean imports: import { getUserData } from '@/services/users'

Database Layer

Extended repositories with 15+ missing methods:

  • ConnectsRepository: upsertConnect()
  • ScoringRepository: getScoringDocument(userId, year)
  • TeamsRepository: getTeamRelationships(), createTeam(), updateTeam()
  • UserRepository: getAllUsers(), getUsersByIds(), updateUserProfile()
  • DreamsRepository: getDreamsDocuments()
  • ItemsRepository: New repository for deprecated container

Authentication

Three auth wrapper patterns:

// Standard user auth
export const getUserData = withAuth(async (user, userId: string) => { ... });

// Admin-only operations  
export const getAllUsers = withAdminAuth(async (user, filters) => { ... });

// Coach-specific actions
export const getCoachingAlerts = withCoachAuth(async (user) => { ... });

Response Pattern

Consistent ActionResult across all actions:

// Success
return createActionSuccess({ user, profile, dreams });

// Validation error
return createActionError('Forbidden');

// Exception handling  
return handleActionError(error, 'Failed to save user data');

Implementation Notes

  • All actions follow migration guide template: 'use server' directive, JSDoc, auth check, error handling
  • Business logic ported directly from Azure Functions with minimal changes
  • Type-safe throughout - no any types except for legacy dynamic properties
  • AI generation functions (generateImage, generateVision) are stubs awaiting OpenAI integration
  • Added @azure/storage-blob dependency for upload functions

Next Steps

  • Integrate OpenAI API for AI generation stubs
  • Update frontend components to consume server actions
  • Write unit tests for critical flows
  • Deprecate Azure Functions after verification
Original prompt

Follow the migration guide in this project and begin refactor the azure functions into server actions. Make sure you identify how to group the services into types so they can be organized according to your guidelines.

Custom agent used: Netsurit Architect
Enterprise-grade software architecture patterns and standards for TypeScript/NextJS projects. Use when architecting new projects, refactoring existing codebases, designing APIs, setting up monorepos, implementing authentication, data fetching patterns, or establishing team coding standards. Ensures maintainability, deployment readiness, and reduced cognitive load for both AI and human developers.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 7 commits February 4, 2026 04:58
… (4), Connects (3)

Co-authored-by: mlynam <2816612+mlynam@users.noreply.github.com>
Co-authored-by: mlynam <2816612+mlynam@users.noreply.github.com>
Co-authored-by: mlynam <2816612+mlynam@users.noreply.github.com>
- Add missing repository methods (upsertConnect, getScoringDocument, etc.)
- Create ItemsRepository for deprecated items container
- Fix all server actions to use repository methods instead of getContainer()
- Add @azure/storage-blob dependency for upload functions
- Fix lint warnings in idGenerator and BaseRepository
- All type checks and lints now pass successfully

Co-authored-by: mlynam <2816612+mlynam@users.noreply.github.com>
Complete documentation of Azure Functions to Server Actions migration with all metrics, benefits, and next steps.

Co-authored-by: mlynam <2816612+mlynam@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor Azure functions into server actions Migrate Azure Functions to NextJS Server Actions following architecture standards Feb 4, 2026
Copilot AI requested a review from mlynam February 4, 2026 05:29
@mlynam mlynam marked this pull request as ready for review February 4, 2026 20:14
@mlynam mlynam merged commit 5ef0e05 into main Feb 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants