Skip to content

Commit

Permalink
feat(new-arch): update to new arch
Browse files Browse the repository at this point in the history
  • Loading branch information
wangxin688 committed May 15, 2024
1 parent 80f17af commit 86eb6b2
Show file tree
Hide file tree
Showing 65 changed files with 1,072 additions and 363 deletions.
2 changes: 1 addition & 1 deletion .env_example
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ REFRESH_TOKEN_EXPIRE_MINUTES=11520
SQLALCHEMY_DATABASE_URI=postgresql+asyncpg://demo:91fb8e9e009f5b9ce1854d947e6fe4a3@localhost:5432/naas
REDIS_DSN=redis://:cfe1c2c4703abb205d71abdc07cc3f3d@localhost:6379

APP_ENV=PRD
APP_ENV=PROD

# docker compose
DEFAULT_DB_PASSWORD=91fb8e9e009f5b9ce1854d947e6fe4a3
Expand Down
2 changes: 1 addition & 1 deletion .python-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.11.6
3.12.3
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ Please notice that this project is still working in progress.
11. I18N support for backed db and error message.
12. X-request-id for logging and request.
13. ...

## Project Structure

## planning
1. Fix some errors and type hint issues
2. Enhance DTO base for better crud support.
3. Release beta version.
4. enhance docs.

2 changes: 1 addition & 1 deletion alembic/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from sqlalchemy import pool, Connection
from sqlalchemy.ext.asyncio import AsyncEngine
import asyncio
from src import config as app_config
from src.core import config as app_config
from alembic import context


Expand Down
4 changes: 2 additions & 2 deletions deploy/init_pg.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from sqlalchemy.ext.asyncio import AsyncSession

from src.auth.models import Group, Role, User
from src.db.session import async_session
from src.enums import ReservedRoleSlug
from src.core.database.session import async_session
from src.features.auth.consts import ReservedRoleSlug


async def create_pg_extensions(session: AsyncSession) -> None:
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ dependencies = [
"pydantic_extra_types>=2.4.1",
"phonenumbers>=8.13.27",
"asyncpg>=0.29.0",
"sqladmin>=0.16.1",
]
readme = "README.md"
requires-python = ">= 3.11"
requires-python = ">= 3.12"

# [project.scripts]
# hello = "naas-backend:hello"
Expand Down
95 changes: 92 additions & 3 deletions requirements-dev.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,69 +5,158 @@
# pre: false
# features: []
# all-features: false
# with-sources: false

-e file:.
alembic==1.13.1
# via fastapi-enterprise-template
annotated-types==0.6.0
# via pydantic
anyio==4.2.0
async-timeout==4.0.3
# via httpx
# via starlette
# via watchfiles
asyncpg==0.29.0
# via fastapi-enterprise-template
black==23.12.1
certifi==2023.11.17
# via httpcore
# via httpx
# via sentry-sdk
cfgv==3.4.0
# via pre-commit
click==8.1.7
# via black
# via uvicorn
coverage==7.4.0
# via pytest-cov
distlib==0.3.8
# via virtualenv
fastapi==0.108.0
# via fastapi-enterprise-template
filelock==3.13.1
# via virtualenv
greenlet==3.0.3
# via sqlalchemy
h11==0.14.0
# via httpcore
# via uvicorn
httpcore==1.0.2
# via httpx
httptools==0.6.1
# via uvicorn
httpx==0.26.0
# via fastapi-enterprise-template
identify==2.5.33
# via pre-commit
idna==3.6
# via anyio
# via httpx
iniconfig==2.0.0
# via pytest
jinja2==3.1.3
# via sqladmin
mako==1.3.0
# via alembic
markupsafe==2.1.3
# via jinja2
# via mako
# via wtforms
mypy==1.8.0
mypy-extensions==1.0.0
# via black
# via mypy
nodeenv==1.8.0
# via pre-commit
numpy==1.26.3
# via pandas
packaging==23.2
# via black
# via pytest
pandas==2.1.4
# via fastapi-enterprise-template
passlib==1.7.4
# via fastapi-enterprise-template
pathspec==0.12.1
# via black
phonenumbers==8.13.27
# via fastapi-enterprise-template
platformdirs==4.1.0
# via black
# via virtualenv
pluggy==1.3.0
# via pytest
pre-commit==3.6.0
pydantic==2.5.3
# via fastapi
# via pydantic-extra-types
# via pydantic-settings
pydantic-core==2.14.6
# via pydantic
pydantic-extra-types==2.4.1
# via fastapi-enterprise-template
pydantic-settings==2.1.0
# via fastapi-enterprise-template
pyjwt==2.8.0
# via fastapi-enterprise-template
pytest==7.4.4
# via pytest-asyncio
# via pytest-cov
pytest-asyncio==0.23.3
pytest-cov==4.1.0
python-dateutil==2.8.2
# via pandas
python-dotenv==1.0.0
# via pydantic-settings
# via uvicorn
python-multipart==0.0.9
# via sqladmin
pytz==2023.3.post1
# via pandas
pyyaml==6.0.1
# via pre-commit
# via uvicorn
redis==5.0.1
# via fastapi-enterprise-template
ruff==0.1.11
sentry-sdk==1.39.2
# via fastapi-enterprise-template
setuptools==69.0.3
# via nodeenv
six==1.16.0
# via python-dateutil
sniffio==1.3.0
# via anyio
# via httpx
sqladmin==0.16.1
# via fastapi-enterprise-template
sqlalchemy==2.0.25
# via alembic
# via fastapi-enterprise-template
# via sqladmin
starlette==0.32.0.post1
# via fastapi
# via sqladmin
typing-extensions==4.9.0
# via alembic
# via fastapi
# via mypy
# via pydantic
# via pydantic-core
# via sqlalchemy
tzdata==2023.4
# via pandas
urllib3==2.1.0
# via sentry-sdk
uvicorn==0.25.0
# via fastapi-enterprise-template
uvloop==0.19.0
# via uvicorn
virtualenv==20.25.0
# via pre-commit
watchfiles==0.21.0
# via uvicorn
websockets==12.0
# The following packages are considered to be unsafe in a requirements file:
setuptools==69.0.3
# via uvicorn
wtforms==3.1.2
# via sqladmin
70 changes: 69 additions & 1 deletion requirements.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,47 +5,115 @@
# pre: false
# features: []
# all-features: false
# with-sources: false

-e file:.
alembic==1.13.1
# via fastapi-enterprise-template
annotated-types==0.6.0
# via pydantic
anyio==4.2.0
async-timeout==4.0.3
# via httpx
# via starlette
# via watchfiles
asyncpg==0.29.0
# via fastapi-enterprise-template
certifi==2023.11.17
# via httpcore
# via httpx
# via sentry-sdk
click==8.1.7
# via uvicorn
fastapi==0.108.0
# via fastapi-enterprise-template
greenlet==3.0.3
# via sqlalchemy
h11==0.14.0
# via httpcore
# via uvicorn
httpcore==1.0.2
# via httpx
httptools==0.6.1
# via uvicorn
httpx==0.26.0
# via fastapi-enterprise-template
idna==3.6
# via anyio
# via httpx
jinja2==3.1.3
# via sqladmin
mako==1.3.0
# via alembic
markupsafe==2.1.3
# via jinja2
# via mako
# via wtforms
numpy==1.26.3
# via pandas
pandas==2.1.4
# via fastapi-enterprise-template
passlib==1.7.4
# via fastapi-enterprise-template
phonenumbers==8.13.27
# via fastapi-enterprise-template
pydantic==2.5.3
# via fastapi
# via pydantic-extra-types
# via pydantic-settings
pydantic-core==2.14.6
# via pydantic
pydantic-extra-types==2.4.1
# via fastapi-enterprise-template
pydantic-settings==2.1.0
# via fastapi-enterprise-template
pyjwt==2.8.0
# via fastapi-enterprise-template
python-dateutil==2.8.2
# via pandas
python-dotenv==1.0.0
# via pydantic-settings
# via uvicorn
python-multipart==0.0.9
# via sqladmin
pytz==2023.3.post1
# via pandas
pyyaml==6.0.1
# via uvicorn
redis==5.0.1
# via fastapi-enterprise-template
sentry-sdk==1.39.2
# via fastapi-enterprise-template
six==1.16.0
# via python-dateutil
sniffio==1.3.0
# via anyio
# via httpx
sqladmin==0.16.1
# via fastapi-enterprise-template
sqlalchemy==2.0.25
# via alembic
# via fastapi-enterprise-template
# via sqladmin
starlette==0.32.0.post1
# via fastapi
# via sqladmin
typing-extensions==4.9.0
# via alembic
# via fastapi
# via pydantic
# via pydantic-core
# via sqlalchemy
tzdata==2023.4
# via pandas
urllib3==2.1.0
# via sentry-sdk
uvicorn==0.25.0
# via fastapi-enterprise-template
uvloop==0.19.0
# via uvicorn
watchfiles==0.21.0
# via uvicorn
websockets==12.0
# via uvicorn
wtforms==3.1.2
# via sqladmin
12 changes: 6 additions & 6 deletions src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
from starlette.middleware.cors import CORSMiddleware
from starlette.middleware.errors import ServerErrorMiddleware

from src.config import settings
from src.core.config import settings
from src.core.error.auth_exceptions import default_exception_handler, exception_handlers, sentry_ignore_errors
from src.enums import Env
from src.exceptions import default_exception_handler, exception_handlers, sentry_ignore_errors
from src.middlewares import RequestMiddleware
from src.libs.redis import cache
from src.openapi import openapi_description
from src.routers import router
from src.utils import cache
from src.register.middlewares import RequestMiddleware
from src.register.routers import router


def create_app() -> FastAPI:
Expand All @@ -26,7 +26,7 @@ async def lifespan(app: FastAPI) -> AsyncIterator[None]: # noqa: ARG001
yield
await pool.disconnect()

if settings.ENV == Env.PRD.name: # noqa: SIM300
if settings.ENV == Env.PROD.name: # noqa: SIM300
sentry_sdk.init(
dsn=settings.WEB_SENTRY_DSN,
sample_rate=settings.SENTRY_SAMPLE_RATE,
Expand Down
Loading

0 comments on commit 86eb6b2

Please sign in to comment.