How setosystems/previanza works
Project Type and Purpose
• This is a full-stack web application (“Sistema de Gestión de Seguros Previanza”) built with Flask (Python) for an insurance company’s end-to-end policy, client, agent, and report management.
• It uses Docker Compose to orchestrate four services: web (Flask/Gunicorn), db (PostgreSQL), nginx (reverse proxy), and redis (cache/sessions).
File Structure
• Top-level files:
• Dockerfile / docker-compose.yml / nginx.conf / docker-entrypoint.sh – container build & orchestration
• app.py / wsgi.py / gunicorn_config.py – Flask entrypoints
• config.py / extensions.py – application configuration & extension initialization
• models.py / migrations/ – SQLAlchemy models + Alembic migrations
• routes/ – Flask Blueprints for each module (auth, clients, policies, agents, products, reports, config)
• static/ + templates/ – frontend assets (Tailwind CSS, JS) & Jinja2 templates
• utils/ – helper modules (crypto, email, image handling, security, URL helpers)
• backup.sh, reset_db.py, update_product_images.py, worker.py – utilities & background jobs
README Insights
• Modules: auth, clients, policies, agents, reports, config
• Highlights use of sessions, email, CSRF, role-based access control
Main Components
a. Frontend Layer
• Browser (user) ←→ nginx (reverse proxy & static file server)
• Static assets: CSS (Tailwind) and JS served by nginx
• Jinja2 templates rendered by Flask
b. Backend Layer (Flask App)
• app.py → initializes Flask + Blueprints (routes/…)
• extensions: SQLAlchemy, Redis Session, Mail, WTForms, Security
• Worker (Celery or custom background scripts) for long-running tasks
c. Database Layer
• PostgreSQL (persistent storage for users, clients, policies, products, commissions)
• Alembic for schema migrations
d. Cache/Session Layer
• Redis for session storage & caching
e. External Services
• SMTP server for email notifications
• (Optional) File storage for uploads (local or S3)
Relationships and Data Flows
• User action in browser → HTTP request to nginx → forwarded to Gunicorn/Flask
• Flask authenticates via sessions in Redis, executes business logic, reads/writes to PostgreSQL
• Flask renders template + injects data → response back to browser via nginx
• Background jobs (worker.py) communicate with Flask context or directly with PostgreSQL/Redis
• Email flows: Flask → SMTP
• Migrations: developer/local CLI → Alembic → PostgreSQL
Architectural Patterns & Design Principles
• MVC-inspired:
• Models (models.py + migrations)
• Views (templates/)
• Controllers (routes/)
• Modular Blueprints for separation of concerns
• 12-factor app principles: config via environment, stateless services (sessions in Redis), logs to stdout
• Containerized micro-services (web, db, redis, nginx)