From 18ed6dd4891a1bdbfaa42733c40fa427d688b09b Mon Sep 17 00:00:00 2001 From: Saahi30 Date: Sat, 1 Nov 2025 00:46:58 +0530 Subject: [PATCH 1/3] feat(backend): initialize FastAPI project with core structure and dependencies --- backend/.env | 3 +++ backend/README.md | 3 +++ backend/app/__init__.py | 1 + backend/app/api/__init__.py | 1 + backend/app/api/routes/__init__.py | 1 + backend/app/core/__init__.py | 1 + backend/app/core/config.py | 11 +++++++++++ backend/app/db/__init__.py | 1 + backend/app/db/database.py | 1 + backend/app/main.py | 17 +++++++++++++++++ backend/app/models/__init__.py | 1 + backend/env_example | 2 ++ backend/requirements.txt | 22 ++++++++++++++++++++++ 13 files changed, 65 insertions(+) create mode 100644 backend/.env create mode 100644 backend/README.md create mode 100644 backend/app/__init__.py create mode 100644 backend/app/api/__init__.py create mode 100644 backend/app/api/routes/__init__.py create mode 100644 backend/app/core/__init__.py create mode 100644 backend/app/core/config.py create mode 100644 backend/app/db/__init__.py create mode 100644 backend/app/db/database.py create mode 100644 backend/app/main.py create mode 100644 backend/app/models/__init__.py create mode 100644 backend/env_example create mode 100644 backend/requirements.txt diff --git a/backend/.env b/backend/.env new file mode 100644 index 0000000..c02710b --- /dev/null +++ b/backend/.env @@ -0,0 +1,3 @@ +# Environment variables for backend +DATABASE_URL=postgresql://user:password@localhost:5432/inpactdb +AI_API_KEY=sk-xxxx diff --git a/backend/README.md b/backend/README.md new file mode 100644 index 0000000..666559c --- /dev/null +++ b/backend/README.md @@ -0,0 +1,3 @@ +# Backend + +Project backend structure and setup instructions. diff --git a/backend/app/__init__.py b/backend/app/__init__.py new file mode 100644 index 0000000..2839885 --- /dev/null +++ b/backend/app/__init__.py @@ -0,0 +1 @@ +# app package init diff --git a/backend/app/api/__init__.py b/backend/app/api/__init__.py new file mode 100644 index 0000000..04823ca --- /dev/null +++ b/backend/app/api/__init__.py @@ -0,0 +1 @@ +# api package init diff --git a/backend/app/api/routes/__init__.py b/backend/app/api/routes/__init__.py new file mode 100644 index 0000000..8ebd595 --- /dev/null +++ b/backend/app/api/routes/__init__.py @@ -0,0 +1 @@ +# routes package init diff --git a/backend/app/core/__init__.py b/backend/app/core/__init__.py new file mode 100644 index 0000000..eebe93b --- /dev/null +++ b/backend/app/core/__init__.py @@ -0,0 +1 @@ +# core package init diff --git a/backend/app/core/config.py b/backend/app/core/config.py new file mode 100644 index 0000000..c978c5b --- /dev/null +++ b/backend/app/core/config.py @@ -0,0 +1,11 @@ +# Configuration settings for FastAPI app +from pydantic import BaseSettings + +class Settings(BaseSettings): + database_url: str + ai_api_key: str + + class Config: + env_file = ".env" + +settings = Settings() diff --git a/backend/app/db/__init__.py b/backend/app/db/__init__.py new file mode 100644 index 0000000..691cef1 --- /dev/null +++ b/backend/app/db/__init__.py @@ -0,0 +1 @@ +# db package init diff --git a/backend/app/db/database.py b/backend/app/db/database.py new file mode 100644 index 0000000..f55fa7c --- /dev/null +++ b/backend/app/db/database.py @@ -0,0 +1 @@ +# Database connection setup diff --git a/backend/app/main.py b/backend/app/main.py new file mode 100644 index 0000000..1fc1922 --- /dev/null +++ b/backend/app/main.py @@ -0,0 +1,17 @@ +from fastapi import FastAPI +from fastapi.middleware.cors import CORSMiddleware + +app = FastAPI(title="Inpact Backend", version="0.1.0") + +# --- CORS Setup (so frontend can talk to backend) --- +app.add_middleware( + CORSMiddleware, + allow_origins=["*"], # later we’ll restrict this to your frontend URL + allow_credentials=True, + allow_methods=["*"], + allow_headers=["*"], +) + +@app.get("/") +def root(): + return {"message": "Welcome to Inpact Backend 🚀"} diff --git a/backend/app/models/__init__.py b/backend/app/models/__init__.py new file mode 100644 index 0000000..654e47b --- /dev/null +++ b/backend/app/models/__init__.py @@ -0,0 +1 @@ +# models package init diff --git a/backend/env_example b/backend/env_example new file mode 100644 index 0000000..45a9804 --- /dev/null +++ b/backend/env_example @@ -0,0 +1,2 @@ +DATABASE_URL=postgresql://user:password@localhost:5432/inpactdb +AI_API_KEY=sk-xxxx diff --git a/backend/requirements.txt b/backend/requirements.txt new file mode 100644 index 0000000..0d7f3c5 --- /dev/null +++ b/backend/requirements.txt @@ -0,0 +1,22 @@ +annotated-doc==0.0.3 +annotated-types==0.7.0 +anyio==4.11.0 +black==25.9.0 +click==8.3.0 +fastapi==0.120.3 +h11==0.16.0 +idna==3.11 +mypy_extensions==1.1.0 +packaging==25.0 +pathspec==0.12.1 +platformdirs==4.5.0 +pydantic==2.12.3 +pydantic_core==2.41.4 +python-dotenv==1.2.1 +pytokens==0.2.0 +ruff==0.14.3 +sniffio==1.3.1 +starlette==0.49.1 +typing-inspection==0.4.2 +typing_extensions==4.15.0 +uvicorn==0.38.0 From d67acfe578597027d300729adfe903b22cabbb1f Mon Sep 17 00:00:00 2001 From: Saahi30 Date: Sat, 1 Nov 2025 18:39:28 +0530 Subject: [PATCH 2/3] chore: update env handling and pydantic config --- .gitignore | 11 ++++++++++- backend/.env | 3 --- backend/app/core/config.py | 5 +++-- backend/env_example | 4 +++- backend/requirements.txt | 1 + 5 files changed, 17 insertions(+), 7 deletions(-) delete mode 100644 backend/.env diff --git a/.gitignore b/.gitignore index 1262b41..8b7c2d8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +# Ignore VS Code settings +.vscode/ # Logs logs *.log @@ -35,4 +37,11 @@ venv/ env/ ENV/ venv.bak/ -pycache/ \ No newline at end of file +pycache/ + +# Environment files +.env +backend/.env + +#next.js +.next/ diff --git a/backend/.env b/backend/.env deleted file mode 100644 index c02710b..0000000 --- a/backend/.env +++ /dev/null @@ -1,3 +0,0 @@ -# Environment variables for backend -DATABASE_URL=postgresql://user:password@localhost:5432/inpactdb -AI_API_KEY=sk-xxxx diff --git a/backend/app/core/config.py b/backend/app/core/config.py index c978c5b..e855aba 100644 --- a/backend/app/core/config.py +++ b/backend/app/core/config.py @@ -5,7 +5,8 @@ class Settings(BaseSettings): database_url: str ai_api_key: str - class Config: - env_file = ".env" + model_config = { + "env_file": ".env" + } settings = Settings() diff --git a/backend/env_example b/backend/env_example index 45a9804..c425630 100644 --- a/backend/env_example +++ b/backend/env_example @@ -1,2 +1,4 @@ +# Example environment file for backend + DATABASE_URL=postgresql://user:password@localhost:5432/inpactdb -AI_API_KEY=sk-xxxx +AI_API_KEY=your-ai-api-key-here diff --git a/backend/requirements.txt b/backend/requirements.txt index 0d7f3c5..cfc171a 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -11,6 +11,7 @@ packaging==25.0 pathspec==0.12.1 platformdirs==4.5.0 pydantic==2.12.3 +pydantic-settings pydantic_core==2.41.4 python-dotenv==1.2.1 pytokens==0.2.0 From cde8a627f9acfc2daf6e3a432bd0af06468edf59 Mon Sep 17 00:00:00 2001 From: Saahi30 Date: Sat, 1 Nov 2025 18:43:22 +0530 Subject: [PATCH 3/3] chore: restrict CORS origins and update env example --- backend/app/core/config.py | 2 +- backend/app/main.py | 3 ++- backend/env_example | 2 ++ backend/requirements.txt | 2 +- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/backend/app/core/config.py b/backend/app/core/config.py index e855aba..64ba7f2 100644 --- a/backend/app/core/config.py +++ b/backend/app/core/config.py @@ -1,5 +1,5 @@ # Configuration settings for FastAPI app -from pydantic import BaseSettings +from pydantic_settings import BaseSettings class Settings(BaseSettings): database_url: str diff --git a/backend/app/main.py b/backend/app/main.py index 1fc1922..1b0dad4 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -1,12 +1,13 @@ from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware +import os app = FastAPI(title="Inpact Backend", version="0.1.0") # --- CORS Setup (so frontend can talk to backend) --- app.add_middleware( CORSMiddleware, - allow_origins=["*"], # later we’ll restrict this to your frontend URL + allow_origins=os.getenv("ALLOWED_ORIGINS", "http://localhost:3000").split(","), allow_credentials=True, allow_methods=["*"], allow_headers=["*"], diff --git a/backend/env_example b/backend/env_example index c425630..a56d896 100644 --- a/backend/env_example +++ b/backend/env_example @@ -2,3 +2,5 @@ DATABASE_URL=postgresql://user:password@localhost:5432/inpactdb AI_API_KEY=your-ai-api-key-here + +ALLOWED_ORIGINS=http://localhost:3000 diff --git a/backend/requirements.txt b/backend/requirements.txt index cfc171a..da081ce 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -11,7 +11,7 @@ packaging==25.0 pathspec==0.12.1 platformdirs==4.5.0 pydantic==2.12.3 -pydantic-settings +pydantic-settings>=2.0.3 pydantic_core==2.41.4 python-dotenv==1.2.1 pytokens==0.2.0