Skip to main content

Project Structure

CORTEX uses a Turborepo monorepo with pnpm workspaces. This guide explains the directory structure and how packages relate to each other.

Root Structure

cortex-platform/
├── apps/ # Application services
├── packages/ # Shared packages
├── infra/ # Infrastructure as Code
├── pipelines/ # CI/CD pipeline definitions
├── docs/ # Project documentation
├── scripts/ # Utility scripts
├── requirements/ # Requirements documents
├── turbo.json # Turborepo configuration
├── pnpm-workspace.yaml # pnpm workspace config
└── package.json # Root package.json

Applications (apps/)

AppTechnologyPortDescription
cortex-webNext.js 143090Frontend application
cortex-api-gatewayNestJS 108090API gateway (future)
cortex-coreNestJS 108091Core business logic
cortex-agent-runnerGo 1.22+9090AI agent execution (future)
cortex-integration-workersNestJS 108092Background workers (future)
docsDocusaurus3000Documentation portal

Core Service Structure (apps/core/)

apps/core/
├── prisma/
│ ├── schema.prisma # Database schema
│ ├── migrations/ # Database migrations
│ └── seed.ts # Seed data script
├── src/
│ ├── main.ts # Application entry point
│ ├── app.module.ts # Root module
│ ├── common/ # Shared utilities
│ │ ├── decorators/ # Custom decorators
│ │ ├── guards/ # Auth guards
│ │ ├── interceptors/ # Request interceptors
│ │ └── filters/ # Exception filters
│ └── modules/ # Feature modules
│ ├── auth/ # Authentication
│ ├── tenant/ # Tenant management
│ ├── organization/ # Organization management
│ ├── user/ # User management
│ ├── rbac/ # Role-based access control
│ ├── audit/ # Audit logging
│ └── health/ # Health checks
├── test/
│ ├── unit/ # Unit tests
│ ├── integration/ # Integration tests
│ └── functional/ # End-to-end functional tests
└── package.json

Shared Packages (packages/)

PackageDescription
shared-typesTypeScript type definitions shared across apps
ui-componentsShared React components for the frontend
utilsCommon utility functions
eslint-configShared ESLint configuration
tsconfigShared TypeScript configurations

Package Dependencies

┌──────────────┐     ┌──────────────┐
│ cortex-web │────▶│ ui-components│
│ │ └──────────────┘
│ │ │
│ │ ▼
│ │────▶┌──────────────┐
│ │ │ shared-types │◀────┐
└──────────────┘ └──────────────┘ │
▲ │
┌──────────────┐ │ │
│ cortex-core │────────────┴─────────────┤
└──────────────┘ │

┌──────────────┐ │
│ cortex-api- │──────────────────────────┘
│ gateway │
└──────────────┘

Infrastructure (infra/)

infra/
├── terraform/ # Terraform modules
│ ├── modules/ # Reusable modules
│ │ ├── networking/ # VNet, subnets
│ │ ├── database/ # PostgreSQL
│ │ ├── redis/ # Redis cache
│ │ └── app-service/ # Container apps
│ └── environments/ # Environment configs
│ ├── dev/
│ ├── staging/
│ └── prod/
└── docker/
├── docker-compose.yml # Local development
└── Dockerfile.* # Service Dockerfiles

Module Architecture

Each NestJS module follows a consistent structure:

modules/auth/
├── auth.module.ts # Module definition
├── auth.controller.ts # HTTP endpoints
├── auth.service.ts # Business logic
├── dto/ # Data Transfer Objects
│ ├── login.dto.ts
│ ├── register.dto.ts
│ └── index.ts
├── entities/ # Prisma model extensions
├── guards/ # Module-specific guards
└── strategies/ # Passport strategies

Key Files

FilePurpose
turbo.jsonDefines build pipeline and task dependencies
pnpm-workspace.yamlLists workspace packages
prisma/schema.prismaDatabase schema (single source of truth)
.envEnvironment variables (not committed)
.env.exampleTemplate for environment variables

Development Workflow

# Install all dependencies
pnpm install

# Start all services in dev mode
pnpm dev

# Run tests across all packages
pnpm test

# Build all packages
pnpm build

# Lint all packages
pnpm lint

Adding a New Module

  1. Create the module directory:

    mkdir -p apps/core/src/modules/my-feature
  2. Create module files following the standard structure

  3. Register in app.module.ts:

    @Module({
    imports: [
    // ...
    MyFeatureModule,
    ],
    })
    export class AppModule {}
  4. Update Prisma schema if needed:

    cd apps/core
    pnpm db:migrate