From 8b3b4f968adb0d5779741dcda50b6f40b86b6ce8 Mon Sep 17 00:00:00 2001 From: Sean McElwain Date: Tue, 31 Mar 2026 20:45:15 -0500 Subject: [PATCH] initial project structure --- .env.example | 0 .gitignore | 13 +++++++++++++ README.md | 0 app/core/config.py | 9 +++++++++ app/db/base.py | 6 ++++++ app/db/session.py | 14 ++++++++++++++ app/main.py | 10 ++++++++++ app/models/document.py | 12 ++++++++++++ app/routes/health.py | 11 +++++++++++ pyproject.toml | 0 run.sh | 5 +++++ 11 files changed, 80 insertions(+) create mode 100644 .env.example create mode 100644 .gitignore create mode 100644 README.md create mode 100644 app/core/config.py create mode 100644 app/db/base.py create mode 100644 app/db/session.py create mode 100644 app/main.py create mode 100644 app/models/document.py create mode 100644 app/routes/health.py create mode 100644 pyproject.toml create mode 100755 run.sh diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..e69de29 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6846183 --- /dev/null +++ b/.gitignore @@ -0,0 +1,13 @@ +# Python +.venv/ +__pycache__/ +*.pyc + +# Env +.env + +# Data (local only) +data/ + +# Alembic cache +alembic/versions/*.pyc diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/app/core/config.py b/app/core/config.py new file mode 100644 index 0000000..e66e39e --- /dev/null +++ b/app/core/config.py @@ -0,0 +1,9 @@ +import os +from dotenv import load_dotenv + +load_dotenv() + +class Settings: + DATABASE_URL: str = os.getenv("DATABASE_URL", "postgresql://user:pass@localhost:5432/document_processor") + +settings = Settings() diff --git a/app/db/base.py b/app/db/base.py new file mode 100644 index 0000000..1313bfa --- /dev/null +++ b/app/db/base.py @@ -0,0 +1,6 @@ +from sqlalchemy.orm import declarative_base + +Base = declarative_base() + +# import models so Alembic sees them later +from app.models import document # noqa diff --git a/app/db/session.py b/app/db/session.py new file mode 100644 index 0000000..1599e53 --- /dev/null +++ b/app/db/session.py @@ -0,0 +1,14 @@ +from sqlalchemy import create_engine +from sqlalchemy.orm import sessionmaker + +from app.core.config import settings + +engine = create_engine(settings.DATABASE_URL, echo=True) +SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) + +def get_db(): + db = SessionLocal() + try: + yield db + finally: + db.close() diff --git a/app/main.py b/app/main.py new file mode 100644 index 0000000..0d183d4 --- /dev/null +++ b/app/main.py @@ -0,0 +1,10 @@ +from fastapi import FastAPI +from app.routes.health import router as health_router + +app = FastAPI() + +app.include_router(health_router) + +@app.get("/") +def root(): + return {"app": "document-processor", "status": "running"} diff --git a/app/models/document.py b/app/models/document.py new file mode 100644 index 0000000..6a4d416 --- /dev/null +++ b/app/models/document.py @@ -0,0 +1,12 @@ +from sqlalchemy import Column, Integer, String, DateTime +from datetime import datetime + +from app.db.base import Base + +class Document(Base): + __tablename__ = "documents" + + id = Column(Integer, primary_key=True, index=True) + file_path = Column(String, nullable=False) + status = Column(String, default="pending") + created_at = Column(DateTime, default=datetime.utcnow) diff --git a/app/routes/health.py b/app/routes/health.py new file mode 100644 index 0000000..67d98dd --- /dev/null +++ b/app/routes/health.py @@ -0,0 +1,11 @@ +from fastapi import APIRouter, Depends +from sqlalchemy.orm import Session + +from app.db.session import get_db + +router = APIRouter() + +@router.get("/health/db") +def db_health(db: Session = Depends(get_db)): + db.execute("SELECT 1") + return {"status": "ok"} diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..e69de29 diff --git a/run.sh b/run.sh new file mode 100755 index 0000000..203cb3a --- /dev/null +++ b/run.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash +set -e + +source .venv/bin/activate +uvicorn app.main:app --reload --host 0.0.0.0 --port 3004