Skip to content
Closed
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v4
uses: actions/checkout@v6

- name: Initialize CodeQL
Expand Down
44 changes: 5 additions & 39 deletions api/index.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,7 @@
import os
import sys
from pathlib import Path
from fastapi import APIRouter

# Add the project root to Python path
project_root = Path(__file__).parent.parent
sys.path.insert(0, str(project_root))
router = APIRouter()

# Set environment variables for production
os.environ.setdefault("ENVIRONMENT", "production")
os.environ.setdefault(
"SECRET_KEY", os.environ.get("SECRET_KEY", "vercel-production-key-change-in-env")
)

# Import the FastAPI app
from app.main import app

# Vercel expects the app to be named 'app'
# If your FastAPI app is named differently, change this
app = app


# Optional: Add Vercel-specific middleware or configuration
@app.middleware("http")
async def add_vercel_headers(request, call_next):
response = await call_next(request)
response.headers["X-Vercel-Cache"] = "MISS"
return response


# Health check endpoint for Vercel
@app.get("/api/health")
async def health_check():
return {"status": "healthy", "platform": "vercel", "app": "NeuroBank FastAPI"}


# For local development
if __name__ == "__main__":
import uvicorn

uvicorn.run(app, host="0.0.0.0", port=int(os.environ.get("PORT", 8000)))
@router.get("/")
def root():
return {"status": "ok"}
2 changes: 1 addition & 1 deletion api/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
fastapi==0.116.1
starlette==0.37.2
starlette==0.47.2
uvicorn[standard]==0.38.0
uvloop==0.21.0

pydantic==2.7.0
pydantic-settings==2.2.1

Expand Down
252 changes: 0 additions & 252 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,253 +1 @@
import datetime
import logging
import os

from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import JSONResponse

from .backoffice import router as backoffice_router
from .routers import operator
from .utils.logging import setup_logging

# Configuración constantes
APP_NAME = "NeuroBank FastAPI Toolkit"
APP_VERSION = "1.0.0"
APP_DESCRIPTION = """
## 🏦 NeuroBank FastAPI Toolkit
**Professional banking operations API** with enterprise-grade features and **admin backoffice dashboard**:
### 🚀 Key Features
- **Banking Operations**: Comprehensive account management and transactions
- **Admin Dashboard**: Visual backoffice panel at `/backoffice/` with real-time metrics
- **Security First**: API key authentication and request validation
- **Production Ready**: AWS serverless deployment with monitoring
- **High Performance**: Async operations with optimized response times
### 🎨 Backoffice Dashboard
- **Real-time Metrics**: Live transaction monitoring and system health
- **Interactive Charts**: Chart.js visualizations for business intelligence
- **Transaction Management**: Advanced filtering and administration tools
- **Responsive Design**: Bootstrap 5 with professional banking UI
- **Protected Admin Panels**: Secure administrative access
### 🛠️ Technical Stack
- **FastAPI**: Modern, fast web framework for building APIs
- **Jinja2**: Template engine for dynamic HTML generation
- **Bootstrap 5**: Professional UI framework with responsive design
- **Chart.js**: Interactive data visualizations
- **Pydantic**: Data validation using Python type annotations
- **AWS Lambda**: Serverless compute platform
- **CloudWatch**: Monitoring and logging
### 📚 API Documentation
- **Swagger UI**: Available at `/docs` (interactive documentation)
- **ReDoc**: Available at `/redoc` (alternative documentation)
- **Admin Dashboard**: Available at `/backoffice/` (visual interface)
### 🔐 Authentication
All endpoints require a valid API key in the `X-API-Key` header.
### 📊 Health Monitoring
- Health check endpoint at `/health`
- Comprehensive logging with structured JSON format
- CloudWatch integration for production monitoring
---
*Built with ❤️ for modern banking infrastructure*
"""

# Configurar logging
setup_logging()
logger = logging.getLogger(__name__)

# Crear la aplicación FastAPI con documentación mejorada
app = FastAPI(
title=APP_NAME,
description=APP_DESCRIPTION,
version=APP_VERSION,
docs_url="/docs",
redoc_url="/redoc",
contact={
"name": "NeuroBank Development Team",
"email": "[email protected]",
},
license_info={
"name": "MIT License",
"url": "https://opensource.org/licenses/MIT",
},
servers=[
{"url": "https://api.neurobank.com", "description": "Production server"},
{"url": "https://staging-api.neurobank.com", "description": "Staging server"},
{"url": "http://localhost:8000", "description": "Development server"},
],
)

# Configurar CORS - usando configuración de Railway
from .config import get_settings

settings = get_settings()

app.add_middleware(
CORSMiddleware,
allow_origins=settings.cors_origins,
allow_credentials=True,
allow_methods=["GET", "POST", "PUT", "DELETE"],
allow_headers=["*"],
)

# Incluir routers
app.include_router(operator.router, prefix="/api", tags=["api"])
app.include_router(backoffice_router.router, tags=["backoffice"])


# Health check endpoint
@app.get(
"/health",
summary="🏥 Health Check",
description="Comprehensive health check endpoint for monitoring service status",
response_description="Service health status with detailed information",
tags=["Health & Monitoring"],
responses={
200: {
"description": "Service is healthy and operational",
"content": {
"application/json": {
"example": {
"status": "healthy",
"service": "NeuroBank FastAPI Toolkit",
"version": "1.0.0",
"timestamp": "2025-07-20T15:30:45.123456Z",
"environment": "production",
"uptime_seconds": 3600,
}
}
},
}
},
)
async def health_check():
"""
**Endpoint de verificación de salud del sistema**
Retorna información detallada sobre:
- ✅ Estado del servicio
- 📊 Versión actual
- ⏰ Timestamp de respuesta
- 🌍 Entorno de ejecución
- ⏱️ Tiempo de actividad
**Casos de uso:**
- Monitoreo automatizado (Kubernetes, Docker, AWS)
- Load balancers health checks
- Verificación de deployments
- Debugging y troubleshooting
"""
import datetime
import os

return JSONResponse(
status_code=200,
content={
"status": "healthy",
"service": APP_NAME,
"version": APP_VERSION,
"timestamp": f"{datetime.datetime.now(datetime.timezone.utc).isoformat()}",
"environment": os.getenv("ENVIRONMENT", "production"),
"railway": {
"project_name": os.getenv("RAILWAY_PROJECT_NAME", "unknown"),
"project_id": os.getenv("RAILWAY_PROJECT_ID", "unknown"),
"service_name": os.getenv("RAILWAY_SERVICE_NAME", "unknown"),
"environment_name": os.getenv("RAILWAY_ENVIRONMENT_NAME", "unknown"),
"private_domain": os.getenv("RAILWAY_PRIVATE_DOMAIN", "unknown"),
},
"uptime_seconds": "N/A", # Se puede implementar con un contador global
},
)


# Root endpoint
@app.get(
"/",
summary="🏠 API Root",
description="Welcome endpoint with API information and navigation links",
response_description="API overview with quick navigation",
tags=["Information"],
responses={
200: {
"description": "API information and navigation links",
"content": {
"application/json": {
"example": {
"message": "Welcome to NeuroBank FastAPI Toolkit",
"version": "1.0.0",
"status": "operational",
"documentation": {"swagger_ui": "/docs", "redoc": "/redoc"},
"endpoints": {
"health_check": "/health",
"operator_operations": "/operator",
},
"features": [
"🏦 Banking Operations",
"🔐 API Key Authentication",
"📊 Real-time Monitoring",
"☁️ AWS Serverless Ready",
],
}
}
},
}
},
)
async def root():
"""
**Endpoint de bienvenida de la API**
Proporciona información general sobre la API incluyendo:
- 📋 Información básica del servicio
- 🔗 Enlaces de navegación rápida
- 📚 Acceso a documentación
- ⚡ Estado operacional
- 🎯 Características principales
**Útil para:**
- Verificación rápida de conectividad
- Descubrimiento de endpoints principales
- Validación de versión de API
- Navegación inicial para desarrolladores
"""
return {
"message": f"Welcome to {APP_NAME}",
"version": APP_VERSION,
"status": "operational",
"documentation": {"swagger_ui": "/docs", "redoc": "/redoc"},
"endpoints": {"health_check": "/health", "operator_operations": "/operator"},
"features": [
"🏦 Banking Operations",
"🔐 API Key Authentication",
"📊 Real-time Monitoring",
"☁️ AWS Serverless Ready",
],
}


if __name__ == "__main__":
import uvicorn
import uvloop

# Use uvloop for better performance
uvloop.install()

port = int(os.getenv("PORT", 8000))
workers = int(os.getenv("WORKERS", 1)) # Single worker for Railway

uvicorn.run(
"app.main:app",
host="0.0.0.0",
port=port,
workers=workers,
loop="uvloop",
access_log=True,
timeout_keep_alive=120,
)
2 changes: 2 additions & 0 deletions clean_unused_imports.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
autoflake --in-place --remove-unused-variables --remove-all-unused-imports -r app
Copy link

Copilot AI Dec 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This script depends on the autoflake package, which is not listed in requirements.txt or requirements-dev.txt. Either add autoflake to the requirements-dev.txt file or document that it needs to be installed separately. Without this dependency, the script will fail when executed.

Copilot uses AI. Check for mistakes.
11 changes: 10 additions & 1 deletion neurobank-fastapi.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,16 @@
"**/*.pyc": true,
".venv": true
},
"git.ignoreLimitWarning": true
"git.ignoreLimitWarning": true,
"cSpell.words": [
"asyncio",
"dotenv",
"jinja",
"loguru",
"pydantic",
"starlette",
"uvloop"
]
},
"extensions": {
"recommendations": [
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
fastapi==0.116.1
starlette==0.37.2
starlette==0.47.2
uvicorn[standard]==0.38.0
uvloop==0.21.0

pydantic==2.7.0
pydantic-settings==2.2.1

Expand Down
Loading