A FastAPI Clean Architecture project generator
Project description
fastlayer
A FastAPI Clean Architecture (or Layered) project generator.
Features
- Clean Architecture: Layered structure (Domain, Application, Infrastructure, Presentation)
- Layered Architecture: Presentation, Core, DB, Models, Repositories, Services, API layers for simpler projects
- FastAPI: Modern and high-performance web framework
- Docker: Optional Docker and Docker Compose configuration
- Databases: Support for SQLAlchemy, MongoDB, or no database
- Authentication: Templates for JWT, OAuth2, or no authentication
- Testing: Pytest configuration with fixtures and examples
- CI/CD: GitHub Actions or GitLab CI templates
- Update: Ability to update projects with new template versions
Installation
From PyPI
pip install fastlayer
From source
git clone https://github.com/Ulrich75/fastlayer.git
cd fastlayer
pip install -e .
Usage
Create a new project
Interactive mode (recommended):
fastlayer create my-api
Non-interactive mode with options:
fastlayer create my-api \
--database sqlalchemy \
--auth jwt \
--docker \
--cicd github \
--arch clean \
--no-interactive
Available options
--database, -d: Database type (sqlalchemy,mongodb,none)--auth, -a: Authentication method (jwt,oauth2,none)--docker/--no-docker: Include Docker configuration--cicd, -c: CI/CD provider (github,gitlab,none)--output-dir, -o: Custom output directory--interactive/--no-interactive, -i/-n: Interactive mode--arch, -r: Architecture type (clean,layered)
Update an existing project
cd my-api
fastlayer update
Show version
fastlayer --version
Show help
fastlayer --help
fastlayer create --help
Generated project structures
1. Clean Architecture
my-api/
├── src/
│ └── my_api/
│ ├── domain/
│ │ ├── entities/
│ │ ├── repositories/
│ │ └── exceptions.py
│ ├── application/
│ │ ├── use_cases/
│ │ └── dto/
│ ├── infrastructure/
│ │ ├── repositories/
│ │ ├── database.py
│ │ └── config.py
│ ├── presentation/
│ │ └── api/
│ │ ├── routes/
│ │ ├── schemas/
│ │ └── dependencies.py
│ └── main.py
├── tests/
├── pyproject.toml
├── README.md
├── .env.example
├── Dockerfile
├── docker-compose.yml
└── .github/workflows/
2. Layered Architecture
my-api/
├── src/
│ └── my-api/
│ ├── api/
│ │ ├── deps.py
│ │ ├── __init__.py
│ │ └── v1/
│ ├── core/
│ │ ├── config.py
│ │ ├── exceptions.py
│ │ └── __init__.py
│ ├── db/
│ │ ├── __init__.py
│ │ ├── migrations/
│ │ └── session.py
│ ├── __init__.py
│ ├── main.py
│ ├── models/
│ │ └── __init__.py
│ ├── repositories/
│ │ └── __init__.py
│ ├── schemas/
│ │ └── __init__.py
│ └── services/
│ └── __init__.py
└── tests/
| ├── conftest.py
| └── test_api.py
├── README.md
├── pyproject.toml
├── Dockerfile
├── docker-compose.yml
Clean Architecture Principles
Domain Layer
- Entities: Pure business objects with no external dependencies
- Repositories: Abstract interfaces for persistence
- Exceptions: Custom business exceptions
Application Layer
- Use Cases: Application logic and orchestration
- DTOs: Data transfer objects
Infrastructure Layer
- Repositories: Concrete implementations of interfaces
- Database: Configuration and database connection
- Config: Configuration management
Presentation Layer
- Routes: FastAPI endpoints
- Schemas: Pydantic validation
- Dependencies: FastAPI dependency injection
Development
Install in development mode
git clone https://github.com/Ulrich75/fastlayer.git
cd fastlayer
pip install -e ".[dev]"
Run tests
pytest
Linter and formatting
ruff check src/ tests/
black src/ tests/
mypy src/
License
MIT License - see the LICENSE file for details.
Contribution
Contributions are welcome! Feel free to open an issue or a pull request.
Resources
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
fastlayer-0.1.1.tar.gz
(21.9 kB
view details)
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
fastlayer-0.1.1-py3-none-any.whl
(42.2 kB
view details)
File details
Details for the file fastlayer-0.1.1.tar.gz.
File metadata
- Download URL: fastlayer-0.1.1.tar.gz
- Upload date:
- Size: 21.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6c1f3a8db0f47b1ce089a32d0efdaf6a188ff6b666832d6ecb6e0929ccbb6818
|
|
| MD5 |
21bd906c6ee8933cd2da1064e5a1b4b3
|
|
| BLAKE2b-256 |
b1675a8259c50898a7a4565717568155a572087ee2664357111de159da47d104
|
File details
Details for the file fastlayer-0.1.1-py3-none-any.whl.
File metadata
- Download URL: fastlayer-0.1.1-py3-none-any.whl
- Upload date:
- Size: 42.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f74f030b07a7e2aeff990b341d07ce1adf4cc15062c1e225546afba28d40bef8
|
|
| MD5 |
86dce3da3ae813e684b191cdd0e99e6a
|
|
| BLAKE2b-256 |
027332147350010cbdb36037dd637553df9a58c022cfc1822710be1f5bd66f72
|