Skip to content

Commit 1b7823d

Browse files
Initial commit
0 parents  commit 1b7823d

31 files changed

+708
-0
lines changed

.gitattributes

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto

.gitignore

+114
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
*.egg-info/
24+
.installed.cfg
25+
*.egg
26+
MANIFEST
27+
28+
# PyInstaller
29+
# Usually these files are written by a python script from a template
30+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
31+
*.manifest
32+
*.spec
33+
34+
# Installer logs
35+
pip-log.txt
36+
pip-delete-this-directory.txt
37+
38+
# Unit test / coverage reports
39+
htmlcov/
40+
.tox/
41+
.nox/
42+
.coverage
43+
.coverage.*
44+
.cache
45+
nosetests.xml
46+
coverage.xml
47+
*.cover
48+
.hypothesis/
49+
.pytest_cache/
50+
51+
# Translations
52+
*.mo
53+
*.pot
54+
55+
# Django stuff:
56+
*.log
57+
local_settings.py
58+
db.sqlite3
59+
60+
# Flask stuff:
61+
instance/
62+
.webassets-cache
63+
64+
# Scrapy stuff:
65+
.scrapy
66+
67+
# Sphinx documentation
68+
docs/_build/
69+
70+
# PyBuilder
71+
target/
72+
73+
# Jupyter Notebook
74+
.ipynb_checkpoints
75+
76+
# IPython
77+
profile_default/
78+
ipython_config.py
79+
80+
# pyenv
81+
.python-version
82+
83+
# celery beat schedule file
84+
celerybeat-schedule
85+
86+
# SageMath parsed files
87+
*.sage.py
88+
89+
# Environments
90+
.env
91+
.venv
92+
env/
93+
venv/
94+
ENV/
95+
env.bak/
96+
venv.bak/
97+
98+
# Spyder project settings
99+
.spyderproject
100+
.spyproject
101+
102+
# Rope project settings
103+
.ropeproject
104+
105+
# mkdocs documentation
106+
/site
107+
108+
# mypy
109+
.mypy_cache/
110+
.dmypy.json
111+
dmypy.json
112+
113+
# Pyre type checker
114+
.pyre/

.idea/.gitignore

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/FastApiArchitecture.iml

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/inspectionProfiles/Project_Default.xml

+27
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/inspectionProfiles/profiles_settings.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

BaseApp/UserApp/__init__.py

Whitespace-only changes.

BaseApp/UserApp/models.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from sqlalchemy import Boolean, Column, Integer, String, DateTime
2+
import datetime
3+
from BaseApp.database import Base
4+
5+
6+
class User(Base):
7+
__tablename__ = "users"
8+
id = Column(Integer, primary_key=True)
9+
fullname = Column(String)
10+
created_date = Column(DateTime, default=datetime.datetime.utcnow)
11+
username = Column(String, unique=True)
12+
hashed_password = Column(String)
13+
is_active = Column(Boolean, default=True)
14+
is_delete = Column(Boolean, default=False)

BaseApp/UserApp/router.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from fastapi import Depends, APIRouter, HTTPException, status
2+
from BaseApp.UserApp import schemas
3+
4+
api = APIRouter()
5+
6+
7+
@api.get("/")
8+
def index():
9+
return {"key": "value"}

BaseApp/UserApp/schemas.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from pydantic import BaseModel
2+
from typing import Optional
3+
import datetime
4+
from fastapi import Body
5+
6+
7+
class User(BaseModel):
8+
username: str
9+
10+
11+
class UserCreate(User):
12+
password: str
13+
email: str

BaseApp/__init__.py

Whitespace-only changes.

BaseApp/database.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from sqlalchemy import create_engine
2+
from sqlalchemy.ext.declarative import declarative_base
3+
from sqlalchemy.orm import sessionmaker
4+
import os
5+
from dotenv import load_dotenv
6+
7+
load_dotenv()
8+
9+
SQLALCHEMY_DATABASE_URL = os.environ.get('SQL_DB_URL')
10+
11+
engine = create_engine(
12+
SQLALCHEMY_DATABASE_URL,
13+
)
14+
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
15+
16+
Base = declarative_base()

BaseApp/dependencies.py

Whitespace-only changes.

BaseApp/manager.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from fastapi import Depends, FastAPI, HTTPException, status
2+
from BaseApp.database import engine
3+
4+
# Import Apps here
5+
from BaseApp import UserApp
6+
from BaseApp.UserApp import models, router
7+
8+
# Binding Apps to database engine
9+
UserApp.models.Base.metadata.create_all(bind=engine)
10+
11+
# FastApi Object
12+
app = FastAPI()
13+
14+
# Include Apps to main fast app
15+
app.include_router(UserApp.router.api, prefix="/users")

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# FastApiArchitecture
2+
FastApi Project Architecture with database and alembic tools

alembic.ini

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# A generic, single database configuration.
2+
3+
[alembic]
4+
# path to migration scripts
5+
script_location = db-migration
6+
7+
# template used to generate migration files
8+
# file_template = %%(rev)s_%%(slug)s
9+
10+
# sys.path path, will be prepended to sys.path if present.
11+
# defaults to the current working directory.
12+
prepend_sys_path = .
13+
14+
# timezone to use when rendering the date
15+
# within the migration file as well as the filename.
16+
# string value is passed to dateutil.tz.gettz()
17+
# leave blank for localtime
18+
# timezone =
19+
20+
# max length of characters to apply to the
21+
# "slug" field
22+
# truncate_slug_length = 40
23+
24+
# set to 'true' to run the environment during
25+
# the 'revision' command, regardless of autogenerate
26+
# revision_environment = false
27+
28+
# set to 'true' to allow .pyc and .pyo files without
29+
# a source .py file to be detected as revisions in the
30+
# versions/ directory
31+
# sourceless = false
32+
33+
# version location specification; this defaults
34+
# to db-migration/versions. When using multiple version
35+
# directories, initial revisions must be specified with --version-path
36+
# version_locations = %(here)s/bar %(here)s/bat db-migration/versions
37+
38+
# the output encoding used when revision files
39+
# are written from script.py.mako
40+
# output_encoding = utf-8
41+
42+
sqlalchemy.url = postgresql://ajay:143136420@localhost/fastapi
43+
44+
45+
[post_write_hooks]
46+
# post_write_hooks defines scripts or Python functions that are run
47+
# on newly generated revision scripts. See the documentation for further
48+
# detail and examples
49+
50+
# format using "black" - use the console_scripts runner, against the "black" entrypoint
51+
# hooks = black
52+
# black.type = console_scripts
53+
# black.entrypoint = black
54+
# black.options = -l 79 REVISION_SCRIPT_FILENAME
55+
56+
# Logging configuration
57+
[loggers]
58+
keys = root,sqlalchemy,alembic
59+
60+
[handlers]
61+
keys = console
62+
63+
[formatters]
64+
keys = generic
65+
66+
[logger_root]
67+
level = WARN
68+
handlers = console
69+
qualname =
70+
71+
[logger_sqlalchemy]
72+
level = WARN
73+
handlers =
74+
qualname = sqlalchemy.engine
75+
76+
[logger_alembic]
77+
level = INFO
78+
handlers =
79+
qualname = alembic
80+
81+
[handler_console]
82+
class = StreamHandler
83+
args = (sys.stderr,)
84+
level = NOTSET
85+
formatter = generic
86+
87+
[formatter_generic]
88+
format = %(levelname)-5.5s [%(name)s] %(message)s
89+
datefmt = %H:%M:%S

db-migration/README

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Generic single-database configuration.

0 commit comments

Comments
 (0)