Modern ERP Reports Application with microservices architecture Tech Stack: - Backend: FastAPI + python-oracledb (Oracle DB integration) - Frontend: Vue.js 3 + PrimeVue + Vite - Telegram Bot: python-telegram-bot + SQLite - Infrastructure: Shared database pool, JWT authentication, SSH tunnel Features: - FastAPI backend with async Oracle connection pool - Vue.js 3 responsive frontend with PrimeVue components - Telegram bot alternative interface - Microservices architecture with shared components - Complete deployment support (Linux Docker + Windows IIS) - Comprehensive testing (Playwright E2E + pytest) Repository Structure: - reports-app/ - Main application (backend, frontend, telegram-bot) - shared/ - Shared components (database pool, auth, utils) - deployment/ - Deployment scripts (Linux & Windows) - docs/ - Project documentation - security/ - Security scanning and git hooks
3.2 KiB
ROA2WEB Shared Database Pool
Sistem de pool de conexiuni Oracle partajat între toate microserviciile ROA2WEB.
Componente
📦 oracle_pool.py
Clasa singleton OraclePool pentru gestionarea pool-ului de conexiuni Oracle.
📋 models.py
Modele Pydantic comune:
User- Model pentru utilizatoriCompany- Model pentru firme/scheme OracleDatabaseConfig- Configurare conexiune database
⚙️ config.py (în utils/)
Configurări partajate prin environment variables.
❌ exceptions.py (în utils/)
Exception handlers personalizate pentru ROA2WEB.
Utilizare
Inițializare în aplicații FastAPI
from contextlib import asynccontextmanager
from fastapi import FastAPI
import sys
import os
# Import shared pool
sys.path.append(os.path.join(os.path.dirname(__file__), '../../../shared'))
from database.oracle_pool import oracle_pool
@asynccontextmanager
async def lifespan(app: FastAPI):
# Startup - inițializare pool
await oracle_pool.initialize()
print("📊 Oracle pool initialized")
yield
# Shutdown - închidere pool
await oracle_pool.close_pool()
print("📊 Oracle pool closed")
app = FastAPI(lifespan=lifespan)
Utilizare conexiune în endpoint-uri
from fastapi import APIRouter, HTTPException
from database.oracle_pool import oracle_pool
router = APIRouter()
@router.get("/companies")
async def get_companies():
try:
async with oracle_pool.get_connection() as conn:
with conn.cursor() as cursor:
cursor.execute("SELECT schema, firma FROM vdef_util_grup WHERE id_firma <> 0")
results = cursor.fetchall()
companies = []
for row in results:
companies.append({
"code": row[0],
"name": row[1]
})
return companies
except Exception as e:
raise HTTPException(status_code=500, detail=f"Database error: {str(e)}")
Configurare Environment Variables
# Oracle Database
ORACLE_USER=your_oracle_username
ORACLE_PASSWORD=your_oracle_password
ORACLE_DSN=your_oracle_dsn
# Pool Settings
DB_MIN_CONNECTIONS=2
DB_MAX_CONNECTIONS=10
DB_CONNECTION_INCREMENT=1
# JWT (pentru autentificare)
JWT_SECRET_KEY=your-super-secret-key
ACCESS_TOKEN_EXPIRE_MINUTES=30
Testare
Pentru a testa pool-ul de conexiuni:
cd roa2web/shared/database
python test_pool.py
Notă: Testul necesită configurarea variabilelor de environment pentru Oracle.
Caracteristici
✅ Singleton Pattern - O singură instanță de pool pentru toată aplicația
✅ Async Context Manager - Gestionare automată a conexiunilor
✅ Connection Pooling - Performanță optimizată prin reutilizarea conexiunilor
✅ Configurabil - Setări flexibile prin environment variables
✅ Logging - Urmărirea operațiilor de pool
✅ Error Handling - Excepții personalizate pentru debugging
Următorii Pași
👉 ZIUA 3: Implementarea sistemului JWT partajat (shared/auth/)
Documentație generată pentru ROA2WEB Shared Database Pool - ZIUA 2 🚀