Skip to content

A modern, secure, and scalable SaaS application template built with FastAPI, featuring multi-tenancy, authentication, and role-based access control.

Notifications You must be signed in to change notification settings

cycle-sync-ai/cyclesyncai-fastapi-multi-tenancy-saas-template

Repository files navigation

FastAPI Multi-tenancy SaaS Template

A modern, secure, and scalable SaaS application template built with FastAPI, featuring multi-tenancy, authentication, and role-based access control.

Features

  • 🔐 Secure Authentication

    • JWT-based authentication
    • Password hashing with bcrypt
  • 🏢 Multi-tenancy

    • Tenant isolation
    • Tenant-specific data access
    • User-tenant associations
    • Primary tenant selection
  • 🛠 Modern Tech Stack

    • FastAPI for high-performance API
    • SQLAlchemy for database operations
    • Pydantic for data validation
    • Alembic for database migrations
  • 🔄 Database

    • PostgreSQL support
    • Async database operations
    • Unit of Work pattern
    • Repository pattern

Prerequisites

  • Python 3.8+
  • PostgreSQL 12+
  • Docker (optional)

Installation

  1. Clone the repository:
git clone https://github.com/yourusername/fastapi-saas-template.git
cd fastapi-saas-template
  1. Create and activate a virtual environment:
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
  1. Install dependencies:
pip install -r requirements.txt
  1. Set up environment variables:
cp .env.example .env
# Edit .env with your configuration
  1. Run database migrations:
alembic upgrade head

Running the Application

Development

uvicorn app.main:app --reload

Production

uvicorn app.main:app --host 0.0.0.0 --port 8000

API Documentation

Once the application is running, you can access:

  • Swagger UI: http://localhost:8000/docs
  • ReDoc: http://localhost:8000/redoc

Project Structure

app/
├── auth/           # Authentication and authorization
├── core/           # Core functionality and utilities
├── db/             # Database configuration and models
├── tenants/        # Tenant management
├── users/          # User management
└── main.py         # Application entry point

Key Components

Authentication

  • JWT-based authentication
  • Role-based access control
  • Secure password handling

Multi-tenancy

  • Tenant isolation
  • User-tenant associations
  • Tenant-specific data access

Database

  • PostgreSQL with SQLAlchemy
  • Async database operations
  • Migration support with Alembic

Security Features

  • JWT token-based authentication
  • Password hashing with bcrypt
  • Role-based access control
  • Tenant isolation
  • Secure session management
  • Input validation with Pydantic

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

For support, please open an issue in the GitHub repository or contact the maintainers.

About

A modern, secure, and scalable SaaS application template built with FastAPI, featuring multi-tenancy, authentication, and role-based access control.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published