-
Notifications
You must be signed in to change notification settings - Fork 213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: refactor main.py
#1126
Comments
@joboy-dev come see this |
Wow |
can i create a separate issue to work on the port thing then |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Description
The
main.py
file currently contains a mix of configuration, exception handling, routing, and initialization logic, making it difficult to maintain, extend, and test.Introducing this refactoring will make the codebase more maintainable.
Proposed Changes
1. Move Uvicorn Port to Environment File
.env.example
withPORT
variable. Setting a value of7001
as it's default.main.py
to read the port from theSettings
class inapi/utils/settings.py
.2. Extract Configuration to a config file (
api/utils/config.py
):setup_cors
andsetup_middleware
.main.py
to use these functions.3. Move Exception Handlers to a Dedicated File
api/utils/exceptions.py
with handlers forHTTPException
,RequestValidationError
,IntegrityError
, and generic exceptions.main.py
to use these handlers.4. Use a Router for Root Endpoints
api/core/routers/root.py
with anAPIRouter
for the root endpoints (/
and/probe
).main.py
to include the new router.Acceptance Criteria
Environment Configuration:
PORT
variable is defined in.env.example
.Settings
class inapi/utils/settings.py
.Configuration Modularity:
api/utils/config.py
.Exception Handling:
api/utils/exceptions.py
.Root Endpoints:
api/core/routers/root.py
.Testing
.env
.The text was updated successfully, but these errors were encountered: