How luiscastillocruz/sistema_cobranzas works
1. This repository is a monorepo with three distinct layers: a React/Vite single-page frontend, a primary FastAPI backend in Python, and a smaller TypeScript/Node backend under backend/src that appears focused on authentication and email-settings operations. The FastAPI app is the main business backend.
2. The frontend is organized as a routed SPA with auth protection. AuthProvider and ProtectedRoute wrap the app, MainLayout provides the shell, and feature pages are split by domain: Cobros/accounts receivable, Clientes, Dashboard, Vendedores, Login, and email POP3 settings. Each page has its own api.ts, suggesting a page-centric API boundary.
3. The FastAPI backend entrypoint is app/main.py, with routing centralized in app/api/router.py. Request middleware and cross-cutting concerns live in app/middlewares, while app/core holds configuration, security, normalization, dependency injection, logging, and crypto-vault helpers.
4. The core domain model is centered on collections and customer/account management. SQLAlchemy models include account_receivable, client, vendedores, user, email_settings, email_template, and logging tables for email/statement sends. Pydantic schemas mirror these domains for API input/output.
5. The backend is layered in the usual FastAPI style: routes call crud and services, which then access SQLAlchemy models through the DB session layer in app/db. app/crud/accounts_receivable.py and service modules like dashboard_service.py, reminder_engine.py, and mailer.py indicate a separation between data access, orchestration, and integration logic.
6. The main data flows are:
- Browser -> SPA route/page -> page API module -> backend route.
- Backend route -> dependency/auth checks -> CRUD/service -> SQLAlchemy model -> SQLite DB.
- Dashboard pages consume aggregated metrics from dashboard_service.
- Import/export flows likely move bulk receivable data between Excel files and the DB.
7. Reminder and notification delivery are a key subsystem. reminder_scheduler.py and reminder_engine.py suggest periodic processing of overdue or due receivables, while email_recipients.py, smtp_sender.py, and mailer.py handle recipient resolution and outbound email. The logging models imply every send is tracked for auditability.
8. Email configuration is treated as its own bounded area. The FastAPI side stores email settings/templates and logs, while the TypeScript backend under backend/src contains emailSettings.routes.ts, emailSettings.service.ts, plus SMTP/POP3 test services and validators. That separation suggests a dedicated service or a partial migration for mail configuration workflows.
9. The TypeScript backend uses an Express-style stack: app.ts, index.ts, middleware for auth/error handling/rate limiting, Prisma schemas under backend/prisma, and a cryptoVault helper. It likely serves admin-style endpoints around email settings and connection tests rather than the full receivables domain.
10. Authentication and security are handled in both backend stacks. The Python app has security.py, deps.py, and an auth route plus user model; the TS service has its own auth middleware and rate limiter. The frontend’s auth provider and protected routes imply token-based session handling across the API boundary.
11. Persistence defaults to SQLite via backend/cobranzas.db, with a note in the README that PostgreSQL can replace it in production. The presence of both SQLAlchemy and Prisma means the repo currently mixes ORM/data layers across the Python and TypeScript services.
12. Operationally, the repository is designed for local development with Vite on the frontend and Uvicorn on the FastAPI backend, and for deployment behind Nginx/systemd on Ubuntu. Helper scripts like create_user.py, reset_pass.py, and seed_admin.py indicate bootstrap and admin lifecycle support.
Main entry points: App.tsx App shell · routes/accounts_receivable.py Domain routes · crud/accounts_receivable.py Receivables domain · dashboard_service.py Workers
Components 21
Frontend SPA
React/Vite single-page app with routed, auth-protected feature pages.
- App shell · Root app composition, routing, auth provider, and protected layout.
frontend/src/app/App.tsx - Auth guard · Session provider and protected route gate for the SPA.
frontend/src/auth/AuthProvider.tsx - Main layout · Shared application chrome and navigation wrapper.
frontend/src/components/layout/MainLayout.tsx - Cobros · Receivables list, dialogs, bulk import/export, and page-specific API layer.
frontend/src/pages/Cobros/index.tsx - Clientes · Customer management page with its own API and utilities.
frontend/src/pages/Clientes/Clientes.tsx - Dashboard · Metrics and drilldowns for receivables operations.
frontend/src/pages/Dasboard/Dashboard.tsx - Login · Authentication entry page for the SPA.
frontend/src/pages/Login.tsx - Email POP3 · Frontend page for email POP3 settings management.
frontend/src/pages/EmailSettingsPop3.tsx
FastAPI Backend
Primary business API, domain logic, and persistence layer.
- API app · FastAPI application entrypoint and startup composition.
backend/app/main.py - API router · Central router that mounts domain endpoints.
backend/app/api/router.py - Core services · Configuration, security, dependencies, logging, normalization, and vault helpers.
backend/app/core/config.py - DB layer · Session and base wiring for the SQLite-backed persistence layer.
backend/app/db/session.py - Receivables domain · Receivables CRUD plus reminder, dashboard, mail, and vendedores orchestration.
backend/app/crud/accounts_receivable.py - Domain models · SQLAlchemy models for receivables, clients, users, vendors, email settings, templates, and logs.
backend/app/models/account_receivable.py - API schemas · Request/response models for auth, clients, dashboard, receivables, vendors, and email settings.
backend/app/schemas/accounts_receivable.py - Domain routes · Feature endpoints for auth, receivables, clients, dashboard, imports, exports, reminders, vendors, and email settings.
backend/app/api/routes/accounts_receivable.py - Workers · Dashboard aggregation, recipient selection, mail delivery, reminder scheduling, SMTP integration, and vendor logic.
backend/app/services/dashboard_service.py
Node Email Admin
Smaller Express-style backend for auth and email-settings workflows.
- Node app · Express-style entrypoint and server bootstrap for the secondary backend.
backend/src/app.ts - Email routes · Routes for auth and email-settings operations.
backend/src/routes/emailSettings.routes.ts - Email services · Email settings CRUD plus SMTP and POP3 connection tests.
backend/src/services/emailSettings.service.ts - Node security · Auth middleware, rate limiting, error handling, and crypto vault helper.
backend/src/middlewares/auth.ts
Connections 24
- Auth guard → App shell: wraps · Authentication context and protected routing guard the app.
- App shell → Main layout: uses · The router renders pages inside the shared layout shell.
- App shell → Login: routes to · Unauthenticated users land on the login page.
- App shell → Cobros: routes to · Receivables feature page.
- App shell → Clientes: routes to · Customer management page.
- App shell → Dashboard: routes to · Dashboard page.
- App shell → Email POP3: routes to · Email settings page.
- Cobros → Domain routes: calls API · Page-specific API module talks to the backend routes.
- Clientes → Domain routes: calls API · Client page uses the FastAPI domain endpoints.
- Dashboard → Workers: reads metrics · Dashboard requests aggregated operational metrics.
- Email POP3 → Email routes: calls API · Email settings page targets the Node backend for settings workflows.
- API app → API router: mounts · Application startup wires the central API router.
- API router → Domain routes: dispatches · Router exposes the domain route modules.
- Domain routes → Core services: depends on · Routes use security, config, and dependency helpers.
- Domain routes → Receivables domain: orchestrates · Endpoints delegate business work to CRUD and services.
- Receivables domain → DB layer: persists via · Data access runs through the DB session layer.
- DB layer → Domain models: maps · SQLAlchemy models define the persisted tables.
- Receivables domain → Domain models: uses · Domain logic operates on receivables and related entities.
- Receivables domain → API schemas: shapes data · Services and routes exchange typed API payloads.
- Workers → Domain models: reads/writes · Dashboard, reminder, and mail services use domain records and logs.
- Workers → DB layer: queries via · Services access persistence through the DB layer.
- Node app → Node security: uses · Server bootstrap installs middleware and security helpers.
- Node app → Email routes: mounts · Express app registers the email/admin routes.
- Email routes → Email services: delegates · Route handlers forward to service implementations.