How apnileapos-hub/ap-v2 works
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: AcademicProjectsModule.ts Domain contexts · apiClient.ts API clients · ProvisioningPipelineManager.ts Provisioning pipeline · AIExecutionPipeline.ts AI execution pipeline
Components 20
User applications
- Workspace
apps/workspace/src/app/layout.tsx - Admin
apps/admin/app/layout.tsx - Web portal
apps/web/app/page.tsx - API clients
apps/workspace/src/lib/apiClient.ts
Project domain backend
- Project service
services/project-service/src/main.ts - Request policy boundary · Guards requests and establishes correlation/error context.
services/project-service/src/application/policies/RbacGuard.ts - Application layer
services/project-service/src/application/controllers/ProjectProvisioningController.ts - Domain contexts · Academic, project, workspace, communication, and operational domains.
services/project-service/src/domains/academic-projects/AcademicProjectsModule.ts - Provisioning pipeline · Resolves templates, validates, executes providers, and verifies.
services/project-service/src/domains/project-provisioning/services/pipeline/ProvisioningPipelineManager.ts - Project database
services/project-service/prisma/schema.prisma
AI platform
- APAI runtime
services/apai-runtime/src/main.ts - AI execution pipeline · Applies policy, prompts, routing, quotas, retrieval, audit, and telemetry.
services/apai-runtime/src/modules/apai/core/runtime/execution/AIExecutionPipeline.ts - Agent orchestration
services/apai-runtime/src/modules/apai/core/agents/orchestration/AgentOrchestrator.ts - AI database
services/apai-runtime/prisma/schema.prisma - APAI deployment
services/apai-runtime/deploy/kubernetes/k8s-deployment.yaml
Enterprise control plane
- ECP service
services/ecp-service/src/modules/ecp/EcpModule.ts - Sync and sagas · Coordinates connector contracts, webhooks, and synchronization.
services/ecp-service/src/modules/ecp/integration/SagaOrchestrator.ts - Control-plane connectors
services/ecp-service/src/modules/ecp/data/RabbitMqConnector.ts
Shared platform
- Platform kernel · Provides lifecycle, module registry, permissions, navigation, and plugins.
packages/core/src/kernel/PlatformKernel.ts
Other components
- External providers · Atlassian, GitHub, productivity, communications, LLM, and WebRTC services.
services/project-service/src/domains/project-provisioning/providers/ProviderFactory.ts
Connections 22
- 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