Skip to content

Commit a3e18e6

Browse files
authored
Initial commit
0 parents  commit a3e18e6

File tree

260 files changed

+64140
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

260 files changed

+64140
-0
lines changed

.dockerignore

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
node_modules
2+
npm-debug.log
3+
.env
4+
.env.local
5+
.env.*.local
6+
dist
7+
.git
8+
.gitignore
9+
.github
10+
.vscode
11+
.idea
12+
*.md
13+
!README.md
14+
.DS_Store
15+
*.log
16+
coverage
17+
.cache
18+
.replit
19+
replit.md
20+
resale_app
21+
tmp
22+
*.tmp
23+
*.swp
24+
*.swo
25+
*~
26+
.bash_history

.env.example

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Database Configuration (REQUIRED)
2+
DATABASE_URL=postgresql://username:password@host:5432/database
3+
4+
# Security
5+
ENCRYPTION_SECRET=your-encryption-secret-here
6+
7+
# Social Media API (Ayrshare)
8+
AYRSHARE_API_KEY=your-ayrshare-api-key
9+
AYRSHARE_PROFILE_KEY=your-ayrshare-profile-key
10+
11+
# ClickBank Affiliate Integration
12+
CLICKBANK_SECRET_KEY=your-clickbank-secret-key
13+
CLICKBANK_CLERK_KEY=your-clickbank-clerk-key
14+
15+
# Server Configuration
16+
PORT=5000
17+
NODE_ENV=production

.github/copilot/coding-expert.md

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# Affiliate App Coding Expert
2+
3+
You are an elite full-stack developer specializing in the Affiliate & Security App. You excel at TypeScript, React, Node.js, PostgreSQL, and deployment (Docker, Raspberry Pi, PM2).
4+
5+
## Your Expertise
6+
7+
### Codebase Structure
8+
- **/server** - Express.js backend (TypeScript)
9+
- **/client** - React frontend (Vite + TanStack Router)
10+
- **/shared** - Shared types
11+
- **/db** - Drizzle ORM schemas
12+
13+
### Key Technologies
14+
- TypeScript, Node.js 20+, Express
15+
- React, Vite, TanStack Router, shadcn/ui
16+
- PostgreSQL, Drizzle ORM
17+
- Ayrshare (social media API)
18+
- ClickBank (affiliate webhooks)
19+
- PM2, Docker, GitHub Actions
20+
21+
### Self-Healing System (server/automation.ts)
22+
- Health checks every 5 minutes
23+
- Auto-recovery from failures
24+
- Circuit breakers for APIs
25+
- Content optimization every 30 min
26+
- Database reconnection logic
27+
- Rate limiting per platform
28+
29+
### Environment Variables
30+
Required: `DATABASE_URL`, `ENCRYPTION_SECRET`, `NODE_ENV`
31+
Optional: `CLICKBANK_SECRET_KEY`, `AYRSHARE_API_KEY`, `AYRSHARE_PROFILE_KEY`
32+
33+
### Common Commands
34+
```bash
35+
npm run dev # Development with watch
36+
npm run check # TypeScript validation
37+
npm run build # Production build
38+
npm start # Run production server
39+
npm run validate:deployment # Pre-deploy checks
40+
pm2 restart affiliate-app # Restart in production
41+
```
42+
43+
### Your Coding Standards
44+
1. ✅ Strict TypeScript (no `any` unless necessary)
45+
2. ✅ Error handling on all async operations
46+
3. ✅ Security-first (validate inputs, encrypt secrets)
47+
4. ✅ Performance-conscious (Raspberry Pi constraints)
48+
5. ✅ Production-ready (works on Raspberry Pi)
49+
6. ✅ Self-healing compatible (don't break automation)
50+
7. ✅ Rate-limited API calls (respect limits)
51+
52+
### Security Requirements
53+
- Never log secrets/API keys
54+
- Validate all inputs
55+
- Encrypt sensitive data
56+
- Use prepared statements (Drizzle ORM)
57+
- Implement rate limiting
58+
- Use HTTPS in production
59+
60+
### Deployment Knowledge
61+
Deploy to: Heroku, Railway, Docker, Raspberry Pi, VPS
62+
Tools: PM2, Nginx, GitHub Actions, systemd
63+
Always test: TypeScript check, build, environment validation
64+
65+
## What Makes You Better
66+
67+
You understand:
68+
- Complete architecture and patterns
69+
- Self-healing system internals
70+
- Raspberry Pi constraints
71+
- Security requirements
72+
- Production deployment process
73+
- Project conventions
74+
75+
You write code that:
76+
- ✅ Works in production (not just dev)
77+
- ✅ Runs on Raspberry Pi efficiently
78+
- ✅ Self-heals automatically
79+
- ✅ Handles errors gracefully
80+
- ✅ Follows security best practices
81+
- ✅ Deploys successfully every time
82+
83+
## Your Mission
84+
85+
When coding for this project:
86+
1. Review existing code first
87+
2. Match project patterns
88+
3. Write type-safe code
89+
4. Test thoroughly (check, build, manual test)
90+
5. Consider Raspberry Pi deployment
91+
6. Don't break self-healing system
92+
7. Follow security best practices
93+
8. Document complex logic
94+
95+
**You write production-ready code that "just works" on deployment.** 🚀
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: Deploy to Vercel (Mobile-Ready)
2+
3+
on:
4+
push:
5+
branches:
6+
- QuickPass
7+
workflow_dispatch:
8+
9+
env:
10+
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
11+
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
12+
13+
jobs:
14+
deploy:
15+
name: Deploy to Vercel
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- name: Checkout code
20+
uses: actions/checkout@v4
21+
22+
- name: Setup Node.js
23+
uses: actions/setup-node@v4
24+
with:
25+
node-version: '20'
26+
cache: 'npm'
27+
28+
- name: Install dependencies
29+
run: npm ci
30+
31+
- name: Type check
32+
run: npm run check
33+
# Allow deployment even with type errors to avoid blocking critical deployments
34+
continue-on-error: true
35+
36+
- name: Build application
37+
run: npm run build
38+
env:
39+
NODE_ENV: production
40+
41+
- name: Install Vercel CLI
42+
run: npm install --global vercel@latest
43+
44+
- name: Pull Vercel environment information
45+
run: vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }}
46+
47+
- name: Build project artifacts
48+
run: vercel build --prod --token=${{ secrets.VERCEL_TOKEN }}
49+
50+
- name: Deploy to Vercel
51+
id: deploy
52+
run: |
53+
DEPLOYMENT_URL=$(vercel deploy --prebuilt --prod --token=${{ secrets.VERCEL_TOKEN }})
54+
echo "url=$DEPLOYMENT_URL" >> $GITHUB_OUTPUT
55+
echo "Deployed to: $DEPLOYMENT_URL"
56+
57+
- name: Comment deployment URL
58+
if: github.event_name == 'push'
59+
uses: actions/github-script@v7
60+
with:
61+
script: |
62+
const deploymentUrl = '${{ steps.deploy.outputs.url }}';
63+
const message = `🚀 **Deployed to Vercel**\n\n✅ Production: ${deploymentUrl}\n\n📱 **Mobile Access:**\n- Open the URL on your phone\n- Tap "Add to Home Screen" to install as PWA\n- Works offline with cached assets`;
64+
65+
// Find the most recent commit
66+
const { data: commits } = await github.rest.repos.listCommits({
67+
owner: context.repo.owner,
68+
repo: context.repo.repo,
69+
sha: context.sha,
70+
per_page: 1
71+
});
72+
73+
if (commits.length > 0) {
74+
await github.rest.repos.createCommitComment({
75+
owner: context.repo.owner,
76+
repo: context.repo.repo,
77+
commit_sha: context.sha,
78+
body: message
79+
});
80+
}
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
name: Deploy to Raspberry Pi
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
workflow_dispatch: # Allow manual deployment
7+
8+
jobs:
9+
deploy:
10+
runs-on: ubuntu-latest
11+
name: Deploy to Raspberry Pi
12+
permissions:
13+
contents: read
14+
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v4
18+
19+
- name: Setup Node.js
20+
uses: actions/setup-node@v4
21+
with:
22+
node-version: '20.x'
23+
cache: 'npm'
24+
25+
- name: Install dependencies
26+
run: npm ci --production
27+
28+
- name: Run type check
29+
run: npm run check
30+
31+
- name: Build application
32+
run: npm run build
33+
34+
- name: Security audit (production only)
35+
run: npm audit --production --audit-level=high
36+
continue-on-error: true
37+
38+
- name: Deploy to Raspberry Pi via SSH
39+
uses: appleboy/ssh-action@v1.0.3
40+
with:
41+
host: ${{ secrets.RASPBERRY_PI_HOST }}
42+
username: ${{ secrets.RASPBERRY_PI_USER }}
43+
key: ${{ secrets.RASPBERRY_PI_SSH_KEY }}
44+
port: ${{ secrets.RASPBERRY_PI_PORT || 22 }}
45+
script: |
46+
# Navigate to application directory
47+
cd ~/Affiliateandsecurityapp || exit 1
48+
49+
# Backup current version
50+
echo "Creating backup..."
51+
timestamp=$(date +%Y%m%d_%H%M%S)
52+
mkdir -p ~/backups
53+
tar -czf ~/backups/app-backup-$timestamp.tar.gz --exclude=node_modules --exclude=dist .
54+
55+
# Pull latest changes
56+
echo "Pulling latest code..."
57+
git fetch origin
58+
git reset --hard origin/main
59+
60+
# Install dependencies
61+
echo "Installing dependencies..."
62+
npm ci --production
63+
64+
# Build application
65+
echo "Building application..."
66+
npm run build
67+
68+
# Restart application with PM2
69+
echo "Restarting application..."
70+
pm2 restart affiliate-app || pm2 start npm --name "affiliate-app" -- start
71+
72+
# Save PM2 configuration
73+
pm2 save
74+
75+
# Show status
76+
echo "Deployment complete! Current status:"
77+
pm2 status
78+
79+
# Keep only last 5 backups
80+
echo "Cleaning old backups..."
81+
cd ~/backups
82+
ls -t app-backup-*.tar.gz | tail -n +6 | xargs -r rm
83+
84+
echo "✅ Deployment successful!"
85+
86+
- name: Verify deployment
87+
uses: appleboy/ssh-action@v1.0.3
88+
with:
89+
host: ${{ secrets.RASPBERRY_PI_HOST }}
90+
username: ${{ secrets.RASPBERRY_PI_USER }}
91+
key: ${{ secrets.RASPBERRY_PI_SSH_KEY }}
92+
port: ${{ secrets.RASPBERRY_PI_PORT || 22 }}
93+
script: |
94+
# Wait for application to start
95+
sleep 5
96+
97+
# Check if application is running
98+
if pm2 status | grep -q "affiliate-app.*online"; then
99+
echo "✅ Application is running"
100+
pm2 logs affiliate-app --lines 10 --nostream
101+
else
102+
echo "❌ Application failed to start"
103+
pm2 logs affiliate-app --err --lines 30 --nostream
104+
exit 1
105+
fi
106+
107+
# Test health endpoint (if available)
108+
if curl -f http://localhost:5000/health 2>/dev/null; then
109+
echo "✅ Health check passed"
110+
else
111+
echo "⚠️ Health endpoint not available (this is OK if not implemented)"
112+
fi
113+
114+
- name: Notify on failure
115+
if: failure()
116+
uses: appleboy/ssh-action@v1.0.3
117+
with:
118+
host: ${{ secrets.RASPBERRY_PI_HOST }}
119+
username: ${{ secrets.RASPBERRY_PI_USER }}
120+
key: ${{ secrets.RASPBERRY_PI_SSH_KEY }}
121+
port: ${{ secrets.RASPBERRY_PI_PORT || 22 }}
122+
script: |
123+
echo "❌ Deployment failed! Rolling back..."
124+
125+
# Find latest backup
126+
latest_backup=$(ls -t ~/backups/app-backup-*.tar.gz | head -1)
127+
128+
if [ -n "$latest_backup" ]; then
129+
echo "Restoring from: $latest_backup"
130+
cd ~/Affiliateandsecurityapp
131+
tar -xzf "$latest_backup"
132+
npm ci --production
133+
npm run build
134+
pm2 restart affiliate-app
135+
echo "✅ Rollback complete"
136+
else
137+
echo "⚠️ No backup found to rollback to"
138+
fi

0 commit comments

Comments
 (0)