Skip to content
Closed
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
49 changes: 49 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: CI

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

jobs:
build-and-test:
name: Build and Test (Node ${{ matrix.node-version }})
runs-on: ubuntu-latest

permissions:
contents: read

strategy:
matrix:
node-version: [20.x]
fail-fast: false

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'

- name: Install dependencies
run: npm ci --legacy-peer-deps

- name: Type check
run: npm run type-check --if-present

- name: Lint
run: npm run lint --if-present

- name: Build
run: npm run build --if-present

- name: Test
run: npm run test --if-present

- name: Security audit
run: npm run security:audit --if-present
continue-on-error: true
21 changes: 21 additions & 0 deletions apps/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Apps

This directory contains user-facing applications.

## Current Applications

Currently empty. The existing web application will be moved here in a future PR.

## Future Structure

```
apps/
├── web/ # Main web application
├── mobile/ # Mobile application (optional)
└── desktop/ # Desktop application (optional)
```

Each app should have:
- Its own `package.json`
- Independent build configuration
- Shared dependencies from `packages/`
62 changes: 62 additions & 0 deletions docs/ARCHITECTURE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Architecture Overview

## System Design

This is an AI-powered security monitoring application built as a monorepo using npm workspaces.

### Monorepo Structure

```
.
├── apps/ # User-facing applications
├── services/ # Backend services
├── packages/ # Shared libraries and utilities
├── infra/ # Infrastructure as code
└── docs/ # Documentation
```

### Technology Stack

- **Frontend**: React 18 + TypeScript + Vite
- **AI/ML**: TensorFlow.js with COCO-SSD model
- **Camera**: WebRTC Media APIs with canvas overlay
- **Styling**: Tailwind CSS + Framer Motion
- **Storage**: IndexedDB + Azure Blob Storage
- **Authentication**: NextAuth.js + OAuth providers
- **Database**: Prisma + SQLite/PostgreSQL
- **PWA**: Workbox + Service Workers
- **Build**: Vite with TypeScript compilation
- **Deployment**: Azure, Vercel/Netlify ready

## Core Components

### Object Detection
- Real-time video stream processing
- TensorFlow.js COCO-SSD model
- Security-relevant class detection (person, vehicle, etc.)
- Confidence threshold filtering

### Storage Layer
- IndexedDB for local event storage
- Azure Blob Storage for cloud backup
- SAS token authentication

### Authentication
- OAuth 2.0 (Google, GitHub)
- Session-based authentication via NextAuth.js
- Prisma adapter for database sessions

## Security Considerations

- Content Security Policy (CSP) headers
- SAS token-based cloud storage access
- No secrets in source code
- Regular security scanning with CodeQL
- Dependency vulnerability scanning

## Future Enhancements

- Microservices architecture for backend
- Shared component library
- Automated E2E testing
- Advanced analytics dashboard
204 changes: 204 additions & 0 deletions docs/DEPLOY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
# Deployment Guide

## Prerequisites

- Node.js 20 or later
- npm 10 or later
- Azure account (optional, for cloud deployment)
- Domain name (optional)

## Local Development

### Setup

```bash
# Install dependencies
npm install

# Copy environment template
cp .env.example .env.local

# Configure OAuth providers (see README.md)
# Add NEXTAUTH_SECRET, Google OAuth, GitHub OAuth credentials

# Run development server
npm run dev
```

### Testing

```bash
# Run unit tests
npm run test

# Run linter
npm run lint

# Type checking
npm run type-check

# Security audit
npm run security:audit
```

## Production Deployment

### Build

```bash
# Build for production
npm run build

# Preview production build locally
npm run preview
```

### Deployment Options

#### Option 1: Vercel

```bash
# Install Vercel CLI
npm install -g vercel

# Deploy
vercel --prod
```

Configuration:
- Framework Preset: Vite
- Build Command: `npm run build`
- Output Directory: `dist`
- Environment Variables: Configure in Vercel dashboard

#### Option 2: Netlify

```bash
# Install Netlify CLI
npm install -g netlify-cli

# Deploy
netlify deploy --prod
```

Configuration:
- Build Command: `npm run build`
- Publish Directory: `dist`
- Environment Variables: Configure in Netlify dashboard

#### Option 3: Azure Static Web Apps

```bash
# Deploy via GitHub Actions
# See .github/workflows/azure-deploy.yml
```

Configuration:
- Use Azure Static Web Apps GitHub Action
- Configure app location: `/`
- Configure output location: `dist`
- Set environment variables in Azure Portal

### Database Setup

#### Development (SQLite)

```bash
# Initialize database
npx prisma migrate dev

# Open Prisma Studio
npx prisma studio
```

#### Production (PostgreSQL)

```bash
# Set DATABASE_URL in environment
export DATABASE_URL="postgresql://user:password@host:5432/dbname"

# Run migrations
npx prisma migrate deploy

# Generate Prisma Client
npx prisma generate
```

### Environment Variables

Required for production:

- `NEXTAUTH_URL`: Full URL of your deployed app
- `NEXTAUTH_SECRET`: Generate with `openssl rand -base64 32`
- `GOOGLE_CLIENT_ID`: From Google Cloud Console
- `GOOGLE_CLIENT_SECRET`: From Google Cloud Console
- `GITHUB_ID`: From GitHub OAuth Apps
- `GITHUB_SECRET`: From GitHub OAuth Apps
- `DATABASE_URL`: PostgreSQL connection string
- `AZURE_STORAGE_ACCOUNT`: (Optional) Azure Storage account name
- `AZURE_STORAGE_SAS_TOKEN`: (Optional) Azure Storage SAS token

### SSL/TLS Configuration

- Vercel/Netlify: Automatic HTTPS
- Azure: Configure custom domain with SSL in portal
- Self-hosted: Use Let's Encrypt with certbot

### Domain Configuration

1. Point DNS to deployment provider
2. Configure custom domain in provider dashboard
3. Update OAuth redirect URIs
4. Update `NEXTAUTH_URL` environment variable

## Monitoring

### Application Monitoring

- Enable error tracking (Sentry, LogRocket)
- Monitor performance metrics
- Set up uptime monitoring

### Security Monitoring

- Enable GitHub security alerts
- Monitor Azure security center
- Review access logs regularly

## Rollback Procedure

1. Identify last known good deployment
2. Revert via provider dashboard or CLI
3. Verify functionality
4. Investigate and fix issue

## Scaling Considerations

- Use CDN for static assets
- Enable caching headers
- Consider serverless functions for API
- Implement rate limiting
- Use database connection pooling

## Troubleshooting

### Build Failures

- Check Node.js version (requires 20+)
- Verify all dependencies installed
- Check TypeScript errors: `npm run type-check`
- Review build logs

### Runtime Issues

- Check environment variables configured
- Verify database migrations applied
- Check browser console for errors
- Review application logs

### Authentication Issues

- Verify OAuth credentials
- Check redirect URIs match
- Ensure NEXTAUTH_URL is correct
- Verify HTTPS in production
Loading
Loading