Production-ready FastAPI framework with RBAC, OAuth, JWT, billing, modular architecture, and base class patterns. Create projects with 'swx new', scaffold with 'swx make:resource --base'.
Project description
๐ SwX-API
SwX-API is a production-ready, enterprise-grade FastAPI framework designed for building scalable SaaS applications. With comprehensive authentication, authorization, billing, rate limiting, audit logging, and more, it provides everything you need to build and deploy production applications.
Built with โค๏ธ for developers who value flexibility, security, and structure.
๐ Framework Status: Production Ready v2.0.0
โจ Key Features
๐ Security & Authentication
- โ Domain Separation - Admin, User, and System domains completely isolated
- โ OAuth2 + JWT - Secure token-based authentication with refresh tokens
- โ Social Login - Google, Facebook, and other OAuth providers
- โ Token Security - Audience validation, expiration, and revocation
- โ Secrets Management - Secure handling of sensitive configuration
๐ก๏ธ Authorization & Access Control
- โ Permission-First RBAC - Fine-grained access control with team scoping
- โ Policy Engine (ABAC) - Attribute-based access control with conditions
- โ Team-Scoped Permissions - Multi-tenant support with team isolation
- โ Fail-Closed Security - Deny by default, explicit allow
๐ฐ Billing & Entitlements
- โ Feature Registry - Centralized feature management
- โ Plan Management - Flexible subscription plans (Free, Pro, Team, Enterprise)
- โ Entitlement Resolution - Automatic feature access checking
- โ Usage Tracking - Quota and metered feature tracking
- โ Stripe Integration - Payment processing support
โก Performance & Scalability
- โ Async Model - Full async/await support for high performance
- โ Rate Limiting - Plan-based rate limits with burst protection
- โ Redis Caching - In-memory caching for improved performance
- โ Background Jobs - Asynchronous job processing with retries
- โ Connection Pooling - Optimized database connections with health checks
๐ Operations & Monitoring
- โ Audit Logging - Immutable security and business event logs
- โ Alerting System - Multi-channel alerts (Slack, Email, SMS, Logs)
- โ Health Checks - Comprehensive health monitoring
- โ Runtime Settings - Database-backed configuration management
- โ Background Jobs - Job queue with retry logic and dead-letter queue
๐ ๏ธ Developer Experience
- โ Modular Architecture - Clean separation of core and app code
- โ Base Classes Pattern - BaseController, BaseService, BaseRepository for rapid development (v2.0)
- โ SQLModel ORM - Type-safe database models
- โ Alembic Migrations - Database version control
- โ
CLI Tools -
swxcommand for scaffolding with--baseflag for modern patterns - โ Comprehensive Documentation - 50+ documentation files
- โ Testing Tools - Unit tests, integration tests, acceptance tests
- โ Docker Ready - Complete Docker Compose setup
๐ What's New in v2.0
BaseController / BaseService / BaseRepository
Reduce boilerplate by 80% with the new base classes pattern:
# v2.0 - Modern pattern (recommended)
from swx_core.controllers.base import BaseController
from swx_core.services.base import BaseService
from swx_core.repositories.base import BaseRepository
class ProductRepository(BaseRepository[Product]):
def __init__(self):
super().__init__(model=Product)
# Automatic: find_by_id, find_all, create, update, delete, search, paginate...
class ProductService(BaseService[Product, ProductRepository]):
def __init__(self):
super().__init__(repository=ProductRepository())
# Automatic: get, create, update, delete with events and validation hooks...
class ProductController(BaseController[Product, Create, Update, Public]):
def __init__(self):
super().__init__(model=Product, ...)
self.register_routes()
# Automatic: GET, POST, PUT, DELETE endpoints...
New Utilities
- Unit of Work - Transaction management with automatic commit/rollback
- Filter Builder - Fluent query filtering and sorting
- Caching Decorators -
@cached,@memoizefor Redis operations - Rate Limiting -
@rate_limit_by_ip,@rate_limit_by_user - Testing Utilities - ModelFactory, TestClientWithDB, assertions
CLI Improvements
# Generate resources with base classes (recommended)
swx make:resource Product --base
# Generate legacy patterns
swx make:resource Product
See Migration Guide for upgrading from v1.x.
๐ Project Structure
swx-api-latest-backend/
โโโ swx_core/ # Framework code (reusable)
โ โโโ auth/ # Authentication (admin, user, system)
โ โโโ cli/ # CLI commands
โ โโโ config/ # Configuration
โ โโโ controllers/ # BaseController (v2.0)
โ โโโ services/ # BaseService (v2.0)
โ โโโ repositories/ # BaseRepository (v2.0)
โ โโโ database/ # Database setup and utilities
โ โโโ middleware/ # Middleware (CORS, logging, rate limiting)
โ โโโ models/ # Framework models (User, Role, Permission, etc.)
โ โโโ rbac/ # RBAC system
โ โโโ routes/ # Framework routes (admin, user, utils)
โ โโโ security/ # Security utilities
โ โโโ services/ # Framework services (billing, jobs, alerts, etc.)
โ โโโ utils/ # Utility functions (pagination, caching, filters...)
โโโ swx_app/ # Application code (your features)
โ โโโ controllers/ # Application controllers
โ โโโ models/ # Application models
โ โโโ repositories/ # Application repositories
โ โโโ routes/ # Application routes
โ โโโ services/ # Application services
โโโ migrations/ # Alembic migrations
โโโ docs/ # Comprehensive documentation
โ โโโ 04-core-concepts/
โ โ โโโ BASE_CLASSES.md # BaseController/BaseService/BaseRepository (NEW)
โ โ โโโ UTILITIES.md # All utility modules (NEW)
โ โ โโโ USAGE_EXAMPLES.md # Complete usage examples (NEW)
โ โโโ 07-extending/
โ โโโ MIGRATION_GUIDE.md # v1.x to v2.0 migration (NEW)
โโโ scripts/ # Utility scripts
โโโ Dockerfile # Docker configuration
โโโ docker-compose.yml # Docker Compose (development)
โโโ docker-compose.production.yml # Docker Compose (production)
๐ Quick Start
Prerequisites
- Python 3.10+
- Docker & Docker Compose (recommended)
- PostgreSQL 12+
- Redis 6+
Installation
Option 1: Docker (Recommended)
# Clone repository
git clone <repository-url>
cd swx-api-latest-backend
# Copy environment file
cp .env.example .env
# Edit .env with your configuration
# Then start services
docker compose up --build
# Application will be available at:
# - API: http://localhost:8001/api
# - Docs: http://localhost:8001/docs
# - ReDoc: http://localhost:8001/redoc
Option 2: Local Development
# Clone repository
git clone <repository-url>
cd swx-api-latest-backend
# Create virtual environment
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Or using uv (faster)
uv pip install -r requirements.txt
# Copy environment file
cp .env.example .env
# Run database migrations
alembic upgrade head
# Start development server
uvicorn swx_core.main:app --reload --host 0.0.0.0 --port 8001
Initial Setup
After starting the application:
-
Seed System Data:
python scripts/seed_system.py -
Verify Installation:
curl http://localhost:8001/api/utils/health-check -
Access Documentation:
- Swagger UI: http://localhost:8001/docs
- ReDoc: http://localhost:8001/redoc
๐ Documentation
SwX-API includes comprehensive documentation covering all aspects of the framework:
Getting Started
- Getting Started Guide - Installation and setup
- Overview - Framework introduction
- Architecture - System design
Core Concepts (v2.0)
- Base Classes - Controller/Service/Repository pattern
- Utilities - All utility modules
- Usage Examples - Complete code examples
- Authentication - Auth flows and token security
- RBAC - Role-based access control
- Policy Engine - Attribute-based access control
- Billing - Billing and entitlements
- Rate Limiting - Abuse protection
- Audit Logs - Logging system
- Background Jobs - Async job processing
Security
- Security Model - Overall security architecture
- Token Security - JWT token security
- Secrets Management - Secure secrets handling
Extending
- Extending Guide - Extension patterns
- Adding Features - Feature development
- Migration Guide - v1.x to v2.0 migration
๐ See Documentation Index for complete documentation structure.
๐ ๏ธ Development
CLI Commands
# Generate resources with base classes (v2.0 - recommended)
swx make:resource Product --base
# Generate resources with legacy patterns
swx make:resource Product
# Database migrations
swx db migrate
swx db revision -m "description"
# Code quality
swx format # Format code
swx lint # Lint code
# Interactive shell
swx tinker
๐ Example Usage
Base Classes (v2.0)
# Complete resource in minutes
from swx_core.controllers.base import BaseController
from swx_core.services.base import BaseService
from swx_core.repositories.base import BaseRepository
from swx_core.utils.mixins import FullModelMixin
# Model
class Product(FullModelMixin, table=True):
name: str
price: float
# Repository
class ProductRepository(BaseRepository[Product]):
def __init__(self):
super().__init__(model=Product)
# Service
class ProductService(BaseService[Product, ProductRepository]):
def __init__(self):
super().__init__(repository=ProductRepository())
# Controller
class ProductController(BaseController[Product, ProductCreate, ProductUpdate, ProductPublic]):
def __init__(self):
super().__init__(
model=Product,
schema_public=ProductPublic,
schema_create=ProductCreate,
schema_update=ProductUpdate,
prefix="/products",
)
self.register_routes()
# Automatic endpoints:
# GET /products - List with pagination
# GET /products/{id} - Get by ID
# POST /products - Create
# PUT /products/{id} - Update
# DELETE /products/{id} - Delete
Authentication
# User domain authentication
from swx_core.security.dependencies import get_current_user
@router.get("/user/profile")
async def get_profile(user: User = Depends(get_current_user)):
return user
Authorization
# Permission-based access
from swx_core.rbac.dependencies import require_permission
@router.get("/users", dependencies=[Depends(require_permission("user:read"))])
async def list_users():
...
Rate Limiting
from swx_core.utils.rate_limit import rate_limit_by_user
@router.get("/api/search")
@rate_limit_by_user(requests=100, window=60) # 100 req/min
async def search(q: str):
return await search_service.search(q)
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Acknowledgments
- FastAPI for the excellent web framework
- SQLModel for the ORM
- All contributors and users
๐ Support
- Documentation: docs/
- Issues: GitHub Issues
- Discussions: GitHub Discussions
Built with โค๏ธ for developers who value flexibility, security, and structure.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file swx_core-2.3.3.tar.gz.
File metadata
- Download URL: swx_core-2.3.3.tar.gz
- Upload date:
- Size: 484.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
10ebdfecbfdcfb3ba89eb0c5c7d4ab014be6c719d19a7209091272db8f7ab9e8
|
|
| MD5 |
ae9bc5c8b60dded6363ce6a45275bc75
|
|
| BLAKE2b-256 |
3c2d2a59abe4095d8f4639c0f150b731dd7094f47de8d126263c11d363c141ac
|
File details
Details for the file swx_core-2.3.3-py3-none-any.whl.
File metadata
- Download URL: swx_core-2.3.3-py3-none-any.whl
- Upload date:
- Size: 368.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4a0a5e5ef2369c2205bb585e350900585cfdb7aa804ddc98f96b04579f059e0f
|
|
| MD5 |
03e76fc14b3f01cb125226c7db98f1b9
|
|
| BLAKE2b-256 |
e212bd45a841aebf1d9b2aad5150b41d87e92d969a0d13e7380c47cf5b15d59b
|