TASK-001: Setup FastAPI project structure
This commit is contained in:
@@ -1 +1 @@
|
||||
"""SocialPhoto - Instagram Clone API."""
|
||||
"""Application package."""
|
||||
|
||||
1
app/api/__init__.py
Normal file
1
app/api/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
"""API package."""
|
||||
1
app/api/dependencies/__init__.py
Normal file
1
app/api/dependencies/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
"""Dependencies package."""
|
||||
1
app/api/endpoints/__init__.py
Normal file
1
app/api/endpoints/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
"""Endpoints package."""
|
||||
1
app/core/__init__.py
Normal file
1
app/core/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
"""Core module package."""
|
||||
26
app/core/config.py
Normal file
26
app/core/config.py
Normal file
@@ -0,0 +1,26 @@
|
||||
"""Application configuration settings."""
|
||||
|
||||
from pydantic_settings import BaseSettings
|
||||
from typing import Optional
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
"""Application settings loaded from environment variables."""
|
||||
|
||||
# Application
|
||||
APP_NAME: str = "Instagram Clone"
|
||||
APP_VERSION: str = "0.1.0"
|
||||
DEBUG: bool = False
|
||||
|
||||
# Database
|
||||
DATABASE_URL: str = "sqlite:///./instagram_clone.db"
|
||||
|
||||
# Security
|
||||
SECRET_KEY: Optional[str] = None
|
||||
|
||||
class Config:
|
||||
env_file = ".env"
|
||||
case_sensitive = True
|
||||
|
||||
|
||||
settings = Settings()
|
||||
1
app/db/__init__.py
Normal file
1
app/db/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
"""Database module package."""
|
||||
28
app/db/database.py
Normal file
28
app/db/database.py
Normal file
@@ -0,0 +1,28 @@
|
||||
"""Database connection and session management."""
|
||||
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.orm import sessionmaker, DeclarativeBase
|
||||
from app.core.config import settings
|
||||
|
||||
# Create engine
|
||||
engine = create_engine(
|
||||
settings.DATABASE_URL,
|
||||
connect_args={"check_same_thread": False} if "sqlite" in settings.DATABASE_URL else {},
|
||||
)
|
||||
|
||||
# Create session factory
|
||||
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
||||
|
||||
|
||||
class Base(DeclarativeBase):
|
||||
"""SQLAlchemy declarative base class."""
|
||||
pass
|
||||
|
||||
|
||||
def get_db():
|
||||
"""Dependency to get database session."""
|
||||
db = SessionLocal()
|
||||
try:
|
||||
yield db
|
||||
finally:
|
||||
db.close()
|
||||
53
app/main.py
53
app/main.py
@@ -1,21 +1,15 @@
|
||||
"""SocialPhoto - Instagram Clone API.
|
||||
|
||||
A simple social media API for sharing images with likes, comments, and user follows.
|
||||
"""
|
||||
from pathlib import Path
|
||||
"""FastAPI application entry point."""
|
||||
|
||||
from fastapi import FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
|
||||
from app.database import init_db
|
||||
from app.routes import auth, comments, feed, posts, users
|
||||
from app.core.config import settings
|
||||
from app.db.database import engine, Base
|
||||
|
||||
# Create FastAPI app
|
||||
app = FastAPI(
|
||||
title="SocialPhoto",
|
||||
description="Instagram Clone API - Share images with likes, comments, and follows",
|
||||
version="1.0.0",
|
||||
title=settings.APP_NAME,
|
||||
version=settings.APP_VERSION,
|
||||
debug=settings.DEBUG,
|
||||
)
|
||||
|
||||
# CORS middleware
|
||||
@@ -27,43 +21,14 @@ app.add_middleware(
|
||||
allow_headers=["*"],
|
||||
)
|
||||
|
||||
# Mount uploads directory
|
||||
UPLOAD_DIR = Path(__file__).parent.parent / "uploads"
|
||||
UPLOAD_DIR.mkdir(parents=True, exist_ok=True)
|
||||
app.mount("/uploads", StaticFiles(directory=str(UPLOAD_DIR)), name="uploads")
|
||||
|
||||
|
||||
@app.on_event("startup")
|
||||
async def startup_event():
|
||||
"""Initialize database on startup."""
|
||||
init_db()
|
||||
|
||||
|
||||
# Include routers
|
||||
app.include_router(auth.router)
|
||||
app.include_router(users.router)
|
||||
app.include_router(posts.router)
|
||||
app.include_router(comments.router)
|
||||
app.include_router(feed.router)
|
||||
|
||||
|
||||
@app.get("/", tags=["Root"])
|
||||
@app.get("/")
|
||||
async def root():
|
||||
"""Root endpoint."""
|
||||
return {
|
||||
"name": "SocialPhoto",
|
||||
"version": "1.0.0",
|
||||
"description": "Instagram Clone API",
|
||||
}
|
||||
return {"message": f"Welcome to {settings.APP_NAME}", "version": settings.APP_VERSION}
|
||||
|
||||
|
||||
@app.get("/health", tags=["Health"])
|
||||
@app.get("/health")
|
||||
async def health_check():
|
||||
"""Health check endpoint."""
|
||||
return {"status": "healthy"}
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import uvicorn
|
||||
|
||||
uvicorn.run(app, host="0.0.0.0", port=8000)
|
||||
|
||||
1
app/models/__init__.py
Normal file
1
app/models/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
"""Models package."""
|
||||
1
app/schemas/__init__.py
Normal file
1
app/schemas/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
"""Schemas package."""
|
||||
1
app/services/__init__.py
Normal file
1
app/services/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
"""Services package."""
|
||||
1
app/utils/__init__.py
Normal file
1
app/utils/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
"""Utils package."""
|
||||
Reference in New Issue
Block a user