Production-ready AI image generation platform with subscription management, built on Azure cloud infrastructure.
- β AI Image Generation - Text-to-image and image-to-image using FLUX models
- β Real-time Updates - WebSocket integration for live generation status
- β Subscription Management - Three-tier pricing with Stripe integration
- β Credit System - Usage tracking and credit management
- β Authentication - Azure AD B2C with Google sign-in
- β Cloud Storage - Azure Blob Storage for generated images
- β Queue Processing - Azure Service Bus for async generation
- β Content Safety - Azure Content Safety API integration
- Backend: FastAPI (Python) with async/await
- Frontend: Next.js 14 (React, TypeScript)
- Database: Azure Cosmos DB (MongoDB API)
- Storage: Azure Blob Storage with CDN
- Queue: Azure Service Bus
- Payments: Stripe with webhooks
- Auth: Azure AD B2C + MSAL.js
- AI: Replicate API (FLUX models)
- Deployment: Azure Container Apps + Vercel
ImageGenerator/
βββ app/ # Backend (FastAPI)
β βββ api/
β β βββ v1/
β β βββ endpoints/ # API endpoints
β β βββ auth.py # Authentication
β β βββ generate.py # Image generation
β β βββ subscriptions.py # Stripe integration
β βββ core/ # Core functionality
β β βββ auth_dependencies.py
β β βββ azure_clients.py
β β βββ security.py
β βββ models/ # Data models
β β βββ user.py
β β βββ generation.py
β β βββ subscription.py
β βββ repositories/ # Data access layer
β βββ services/ # Business logic
β β βββ replicate_service.py # Replicate API
β β βββ payment_service.py # Stripe integration
β β βββ credit_service.py # Credit management
β β βββ azure_blob_service.py # Storage
β β βββ queue_service.py # Service Bus
β β βββ worker_service.py # Background jobs
β βββ schemas/ # Pydantic schemas
β βββ config.py # Configuration
β βββ main.py # FastAPI app
β
βββ frontend/ # Frontend (Next.js)
β βββ app/ # App router pages
β β βββ auth/ # Authentication pages
β β β βββ login/ # Login page
β β β βββ callback/ # OAuth callback handler
β β βββ generate/ # Generation pages
β β β βββ text-to-image/ # Text-to-image generation
β β β βββ image-to-image/ # Image-to-image generation
β β βββ dashboard/ # User dashboard
β β βββ pricing/ # Subscription pricing
β βββ components/ # React components
β β βββ auth/ # Auth components
β βββ lib/ # Utilities
β β βββ api/ # API functions
β β β βββ auth.ts # Auth API
β β β βββ generate.ts # Generation API
β β β βββ subscription.ts # Subscription API
β β β βββ usage.ts # Usage API
β β βββ auth/ # Authentication
β β β βββ msal-config.ts
β β β βββ auth-context.tsx
β β βββ types/ # TypeScript types
β β βββ api-client.ts # API client
β β βββ websocket-client.ts # WebSocket client
β βββ public/ # Static assets
β
βββ docs/ # Documentation
β βββ AUTHENTICATION_FLOW.md # Complete auth flow documentation
β βββ AUTH_QUICK_START.md # Authentication setup guide
β βββ AUTHENTICATION_IMPLEMENTATION_SUMMARY.md # Auth implementation
β βββ GENERATION_PAGES_IMPLEMENTATION.md # Generation pages guide
β βββ REPLICATE_SERVICE.md # Replicate integration guide
β βββ STRIPE_INTEGRATION.md # Stripe payment guide
β βββ FRONTEND_INTEGRATION.md # Frontend integration
β βββ TESTING_GUIDE.md # Testing guide
β βββ DEPLOYMENT_TROUBLESHOOTING.md # Deployment guide
β
βββ tests/ # Test suites
βββ scripts/ # Utility scripts
βββ Dockerfile # Backend container
βββ docker-compose.yml # Local development
βββ README.md # This file
- Framework: FastAPI 0.104+
- Language: Python 3.11+
- Database: Azure Cosmos DB (MongoDB API)
- Storage: Azure Blob Storage
- Queue: Azure Service Bus
- Auth: Azure AD B2C, JWT
- Payments: Stripe API
- AI: Replicate API (FLUX models)
- Monitoring: Application Insights
- Framework: Next.js 14 (App Router)
- Language: TypeScript 5+
- State: React Context API
- Auth: MSAL.js (Azure AD B2C)
- API Client: Axios
- Real-time: WebSocket
- UI: Tailwind CSS
- Deployment: Vercel
- Python 3.11+
- Node.js 18+
- Docker Desktop (for local development)
- Azure account
- Stripe account
- Replicate API account
git clone https://github.com/yourusername/ImageGenerator.git
cd ImageGenerator
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Copy environment template
cp .env.example .env
# Edit .env with your credentials
nano .env
# Run database migrations
python scripts/init_database.py
# Start backend
uvicorn app.main:app --reload --port 8000
Backend will be available at: http://localhost:8000
API Documentation: http://localhost:8000/docs
cd frontend
# Install dependencies
npm install
# Copy environment template
cp .env.local.example .env.local
# Edit .env.local with your credentials
nano .env.local
# Start development server
npm run dev
Frontend will be available at: http://localhost:3000
# In a new terminal, from project root:
source venv/bin/activate
python worker.py
-
Cosmos DB (MongoDB API)
- Database:
imagegenerator
- Collections:
users
,generations
,subscriptions
,usage_logs
- Database:
-
Storage Account
- Container:
images
- Public access: Blob
- CORS enabled
- Container:
-
Service Bus
- Queue:
image-generation-queue
- Queue:
-
Key Vault
- Secrets: Replicate API token, Stripe keys
-
Azure AD B2C
- User flow: Sign up/sign in
- App registration with API scopes
See .env.example
(backend) and .env.local.example
(frontend) for complete list.
Critical Variables:
# Backend
AZURE_COSMOS_ENDPOINT=...
AZURE_STORAGE_ACCOUNT_URL=...
AZURE_KEY_VAULT_URL=...
REPLICATE_API_TOKEN=...
STRIPE_SECRET_KEY=...
# Frontend
NEXT_PUBLIC_API_URL=http://localhost:8000
NEXT_PUBLIC_AZURE_AD_B2C_TENANT=...
NEXT_PUBLIC_AZURE_AD_B2C_CLIENT_ID=...
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=...
# Backend
pytest tests/ -v --cov=app
# Frontend
cd frontend
npm test
cd frontend
npm run test:e2e
# Backend
pytest --cov=app --cov-report=html
# Frontend
npm test -- --coverage
See TESTING_GUIDE.md for comprehensive testing documentation.
# Build and push image
docker build -t yourregistry.azurecr.io/imagegen-api:latest .
docker push yourregistry.azurecr.io/imagegen-api:latest
# Deploy
az containerapp create \
--name imagegen-api \
--resource-group imagegen-rg \
--environment imagegen-env \
--image yourregistry.azurecr.io/imagegen-api:latest \
--target-port 8000 \
--ingress external
cd frontend
vercel --prod
See DEPLOYMENT_TROUBLESHOOTING.md for complete deployment guide.
Comprehensive documentation is available in the docs/
directory:
- Replicate Service - FLUX model integration
- Stripe Integration - Payment & subscriptions
- Frontend Integration - API client & auth
- Testing Guide - Testing strategies
- Deployment Guide - Production deployment
- API Documentation - Interactive API docs (when running)
- User clicks "Sign In"
- Redirects to Azure AD B2C
- User authenticates (Google, email, etc.)
- Returns with auth code
- MSAL exchanges for tokens
- Tokens stored and used for API calls
- User submits prompt on frontend
- API creates generation record
- Sends message to Service Bus queue
- Worker picks up message
- Calls Replicate API
- Polls for completion
- Downloads image
- Uploads to Azure Blob Storage
- Updates database
- WebSocket notifies frontend
- Image displays to user
- User selects plan
- Frontend calls backend checkout endpoint
- Backend creates Stripe session
- Redirects to Stripe Checkout
- User completes payment
- Stripe sends webhook to backend
- Backend allocates credits
- User can generate images
Feature | Free | Basic ($9.99/mo) | Premium ($29.99/mo) |
---|---|---|---|
Credits | 10/month | 200/month | Unlimited |
Models | FLUX Schnell | Schnell + Dev | All models + Pro |
Priority | No | Yes | Highest |
Watermark | Yes | No | No |
API Access | No | No | Yes |
Support | Community | Priority |
- β JWT authentication with Azure AD B2C
- β API rate limiting
- β CORS configuration
- β Input validation and sanitization
- β SQL injection protection (parameterized queries)
- β Secrets in Azure Key Vault
- β HTTPS only in production
- β Content Safety API integration
- β Stripe webhook signature verification
- β Managed Identity for Azure resources
- Application Insights - Telemetry and logging
- Azure Monitor - Resource metrics
- Stripe Dashboard - Payment monitoring
- Custom alerts - Error rate, response time, etc.
Common issues and solutions:
Authentication fails
- Check redirect URI matches Azure AD B2C config
- Verify client ID and tenant name
API connection fails
- Check CORS settings
- Verify API URL in frontend env variables
Generations stuck
- Check worker service is running
- Verify Service Bus queue has messages
Payment webhook fails
- Check webhook endpoint is accessible
- Verify webhook secret matches
See DEPLOYMENT_TROUBLESHOOTING.md for detailed troubleshooting.
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Make your changes
- Write tests
- Submit a pull request
This project is licensed under the MIT License - see LICENSE file for details.
- FLUX Models by Black Forest Labs
- Replicate for AI model hosting
- Stripe for payment processing
- Microsoft Azure for cloud infrastructure
- FastAPI framework
- Next.js framework
- Documentation: docs/
- Issues: GitHub Issues
- Email: support@yourdomain.com
- Multi-language support
- Mobile apps (iOS, Android)
- Advanced editing tools
- Team collaboration features
- API for developers
- More AI models
- Video generation
- Custom model training
- Backend: β Production Ready
- Frontend: β Production Ready
- Documentation: β Complete
- Tests: β 80%+ Coverage
- Deployment: β Azure + Vercel
- Check documentation
- Review troubleshooting guide
- Search existing issues
- Open a new issue with:
- Problem description
- Steps to reproduce
- Expected vs actual behavior
- Logs/screenshots
Built with β€οΈ using Azure, FastAPI, and Next.js
Last Updated: January 2025 Version: 1.0.0