Skip to content
This repository was archived by the owner on Feb 19, 2023. It is now read-only.

Commit c637882

Browse files
authored
docs: major updates (#7)
* feat: major updates * feat: major updates * feat: major updates * infra: revert GHA steps * GHS fix * chore: remove redundant flake8 config * chore fixes
1 parent d78c319 commit c637882

File tree

12 files changed

+85
-28
lines changed

12 files changed

+85
-28
lines changed

.env_example

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ SECRET_KEY=
1414
NGINX_HOST=localhost
1515
UPSTREAMS=/:backend:8000
1616

17-
REDIS_HOST=redis://redis:6379
17+
REDIS_HOST=redis
18+
REDIS_PORT=6379

.github/workflows/main.yml

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
uses: actions/checkout@v2
1919
- name: Start linter
2020
run: |
21-
docker run --rm -w="/code/backend" -v $(pwd):/code alpine/flake8:3.9.2 .
21+
docker run --rm -w="/code/backend" -v $(pwd):/code alpine/flake8:3.9.2 --config=pyproject.toml .
2222
2323
black:
2424
runs-on: ubuntu-20.04
@@ -34,10 +34,26 @@ jobs:
3434
working-directory: ./backend
3535
run: |
3636
pip install black==22.6.0
37-
black --check .
37+
black --check --config=pyproject.toml .
38+
39+
isort:
40+
runs-on: ubuntu-20.04
41+
name: isort imports
42+
steps:
43+
- name: Checkout
44+
uses: actions/checkout@v2
45+
- name: Set up Python
46+
uses: actions/setup-python@v1
47+
with:
48+
python-version: '3.9'
49+
- name: run black
50+
working-directory: ./backend
51+
run: |
52+
pip install isort==5.10.1
53+
isort --settings-path=pyproject.toml src
3854
3955
create-release:
40-
needs: [linter, black]
56+
needs: [linter, black, isort]
4157
runs-on: ubuntu-20.04
4258
steps:
4359
- name: checkout

.pre-commit-config.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
default_language_version:
2+
python: python3.9
3+
4+
repos:
5+
- repo: https://github.com/pre-commit/pre-commit-hooks
6+
rev: v4.3.0
7+
hooks:
8+
- id: trailing-whitespace
9+
- id: end-of-file-fixer
10+
- id: check-yaml
11+
- id: debug-statements
12+
- id: requirements-txt-fixer
13+
- repo: https://github.com/psf/black
14+
rev: 22.6.0
15+
hooks:
16+
- id: black
17+
args: ["--config=./backend/pyproject.toml"]
18+
- repo: https://github.com/PyCQA/flake8
19+
rev: 5.0.4
20+
hooks:
21+
- id: flake8
22+
args: ["--config=./backend/pyproject.toml"]
23+
- repo: https://github.com/PyCQA/isort
24+
rev: 5.10.1
25+
hooks:
26+
- id: isort
27+
args: ["--settings-path=./backend/pyproject.toml"]

README.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,30 @@ Small base project to build and deploy a fastapi backend..batteries included.
2020
* **Robust**: Get production-ready code. With automatic interactive documentation.
2121
* **Standards-based**: Based on (and fully compatible with) the open standards for APIs: <a href="https://github.com/OAI/OpenAPI-Specification" class="external-link" target="_blank">OpenAPI</a> and <a href="http://json-schema.org/" class="external-link" target="_blank">JSON Schema</a>.
2222
* <a href="https://fastapi.tiangolo.com/features/" class="external-link" target="_blank">**Many other features**</a> including automatic validation, serialization, interactive documentation, authentication with OAuth2 JWT tokens, etc.
23-
* **SQLAlchemy** models
23+
* **SQLModel** Library for interacting with SQL databases from Python code, with Python objects. It is designed to be intuitive, easy to use, highly compatible, and robust
2424
* **CORS** (Cross Origin Resource Sharing).
2525
* **NGINX** High Performance Load Balancer, Web Server, & Reverse Proxy
2626
* **Let's Encrypt** A free, automated, and open certificate authority (CA), provided by the Internet Security Research Group (ISRG)...with automatic cert renewal.
27-
* **MongoDB** General purpose, document-based, distributed database built for modern application developers.
28-
* **Motor** Coroutine-based API for non-blocking access to MongoDB
29-
* Request rate limiting for api routes.
27+
* **PostgresSQL** Powerfull open source object-relational database
28+
* **AsyncPG** Database interface library designed specifically for PostgreSQL and Python/asyncio.
29+
* **Redis** In-memory data structure store, used as a distributed, in-memory key–value database, cache and message broker.
3030

31+
<p align="center">
32+
<a href="#">
33+
<img alt="Architecture Workflow" src="docs/fastapi-backend-base.png">
34+
</a>
35+
</p>
3136

3237
## Usage
3338
1. `git clone https://github.com/nickatnight/fastapi-backend-base.git`
3439
2. `cd fastapi-backend-base`
3540
3. `mv .env_example .env`
3641
4. `docker compose up --build`
37-
5. visit `http://localhost:8000` for uvicorn server, or `http://localhost` for nginx
42+
5. visit `http://localhost:8000` for uvicorn server, or `http://localhost` for nginx proxy
3843

3944
## Deploy
45+
A common scenario is to use an orchestration tool, such as docker swarm, to deploy your containers to the cloud (DigitalOcean)
46+
47+
## Configuration
48+
49+
## Development

backend/.flake8

Lines changed: 0 additions & 4 deletions
This file was deleted.

backend/pyproject.toml

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1+
[flake8]
2+
max-line-length = 100
3+
exclude = '__init__.py,__pycache__,git'
4+
ignore = 'F403,F405,W605,W503,E203,E231'
5+
6+
[tool.isort]
7+
multi_line_output = 3
8+
lines_after_imports = 2
9+
line_length = 88
10+
include_trailing_comma = true
11+
sections = 'FUTURE,STDLIB,THIRDPARTY,FIRSTPARTY,LOCALFOLDER'
12+
113
[tool.black]
214
line-length = 100
315
include = '\.pyi?$'
4-
exclude = '''
5-
/(
6-
\.git
7-
| \.hg
8-
| \.mypy_cache
9-
| \.tox
10-
| \.venv
11-
| _build
12-
)/
13-
'''
16+
exclude = '(\.git|\.hg|\.mypy_cache|\.tox|\.venv|_build)'

backend/requirements/dev.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
-r base.txt
2-
3-
pytest==6.2.3
42
black==22.6.0
5-
flake8==3.9.2
3+
flake8==5.0.4
4+
isort==5.10.1
5+
pytest==6.2.3
66
pytest-cov==2.12.0

backend/src/api/v1/health.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from fastapi import APIRouter
22

3+
34
# from fastapi_limiter.depends import RateLimiter
45

56

backend/src/core/config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ class Settings(BaseSettings):
1818
POSTGRES_PASSWORD: str = Field(..., env="POSTGRES_PASSWORD")
1919
POSTGRES_DB: str = Field(..., env="POSTGRES_DB")
2020
POSTGRES_PORT: str = Field(..., env="POSTGRES_PORT")
21+
2122
REDIS_HOST: str = Field(..., env="REDIS_HOST")
23+
REDIS_PORT: str = Field(..., env="REDIS_PORT")
24+
REDIS_URL: str = f"redis://{REDIS_HOST}:{REDIS_PORT}/0"
2225

2326
VERSION: str = Field(..., env="VERSION")
2427

backend/src/db/session.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from fastapi import HTTPException
2-
from sqlmodel import SQLModel
32
from sqlalchemy.exc import SQLAlchemyError
43
from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine
54
from sqlalchemy.orm import sessionmaker
5+
from sqlmodel import SQLModel
66

77
from src.core.config import settings
88

0 commit comments

Comments
 (0)