Skip to content
Open
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
82 changes: 57 additions & 25 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,84 @@
# Dependencies
node_modules/

# Build outputs
dist/
build/
.next/
out/

# Environment variables
# Environment
.env
.env.local
.env.*

# IDE files
# Editors
.vscode/
.idea/
*.swp
*.swo

# Build artifacts
dist/
build/
target/

# Logs
*.log

# Temporary files
*.tmp
*.swp

# Python cache (if any Python files exist in the project)
# Python
__pycache__/
*.pyc
*.pyo
*.pyd

# Coverage reports
# Java
*.class
*.jar
*.war
*.ear
target/
.gradle/

# C/C++
*.o
*.obj
*.so
*.a
*.dll
*.exe

# Coverage
coverage/
htmlcov/
.coverage

# TypeScript/JavaScript build artifacts
*.tsbuildinfo
*.js.map
*.jsx.map
*.ts.map

# Database files (if any exist)
*.db
*.sqlite
*.sqlite3

# OS generated files
# OS
.DS_Store
Thumbs.db

# MyPy
.mypy_cache/

# Pytest
.pytest_cache/

# Compressed files
*.zip
*.gz
*.tar
*.tgz
*.bz2
*.xz
*.7z
*.rar
*.zst
*.lz4
*.lzh
*.cab
*.arj
*.rpm
*.deb
*.Z
*.lz
*.lzo
*.tar.gz
*.tar.bz2
*.tar.xz
*.tar.zst
```
232 changes: 232 additions & 0 deletions glyph-saas/DEPLOYMENT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@
# GLYPH SaaS - Production Deployment Guide

## Prerequisites

- Node.js 20+ installed
- PostgreSQL database (Neon, Supabase, or self-hosted)
- Redis instance (Upstash or self-hosted)
- Clerk account for authentication
- Stripe account for payments
- AWS S3 bucket for file storage
- OpenAI API key
- Vercel account for deployment

## Local Development Setup

### 1. Clone and Install

```bash
cd glyph-saas
npm install
```

### 2. Environment Variables

Copy `.env.example` to `.env.local` and fill in all values:

```bash
cp .env.example .env.local
```

Required services:
- **Database**: PostgreSQL with pgvector extension
- **Redis**: For caching and rate limiting
- **Clerk**: Configure OAuth providers (Google, GitHub)
- **Stripe**: Create products and prices for Pro/Team tiers
- **S3**: Create bucket and configure CORS
- **OpenAI**: Enable required models

### 3. Database Setup

Run migrations:

```bash
npm run db:migrate
```

Seed initial data (optional):

```bash
npm run db:seed
```

### 4. Start Development Servers

```bash
npm run dev
```

This starts both the web app (port 3000) and API (port 4000).

## Production Deployment

### Option A: Vercel (Recommended)

#### 1. Connect Repository

1. Push code to GitHub/GitLab
2. Import project in Vercel dashboard
3. Set root directory to `glyph-saas/web`

#### 2. Configure Environment Variables

Add all environment variables from `.env.example` in Vercel dashboard:
- Use Vercel Secrets for sensitive values
- Link to your PostgreSQL and Redis instances

#### 3. Deploy

```bash
cd glyph-saas/web
vercel --prod
```

#### 4. Stripe Webhooks

Configure webhook endpoint in Stripe dashboard:
```
https://your-app.vercel.app/api/webhooks/stripe
```

Events to subscribe:
- `customer.subscription.created`
- `customer.subscription.updated`
- `customer.subscription.deleted`
- `invoice.payment_succeeded`
- `invoice.payment_failed`

### Option B: Self-Hosted

#### 1. Build Applications

```bash
npm run build
```

#### 2. Start Services

API Server:
```bash
cd api
npm start
```

Web App:
```bash
cd web
npm start
```

#### 3. Process Manager (PM2)

```bash
pm2 start ecosystem.config.js
```

## Post-Deployment Checklist

### Security
- [ ] HTTPS enabled (automatic on Vercel)
- [ ] CORS configured correctly
- [ ] Rate limiting active
- [ ] CSP headers set
- [ ] Secure cookies enabled

### Functionality
- [ ] Authentication working (sign up/in)
- [ ] Stripe checkout flow complete
- [ ] Webhooks processing correctly
- [ ] File uploads working
- [ ] AI features responding
- [ ] Email delivery confirmed

### Monitoring
- [ ] Sentry connected
- [ ] PostHog analytics tracking
- [ ] Error alerts configured
- [ ] Uptime monitoring active

### Performance
- [ ] CDN configured for static assets
- [ ] Database indexes created
- [ ] Redis caching active
- [ ] Image optimization enabled

## Cron Jobs

Set up automated tasks:

1. **Daily Usage Reset** (`/api/cron/daily-reset`)
- Runs at midnight UTC
- Resets daily AI message limits
- Clears temporary usage counters

2. **Flashcard Review Scheduler** (`/api/cron/flashcard-reviews`)
- Runs every 6 hours
- Updates due dates for spaced repetition
- Sends review reminders

Configure via:
- Vercel Cron Jobs (in vercel.json)
- External scheduler (Cronitor, EasyCron)
- System cron (self-hosted)

## Scaling Considerations

### Database
- Use connection pooling (PgBouncer)
- Add read replicas for analytics queries
- Implement query caching

### API
- Deploy to multiple regions
- Enable edge functions for latency-sensitive routes
- Implement request queuing for AI operations

### File Storage
- Use CDN (CloudFront)
- Implement lifecycle policies
- Enable versioning for critical files

### Rate Limiting
- Adjust limits based on tier
- Monitor abuse patterns
- Implement exponential backoff

## Troubleshooting

### Common Issues

**Database Connection Errors**
- Verify DATABASE_URL format
- Check SSL requirements
- Ensure IP allowlist includes deployment IPs

**Stripe Webhook Failures**
- Verify webhook secret matches
- Check signature verification logic
- Review Stripe dashboard for errors

**AI Service Timeouts**
- Increase timeout limits
- Implement streaming responses
- Add retry logic with backoff

**File Upload Failures**
- Check S3 bucket permissions
- Verify CORS configuration
- Ensure file size limits are appropriate

## Support

For issues:
1. Check Sentry error logs
2. Review application logs
3. Test in staging environment
4. Contact support team

---

**Version**: 1.0.0
**Last Updated**: 2024
**Maintained By**: GLYPH Engineering Team
Loading