Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 97 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: CI

on:
push:
branches: [main]
pull_request:
branches: [main]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
lint-and-typecheck:
name: Lint & Type Check
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup pnpm
uses: pnpm/action-setup@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
cache: 'pnpm'

- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Generate Prisma client
run: pnpm --filter db db:generate
env:
DATABASE_URL: "postgresql://localhost:5432/test"
Comment on lines +33 to +36

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Add a PostgreSQL service for proper Prisma validation.

The workflow sets DATABASE_URL to postgresql://localhost:5432/test, but there's no PostgreSQL service configured. While prisma generate and basic prisma validate can work without a live database, using a proper PostgreSQL service ensures:

  1. Full schema validation including database-specific features (like partial indexes, check constraints)
  2. Migration compatibility testing
  3. Consistency with the production environment (PostgreSQL 16 per docker-compose.yml)
🐘 Add PostgreSQL service to each job

Add this services block to each job that needs database access:

services:
  postgres:
    image: postgres:16
    env:
      POSTGRES_USER: cortex
      POSTGRES_PASSWORD: cortex
      POSTGRES_DB: cortex_test
    options: >-
      --health-cmd pg_isready
      --health-interval 10s
      --health-timeout 5s
      --health-retries 5
    ports:
      - 5432:5432

Then update the DATABASE_URL to match:

env:
  DATABASE_URL: "postgresql://cortex:cortex@localhost:5432/cortex_test"

Also applies to: 67-70, 94-97

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/ci.yml around lines 33 - 36, The CI step that runs the
"Generate Prisma client" job sets DATABASE_URL to
postgresql://localhost:5432/test but does not start a PostgreSQL service, so add
a postgres service to any job that runs Prisma (the job containing the "Generate
Prisma client" step and the other similar steps) using image postgres:16 with
POSTGRES_USER/POSTGRES_PASSWORD/POSTGRES_DB (e.g., cortex/cortex/cortex_test)
and appropriate health checks, and update the step's env DATABASE_URL to
postgresql://cortex:cortex@localhost:5432/cortex_test so Prisma can perform full
DB-specific validation and migrations; ensure each job that runs pnpm --filter
db db:generate or similar Prisma commands gets the same services block and env
update.


- name: Type check
run: pnpm check-types

- name: Lint
run: pnpm lint

- name: Format check
run: pnpm format --check

build:
name: Build
runs-on: ubuntu-latest
needs: lint-and-typecheck
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup pnpm
uses: pnpm/action-setup@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
cache: 'pnpm'

- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Generate Prisma client
run: pnpm --filter db db:generate
env:
DATABASE_URL: "postgresql://localhost:5432/test"

- name: Build
run: pnpm build

validate-schema:
name: Validate Prisma Schema
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup pnpm
uses: pnpm/action-setup@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
cache: 'pnpm'

- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Validate Prisma schema
run: pnpm --filter db db:validate
env:
DATABASE_URL: "postgresql://localhost:5432/test"
14 changes: 14 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Dependencies
node_modules/
pnpm-lock.yaml

# Build outputs
dist/
.next/
out/

# Generated files
packages/db/generated/

# Package manager
.pnpm-store/
185 changes: 74 additions & 111 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,159 +1,122 @@
# Turborepo starter
# Cortex

This Turborepo starter is maintained by the Turborepo core team.
A TypeScript monorepo for an MCP-first context, policy, and audit platform.

## Using this example
## Getting Started

Run the following command:
### Prerequisites

```sh
npx create-turbo@latest
```

## What's inside?

This Turborepo includes the following packages/apps:

### Apps and Packages

- `docs`: a [Next.js](https://nextjs.org/) app
- `web`: another [Next.js](https://nextjs.org/) app
- `@repo/ui`: a stub React component library shared by both `web` and `docs` applications
- `@repo/eslint-config`: `eslint` configurations (includes `eslint-config-next` and `eslint-config-prettier`)
- `@repo/typescript-config`: `tsconfig.json`s used throughout the monorepo

Each package/app is 100% [TypeScript](https://www.typescriptlang.org/).

### Utilities
- Node.js >= 18
- pnpm 9.x
- Docker (for local development with PostgreSQL and Redis)

This Turborepo has some additional tools already setup for you:

- [TypeScript](https://www.typescriptlang.org/) for static type checking
- [ESLint](https://eslint.org/) for code linting
- [Prettier](https://prettier.io) for code formatting

### Build

To build all apps and packages, run the following command:

With [global `turbo`](https://turborepo.dev/docs/getting-started/installation#global-installation) installed (recommended):
### Installation

```sh
cd my-turborepo
turbo build
```

Without global `turbo`, use your package manager:
# Install dependencies
pnpm install

```sh
cd my-turborepo
npx turbo build
pnpm dlx turbo build
pnpm exec turbo build
# Generate Prisma client (requires DATABASE_URL)
DATABASE_URL="postgresql://cortex:cortex@localhost:5432/cortex" pnpm --filter db db:generate
```

You can build a specific package by using a [filter](https://turborepo.dev/docs/crafting-your-repository/running-tasks#using-filters):
### Development

With [global `turbo`](https://turborepo.dev/docs/getting-started/installation#global-installation) installed:
Start the development environment:

```sh
turbo build --filter=docs
```
# Start PostgreSQL and Redis
docker-compose up -d

Without global `turbo`:

```sh
npx turbo build --filter=docs
pnpm exec turbo build --filter=docs
pnpm exec turbo build --filter=docs
# Run all apps in development mode
pnpm dev
```

### Develop
## Project Structure

To develop all apps and packages, run the following command:
### Apps

With [global `turbo`](https://turborepo.dev/docs/getting-started/installation#global-installation) installed (recommended):
- `apps/web` - Admin Web (Next.js)
- `apps/docs` - Documentation site (Next.js)
- `apps/api` - API + MCP entrypoint (NestJS)

```sh
cd my-turborepo
turbo dev
```
### Packages

Without global `turbo`, use your package manager:
- `packages/db` - Prisma schema and database client
- `packages/ui` - Shared React component library (`@cortex/ui`)
- `packages/shared` - Shared types and utilities (`@cortex/shared`)
- `packages/eslint-config` - ESLint configurations (`@cortex/eslint-config`)
- `packages/typescript-config` - TypeScript configurations (`@cortex/typescript-config`)

## Commands

```sh
cd my-turborepo
npx turbo dev
pnpm exec turbo dev
pnpm exec turbo dev
```
# Install dependencies
pnpm install

You can develop a specific package by using a [filter](https://turborepo.dev/docs/crafting-your-repository/running-tasks#using-filters):
# Build all workspaces
pnpm build

With [global `turbo`](https://turborepo.dev/docs/getting-started/installation#global-installation) installed:
# Type-check all workspaces
pnpm check-types

```sh
turbo dev --filter=web
```
# Lint all workspaces
pnpm lint

Without global `turbo`:
# Format code
pnpm format

```sh
npx turbo dev --filter=web
pnpm exec turbo dev --filter=web
pnpm exec turbo dev --filter=web
# Run dev servers
pnpm dev
```

### Remote Caching

> [!TIP]
> Vercel Remote Cache is free for all plans. Get started today at [vercel.com](https://vercel.com/signup?utm_source=remote-cache-sdk&utm_campaign=free_remote_cache).
### Database Commands

Turborepo can use a technique known as [Remote Caching](https://turborepo.dev/docs/core-concepts/remote-caching) to share cache artifacts across machines, enabling you to share build caches with your team and CI/CD pipelines.
```sh
# Generate Prisma client
pnpm --filter db db:generate

By default, Turborepo will cache locally. To enable Remote Caching you will need an account with Vercel. If you don't have an account you can [create one](https://vercel.com/signup?utm_source=turborepo-examples), then enter the following commands:
# Validate Prisma schema
pnpm --filter db db:validate

With [global `turbo`](https://turborepo.dev/docs/getting-started/installation#global-installation) installed (recommended):
# Create a new migration
pnpm --filter db db:migrate

```sh
cd my-turborepo
turbo login
# Apply pending migrations (production)
pnpm --filter db db:migrate:deploy
```

Without global `turbo`, use your package manager:
## Docker Services

```sh
cd my-turborepo
npx turbo login
pnpm exec turbo login
pnpm exec turbo login
```
The `docker-compose.yml` provides:

This will authenticate the Turborepo CLI with your [Vercel account](https://vercel.com/docs/concepts/personal-accounts/overview).
- **PostgreSQL 16** - Available at `localhost:5432` (user: `cortex`, password: `cortex`, database: `cortex`)
- **Redis 7** - Available at `localhost:6379`

Next, you can link your Turborepo to your Remote Cache by running the following command from the root of your Turborepo:

With [global `turbo`](https://turborepo.dev/docs/getting-started/installation#global-installation) installed:
Start services:

```sh
turbo link
docker-compose up -d
```

Without global `turbo`:
Stop services:

```sh
npx turbo link
pnpm exec turbo link
pnpm exec turbo link
docker-compose down
```

## Useful Links
## Tech Stack

- **Package Manager**: pnpm (workspace monorepo)
- **Task Runner**: Turborepo
- **Language**: TypeScript
- **Web Framework**: Next.js 16
- **API Framework**: NestJS
- **Database**: PostgreSQL with Prisma ORM
- **Cache**: Redis
- **Linting**: ESLint
- **Formatting**: Prettier

Learn more about the power of Turborepo:
## License

- [Tasks](https://turborepo.dev/docs/crafting-your-repository/running-tasks)
- [Caching](https://turborepo.dev/docs/crafting-your-repository/caching)
- [Remote Caching](https://turborepo.dev/docs/core-concepts/remote-caching)
- [Filtering](https://turborepo.dev/docs/crafting-your-repository/running-tasks#using-filters)
- [Configuration Options](https://turborepo.dev/docs/reference/configuration)
- [CLI Usage](https://turborepo.dev/docs/reference/command-line-reference)
ISC
4 changes: 4 additions & 0 deletions apps/api/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { config as baseConfig } from "@cortex/eslint-config/base";

/** @type {import("eslint").Linter.Config[]} */
export default baseConfig;
Loading
Loading