# rg727876-hub/clinica-padre-pio architecture

> Architecture diagram of the GitHub repository rg727876-hub/clinica-padre-pio, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rg727876-hub/clinica-padre-pio
- Repository: https://github.com/rg727876-hub/clinica-padre-pio

## Overview

1. **Architecture style**
   - This is a small, server-rendered **Flask monolith** for a dental clinic.
   - The main application logic lives in a single Python entrypoint, `app.py`, with persistence handled by local **SQLite** via `clinica.db`.
   - There is no separate frontend app, API service, or background worker layer.

2. **Core runtime boundary**
   - The system is a classic request/response web app:
     - Browser request → Flask route in `app.py` → database read/write → Jinja2 template render → HTML response.
   - The UI is built from server-rendered templates, with Bootstrap 5 styling and a small amount of client-side JavaScript in `static/js/app.js`.

3. **Data layer**
   - `database.py` is the persistence bootstrap and audit helper layer.
   - The database is local and file-based (`clinica.db`), which makes the deployment self-contained but also means the app is stateful on disk rather than using an external DB server.
   - The README indicates an **audit log/bitácora** is part of the system, so database writes are not just transactional domain updates but also traceable actions.

4. **Main application coordinator**
   - `app.py` is the central orchestrator for routes, role checks, form handling, and business rules.
   - It likely owns the full workflow for authentication, authorization, CRUD operations, and state transitions for appointments, patients, users, services, and payments.
   - Because the repository is small and template-driven, `app.py` is effectively both controller and service layer.

5. **Role-based subsystems**
   - The app is partitioned by user role, and each role has its own view set:
     - **Administrador**: users, services, schedules, reports, audit.
     - **Recepcionista**: patients, appointment creation, reprogramming, schedule management.
     - **Doctor**: own agenda, own schedule, patient history, clinical observations.
     - **Cajero**: payment lookup, payment registration, receipt/comprobante generation.
   - This role segmentation is a primary architectural boundary and should be shown prominently in a diagram.

6. **Patient and appointment flow**
   - Receptionists create and edit patients, then schedule appointments by selecting a doctor, service, date, and time.
   - Appointments move through a defined lifecycle: `confirmada` → `atendida` → `pagada`, with alternate terminal states like `cancelada` and `no_asistio`.
   - Reprogramming and cancellation are separate operational paths, implying appointment state is a key domain object.

7. **Clinical workflow boundary**
   - Doctors do not manage the full patient registry; they see only their assigned agenda and their own patients’ histories.
   - Clinical data appears to be appended at attendance time via observations/notes, separating administrative scheduling from clinical follow-up.
   - This creates an important access boundary: clinicians can read and update only the records relevant to their assignments.

8. **Billing / cashier flow**
   - The cashier module is downstream of attended appointments.
   - The typical path is: search by appointment code or DNI → verify attended status → register payment method → generate receipt/invoice view.
   - The system tracks payment methods such as efectivo, tarjeta, Yape, Plin, and transferencia, so payment capture is part of the domain model rather than a simple confirmation flag.

9. **Administration and governance**
   - The admin area covers the clinic’s operational configuration:
     - user accounts and roles
     - active/inactive status control
     - dental services catalog
     - doctor schedules
     - exportable reports
     - audit trail review
   - This is the system’s configuration and governance boundary, distinct from day-to-day patient care and billing.

10. **Presentation layer structure**
   - Templates are grouped by role under `templates/admin`, `templates/recepcionista`, `templates/doctor`, and `templates/cajero`.
   - Shared layout is centralized in `templates/base.html`, with a standalone `login.html` and a high-level `dashboard.html`.
   - This structure reinforces the role-based navigation model and makes the page hierarchy easy to map in an architecture diagram.

11. **Static assets**
   - `static/css/style.css` provides custom styling on top of Bootstrap.
   - `static/js/app.js` likely supports small interactions such as form behavior, UI helpers, or client-side enhancements; it does not appear to be a SPA or complex frontend runtime.

12. **Deployment and operational shape**
   - The app is meant to run locally with `python app.py`, using a bundled SQLite file and default admin credentials for first access.
   - `iniciar.bat` suggests a Windows-oriented startup convenience script.
   - Overall, the repo is a compact, single-process clinic management system with clear role-separated screens and a shared data store.

Main entry points: [`app.py`](https://github.com/rg727876-hub/clinica-padre-pio/blob/main/app.py) (App), [`templates/base.html`](https://github.com/rg727876-hub/clinica-padre-pio/blob/main/templates/base.html) (Base layout), [`database.py`](https://github.com/rg727876-hub/clinica-padre-pio/blob/main/database.py) (DB layer), [`static/css/style.css`](https://github.com/rg727876-hub/clinica-padre-pio/blob/main/static/css/style.css) (Styles)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime"]
  node_browser(("Browser<br/>client"))
  node_app_py["App<br/>flask monolith<br/>[app.py]"]
end

subgraph group_presentation["Presentation"]
  node_base_tpl["Base layout<br/>jinja2 layout<br/>[base.html]"]
  node_login_tpl["Login page<br/>jinja2 view<br/>[login.html]"]
  node_dashboard_tpl["Dashboard<br/>jinja2 view<br/>[dashboard.html]"]
  node_admin_views["Admin area<br/>role templates<br/>[usuarios.html]"]
  node_recep_views["Reception area<br/>role templates<br/>[citas.html]"]
  node_doctor_views["Doctor area<br/>role templates<br/>[citas.html]"]
  node_cashier_views["Cashier area<br/>role templates<br/>[pago.html]"]
  node_style_css["Styles<br/>css theme<br/>[style.css]"]
  node_app_js["UI script<br/>client script<br/>[app.js]"]
end

subgraph group_data["Data"]
  node_database_py["DB layer<br/>persistence helper<br/>[database.py]"]
  node_clinica_db[("Clinica DB<br/>sqlite file<br/>[clinica.db]")]
end

subgraph group_ops["Ops"]
  node_readme["README<br/>docs<br/>[README.md]"]
  node_requirements["Deps<br/>[requirements.txt]"]
  node_startup_bat["Startup script<br/>windows helper<br/>[iniciar.bat]"]
end

node_browser -->|"HTTP request"| node_app_py
node_app_py -->|"auth view"| node_login_tpl
node_app_py -->|"home view"| node_dashboard_tpl
node_app_py -->|"admin screens"| node_admin_views
node_app_py -->|"reception screens"| node_recep_views
node_app_py -->|"doctor screens"| node_doctor_views
node_app_py -->|"cashier screens"| node_cashier_views
node_app_py -->|"persistence"| node_database_py
node_database_py -->|"SQLite I/O"| node_clinica_db
node_app_py -->|"layout"| node_base_tpl
node_app_py -->|"assets"| node_style_css
node_app_py -->|"assets"| node_app_js
node_base_tpl -->|"styles"| node_style_css
node_base_tpl -->|"scripts"| node_app_js
node_app_py -.->|"docs"| node_readme
node_app_py -.->|"deps"| node_requirements
node_app_py -.->|"startup"| node_startup_bat

click node_app_py "https://github.com/rg727876-hub/clinica-padre-pio/blob/main/app.py"
click node_database_py "https://github.com/rg727876-hub/clinica-padre-pio/blob/main/database.py"
click node_clinica_db "https://github.com/rg727876-hub/clinica-padre-pio/blob/main/clinica.db"
click node_base_tpl "https://github.com/rg727876-hub/clinica-padre-pio/blob/main/templates/base.html"
click node_login_tpl "https://github.com/rg727876-hub/clinica-padre-pio/blob/main/templates/login.html"
click node_dashboard_tpl "https://github.com/rg727876-hub/clinica-padre-pio/blob/main/templates/dashboard.html"
click node_admin_views "https://github.com/rg727876-hub/clinica-padre-pio/blob/main/templates/admin/usuarios.html"
click node_recep_views "https://github.com/rg727876-hub/clinica-padre-pio/blob/main/templates/recepcionista/citas.html"
click node_doctor_views "https://github.com/rg727876-hub/clinica-padre-pio/blob/main/templates/doctor/citas.html"
click node_cashier_views "https://github.com/rg727876-hub/clinica-padre-pio/blob/main/templates/cajero/pago.html"
click node_style_css "https://github.com/rg727876-hub/clinica-padre-pio/blob/main/static/css/style.css"
click node_app_js "https://github.com/rg727876-hub/clinica-padre-pio/blob/main/static/js/app.js"
click node_readme "https://github.com/rg727876-hub/clinica-padre-pio/blob/main/README.md"
click node_requirements "https://github.com/rg727876-hub/clinica-padre-pio/blob/main/requirements.txt"
click node_startup_bat "https://github.com/rg727876-hub/clinica-padre-pio/blob/main/iniciar.bat"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_browser,node_app_py toneBlue
class node_base_tpl,node_login_tpl,node_dashboard_tpl,node_admin_views,node_recep_views,node_doctor_views,node_cashier_views,node_style_css,node_app_js toneAmber
class node_database_py,node_clinica_db toneMint
class node_readme,node_requirements,node_startup_bat toneRose
```

## Components

### Runtime

Flask request handling, business rules, and persistence.

- **Browser**: client · User-facing HTTP client entering the app.
- [App](https://github.com/rg727876-hub/clinica-padre-pio/blob/main/app.py): flask monolith · Central Flask entrypoint for routes, role checks, workflows, and business rules. · `app.py`

### Presentation

Server-rendered templates and static assets.

- [Base layout](https://github.com/rg727876-hub/clinica-padre-pio/blob/main/templates/base.html): jinja2 layout · Shared page shell and navigation. · `templates/base.html`
- [Login page](https://github.com/rg727876-hub/clinica-padre-pio/blob/main/templates/login.html): jinja2 view · Standalone authentication page. · `templates/login.html`
- [Dashboard](https://github.com/rg727876-hub/clinica-padre-pio/blob/main/templates/dashboard.html): jinja2 view · Role-aware landing page after login. · `templates/dashboard.html`
- [Admin area](https://github.com/rg727876-hub/clinica-padre-pio/blob/main/templates/admin/usuarios.html): role templates · User management, services, schedules, reports, and audit views. · `templates/admin/usuarios.html`
- [Reception area](https://github.com/rg727876-hub/clinica-padre-pio/blob/main/templates/recepcionista/citas.html): role templates · Patient management, appointment creation, and reprogramming screens. · `templates/recepcionista/citas.html`
- [Doctor area](https://github.com/rg727876-hub/clinica-padre-pio/blob/main/templates/doctor/citas.html): role templates · Agenda, patient history, and clinical follow-up screens. · `templates/doctor/citas.html`
- [Cashier area](https://github.com/rg727876-hub/clinica-padre-pio/blob/main/templates/cajero/pago.html): role templates · Payment lookup, registration, and receipt generation screens. · `templates/cajero/pago.html`
- [Styles](https://github.com/rg727876-hub/clinica-padre-pio/blob/main/static/css/style.css): css theme · Custom styling layered on Bootstrap. · `static/css/style.css`
- [UI script](https://github.com/rg727876-hub/clinica-padre-pio/blob/main/static/js/app.js): client script · Small client-side enhancements and form behavior. · `static/js/app.js`

### Data

Local SQLite storage and persistence bootstrap.

- [DB layer](https://github.com/rg727876-hub/clinica-padre-pio/blob/main/database.py): persistence helper · SQLite bootstrap, writes, and audit/bitácora support. · `database.py`
- [Clinica DB](https://github.com/rg727876-hub/clinica-padre-pio/blob/main/clinica.db): sqlite file · Local stateful database file used by the application. · `clinica.db`

### Ops

Repository-level startup and dependency wiring.

- [README](https://github.com/rg727876-hub/clinica-padre-pio/blob/main/README.md): docs · Project overview, usage, and clinic workflow notes. · `README.md`
- [Deps](https://github.com/rg727876-hub/clinica-padre-pio/blob/main/requirements.txt): python deps · Python package requirements for the Flask app. · `requirements.txt`
- [Startup script](https://github.com/rg727876-hub/clinica-padre-pio/blob/main/iniciar.bat): windows helper · Convenience launcher for local execution. · `iniciar.bat`

## Connections

- Browser → App: HTTP request · Browser interactions enter the Flask app.
- App → Login page: auth view · Renders the login page.
- App → Dashboard: home view · Renders the role-aware dashboard.
- App → Admin area: admin screens · Serves administrative workflows.
- App → Reception area: reception screens · Serves patient and appointment workflows.
- App → Doctor area: doctor screens · Serves clinical agenda and history views.
- App → Cashier area: cashier screens · Serves payment and receipt flows.
- App → DB layer: persistence · Delegates reads, writes, and audit logging.
- DB layer → Clinica DB: SQLite I/O · Stores clinic state on disk.
- App → Base layout: layout · Uses shared base template for rendering.
- App → Styles: assets · Includes custom styles in rendered pages.
- App → UI script: assets · Includes small client-side helpers.
- Base layout → Styles: styles · Base layout loads CSS theme.
- Base layout → UI script: scripts · Base layout loads client script.
- App → README: docs · Repository documentation describes workflows and usage.
- App → Deps: deps · Runtime dependencies for the Flask monolith.
- App → Startup script: startup · Windows launcher for local runs.
