Backend prasanna - #15
Open
Prasannaganesann wants to merge 15 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR refactors backend configuration and database wiring (moving from app.core.config / app.db.* to app.config.* / app.database.*), and tightens user role handling so clients can’t self-assign roles during registration or profile updates.
Changes:
- Enforce server-side default user role (
analyst) during registration and prohibit role updates via profile edits. - Introduce new
app/configandapp/databasemodules (Postgres engine/session + shared SQLAlchemyBase) and update imports accordingly. - Add
.envignoring and a simple authentication-flow diagram file.
Reviewed changes
Copilot reviewed 16 out of 32 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| backend/app/services/auth_service.py | Enforces default analyst role on registration; blocks role changes in profile update. |
| backend/app/schemas/user.py | Removes role from create/update inputs; ensures role appears in API responses. |
| backend/app/models/user.py | Switches model to use the new authoritative SQLAlchemy Base. |
| backend/app/middleware/auth_middleware.py | Updates imports to new settings and database session modules. |
| backend/app/main.py | Switches to new settings/db imports; wraps table auto-create in a try/except. |
| backend/app/db/session.py | Removes legacy DB session/Base/engine module. |
| backend/app/db/init.py | Removes legacy DB re-exports. |
| backend/app/database/session.py | Adds new get_db() dependency provider using SessionLocal. |
| backend/app/database/postgres.py | Adds Postgres engine/session configuration and dotenv loading. |
| backend/app/database/base.py | Adds single authoritative SQLAlchemy declarative Base. |
| backend/app/database/init.py | Re-exports new database primitives (Base, SessionLocal, engine, get_db). |
| backend/app/core/security.py | Updates settings import to new config module. |
| backend/app/core/init.py | Updates settings import re-export to new config module. |
| backend/app/config/settings.py | Adds settings object for project metadata + JWT config. |
| backend/app/config/init.py | Adds config package re-export for settings. |
| backend/app/authentication flow | Adds a plaintext authentication flow diagram. |
| backend/app/api/auth.py | Updates imports and docs around default role; minor login comment adjustment. |
| .gitignore | Ignores .env, venvs, caches, and local DB files. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+6
to
+7
| # Load variables from backend/.env | ||
| load_dotenv() |
Comment on lines
+9
to
+12
| DATABASE_URL = os.getenv( | ||
| "DATABASE_URL", | ||
| "postgresql://postgres:postgres@localhost:5432/malware_db" | ||
| ) |
Comment on lines
+9
to
+13
| # Initialize database tables on startup if database is reachable | ||
| try: | ||
| Base.metadata.create_all(bind=engine) | ||
| except Exception as e: | ||
| print(f"[Warning] Database table auto-creation skipped: {e}") |
| @@ -0,0 +1,28 @@ | |||
| User | |||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.