# apnileapos-hub/ap-v2 architecture

> Architecture diagram of the GitHub repository apnileapos-hub/ap-v2, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/apnileapos-hub/ap-v2
- Repository: https://github.com/apnileapos-hub/ap-v2

## Overview

#### Purpose and Repository Shape
APNILEAP v2 is a pnpm/Turborepo monorepo for an education, project-management, collaboration, and enterprise-platform product. It combines Next.js user interfaces, NestJS backend services, a reusable platform kernel, and an AI runtime. Root development entry is `package.json` via `pnpm dev`; workspace topology is in `pnpm-workspace.yaml` and `turbo.json`.

#### User-Facing Applications
Three Next.js App Router surfaces are present:
- **Workspace** is the role-based collaboration UI (dashboards, projects, chat, meetings, tasks, team) with authentication and WebSocket/API clients. Paths: `apps/workspace/src/app/layout.tsx`, `apps/workspace/src/app/(workspace)/projects/[id]/page.tsx`, `apps/workspace/src/lib/apiClient.ts`.
- **Admin** provides configuration, database, identity, infrastructure, integrations, and observability views. Paths: `apps/admin/app/layout.tsx`, `apps/admin/app/infrastructure/page.tsx`, `apps/admin/src/lib/AuthContext.tsx`.
- **Web** is a broad module-oriented portal for project management and SIS/academic workflows. Paths: `apps/web/app/page.tsx`, `apps/web/src/modules/project-management/hooks/useProjectApi.ts`, `apps/web/src/modules/sis/academic-planning/planner/page.tsx`.

#### Primary Business Backend
`services/project-service` is the main NestJS domain backend, entered at `services/project-service/src/main.ts` and assembled by `services/project-service/src/app.module.ts`. Its application layer exposes controllers, commands, queries, policies, and standard responses; the domain layer models academic, industry, research, project, workspace, communication, and operational contexts. Paths: `services/project-service/src/application/controllers/ProjectProvisioningController.ts`, `services/project-service/src/domains/academic-projects/AcademicProjectsModule.ts`, `services/project-service/src/domains/project-intelligence/knowledge/RAGPipeline.ts`.

Primary request flow is UI → API client → project-service controller → application command/query/service → domain aggregates/engines → persistence or external provider. RBAC and correlation/error boundaries are represented by `services/project-service/src/application/policies/RbacGuard.ts` and `services/project-service/src/application/middlewares/CorrelationIdMiddleware.ts`.

#### Provisioning, Integration, and Synchronization
Project/workspace creation is modeled as staged provisioning: template resolution, validation, external execution, and verification. Provider adapters target Atlassian and GitHub, isolating domain workflow from vendor APIs. Paths: `services/project-service/src/domains/project-provisioning/services/pipeline/ProvisioningPipelineManager.ts`, `services/project-service/src/domains/project-provisioning/providers/ProviderFactory.ts`, `services/project-service/src/domains/synchronization/pipeline/SynchronizationPipeline.ts`.

The enterprise control-plane service separately centralizes connectors, integration contracts, sagas, webhooks, and sync orchestration. Paths: `services/ecp-service/src/modules/ecp/EcpModule.ts`, `services/ecp-service/src/modules/ecp/integration/SagaOrchestrator.ts`, `services/ecp-service/src/modules/ecp/business/SynchronizationEngine.ts`.

#### AI Execution Platform
`services/apai-runtime` is a NestJS AI runtime with an API/controller edge, execution pipeline, agent planning/orchestration, model routing, governance, prompts, knowledge retrieval, and memory. Paths: `services/apai-runtime/src/main.ts`, `services/apai-runtime/src/modules/apai/core/runtime/execution/AIExecutionPipeline.ts`, `services/apai-runtime/src/modules/apai/core/agents/orchestration/AgentOrchestrator.ts`.

AI flow: request/session context → policy/security and prompt resolution → provider capability routing and quota/cost controls → optional agents/tools/retrieval → audited response and telemetry. Model adapters include Ollama and mock support; project service integrates AI through `services/project-service/src/infrastructure/ai-orchestration/AiOrchestratorAdapter.ts`.

#### Data, Messaging, and External Boundaries
Prisma schemas define relational persistence for the main project and AI runtime services: `services/project-service/prisma/schema.prisma` and `services/apai-runtime/prisma/schema.prisma`. The control plane declares connectors for PostgreSQL, Redis, RabbitMQ, and MinIO: `services/ecp-service/src/modules/ecp/data/PostgreSqlConnector.ts`, `services/ecp-service/src/modules/ecp/data/RabbitMqConnector.ts`, `services/ecp-service/src/modules/ecp/data/MinIoConnector.ts`.

External-service boundaries include Atlassian/Jira/Confluence, GitHub, Google Workspace, Microsoft 365, Loom, Slack/email, LLM providers, and WebRTC infrastructure. Relevant adapters: `services/ecp-service/src/modules/ecp/business/AtlassianConnector.ts`, `services/ecp-service/src/modules/ecp/ai/AiProviderRouter.ts`, `services/project-service/src/domains/communications/gateways/WebRTCSignalingGateway.ts`.

#### Shared Platform and Deployment
`packages/core` defines a generic modular platform: dependency container, kernel lifecycle, module registry, navigation, permissions, and plugin runtime. Paths: `packages/core/src/kernel/PlatformKernel.ts`, `packages/core/src/registry/ModuleRegistry.ts`, `packages/core/src/plugins/PluginManager.ts`. Shared placeholders/packages exist for database, SDK, UI, and shared code.

Deployment material is strongest for APAI runtime, with Docker, Kubernetes, and Helm artifacts: `services/apai-runtime/deploy/docker/Dockerfile`, `services/apai-runtime/deploy/kubernetes/k8s-deployment.yaml`, `services/apai-runtime/deploy/helm/apai-runtime/values.yaml`. A legacy Express-era backend remains under `apps/legacy-backend/` and is explicitly marked obsolete by `apps/legacy-backend/OBSOLETE_FOR_V2.md`.

Main entry points: [`services/project-service/src/domains/academic-projects/AcademicProjectsModule.ts`](https://github.com/apnileapos-hub/ap-v2/blob/main/services/project-service/src/domains/academic-projects/AcademicProjectsModule.ts) (Domain contexts), [`apps/workspace/src/lib/apiClient.ts`](https://github.com/apnileapos-hub/ap-v2/blob/main/apps/workspace/src/lib/apiClient.ts) (API clients), [`services/project-service/src/domains/project-provisioning/services/pipeline/ProvisioningPipelineManager.ts`](https://github.com/apnileapos-hub/ap-v2/blob/main/services/project-service/src/domains/project-provisioning/services/pipeline/ProvisioningPipelineManager.ts) (Provisioning pipeline), [`services/apai-runtime/src/modules/apai/core/runtime/execution/AIExecutionPipeline.ts`](https://github.com/apnileapos-hub/ap-v2/blob/main/services/apai-runtime/src/modules/apai/core/runtime/execution/AIExecutionPipeline.ts) (AI execution pipeline)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_apps["User applications"]
  node_workspace["Workspace<br/>Next.js collaboration UI<br/>[layout.tsx]"]
  node_admin["Admin<br/>[layout.tsx]"]
  node_web["Web portal<br/>Next.js SIS/project UI<br/>[page.tsx]"]
  node_project_api["API clients<br/>UI API boundary<br/>[apiClient.ts]"]
end

subgraph group_project["Project domain backend"]
  node_project_service["Project service<br/>NestJS domain API<br/>[main.ts]"]
  node_request_boundary["Request policy boundary<br/>RBAC and correlation<br/>[RbacGuard.ts]"]
  node_application_layer["Application layer<br/>controllers, commands, queries"]
  node_project_domain["Domain contexts<br/>aggregates and engines"]
  node_provisioning["Provisioning pipeline<br/>staged workflow"]
  node_project_data[("Project database<br/>Prisma relational store<br/>[schema.prisma]")]
end

subgraph group_ai["AI platform"]
  node_apai["APAI runtime<br/>NestJS AI API<br/>[main.ts]"]
  node_ai_execution["AI execution pipeline<br/>governed execution"]
  node_agent_orchestration["Agent orchestration<br/>agents, tools, retrieval"]
  node_ai_data[("AI database<br/>Prisma relational store<br/>[schema.prisma]")]
  node_apai_deployment["APAI deployment<br/>Docker, Kubernetes, Helm"]
end

subgraph group_control["Enterprise control plane"]
  node_ecp["ECP service<br/>integration control plane<br/>[EcpModule.ts]"]
  node_sync_orchestration["Sync and sagas<br/>orchestration layer"]
  node_control_data[("Control-plane connectors<br/>Postgres, Redis, RabbitMQ, MinIO")]
end

subgraph group_platform["Shared platform"]
  node_platform_kernel{{"Platform kernel<br/>modular runtime<br/>[PlatformKernel.ts]"}}
end

node_external_providers["External providers<br/>vendor and infrastructure boundary<br/>[ProviderFactory.ts]"]

node_workspace -->|"uses"| node_project_api
node_admin -->|"admin APIs"| node_project_api
node_web -->|"domain APIs"| node_project_api
node_project_api -->|"requests"| node_project_service
node_project_service -->|"enters through"| node_request_boundary
node_request_boundary -->|"authorizes"| node_application_layer
node_application_layer -->|"commands and queries"| node_project_domain
node_project_domain -->|"persists"| node_project_data
node_project_domain -->|"provisions"| node_provisioning
node_provisioning -->|"delegates integrations"| node_ecp
node_ecp -->|"coordinates"| node_sync_orchestration
node_sync_orchestration -->|"uses"| node_control_data
node_provisioning -->|"executes via"| node_external_providers
node_sync_orchestration -->|"connects to"| node_external_providers
node_project_domain -->|"AI orchestration"| node_apai
node_apai -->|"executes"| node_ai_execution
node_ai_execution -.->|"optional agents/tools"| node_agent_orchestration
node_ai_execution -->|"audits and stores"| node_ai_data
node_agent_orchestration -->|"LLM and retrieval"| node_external_providers
node_apai_deployment -.->|"deploys"| node_apai
node_platform_kernel -.->|"shared platform capability"| node_project_service
node_platform_kernel -.->|"shared platform capability"| node_workspace

click node_workspace "https://github.com/apnileapos-hub/ap-v2/blob/main/apps/workspace/src/app/layout.tsx"
click node_admin "https://github.com/apnileapos-hub/ap-v2/blob/main/apps/admin/app/layout.tsx"
click node_web "https://github.com/apnileapos-hub/ap-v2/blob/main/apps/web/app/page.tsx"
click node_project_api "https://github.com/apnileapos-hub/ap-v2/blob/main/apps/workspace/src/lib/apiClient.ts"
click node_project_service "https://github.com/apnileapos-hub/ap-v2/blob/main/services/project-service/src/main.ts"
click node_request_boundary "https://github.com/apnileapos-hub/ap-v2/blob/main/services/project-service/src/application/policies/RbacGuard.ts"
click node_application_layer "https://github.com/apnileapos-hub/ap-v2/blob/main/services/project-service/src/application/controllers/ProjectProvisioningController.ts"
click node_project_domain "https://github.com/apnileapos-hub/ap-v2/blob/main/services/project-service/src/domains/academic-projects/AcademicProjectsModule.ts"
click node_provisioning "https://github.com/apnileapos-hub/ap-v2/blob/main/services/project-service/src/domains/project-provisioning/services/pipeline/ProvisioningPipelineManager.ts"
click node_project_data "https://github.com/apnileapos-hub/ap-v2/blob/main/services/project-service/prisma/schema.prisma"
click node_ecp "https://github.com/apnileapos-hub/ap-v2/blob/main/services/ecp-service/src/modules/ecp/EcpModule.ts"
click node_sync_orchestration "https://github.com/apnileapos-hub/ap-v2/blob/main/services/ecp-service/src/modules/ecp/integration/SagaOrchestrator.ts"
click node_control_data "https://github.com/apnileapos-hub/ap-v2/blob/main/services/ecp-service/src/modules/ecp/data/RabbitMqConnector.ts"
click node_apai "https://github.com/apnileapos-hub/ap-v2/blob/main/services/apai-runtime/src/main.ts"
click node_ai_execution "https://github.com/apnileapos-hub/ap-v2/blob/main/services/apai-runtime/src/modules/apai/core/runtime/execution/AIExecutionPipeline.ts"
click node_agent_orchestration "https://github.com/apnileapos-hub/ap-v2/blob/main/services/apai-runtime/src/modules/apai/core/agents/orchestration/AgentOrchestrator.ts"
click node_ai_data "https://github.com/apnileapos-hub/ap-v2/blob/main/services/apai-runtime/prisma/schema.prisma"
click node_platform_kernel "https://github.com/apnileapos-hub/ap-v2/blob/main/packages/core/src/kernel/PlatformKernel.ts"
click node_external_providers "https://github.com/apnileapos-hub/ap-v2/blob/main/services/project-service/src/domains/project-provisioning/providers/ProviderFactory.ts"
click node_apai_deployment "https://github.com/apnileapos-hub/ap-v2/blob/main/services/apai-runtime/deploy/kubernetes/k8s-deployment.yaml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_workspace,node_admin,node_web,node_project_api toneBlue
class node_project_service,node_request_boundary,node_application_layer,node_project_domain,node_provisioning,node_project_data toneAmber
class node_apai,node_ai_execution,node_agent_orchestration,node_ai_data,node_apai_deployment toneMint
class node_ecp,node_sync_orchestration,node_control_data toneRose
class node_platform_kernel toneIndigo
class node_external_providers toneNeutral
```

## Components

### User applications

- [Workspace](https://github.com/apnileapos-hub/ap-v2/blob/main/apps/workspace/src/app/layout.tsx): Next.js collaboration UI · `apps/workspace/src/app/layout.tsx`
- [Admin](https://github.com/apnileapos-hub/ap-v2/blob/main/apps/admin/app/layout.tsx): Next.js admin UI · `apps/admin/app/layout.tsx`
- [Web portal](https://github.com/apnileapos-hub/ap-v2/blob/main/apps/web/app/page.tsx): Next.js SIS/project UI · `apps/web/app/page.tsx`
- [API clients](https://github.com/apnileapos-hub/ap-v2/blob/main/apps/workspace/src/lib/apiClient.ts): UI API boundary · `apps/workspace/src/lib/apiClient.ts`

### Project domain backend

- [Project service](https://github.com/apnileapos-hub/ap-v2/blob/main/services/project-service/src/main.ts): NestJS domain API · `services/project-service/src/main.ts`
- [Request policy boundary](https://github.com/apnileapos-hub/ap-v2/blob/main/services/project-service/src/application/policies/RbacGuard.ts): RBAC and correlation · Guards requests and establishes correlation/error context. · `services/project-service/src/application/policies/RbacGuard.ts`
- [Application layer](https://github.com/apnileapos-hub/ap-v2/blob/main/services/project-service/src/application/controllers/ProjectProvisioningController.ts): controllers, commands, queries · `services/project-service/src/application/controllers/ProjectProvisioningController.ts`
- [Domain contexts](https://github.com/apnileapos-hub/ap-v2/blob/main/services/project-service/src/domains/academic-projects/AcademicProjectsModule.ts): aggregates and engines · Academic, project, workspace, communication, and operational domains. · `services/project-service/src/domains/academic-projects/AcademicProjectsModule.ts`
- [Provisioning pipeline](https://github.com/apnileapos-hub/ap-v2/blob/main/services/project-service/src/domains/project-provisioning/services/pipeline/ProvisioningPipelineManager.ts): staged workflow · Resolves templates, validates, executes providers, and verifies. · `services/project-service/src/domains/project-provisioning/services/pipeline/ProvisioningPipelineManager.ts`
- [Project database](https://github.com/apnileapos-hub/ap-v2/blob/main/services/project-service/prisma/schema.prisma): Prisma relational store · `services/project-service/prisma/schema.prisma`

### AI platform

- [APAI runtime](https://github.com/apnileapos-hub/ap-v2/blob/main/services/apai-runtime/src/main.ts): NestJS AI API · `services/apai-runtime/src/main.ts`
- [AI execution pipeline](https://github.com/apnileapos-hub/ap-v2/blob/main/services/apai-runtime/src/modules/apai/core/runtime/execution/AIExecutionPipeline.ts): governed execution · Applies policy, prompts, routing, quotas, retrieval, audit, and telemetry. · `services/apai-runtime/src/modules/apai/core/runtime/execution/AIExecutionPipeline.ts`
- [Agent orchestration](https://github.com/apnileapos-hub/ap-v2/blob/main/services/apai-runtime/src/modules/apai/core/agents/orchestration/AgentOrchestrator.ts): agents, tools, retrieval · `services/apai-runtime/src/modules/apai/core/agents/orchestration/AgentOrchestrator.ts`
- [AI database](https://github.com/apnileapos-hub/ap-v2/blob/main/services/apai-runtime/prisma/schema.prisma): Prisma relational store · `services/apai-runtime/prisma/schema.prisma`
- [APAI deployment](https://github.com/apnileapos-hub/ap-v2/blob/main/services/apai-runtime/deploy/kubernetes/k8s-deployment.yaml): Docker, Kubernetes, Helm · `services/apai-runtime/deploy/kubernetes/k8s-deployment.yaml`

### Enterprise control plane

- [ECP service](https://github.com/apnileapos-hub/ap-v2/blob/main/services/ecp-service/src/modules/ecp/EcpModule.ts): integration control plane · `services/ecp-service/src/modules/ecp/EcpModule.ts`
- [Sync and sagas](https://github.com/apnileapos-hub/ap-v2/blob/main/services/ecp-service/src/modules/ecp/integration/SagaOrchestrator.ts): orchestration layer · Coordinates connector contracts, webhooks, and synchronization. · `services/ecp-service/src/modules/ecp/integration/SagaOrchestrator.ts`
- [Control-plane connectors](https://github.com/apnileapos-hub/ap-v2/blob/main/services/ecp-service/src/modules/ecp/data/RabbitMqConnector.ts): Postgres, Redis, RabbitMQ, MinIO · `services/ecp-service/src/modules/ecp/data/RabbitMqConnector.ts`

### Shared platform

- [Platform kernel](https://github.com/apnileapos-hub/ap-v2/blob/main/packages/core/src/kernel/PlatformKernel.ts): modular runtime · Provides lifecycle, module registry, permissions, navigation, and plugins. · `packages/core/src/kernel/PlatformKernel.ts`

### Other components

- [External providers](https://github.com/apnileapos-hub/ap-v2/blob/main/services/project-service/src/domains/project-provisioning/providers/ProviderFactory.ts): vendor and infrastructure boundary · Atlassian, GitHub, productivity, communications, LLM, and WebRTC services. · `services/project-service/src/domains/project-provisioning/providers/ProviderFactory.ts`

## Connections

- Workspace → API clients: uses
- Admin → API clients: admin APIs
- Web portal → API clients: domain APIs
- API clients → Project service: requests
- Project service → Request policy boundary: enters through
- Request policy boundary → Application layer: authorizes
- Application layer → Domain contexts: commands and queries
- Domain contexts → Project database: persists
- Domain contexts → Provisioning pipeline: provisions
- Provisioning pipeline → ECP service: delegates integrations
- ECP service → Sync and sagas: coordinates
- Sync and sagas → Control-plane connectors: uses
- Provisioning pipeline → External providers: executes via
- Sync and sagas → External providers: connects to
- Domain contexts → APAI runtime: AI orchestration
- APAI runtime → AI execution pipeline: executes
- AI execution pipeline → Agent orchestration: optional agents/tools
- AI execution pipeline → AI database: audits and stores
- Agent orchestration → External providers: LLM and retrieval
- APAI deployment → APAI runtime: deploys
- Platform kernel → Project service: shared platform capability
- Platform kernel → Workspace: shared platform capability
