FastAPI REST boilerplate for typical project
- Features
- Project structure
- Environmnent variables
- Quick run
- Comfortable development
- Links
- Database utils
- Precommit (Pre-commit)
- Config Service (Pydantic).
- Database (Sqlalchemy).
- Database migration (Alembic)
- Swagger.
- Redoc.
- Sign in and sign up via email.
- Social sign in (apple, facebook, google, linkedin, microsoft)
- Seeding (sqlalchemyseed).
- Mailing
- Realtime notification using messaging queue and python-socketio
- File uploads (aws s3, cloudinary, google cloud storage)
- Redis
- Admin and User roles using RBAC (Casbin).
- Admin dashboard using (sqladmin)
- I18N
- Elasticseach
- E2E and units tests.
- Monitoring using grafana and prometheus (Grafana)
- Docker.
- CI (Gitlab).
seeder # Configurtion for database seeding
migrations # Alembic migration files
app # Rest api files
app.core # General components like config, security, types, role, etc...
app.db # Database connection specific
app.crud # CRUD for types from models
app.models # Sqlalchemy models
app.schemas # Pydantic models that used in crud or handlers
app.templates # Html files for mails
app.endpoints # Restapi endpoints files
├── app
| |
│ ├── core
│ ├── crud
│ ├── db
│ ├── endpoints
│ │ ├── api.py
│ │ └── v1
│ │ └── v2
│ │ └── ...
│ ├── main.py
│ ├── models
│ ├── schemas
| |
│ └── templates
|
├── migrations
├── seeder
|── .vscode
To correctly run the project, you will need some environment variables. Expose & import them in core/config.py
befor starting you need to generate RSA key pairs, both public and private keys.
You can use this website or any other method you prefer to generate these keys.
Keep a note of the file paths where you save these keys on your project folder (like private_key.pem
and public_key.pem
) or local machine.
ENV
: Running Environment can be dev, staging, preprodAPI_BASE_URL
: The pathname of the api version urlAPI_URL
: api base urlDB_HOST
: Postgres database hostDB_PORT
: Postgres database portDB_NAME
: Postgres database nameDB_USER_NAME
: Postgres userDB_PASSWORD
: Postgres passwordSECRET_KEY
: Postgres passwordACCESS_TOKEN_EXPIRE_MINUTES
: Access token durationPRIVATE_KEY_PATH
: Specify the absolute file paths to the RSA private key you generated earlier (private_key.pem
if you saved it in your project root folder)PUBLIC_KEY_PATH
: Specify the absolute file paths to the RSA public key you generated earlier (public_key.pem
if you saved it in your project root folder)SMTP_TLS
: Indicates whether to use TLS (true or false) for SMTP email communication.SMTP_PORT
: The port number for SMTP email communication.SMTP_HOST
: The hostname or IP address of the SMTP server for sending emails.SMTP_USER
: The username for authenticating with the SMTP server.SMTP_PASSWORD
: The password for authenticating with the SMTP server.RABBIT_MQ_HOST
: RabbitMQ host (localhost in this case)RABBIT_MQ_PORT
: RabbitMQ port (5672 in this case)RABBIT_MQ_PASSWORD
: RabbitMQ password (password123 in this case)RABBIT_MQ_USER
: RabbitMQ user (root in this case)APPLE_CLIENT_ID
: Apple OAuth client IDAPPLE_SECRET_KEY
: Apple OAuth secret keyAPPLE_WEBHOOK_OAUTH_REDIRECT_URI
: Redirect URI for Apple OAuth callbacksFACEBOOK_CLIENT_ID
: Facebook OAuth client IDFACEBOOK_SECRET_KEY
: Facebook OAuth secret keyFACEBOOK_WEBHOOK_OAUTH_REDIRECT_URI
: Redirect URI for Facebook OAuth callbacksGOOGLE_CLIENT_ID
: Google OAuth client IDGOOGLE_SECRET_KEY
: Google OAuth secret keyGOOGLE_WEBHOOK_OAUTH_REDIRECT_URI
: Redirect URI for Google OAuth callbacksLINKEDIN_CLIENT_ID
: LinkedIn OAuth client IDLINKEDIN_SECRET_KEY
: LinkedIn OAuth secret keyLINKEDIN_WEBHOOK_OAUTH_REDIRECT_URI
: Redirect URI for LinkedIn OAuth callbacksMSAL_CLIENT_ID
: Microsoft MSAL client IDMSAL_CLIENT_SECRET
: Microsoft MSAL client secretMSAL_WEBHOOK_OAUTH_REDIRECT_URI
: Redirect URI for Microsoft MSAL OAuth callbacksCLOUDINARY_CLOUD_NAME
: The name of your Cloudinary cloud.CLOUDINARY_API_KEY
: Your Cloudinary API key.CLOUDINARY_API_SECRET
: Your Cloudinary API secret.AWS_BUCKET_NAME
: The name of the AWS S3 bucket you want to access.AWS_KEY_ID
: AWS access key ID for accessing the S3 bucket.AWS_SECRET_KEY
: AWS secret key for accessing the S3 bucket.AWS_REGION
: The AWS region where the S3 bucket is located.GCS_BUCKET_NAME
: The name of the Google Cloud Storage (GCS) bucket you want to access.REDIS_HOST
:REDIS_PORT
:REDIS_DB
:
git clone --depth 1 https://github.com/kaanari-tech/fastapi-boilerplate.git my-app
cd my-app/
cp .env.example .env
docker-compose up -d --build
For check status run
docker-compose logs
git clone --depth 1 https://github.com/kaanari-tech/fastapi-boilerplate.git my-app
cd my-app/
cp .env.example .env
Change DB_HOST=postgres
to DB_HOST=localhost
, DB_PORT=5432
to DB_PORT=6001
RABBIT_MQ_HOST=rabbitmq
to RABBIT_MQ_HOST=localhost
REDIS_HOST=redis-cache
to REDIS_HOST=localhost
make sure you have poetry install
Run additional container:
docker-compose up -d postgres-db redis-cache rabbitmq adminer
poetry install
poe migrate
poe run
- Swagger: http://localhost:8001/docs
- Redoc: http://localhost:8001/redoc
- Openapi json: http://localhost:8001/api/v1/openapi.json
- Adminer (client for DB): http://localhost:8080
Generate migration
poe makemigrations
Run migration
poe migrate
Revert migration
poe dwngrade
Drop all tables in database
poe drop-tables