Skip to content

Commit a5009c2

Browse files
author
Athira C
committed
first commit
0 parents  commit a5009c2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1946
-0
lines changed

.env

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
DB_USER = "postgres"
2+
DB_PASS = "123456"
3+
DB_HOST = "localhost"
4+
TS_DB_NAME = "flaskdemo"
5+
DB_DRIVER = "postgres"
6+
TS_SCHEMA = "testflask"
7+
POOL_SIZE = 20
8+
TYPE=prod
9+
PORT=5000
10+
SECRET_KEY = "mlkjhgfdghjkhgfdghjkjhgfcd"

.gitignore

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
web/techstack/__pycache__
2+
common/__pycache__
3+
web/swagger/__pycache__
4+
web/__pycache__
5+
repository/__pycache__
6+
.idea/
7+
middleware/__pycache__
8+
.vscode/
9+
tests/__pycache__/
10+
migrations/

README.md

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
2+
# Tech Stack App
3+
4+
This is the basic structure of the Flask App. Folder Structure as well as basic code is included with this app. The Swagger part is also present with this basic app.
5+
6+
7+
How to Setup the Basic Flask App
8+
```
9+
- Create a virtual enviornment and activate the enviornment
10+
- pip install -r requirements.txt
11+
- cd web
12+
- python .\techstack_app.py
13+
14+
```
15+
16+
The basic flask app will be open in http://127.0.0.1:5000
17+
The basic flask swagger api will be open in http://127.0.0.1:5000/apidocs/
18+
19+
How to upgrade the database
20+
21+
```
22+
- Create a folder 'migrations --mkdir migrations
23+
- cd migrations
24+
- alembic init alembic
25+
26+
```
27+
it will create a alembic folder as well as alembic.ini
28+
29+
- Edit the alembic.ini file by changing the sqlalchemy.url
30+
31+
`sqlalchemy.url = postgresql+psycopg2://{username}:{password}@{hostname}/{dbname}`
32+
33+
- In alembic/env.py Add
34+
35+
`sys.path.append(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))), "repository"))`
36+
37+
`import models`
38+
39+
`target_metadata = models.Base.metadata`
40+
-
41+
```
42+
- alembic revision --autogenerate -m {proper message}
43+
- alembic upgrade head
44+
```
45+

common/app_blueprint.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from flask import Blueprint
2+
3+
4+
class AppBP(Blueprint):
5+
def __init__(self, name, import_name):
6+
super().__init__(name, import_name)

common/app_constants.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class AppConstants:
2+
CODE_OK = 200
3+
CODE_INVALID_REQUEST = 400
4+
CODE_UNAUTHORISED = 401
5+
CODE_FORBIDDEN = 403
6+
CODE_INTERNAL_SERVER_ERROR = 500
7+
CODE_NOT_IMPLEMENTED = 501
8+
CODE_BAD_GATEWAY = 502
9+
CODE_SERVICE_UNAVAILABLE = 503
10+
CODE_GATEWAY_TIMEOUT = 504
11+
SUCCESSFULL_STATUS_CODE = "200"
12+
UNSUCCESSFULL_STATUS_CODE = "500"

common/app_response.py

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from app_constants import AppConstants
2+
from string_table import AppMessages
3+
from structlogconfig import log_config
4+
5+
logdata = log_config()
6+
7+
8+
class AppResponse(dict):
9+
def __init__(
10+
self,
11+
code_param=AppConstants.CODE_INTERNAL_SERVER_ERROR,
12+
data_param={},
13+
message_param=AppMessages.FAILED,
14+
status_param=AppMessages.FALSE,
15+
):
16+
dict.__init__(
17+
self,
18+
code=code_param,
19+
data=data_param,
20+
message=message_param,
21+
status=status_param,
22+
)
23+
24+
def set_response(self, code_param, data_param, message_param, status_param):
25+
self["code"] = code_param
26+
self["data"] = data_param
27+
self["message"] = message_param
28+
self["status"] = status_param
29+
if code_param == 200:
30+
try:
31+
if "User is created with given name" in data_param.get("Success"):
32+
data_param = data_param.get("Success").split("Generated")[0]
33+
elif "User is loggedinn" in data_param.get("Success"):
34+
data_param = data_param.get("Success").split("and token")[0]
35+
except:
36+
pass
37+
logdata.info(data_param, message=message_param, status_code=status_param)
38+
else:
39+
logdata.error(data_param, message=message_param, status_code=status_param)

common/log_data.py

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import logging
2+
3+
4+
class ApplicationLogger:
5+
def info(msg):
6+
return logging.getLogger("info_application").info(msg)
7+
8+
def error(msg):
9+
return logging.getLogger("error_application").error(msg)
10+
11+
def debug(msg):
12+
return logging.getLogger("debug_application").debug(msg)
13+
14+
def warn(msg):
15+
return logging.getLogger("warning_application").warn(msg)
16+
17+
18+
class ThirdPartyLogger:
19+
def info(msg):
20+
return logging.getLogger("info_third_party").info(msg)
21+
22+
def error(msg):
23+
return logging.getLogger("error_third_party").error(msg)
24+
25+
def debug(msg):
26+
return logging.getLogger("debug_third_party").debug(msg)
27+
28+
def warn(msg):
29+
return logging.getLogger("warning_third_party").warn(msg)
30+
31+
32+
class AuditLogger:
33+
def info(msg):
34+
return logging.getLogger("info_audit").info(msg)
35+
36+
def error(msg):
37+
return logging.getLogger("error_audit").error(msg)
38+
39+
def debug(msg):
40+
return logging.getLogger("debug_audit").debug(msg)
41+
42+
def warn(msg):
43+
return logging.getLogger("warning_audit").warn(msg)

common/string_table.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class AppMessages:
2+
FAILED = "failed"
3+
FALSE = False
4+
OPERATION_SUCCESS = "Operation Successfully Completed"
5+
OPERATION_FAILED = "Operation Failed"
6+
INTERNAL_ERROR = "Internal Server Error Occurred"
7+
SOMETHING_WENT_WRONG = "Something went wrong, please try again"
8+
INVALID_JWT = "Invalid jwt token"
9+
UNAUTHORIZED_REQUEST = "Unauthorized request"
10+
AUTHENTICATION_FAILED = "Authentication Failed"

common/structlogconfig.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import structlog
2+
3+
4+
def log_config():
5+
log = structlog.get_logger()
6+
return log

0 commit comments

Comments
 (0)