Project Structure
FastAPI νλ‘μ νΈ κ΅¬μ‘° μ€κ³ ν λ μ°Έκ³ νκΈ° μ’λ€.
Netflaix/Dipatchλ₯Ό μ°Έμ‘°νμ¬ μμ ν μλ£μ΄λ€.
fastapi-project
βββ alembic/
βββ app # μλ³Έμ src μ΄μ§λ§ λ³ΈμΈμ app μ νΈν¨.
β βββ auth
β β βββ router.py
β β βββ schemas.py # pydantic models
β β βββ models.py # db models
β β βββ dependencies.py
β β βββ config.py # local configs
β β βββ constants.py
β β βββ exceptions.py
β β βββ service.py
β β βββ utils.py
β βββ aws
β β βββ client.py # client model for external service communication
β β βββ schemas.py
β β βββ config.py
β β βββ constants.py
β β βββ exceptions.py
β β βββ utils.py
β βββ posts
β β βββ router.py
β β βββ schemas.py
β β βββ models.py
β β βββ dependencies.py
β β βββ constants.py
β β βββ exceptions.py
β β βββ service.py
β β βββ utils.py
β βββ config.py # global configs
β βββ models.py # global models
β βββ exceptions.py # global exceptions
β βββ pagination.py # global module e.g. pagination
β βββ database.py # db connection related stuff
β βββ main.py
βββ tests/
β βββ auth
β βββ aws
β βββ posts
βββ templates/
β βββ index.html
βββ requirements
β βββ base.txt
β βββ dev.txt
β βββ prod.txt
βββ .env
βββ .gitignore
βββ logging.ini
βββ alembic.ini
νλ‘μ νΈκ° νμ₯λ κ²μ μΌλνμ¬, λλ©μΈ λ³λ‘ ꡬ쑰λ₯Ό κ°μ Έκ°λ€ ( crud, router, models λ‘ λλλ κ²μ΄ μλ)
1. λͺ¨λ λλ©μΈ λλ ν 리λ₯Ό app/ μμ μ μ₯νλ€.
- app/- μ±μ μ΅μμ λλ ν 리λ‘, μΌλ°μ μΈ λͺ¨λΈ, μ€μ , μμ λ±μ ν¬ν¨νλ€.
- app/main.py- FastAPI μ±μ μ΄κΈ°ννλ νλ‘μ νΈμ 루νΈ
2. κ° ν¨ν€μ§μλ λΌμ°ν°, μ€ν€λ§, λͺ¨λΈ λ±μ΄ μλ€.
- router.py- λͺ¨λ μλν¬μΈνΈλ₯Ό κ°μΆ κ° λͺ¨λμ ν΅μ¬
- schemas.py- pydantic λͺ¨λΈμ©
- models.py- db λͺ¨λΈμ©
- service.py- λͺ¨λλ³ λΉμ¦λμ€ λ‘μ§
- dependencies.py- λΌμ°ν° μ’ μμ±
- constants.py- λͺ¨λλ³ μμ λ° μ€λ₯ μ½λ
- config.py- μ: νκ²½ λ³μ
- utils.py- λΉμ¦λμ€ λ‘μ§μ΄ μλ κΈ°λ₯, μ: μλ΅ μ κ·ν, λ°μ΄ν° λ³΄κ° λ±
- exceptions.py- λͺ¨λλ³ μμΈ, μ PostNotFound:InvalidUserData
3. λ€λ₯Έ ν¨ν€μ§μμ (μλΉμ€, μμ) λ±μ΄ νμν κ²½μ° λͺ μμ μΌλ‘ λͺ¨λ μ΄λ¦μΌλ‘ κ°μ Έμ¨λ€.
from src.auth import constants as auth_constants
from src.notifications import service as notification_service
from src.posts.constants import ErrorCode as PostsErrorCode # PostsErrorCodeλ‘ κ°μ Έμ¨λ€.
μΆμ²
GitHub - zhanymkanov/fastapi-best-practices: FastAPI Best Practices and Conventions we used at our startup
FastAPI Best Practices and Conventions we used at our startup - zhanymkanov/fastapi-best-practices
github.com
'π Backend' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
[FastAPI] SQLModel (0) | 2025.03.14 |
---|---|
[SQL] SELECT κ΄λ ¨ ν¨μ (0) | 2025.02.05 |
[Security] μ€νλ§ μνλ¦¬ν° (0) | 2024.02.27 |
[Spring Basic] μ€νλ§ μ±κΈν€ (0) | 2024.01.18 |
[Spring Basic] μ€νλ§ μ»¨ν μ΄λμ λΉ (0) | 2024.01.18 |