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
12 changes: 6 additions & 6 deletions .cursor/rules/data-fetching-and-writing.mdc
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
---
description:
globs:
description:
globs:
alwaysApply: true
---

We use the following conversions for data:

For reading data:
- Always try to fetch data from a server side rendered component (at Next.js page or server component level)

- Always try to fetch data from a server side rendered component (at Next.js page or server component level) and then create client components for anythign that requires useState/useEffect, etc..
- Only resort to client side fetching if there is a strong reason why server component fetching wouldn't work.
- Refer to [page.tsx](mdc:apps/app/src/app/[locale]/(app)/(dashboard)/[orgId]/tests/all/[testId]/page.tsx) for an example.
- Avoid using cache, if you encounter a cache usage, remove it. We will reintroduce this later in an intentional way.


For writing data:
- We use server actions, refer to [create-new-policy.ts](mdc:apps/app/src/actions/policies/create-new-policy.ts) for an example.

- We use server actions, refer to [create-new-policy.ts](mdc:apps/app/src/actions/policies/create-new-policy.ts) for an example.
56 changes: 56 additions & 0 deletions apps/api/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# compiled output
/dist
/node_modules
/build

# Logs
logs
*.log
npm-debug.log*
pnpm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# OS
.DS_Store

# Tests
/coverage
/.nyc_output

# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# temp directory
.temp
.tmp

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
4 changes: 4 additions & 0 deletions apps/api/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"singleQuote": true,
"trailingComma": "all"
}
32 changes: 32 additions & 0 deletions apps/api/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Use Node.js runtime for production
FROM node:20-alpine

# Install wget for health check
RUN apk add --no-cache wget

WORKDIR /app

# Copy the entire pre-built bundle (no dependencies needed)
COPY . .

# Set environment variables
ENV NODE_ENV=production
ENV PORT=3333

# Create a non-root user for security
RUN addgroup --system nestjs && adduser --system --ingroup nestjs nestjs

# Change ownership to nestjs user
RUN chown -R nestjs:nestjs /app

USER nestjs

# Expose the port the app runs on
EXPOSE 3333

# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:3333/v1/health || exit 1

# Start the application
CMD ["node", "main.js"]
98 changes: 98 additions & 0 deletions apps/api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<p align="center">
<a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo-small.svg" width="120" alt="Nest Logo" /></a>
</p>

[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456
[circleci-url]: https://circleci.com/gh/nestjs/nest

<p align="center">A progressive <a href="http://nodejs.org" target="_blank">Node.js</a> framework for building efficient and scalable server-side applications.</p>
<p align="center">
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/v/@nestjs/core.svg" alt="NPM Version" /></a>
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/l/@nestjs/core.svg" alt="Package License" /></a>
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/dm/@nestjs/common.svg" alt="NPM Downloads" /></a>
<a href="https://circleci.com/gh/nestjs/nest" target="_blank"><img src="https://img.shields.io/circleci/build/github/nestjs/nest/master" alt="CircleCI" /></a>
<a href="https://discord.gg/G7Qnnhy" target="_blank"><img src="https://img.shields.io/badge/discord-online-brightgreen.svg" alt="Discord"/></a>
<a href="https://opencollective.com/nest#backer" target="_blank"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a>
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://opencollective.com/nest/sponsors/badge.svg" alt="Sponsors on Open Collective" /></a>
<a href="https://paypal.me/kamilmysliwiec" target="_blank"><img src="https://img.shields.io/badge/Donate-PayPal-ff3f59.svg" alt="Donate us"/></a>
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://img.shields.io/badge/Support%20us-Open%20Collective-41B883.svg" alt="Support us"></a>
<a href="https://twitter.com/nestframework" target="_blank"><img src="https://img.shields.io/twitter/follow/nestframework.svg?style=social&label=Follow" alt="Follow us on Twitter"></a>
</p>
<!--[![Backers on Open Collective](https://opencollective.com/nest/backers/badge.svg)](https://opencollective.com/nest#backer)
[![Sponsors on Open Collective](https://opencollective.com/nest/sponsors/badge.svg)](https://opencollective.com/nest#sponsor)-->

## Description

[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository.

## Project setup

```bash
$ npm install
```

## Compile and run the project

```bash
# development
$ npm run start

# watch mode
$ npm run start:dev

# production mode
$ npm run start:prod
```

## Run tests

```bash
# unit tests
$ npm run test

# e2e tests
$ npm run test:e2e

# test coverage
$ npm run test:cov
```

## Deployment

When you're ready to deploy your NestJS application to production, there are some key steps you can take to ensure it runs as efficiently as possible. Check out the [deployment documentation](https://docs.nestjs.com/deployment) for more information.

If you are looking for a cloud-based platform to deploy your NestJS application, check out [Mau](https://mau.nestjs.com), our official platform for deploying NestJS applications on AWS. Mau makes deployment straightforward and fast, requiring just a few simple steps:

```bash
$ npm install -g @nestjs/mau
$ mau deploy
```

With Mau, you can deploy your application in just a few clicks, allowing you to focus on building features rather than managing infrastructure.

## Resources

Check out a few resources that may come in handy when working with NestJS:

- Visit the [NestJS Documentation](https://docs.nestjs.com) to learn more about the framework.
- For questions and support, please visit our [Discord channel](https://discord.gg/G7Qnnhy).
- To dive deeper and get more hands-on experience, check out our official video [courses](https://courses.nestjs.com/).
- Deploy your application to AWS with the help of [NestJS Mau](https://mau.nestjs.com) in just a few clicks.
- Visualize your application graph and interact with the NestJS application in real-time using [NestJS Devtools](https://devtools.nestjs.com).
- Need help with your project (part-time to full-time)? Check out our official [enterprise support](https://enterprise.nestjs.com).
- To stay in the loop and get updates, follow us on [X](https://x.com/nestframework) and [LinkedIn](https://linkedin.com/company/nestjs).
- Looking for a job, or have a job to offer? Check out our official [Jobs board](https://jobs.nestjs.com).

## Support

Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support).

## Stay in touch

- Author - [Kamil Myśliwiec](https://twitter.com/kammysliwiec)
- Website - [https://nestjs.com](https://nestjs.com/)
- Twitter - [@nestframework](https://twitter.com/nestframework)

## License

Nest is [MIT licensed](https://github.com/nestjs/nest/blob/master/LICENSE).
95 changes: 95 additions & 0 deletions apps/api/buildspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
version: 0.2

phases:
pre_build:
commands:
- echo "Logging in to Amazon ECR..."
- aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com
- REPOSITORY_URI=$ECR_REPOSITORY_URI
- COMMIT_HASH=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7)
- IMAGE_TAG=${COMMIT_HASH:=latest}
- echo "Installing dependencies..."
- curl -fsSL https://bun.sh/install | bash

build:
commands:
# Environment setup
- export PATH="/root/.bun/bin:$PATH"
- export PGSSLMODE=require
- export NODE_ENV=production
- export NEXT_TELEMETRY_DISABLED=1
- export UV_THREADPOOL_SIZE=36
- export NODE_OPTIONS="--max-old-space-size=65536"

# Validate environment variables
- echo "Validating environment variables..."
- '[ -n "$DATABASE_URL" ] || { echo "❌ DATABASE_URL is not set"; exit 1; }'
- '[ -n "$BASE_URL" ] || { echo "❌ BASE_URL is not set"; exit 1; }'

# Install dependencies
- echo "Installing dependencies..."
- bun install --frozen-lockfile

# Generate Prisma client
- echo "Generating Prisma client..."
- cd packages/db && bun x prisma generate && cd ../../

# Build NestJS application
- echo "Building NestJS application..."
- cd apps/$APP_NAME && bun run build && cd ../../

# Create self-contained bundle for Docker
- echo "Creating self-contained bundle..."
- cd apps/$APP_NAME
- mkdir -p ../docker-build

# Copy built application
- cp -r dist/* ../docker-build/

# Copy only the necessary node_modules for runtime
- echo "Bundling runtime dependencies..."
- mkdir -p ../docker-build/node_modules
- cp -r node_modules/@nestjs ../docker-build/node_modules/ 2>/dev/null || echo "No @nestjs modules"
- cp -r node_modules/reflect-metadata ../docker-build/node_modules/ 2>/dev/null || echo "No reflect-metadata"
- cp -r node_modules/rxjs ../docker-build/node_modules/ 2>/dev/null || echo "No rxjs"
- cp -r node_modules/class-transformer ../docker-build/node_modules/ 2>/dev/null || echo "No class-transformer"
- cp -r node_modules/class-validator ../docker-build/node_modules/ 2>/dev/null || echo "No class-validator"
- cp -r node_modules/zod ../docker-build/node_modules/ 2>/dev/null || echo "No zod"

# Copy Prisma client
- cp -r ../../node_modules/.prisma ../docker-build/node_modules/ 2>/dev/null || echo "No .prisma"
- cp -r ../../node_modules/@prisma ../docker-build/node_modules/ 2>/dev/null || echo "No @prisma"

# Copy @trycompai/db package
- mkdir -p ../docker-build/node_modules/@trycompai
- cp -r ../../packages/db ../docker-build/node_modules/@trycompai/

# Copy Dockerfile
- cp Dockerfile ../docker-build/

# Build Docker image
- echo "Building Docker image..."
- docker build --build-arg BUILDKIT_INLINE_CACHE=1 -t $ECR_REPOSITORY_URI:$IMAGE_TAG ../docker-build/
- docker tag $ECR_REPOSITORY_URI:$IMAGE_TAG $ECR_REPOSITORY_URI:latest

post_build:
commands:
- echo "Pushing images to ECR..."
- docker push $ECR_REPOSITORY_URI:$IMAGE_TAG
- docker push $ECR_REPOSITORY_URI:latest
- echo "Updating ECS service..."
- aws ecs update-service --cluster $ECS_CLUSTER_NAME --service $ECS_SERVICE_NAME --force-new-deployment
- 'printf "[{\"name\":\"%s-container\",\"imageUri\":\"%s\"}]" $APP_NAME $ECR_REPOSITORY_URI:$IMAGE_TAG > imagedefinitions.json'

cache:
paths:
- 'node_modules/**/*'
- 'packages/db/node_modules/**/*'
- 'apps/api/node_modules/**/*'
- '/root/.bun/install/cache/**/*'
- 'bun.lock'

artifacts:
files:
- imagedefinitions.json
name: ${APP_NAME}-build
34 changes: 34 additions & 0 deletions apps/api/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// @ts-check
import eslint from '@eslint/js';
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';
import globals from 'globals';
import tseslint from 'typescript-eslint';

export default tseslint.config(
{
ignores: ['eslint.config.mjs'],
},
eslint.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
eslintPluginPrettierRecommended,
{
languageOptions: {
globals: {
...globals.node,
...globals.jest,
},
sourceType: 'commonjs',
parserOptions: {
projectService: true,
tsconfigRootDir: import.meta.dirname,
},
},
},
{
rules: {
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-floating-promises': 'warn',
'@typescript-eslint/no-unsafe-argument': 'warn'
},
},
);
8 changes: 8 additions & 0 deletions apps/api/nest-cli.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"$schema": "https://json.schemastore.org/nest-cli",
"collection": "@nestjs/schematics",
"sourceRoot": "src",
"compilerOptions": {
"deleteOutDir": true
}
}
Loading
Loading