Skip to content

bron10/cortex-ai

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

CortexAI Monorepo

A complete multi-tenant AI-powered data processing platform with AWS CDK infrastructure and Next.js frontend.Learn more

πŸ—οΈ Architecture

CortexAI/
β”œβ”€β”€ πŸ“ infra/                    # AWS CDK Infrastructure
β”‚   β”œβ”€β”€ πŸ“ bin/                 # CDK App Entry Points
β”‚   β”œβ”€β”€ πŸ“ lib/                 # CDK Constructs & Stacks
β”‚   β”œβ”€β”€ πŸ“ lambda/              # Lambda Functions
β”‚   └── πŸ“ scripts/             # Deployment Scripts
β”œβ”€β”€ πŸ“ frontend/                # Next.js Frontend
β”‚   β”œβ”€β”€ πŸ“ src/                 # Source Code
β”‚   β”œβ”€β”€ πŸ“ public/              # Static Assets
β”‚   └── πŸ“ .env.local           # Environment Variables (auto-generated)
└── πŸ“„ package.json             # Monorepo Configuration

πŸš€ Quick Start

Prerequisites

  • Node.js 18+
  • AWS CLI configured
  • AWS CDK CLI installed

1. Install Dependencies

npm install

2. Build Everything

npm run build

3. Deploy Infrastructure

npm run deploy:infra

4. Start Frontend Development

npm run dev

πŸ“‹ Features

πŸ” Multi-tenant Authentication

  • AWS Cognito User Pool with custom attributes
  • Identity Pool for AWS service access
  • Tenant isolation through custom attributes

πŸ—„οΈ Data Storage

  • DynamoDB with tenant-based partitioning
  • S3 bucket with tenant-prefixed paths
  • Automatic data lifecycle management

πŸ€– AI Processing Pipeline

  • Event-driven data processing
  • Amazon Bedrock integration for AI insights
  • Configurable processing workflows

🌐 Frontend Features

  • Next.js 14 with TypeScript
  • AWS Amplify UI for authentication
  • Real-time file upload and processing status
  • AI insights visualization

πŸ› οΈ Development

Infrastructure (CDK)

cd infra

# Build Lambda functions
cd lambda/upload && npm install && npm run build && cd ../..
cd lambda/process && npm install && npm run build && cd ../..
cd lambda/insights && npm install && npm run build && cd ../..

# Deploy to development
npm run deploy

# View changes
npm run diff

Frontend (Next.js)

cd frontend

# Start development server
npm run dev

# Build for production
npm run build

πŸ”§ Configuration

Environment Variables

After deployment, the infrastructure automatically generates:

  • frontend/.env.local - Frontend environment variables
  • frontend/src/config/aws-config.ts - AWS Amplify configuration

Custom Configuration

// infra/bin/cortex-ai.ts
new CortexAIStack(app, 'CustomCortexAI', {
  environment: 'prod',
  applicationName: 'my-enterprise-ai',
  enableAIInsights: true,
  cognitoConfig: {
    userPoolName: 'enterprise-users',
  },
});

πŸ“Š Data Flow

  1. User Authentication β†’ Cognito β†’ Identity Pool
  2. File Upload β†’ Next.js β†’ API Gateway β†’ Lambda β†’ S3 + DynamoDB
  3. Data Processing β†’ EventBridge β†’ Lambda β†’ Analysis
  4. AI Insights β†’ EventBridge β†’ Lambda β†’ Bedrock β†’ Storage
  5. Frontend Display β†’ API Gateway β†’ Next.js

πŸ” Security

Tenant Isolation

  • DynamoDB partition keys based on tenantId
  • S3 object prefixes for tenant separation
  • IAM policies with tenant-specific conditions

Authentication Flow

  • Cognito User Pool for user management
  • JWT tokens for API access
  • Identity Pool for AWS service access

πŸš€ Deployment

Infrastructure Deployment

# Deploy to different environments
npm run deploy:infra -- --context environment=dev
npm run deploy:infra -- --context environment=staging
npm run deploy:infra -- --context environment=prod

Frontend Deployment

# Build and deploy frontend
npm run deploy:frontend

Complete Deployment

# Deploy everything
npm run deploy:all

πŸ§ͺ Testing

Manual Testing

  1. Deploy infrastructure
  2. Create test user in Cognito
  3. Upload JSON files through frontend
  4. Monitor processing pipeline
  5. View AI insights

API Testing

# Test health endpoint
curl https://your-api-url/health

# Test upload (with auth token)
curl -X POST https://your-api-url/upload \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "X-Tenant-ID: tenant-123" \
  -H "Content-Type: application/json" \
  -d '{"dataType": "customer", "data": {...}}'

πŸ“ˆ Monitoring

CloudWatch Logs

  • Lambda function execution logs
  • API Gateway access logs
  • Application performance metrics

EventBridge Events

  • Data upload events
  • Processing pipeline events
  • AI insights generation events

πŸ”„ CI/CD

GitHub Actions Example

name: Deploy CortexAI
on:
  push:
    branches: [main]

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: '18'
      - run: npm install
      - run: npm run build
      - run: npm run deploy:all

🚨 Troubleshooting

Common Issues

  1. CDK Bootstrap Required

    cdk bootstrap
  2. Lambda Build Errors

    cd infra/lambda/upload && npm install && npm run build
  3. Frontend Configuration Missing

    npm run deploy:infra  # This generates frontend config

Debug Mode

export CDK_DEBUG=1
npm run deploy:infra

πŸ“š Documentation

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests
  5. Submit a pull request

πŸ“„ License

This project is licensed under the MIT License.


Built with ❀️ using AWS CDK and Next.js

About

No description, website, or topics provided.

Resources

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published