The backend is built with:
- FastAPI
- PostgreSQL
- SQLAlchemy
- Alembic (migrations)
- Python 3.12+
backend/
├── app/
│ ├── api/ # API endpoints
│ ├── core/ # Core functionality
│ ├── db/ # Database models and migrations
│ ├── schemas/ # Pydantic models
│ ├── services/ # Business logic
│ └── main.py # Application entry point
├── tests/ # Test suite
├── alembic/ # Database migrations
├── requirements.txt # Python dependencies
└── Dockerfile # Docker configuration
Required environment variables:
# Database
DATABASE_URL=postgresql+asyncpg://user:password@localhost:5432/dd_db
# Google OAuth
GOOGLE_CLIENT_ID=your_google_client_id
GOOGLE_CLIENT_SECRET=your_google_client_secret
# Security
SECRET_KEY=your_random_secret_key
# URLs
BASE_URL=http://localhost:56000
FRONTEND_URL=http://localhost:54287-
Create database:
psql -c "CREATE DATABASE dd_db;" -
Run migrations:
alembic upgrade head
-
Seed initial data:
python -m app.db.seed
# Run all tests
pytest
# Run with coverage
pytest --cov=app
# Run specific test file
pytest tests/test_api.pyOAuth implementation:
app/api/auth.py- Authentication endpointsapp/core/auth.py- Authentication logicapp/core/security.py- Security utilities
Key models:
app/db/models/user.py- User modelapp/db/models/task.py- Task modelapp/db/models/contract.py- Contract modelapp/db/models/wallet.py- Wallet model
Endpoint implementation:
app/api/tasks.py- Task endpointsapp/api/contracts.py- Contract endpointsapp/api/wallets.py- Wallet endpoints
Service layer:
app/services/task.py- Task serviceapp/services/contract.py- Contract serviceapp/services/wallet.py- Wallet service
Using Alembic for migrations:
# Create new migration
alembic revision --autogenerate -m "description"
# Apply migrations
alembic upgrade head
# Rollback migration
alembic downgrade -1Automatic contract processing:
app/core/scheduler.py- Task schedulerapp/services/contract_processor.py- Contract processing logic
Security measures:
-
Authentication:
- OAuth 2.0 with Google
- JWT session tokens
- CSRF protection
-
Authorization:
- Role-based access control
- Parent/child permissions
-
Data Protection:
- Input validation
- SQL injection prevention
- XSS protection
-
Rate Limiting:
- API rate limiting
- Brute force protection
Error handling implementation:
app/core/exceptions.py- Custom exceptionsapp/core/error_handlers.py- Error handlers
Logging configuration:
app/core/logging.py- Logging setup- Application logs
- Access logs
- Error logs
Test implementation:
- Unit tests
- Integration tests
- API tests
- Database tests
Performance optimizations:
-
Database:
- Connection pooling
- Query optimization
- Indexing strategy
-
Caching:
- Response caching
- Query result caching
-
Async Implementation:
- Async database operations
- Async API endpoints
Monitoring setup:
- Health checks
- Performance metrics
- Error tracking
- Resource usage
Deployment configurations:
- Docker setup
- Production settings
- SSL/TLS configuration
- Backup strategy