Skip to content

Commit a59d7a0

Browse files
committed
Update backend services, add payment functionality, and improve dashboard UI
1 parent 235901a commit a59d7a0

File tree

26 files changed

+4348
-570
lines changed

26 files changed

+4348
-570
lines changed

.env.example

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ LINKEDIN_ACCESS_TOKEN=your_linkedin_access_token_here
2323
LINKEDIN_USER_URN=your_linkedin_user_urn_here
2424

2525
# ========================================
26-
# AI SERVICE (GROQ)
26+
# AI SERVICE (GROQ) - Free Tier Default
2727
# ========================================
2828
# Get your API key from: https://console.groq.com/keys
2929
# 1. Sign up for a free account
@@ -33,6 +33,24 @@ LINKEDIN_USER_URN=your_linkedin_user_urn_here
3333

3434
GROQ_API_KEY=your_groq_api_key_here
3535

36+
# ========================================
37+
# AI SERVICE (OPENAI) - Pro Tier
38+
# ========================================
39+
# Get your API key from: https://platform.openai.com/api-keys
40+
# Required for GPT-4o access (Pro tier only)
41+
# Usage-based pricing, ~$5-15/1M tokens
42+
43+
OPENAI_API_KEY=your_openai_api_key_here
44+
45+
# ========================================
46+
# AI SERVICE (ANTHROPIC) - Pro Tier
47+
# ========================================
48+
# Get your API key from: https://console.anthropic.com/
49+
# Required for Claude 3.5 Sonnet access (Pro tier only)
50+
# Usage-based pricing, ~$3-15/1M tokens
51+
52+
ANTHROPIC_API_KEY=your_anthropic_api_key_here
53+
3654
# ========================================
3755
# GITHUB INTEGRATION (Optional)
3856
# ========================================
@@ -84,6 +102,30 @@ CLERK_ISSUER=https://your-clerk-instance.clerk.accounts.dev
84102
# WARNING: Never set to 'true' in production!
85103
DEV_MODE=false
86104

105+
# ========================================
106+
# PRODUCTION SETTINGS
107+
# ========================================
108+
# Set to 'production' for JSON structured logging
109+
# Leave unset or 'development' for human-readable console logs
110+
ENVIRONMENT=development
111+
112+
# SSL Certificate Verification (default: true)
113+
# SECURITY: NEVER set to 'false' in production!
114+
# Only disable for local development with self-signed certificates
115+
SSL_VERIFY=true
116+
117+
# Request timeout for OAuth API calls (in seconds)
118+
AUTH_REQUEST_TIMEOUT=15
119+
120+
# ========================================
121+
# REDIS (Task Queue)
122+
# ========================================
123+
# Redis URL for Celery message broker and result backend
124+
# Format: redis://[[username]:[password]]@host:port/db
125+
# Docker Compose default: redis://redis:6379/0
126+
# Local development: redis://localhost:6379/0
127+
REDIS_URL=redis://localhost:6379/0
128+
87129
# ========================================
88130
# DATABASE (Production)
89131
# ========================================
@@ -92,6 +134,31 @@ DEV_MODE=false
92134
# Leave unset for local SQLite fallback
93135
# DATABASE_URL=postgresql://user:password@host:5432/database
94136

137+
# ========================================
138+
# STRIPE PAYMENTS (Optional)
139+
# ========================================
140+
# Get these from: https://dashboard.stripe.com/developers
141+
# 1. Go to Developers → API keys
142+
# 2. Copy the Secret key (sk_test_... or sk_live_...)
143+
# For webhooks:
144+
# 1. Go to Developers → Webhooks → Add endpoint
145+
# 2. URL: https://your-api-domain.com/webhook/stripe
146+
# 3. Select events: checkout.session.completed, invoice.payment_succeeded,
147+
# invoice.payment_failed, customer.subscription.updated, customer.subscription.deleted
148+
# 4. Copy the Signing secret (whsec_...)
149+
150+
STRIPE_SECRET_KEY=sk_test_your_stripe_secret_key_here
151+
STRIPE_WEBHOOK_SECRET=whsec_your_stripe_webhook_secret_here
152+
153+
# Stripe Price IDs for your subscription plans
154+
# Create these in Stripe Dashboard → Products
155+
STRIPE_PRICE_PRO_MONTHLY=price_your_monthly_price_id
156+
STRIPE_PRICE_PRO_YEARLY=price_your_yearly_price_id
157+
158+
# Redirect URLs after checkout
159+
STRIPE_SUCCESS_URL=http://localhost:3000/dashboard?payment=success
160+
STRIPE_CANCEL_URL=http://localhost:3000/pricing
161+
95162
# ========================================
96163
# SECURITY - Token Encryption
97164
# ========================================

.github/workflows/ci.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,14 @@ jobs:
4545
LINKEDIN_CLIENT_ID: test_client_id
4646
LINKEDIN_CLIENT_SECRET: test_client_secret
4747
GROQ_API_KEY: test_groq_key
48+
OPENAI_API_KEY: test_openai_key
49+
ANTHROPIC_API_KEY: test_anthropic_key
4850
DATABASE_URL: sqlite+aiosqlite:///./test.db
51+
REDIS_URL: redis://localhost:6379/0
4952
ENCRYPTION_KEY: Ag45Scx9q_Q6w3xF8Lz5j2p7n9v0k1m3b5v7c9x1z3m=
5053
CLERK_ISSUER: https://test-clerk.accounts.dev
54+
STRIPE_SECRET_KEY: sk_test_placeholder
55+
STRIPE_WEBHOOK_SECRET: whsec_test_placeholder
5156

5257
# ============================================
5358
# Frontend Tests (Next.js/React)

.github/workflows/daily-post.yml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,36 @@ jobs:
1313
contents: read
1414
steps:
1515
- name: Checkout code
16-
uses: actions/checkout@v3
16+
uses: actions/checkout@v4
1717

1818
- name: Set up Python
19-
uses: actions/setup-python@v4
19+
uses: actions/setup-python@v5
2020
with:
21-
python-version: '3.10'
21+
python-version: '3.11'
2222

2323
- name: Install dependencies
2424
run: |
2525
python -m pip install --upgrade pip
26-
pip install requests python-dateutil groq python-dotenv
26+
pip install requests python-dateutil groq openai anthropic python-dotenv structlog
2727
2828
- name: Run LinkedIn Post Bot
2929
env:
3030
LINKEDIN_ACCESS_TOKEN: ${{ secrets.LINKEDIN_ACCESS_TOKEN }}
3131
LINKEDIN_USER_URN: ${{ secrets.LINKEDIN_USER_URN }}
32+
# AI Providers
3233
GROQ_API_KEY: ${{ secrets.GROQ_API_KEY }}
34+
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
35+
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
36+
# Optional: Image service
3337
UNSPLASH_ACCESS_KEY: ${{ secrets.UNSPLASH_ACCESS_KEY }}
34-
# Prefer a repo secret `MY_GITHUB_USERNAME`; if not set, fall back to the workflow actor
38+
# GitHub config
3539
MY_GITHUB_USERNAME: ${{ secrets.MY_GITHUB_USERNAME || github.actor }}
36-
# Pass token for authenticated API calls: prefer custom secret, otherwise built-in GITHUB_TOKEN
3740
MY_GITHUB_TOKEN: ${{ secrets.MY_GITHUB_TOKEN || secrets.GITHUB_TOKEN }}
3841
run: python bot.py
3942

4043
- name: Upload last generated post
4144
if: always()
42-
uses: actions/upload-artifact@v3
45+
uses: actions/upload-artifact@v4
4346
with:
4447
name: generated-posts
4548
path: last_generated_post.txt

Makefile

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
# =============================================================================
2+
# PostBot - Docker Development Commands
3+
# =============================================================================
4+
#
5+
# Usage: make <command>
6+
#
7+
# Run `make help` to see all available commands.
8+
#
9+
# Prerequisites:
10+
# - Docker & Docker Compose installed
11+
# - .env file configured (copy from .env.example)
12+
#
13+
# =============================================================================
14+
15+
.PHONY: help up down logs restart build worker-logs beat-logs migrate test shell clean prune redis-cli status
16+
17+
.DEFAULT_GOAL := help
18+
19+
# Colors for terminal output
20+
CYAN := \033[36m
21+
GREEN := \033[32m
22+
YELLOW := \033[33m
23+
RED := \033[31m
24+
RESET := \033[0m
25+
26+
# =============================================================================
27+
# HELP
28+
# =============================================================================
29+
30+
help: ## Show this help message
31+
@echo ""
32+
@echo "$(CYAN)PostBot - Docker Development Commands$(RESET)"
33+
@echo "======================================="
34+
@echo ""
35+
@echo "$(GREEN)Quick Start:$(RESET)"
36+
@echo " 1. Copy .env.example to .env and configure"
37+
@echo " 2. Run: make up"
38+
@echo " 3. Open: http://localhost:3000"
39+
@echo ""
40+
@echo "$(GREEN)Available Commands:$(RESET)"
41+
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " $(CYAN)%-15s$(RESET) %s\n", $$1, $$2}'
42+
@echo ""
43+
44+
# =============================================================================
45+
# DOCKER COMPOSE COMMANDS
46+
# =============================================================================
47+
48+
up: ## Start the entire stack (detached mode)
49+
@echo "$(GREEN)Starting PostBot stack...$(RESET)"
50+
docker-compose up -d
51+
@echo ""
52+
@echo "$(GREEN)✓ Stack started!$(RESET)"
53+
@echo " Frontend: http://localhost:3000"
54+
@echo " Backend: http://localhost:8000"
55+
@echo " API Docs: http://localhost:8000/docs"
56+
@echo ""
57+
@echo "$(YELLOW)Tip: Run 'make logs' to see output$(RESET)"
58+
59+
down: ## Stop the entire stack
60+
@echo "$(RED)Stopping PostBot stack...$(RESET)"
61+
docker-compose down
62+
@echo "$(GREEN)✓ Stack stopped$(RESET)"
63+
64+
restart: ## Restart all services
65+
@echo "$(YELLOW)Restarting PostBot stack...$(RESET)"
66+
docker-compose restart
67+
@echo "$(GREEN)✓ Stack restarted$(RESET)"
68+
69+
build: ## Rebuild all Docker images (use after requirements.txt changes)
70+
@echo "$(YELLOW)Rebuilding Docker images...$(RESET)"
71+
docker-compose build --no-cache
72+
@echo "$(GREEN)✓ Images rebuilt$(RESET)"
73+
74+
status: ## Show status of all containers
75+
@echo "$(CYAN)Container Status:$(RESET)"
76+
docker-compose ps
77+
78+
# =============================================================================
79+
# LOGS
80+
# =============================================================================
81+
82+
logs: ## Tail logs for all services
83+
docker-compose logs -f
84+
85+
worker-logs: ## Tail Celery worker logs (for debugging background tasks)
86+
@echo "$(CYAN)Tailing Celery worker logs...$(RESET)"
87+
docker-compose logs -f worker
88+
89+
beat-logs: ## Tail Celery beat scheduler logs
90+
@echo "$(CYAN)Tailing Celery beat logs...$(RESET)"
91+
docker-compose logs -f beat
92+
93+
backend-logs: ## Tail backend API logs
94+
docker-compose logs -f backend
95+
96+
frontend-logs: ## Tail frontend logs
97+
docker-compose logs -f frontend
98+
99+
# =============================================================================
100+
# DATABASE & MIGRATIONS
101+
# =============================================================================
102+
103+
migrate: ## Run Alembic migrations inside the backend container
104+
@echo "$(YELLOW)Running database migrations...$(RESET)"
105+
docker-compose exec backend alembic upgrade head
106+
@echo "$(GREEN)✓ Migrations complete$(RESET)"
107+
108+
migrate-create: ## Create a new migration (usage: make migrate-create MSG="add user table")
109+
@echo "$(YELLOW)Creating new migration...$(RESET)"
110+
docker-compose exec backend alembic revision --autogenerate -m "$(MSG)"
111+
@echo "$(GREEN)✓ Migration created$(RESET)"
112+
113+
migrate-history: ## Show migration history
114+
docker-compose exec backend alembic history
115+
116+
# =============================================================================
117+
# TESTING
118+
# =============================================================================
119+
120+
test: ## Run backend tests (pytest)
121+
@echo "$(CYAN)Running backend tests...$(RESET)"
122+
docker-compose exec backend pytest -v
123+
@echo "$(GREEN)✓ Tests complete$(RESET)"
124+
125+
test-cov: ## Run tests with coverage report
126+
@echo "$(CYAN)Running tests with coverage...$(RESET)"
127+
docker-compose exec backend pytest --cov=. --cov-report=term-missing
128+
129+
# =============================================================================
130+
# SHELL ACCESS
131+
# =============================================================================
132+
133+
shell: ## Open a bash shell inside the backend container
134+
@echo "$(CYAN)Opening shell in backend container...$(RESET)"
135+
docker-compose exec backend /bin/bash
136+
137+
shell-frontend: ## Open a shell inside the frontend container
138+
docker-compose exec frontend /bin/sh
139+
140+
redis-cli: ## Open Redis CLI
141+
@echo "$(CYAN)Opening Redis CLI...$(RESET)"
142+
docker-compose exec redis redis-cli
143+
144+
# =============================================================================
145+
# CLEANUP
146+
# =============================================================================
147+
148+
clean: ## Stop stack and remove volumes (WARNING: deletes data)
149+
@echo "$(RED)Stopping stack and removing volumes...$(RESET)"
150+
docker-compose down -v
151+
@echo "$(GREEN)✓ Stack stopped and volumes removed$(RESET)"
152+
153+
prune: ## Remove unused Docker resources
154+
@echo "$(YELLOW)Pruning unused Docker resources...$(RESET)"
155+
docker system prune -f
156+
@echo "$(GREEN)✓ Cleanup complete$(RESET)"
157+
158+
# =============================================================================
159+
# DEVELOPMENT SHORTCUTS
160+
# =============================================================================
161+
162+
dev-backend: ## Start only backend services (redis + backend + worker + beat)
163+
docker-compose up -d redis backend worker beat
164+
165+
dev-frontend: ## Start only frontend (assumes backend is running elsewhere)
166+
docker-compose up -d frontend
167+
168+
# =============================================================================
169+
# HEALTH CHECKS
170+
# =============================================================================
171+
172+
health: ## Check health of all services
173+
@echo "$(CYAN)Checking service health...$(RESET)"
174+
@echo ""
175+
@echo "Backend API:"
176+
@curl -s http://localhost:8000/health | python -m json.tool 2>/dev/null || echo " $(RED)✗ Not responding$(RESET)"
177+
@echo ""
178+
@echo "Redis:"
179+
@docker-compose exec -T redis redis-cli ping 2>/dev/null || echo " $(RED)✗ Not responding$(RESET)"
180+
@echo ""
181+
@echo "Frontend:"
182+
@curl -s -o /dev/null -w " Status: %{http_code}\n" http://localhost:3000 2>/dev/null || echo " $(RED)✗ Not responding$(RESET)"

0 commit comments

Comments
 (0)