This is a complete backend implementation for the AlphaZee Client Platform, built with Flask and PostgreSQL. The backend provides a comprehensive API for managing clients, projects, contracts, payments, and communication.
- User registration and login with JWT tokens
- Password reset functionality
- Identity verification with ID card and signature uploads
- Role-based access control (Admin/Client)
- Session management
- Project submission with automatic account creation
- Project status tracking and milestone management
- File uploads and project documentation
- Project type categorization
- Progress tracking and reporting
- Contract creation and digital signing
- Contract lifecycle management (draft → sent → signed → active → completed)
- Digital signature verification
- Contract expiration handling
- PDF generation support
- Stripe payment integration
- Invoice generation and management
- Payment tracking and history
- Milestone-based payments
- Tax calculation
- Messaging between clients and admin
- Real-time notifications
- Message threading and replies
- File attachments support
- User management and verification
- Project oversight and status updates
- Contract and payment management
- System analytics and reporting
- Activity logging
- Framework: Flask 3.1.1
- Database: PostgreSQL with SQLAlchemy ORM
- Authentication: Flask-JWT-Extended
- Migrations: Flask-Migrate
- Email: Flask-Mail
- File Storage: Local storage with AWS S3 support
- Payments: Stripe integration
- CORS: Flask-CORS
The database includes the following main tables:
users- User accounts and profilesidentity_verifications- Identity verification dataprojects- Project information and statusproject_types- Project categorizationproject_milestones- Project milestone trackingproject_files- File attachmentscontracts- Contract managementcontract_signatures- Digital signaturespayments- Payment transactionsinvoices- Invoice managementmessages- Communication systemnotifications- User notificationsactivity_logs- System activity tracking
POST /register- User registrationPOST /login- User loginPOST /logout- User logoutPOST /refresh- Refresh JWT tokenPOST /forgot-password- Request password resetPOST /reset-password- Reset password
GET /profile- Get user profilePUT /profile- Update user profilePOST /upload-avatar- Upload profile picturePOST /verify-identity- Submit identity verificationGET /verification-status- Check verification status
GET /types- Get project typesPOST /submit- Submit new project (public endpoint)GET /- Get user projectsGET /{id}- Get project detailsPUT /{id}/status- Update project status (admin)GET /{id}/milestones- Get project milestonesPOST /{id}/milestones- Create milestone (admin)PUT /{id}/milestones/{milestone_id}/complete- Complete milestone (admin)GET /{id}/files- Get project filesPOST /{id}/files- Upload project file
GET /- Get contractsGET /{id}- Get contract detailsPOST /- Create contract (admin)PUT /{id}/send- Send contract to client (admin)POST /{id}/sign- Sign contractPUT /{id}/activate- Activate contract (admin)PUT /{id}/complete- Complete contract (admin)
GET /- Get paymentsGET /{id}- Get payment detailsPOST /- Create payment request (admin)POST /{id}/process- Process paymentPOST /{id}/intent- Create Stripe payment intentPOST /{id}/confirm- Confirm paymentGET /invoices- Get invoicesPOST /invoices- Create invoice (admin)
GET /- Get messagesGET /{id}- Get message detailsPOST /- Send messagePOST /{id}/reply- Reply to messagePUT /{id}/read- Mark message as readGET /unread-count- Get unread message countGET /notifications- Get notificationsPUT /notifications/{id}/read- Mark notification as read
POST /upload- Upload general fileGET /download/{path}- Download fileGET /info/{path}- Get file informationDELETE /delete/{path}- Delete file
GET /dashboard- Get admin dashboardGET /users- Get all usersGET /users/{id}- Get user detailsPUT /users/{id}/status- Update user statusPUT /users/{id}/verification- Update verification statusGET /project-types- Manage project typesPOST /project-types- Create project typeGET /activity-logs- Get activity logsPOST /system/cleanup- System cleanupPOST /system/broadcast- Broadcast message
- Python 3.11+
- PostgreSQL 14+
- Virtual environment
cd alphazee_backend
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txt# Install PostgreSQL
sudo apt update
sudo apt install postgresql postgresql-contrib
# Start PostgreSQL
sudo systemctl start postgresql
sudo systemctl enable postgresql
# Create database and user
sudo -u postgres createdb alphazee_db
sudo -u postgres psql -c "CREATE USER alphazee_user WITH PASSWORD 'alphazee_password';"
sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE alphazee_db TO alphazee_user;"
sudo -u postgres psql -c "ALTER USER alphazee_user CREATEDB;"cp .env.example .env
# Edit .env file with your configurationexport FLASK_APP=src/main.py
flask db init
flask db migrate -m "Initial migration"
flask db upgradepython src/main.pyThe application will be available at http://localhost:5000
# Flask Configuration
SECRET_KEY=your-secret-key-here
JWT_SECRET_KEY=your-jwt-secret-key-here
# Database Configuration
DATABASE_URL=postgresql://alphazee_user:alphazee_password@localhost/alphazee_db
# Email Configuration
MAIL_SERVER=smtp.gmail.com
MAIL_PORT=587
MAIL_USE_TLS=true
MAIL_USERNAME=your-email@gmail.com
MAIL_PASSWORD=your-app-password
MAIL_DEFAULT_SENDER=noreply@alphazee.com
# Stripe Configuration
STRIPE_PUBLISHABLE_KEY=pk_test_your-stripe-publishable-key
STRIPE_SECRET_KEY=sk_test_your-stripe-secret-key
# Application URLs
FRONTEND_URL=http://localhost:5173
BACKEND_URL=http://localhost:5000
# CORS Configuration
CORS_ORIGINS=http://localhost:5173,http://localhost:3000pip install gunicorn
gunicorn -w 4 -b 0.0.0.0:5000 src.main:appFROM python:3.11-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
EXPOSE 5000
CMD ["gunicorn", "-w", "4", "-b", "0.0.0.0:5000", "src.main:app"]- Set
DEBUG=False - Use strong secret keys
- Configure proper database credentials
- Set up SSL/TLS certificates
- Configure email server
- Set up Stripe production keys
- Configure file storage (AWS S3 recommended)
- JWT token-based authentication
- Password hashing with bcrypt
- CORS protection
- SQL injection prevention with SQLAlchemy ORM
- File upload validation
- Rate limiting (can be added with Flask-Limiter)
- Input validation and sanitization
The system supports both local file storage and AWS S3:
Files are stored in the uploads/ directory with organized subdirectories:
avatars/- User profile picturesidentity/front_id/- Front ID card imagesidentity/back_id/- Back ID card imagesidentity/signatures/- Digital signaturesprojects/{project_id}/- Project filescontracts/{contract_id}/signatures/- Contract signatures
Configure AWS credentials in environment variables to use S3 storage.
The application includes comprehensive error handling and logging. Test the API endpoints using:
# Health check
curl http://localhost:5000/api/health
# Test project types endpoint
curl http://localhost:5000/api/projects/types- Application logs are written to console and can be redirected to files
- Activity logging tracks all user actions
- Database queries are logged in debug mode
- Error handling with proper HTTP status codes
For issues or questions regarding the backend implementation, please refer to the code comments and documentation within each module.
This backend implementation is proprietary software for AlphaZee Client Platform.