# algorithmquantum/proyecto architecture

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

- Interactive diagram: https://gitdiagram.com/algorithmquantum/proyecto
- Repository: https://github.com/algorithmquantum/proyecto

## Overview

1. **Overall shape**
   - This is a **Python Flask-style monolith** for a clinic/hospital workflow system.
   - The backend serves both **HTML pages** and **application routes**; there is no separate frontend app or API-only layer in the tree.

2. **Application entrypoint**
   - `backend/app.py` is the runtime entrypoint described in the README.
   - It likely creates the Flask app, registers route modules, applies middleware, and starts the local server.

3. **Web layer / route boundaries**
   - The route modules in `backend/routes/` split the app by domain:
     - `auth.py` for login/registration/session entry.
     - `index.py` for landing/public pages.
     - `dashboard.py` for role-specific home screens.
     - `citas.py` for appointments.
     - `ajustes.py` for account/settings.
     - Role modules: `doctor.py`, `paciente.py`, `recepcionista.py`, `farmacia.py`, `soporte.py`.
   - This suggests a **server-rendered, role-based navigation model**, where each user type sees different pages and actions.

4. **Presentation layer**
   - UI is built with **Jinja templates** under `backend/templates/`.
   - There are separate template folders per role (`doctor/`, `paciente/`, `recepcionista/`, `farmacia/`) plus shared/public pages like `login.html`, `registro.html`, and error pages `403.html`, `404.html`, `500.html`.
   - The presence of many role-specific pages indicates the server renders distinct views rather than a single generic UI.

5. **Static assets**
   - CSS and JS live in `backend/static/`.
   - There are role-specific stylesheets such as `style_doctor.css`, `style_paciente.css`, `style_recepcion.css`, and `farmacia.css`, plus shared assets like `main.js` and `style.css`.
   - This means the UI is mostly server-rendered, with lightweight client-side behavior.

6. **Data access boundary**
   - `backend/db.py` and `backend/db_fake.py` imply a database abstraction with a real backend and a fake/test implementation.
   - The app likely centralizes persistence access through these modules rather than talking to the database directly from templates or routes.
   - For an architecture diagram, this is the main boundary between the web app and persistent storage.

7. **Authentication and authorization**
   - `backend/middleware/auth.py` provides access control middleware.
   - `backend/utils/decorador.py` likely contains decorators used to protect routes by role or login state.
   - Combined with the role-based route modules, this indicates **session-based authorization** enforced at the route level.

8. **Business-domain subsystems**
   - The repository models a clinic workflow with several clear functional areas:
     - **Appointments** (`citas`)
     - **Patients** (`paciente`)
     - **Doctors** (`doctor`)
     - **Reception operations** (`recepcionista`)
     - **Pharmacy / prescription validation** (`farmacia`)
     - **Support** (`soporte`)
     - **Dashboard and settings**
   - These are the core subsystems to show as separate boxes in a diagram, all feeding through the shared auth and DB layers.

9. **Operational/admin workflows**
   - The receptionist area is especially broad: templates include doctor, patient, specialty, schedules, consult rooms, tickets, and history/bitácora screens.
   - That suggests the receptionist role acts as an **operational admin** managing master data and appointment intake.

10. **Audit / logging**
    - `backend/utils/bitacora.py` indicates an audit trail or event log concept.
    - This is reinforced by receptionist templates like `bitacoraCitas.html` and `bitacoraHistorialMedico.html`.
    - In a diagram, treat bitácora as a cross-cutting concern tied to key user actions rather than a standalone feature.

11. **Public / informational pages**
    - The `templates/RASA/` folder contains public-facing informational pages such as contact, doctors, specialties, privacy, support, and index.
    - These look like a marketing/help layer separate from authenticated workflows.
    - If diagramming boundaries, keep these outside the authenticated clinical operations area.

12. **Error handling**
    - Dedicated `403`, `404`, and `500` templates show the app handles permission, not-found, and server-error states with custom pages.
    - This is a small but important boundary around access control and runtime failures.

13. **Runtime and dependencies**
    - The README shows local execution via `python app.py` after installing `requirements.txt`.
    - So the deployment model is a **single Python process** with a virtual environment, not a containerized or microservice setup in this repo.

14. **What to draw**
    - A good architecture diagram would show:
      - Browser/users
      - Flask app entrypoint
      - Auth middleware and decorators
      - Role-based route modules
      - Jinja templates and static assets
      - DB layer (`db.py` / `db_fake.py`)
      - Audit/bitácora utilities
      - Distinct user roles: patient, doctor, receptionist, pharmacy, support
    - The clearest architectural idea is a **monolithic, server-rendered, role-segmented clinic management system** with shared persistence and access control.

Main entry points: [`backend/app.py`](https://github.com/algorithmquantum/proyecto/blob/main/backend/app.py) (Flask app), [`backend/db.py`](https://github.com/algorithmquantum/proyecto/blob/main/backend/db.py) (Database), [`backend/templates`](https://github.com/algorithmquantum/proyecto/tree/main/backend/templates) (Templates), [`backend/routes/auth.py`](https://github.com/algorithmquantum/proyecto/blob/main/backend/routes/auth.py) (Auth routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime"]
  node_users(("Users<br/>actors"))
  node_app["Flask app<br/>entrypoint<br/>[app.py]"]
end

subgraph group_web["Web layer"]
  node_auth["Auth routes<br/>route module<br/>[auth.py]"]
  node_index["Public routes<br/>route module<br/>[index.py]"]
  node_dashboard["Dashboards<br/>route module<br/>[dashboard.py]"]
  node_citas["Citas<br/>route module<br/>[citas.py]"]
  node_ajustes["Ajustes<br/>route module<br/>[ajustes.py]"]
  node_doctor["Doctor routes<br/>route module<br/>[doctor.py]"]
  node_paciente["Paciente routes<br/>route module<br/>[paciente.py]"]
  node_recepcionista["Recepción routes<br/>route module<br/>[recepcionista.py]"]
  node_farmacia["Farmacia routes<br/>route module<br/>[farmacia.py]"]
  node_soporte["Soporte routes<br/>route module<br/>[soporte.py]"]
end

subgraph group_presentation["Presentation"]
  node_templates["Templates<br/>jinja views"]
  node_static["Static assets<br/>css/js"]
end

subgraph group_data["Data"]
  node_authmw["Auth middleware<br/>[auth.py]"]
  node_decorators["Route guards<br/>decorators<br/>[decorador.py]"]
  node_bitacora["Bitácora<br/>audit<br/>[bitacora.py]"]
  node_db[("Database<br/>persistence<br/>[db.py]")]
  node_dbfake[("Fake DB<br/>test store<br/>[db_fake.py]")]
end

node_users -->|"requests"| node_app
node_app -->|"applies"| node_authmw
node_app -->|"registers"| node_auth
node_app -->|"registers"| node_index
node_app -->|"registers"| node_dashboard
node_app -->|"registers"| node_citas
node_app -->|"registers"| node_ajustes
node_app -->|"registers"| node_doctor
node_app -->|"registers"| node_paciente
node_app -->|"registers"| node_recepcionista
node_app -->|"registers"| node_farmacia
node_app -->|"registers"| node_soporte
node_auth -->|"protects"| node_decorators
node_dashboard -->|"renders"| node_templates
node_index -->|"renders"| node_templates
node_citas -->|"renders"| node_templates
node_doctor -->|"renders"| node_templates
node_paciente -->|"renders"| node_templates
node_recepcionista -->|"renders"| node_templates
node_farmacia -->|"renders"| node_templates
node_soporte -->|"renders"| node_templates
node_app -->|"serves"| node_static
node_auth -->|"reads/writes"| node_db
node_citas -->|"reads/writes"| node_db
node_doctor -->|"reads/writes"| node_db
node_paciente -->|"reads/writes"| node_db
node_recepcionista -->|"reads/writes"| node_db
node_farmacia -->|"reads/writes"| node_db
node_soporte -->|"reads/writes"| node_db
node_db -->|"logs"| node_bitacora
node_dbfake -.->|"swap-in"| node_auth

click node_app "https://github.com/algorithmquantum/proyecto/blob/main/backend/app.py"
click node_authmw "https://github.com/algorithmquantum/proyecto/blob/main/backend/middleware/auth.py"
click node_decorators "https://github.com/algorithmquantum/proyecto/blob/main/backend/utils/decorador.py"
click node_bitacora "https://github.com/algorithmquantum/proyecto/blob/main/backend/utils/bitacora.py"
click node_db "https://github.com/algorithmquantum/proyecto/blob/main/backend/db.py"
click node_dbfake "https://github.com/algorithmquantum/proyecto/blob/main/backend/db_fake.py"
click node_auth "https://github.com/algorithmquantum/proyecto/blob/main/backend/routes/auth.py"
click node_index "https://github.com/algorithmquantum/proyecto/blob/main/backend/routes/index.py"
click node_dashboard "https://github.com/algorithmquantum/proyecto/blob/main/backend/routes/dashboard.py"
click node_citas "https://github.com/algorithmquantum/proyecto/blob/main/backend/routes/citas.py"
click node_ajustes "https://github.com/algorithmquantum/proyecto/blob/main/backend/routes/ajustes.py"
click node_doctor "https://github.com/algorithmquantum/proyecto/blob/main/backend/routes/doctor.py"
click node_paciente "https://github.com/algorithmquantum/proyecto/blob/main/backend/routes/paciente.py"
click node_recepcionista "https://github.com/algorithmquantum/proyecto/blob/main/backend/routes/recepcionista.py"
click node_farmacia "https://github.com/algorithmquantum/proyecto/blob/main/backend/routes/farmacia.py"
click node_soporte "https://github.com/algorithmquantum/proyecto/blob/main/backend/routes/soporte.py"
click node_templates "https://github.com/algorithmquantum/proyecto/tree/main/backend/templates"
click node_static "https://github.com/algorithmquantum/proyecto/tree/main/backend/static"

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_users,node_app toneBlue
class node_auth,node_index,node_dashboard,node_citas,node_ajustes,node_doctor,node_paciente,node_recepcionista,node_farmacia,node_soporte toneAmber
class node_templates,node_static toneMint
class node_authmw,node_decorators,node_bitacora,node_db,node_dbfake toneRose
```

## Components

### Runtime

Single-process Flask entrypoint and app startup

- **Users**: actors · Patients, doctors, reception, pharmacy, and support users accessing the system
- [Flask app](https://github.com/algorithmquantum/proyecto/blob/main/backend/app.py): entrypoint · Application entrypoint that initializes and runs the monolith · `backend/app.py`

### Web layer

Public pages, auth, and role-based route modules

- [Auth routes](https://github.com/algorithmquantum/proyecto/blob/main/backend/routes/auth.py): route module · Login, registration, and session entry routes · `backend/routes/auth.py`
- [Public routes](https://github.com/algorithmquantum/proyecto/blob/main/backend/routes/index.py): route module · Landing and public informational pages · `backend/routes/index.py`
- [Dashboards](https://github.com/algorithmquantum/proyecto/blob/main/backend/routes/dashboard.py): route module · Role-specific home screens and landing flows · `backend/routes/dashboard.py`
- [Citas](https://github.com/algorithmquantum/proyecto/blob/main/backend/routes/citas.py): route module · Appointment booking and appointment lifecycle routes · `backend/routes/citas.py`
- [Ajustes](https://github.com/algorithmquantum/proyecto/blob/main/backend/routes/ajustes.py): route module · Account and settings routes · `backend/routes/ajustes.py`
- [Doctor routes](https://github.com/algorithmquantum/proyecto/blob/main/backend/routes/doctor.py): route module · Doctor workflow for agenda, patients, prescriptions, and results · `backend/routes/doctor.py`
- [Paciente routes](https://github.com/algorithmquantum/proyecto/blob/main/backend/routes/paciente.py): route module · Patient workflow for profile, history, and appointments · `backend/routes/paciente.py`
- [Recepción routes](https://github.com/algorithmquantum/proyecto/blob/main/backend/routes/recepcionista.py): route module · Operational administration for doctors, patients, schedules, and records · `backend/routes/recepcionista.py`
- [Farmacia routes](https://github.com/algorithmquantum/proyecto/blob/main/backend/routes/farmacia.py): route module · Pharmacy workflow for prescription validation and history · `backend/routes/farmacia.py`
- [Soporte routes](https://github.com/algorithmquantum/proyecto/blob/main/backend/routes/soporte.py): route module · Support workflow and help-related routes · `backend/routes/soporte.py`

### Presentation

Jinja templates and static assets for server-rendered UI

- [Templates](https://github.com/algorithmquantum/proyecto/tree/main/backend/templates): jinja views · Server-rendered HTML templates for public and role-specific pages · `backend/templates`
- [Static assets](https://github.com/algorithmquantum/proyecto/tree/main/backend/static): css/js · Shared and role-specific stylesheets and client-side scripts · `backend/static`

### Data

Persistence boundary, fake backend, and shared cross-cutting utilities

- [Auth middleware](https://github.com/algorithmquantum/proyecto/blob/main/backend/middleware/auth.py): middleware · Request-time access control for logged-in and role-protected flows · `backend/middleware/auth.py`
- [Route guards](https://github.com/algorithmquantum/proyecto/blob/main/backend/utils/decorador.py): decorators · Reusable decorators for login and role checks · `backend/utils/decorador.py`
- [Bitácora](https://github.com/algorithmquantum/proyecto/blob/main/backend/utils/bitacora.py): audit · Audit trail utilities for tracked clinical and operational actions · `backend/utils/bitacora.py`
- [Database](https://github.com/algorithmquantum/proyecto/blob/main/backend/db.py): persistence · Primary persistence layer used by routes and workflows · `backend/db.py`
- [Fake DB](https://github.com/algorithmquantum/proyecto/blob/main/backend/db_fake.py): test store · Alternate in-memory or mocked persistence implementation · `backend/db_fake.py`

## Connections

- Users → Flask app: requests · Browser users interact with the Flask application
- Flask app → Auth middleware: applies · Entry app wires request filtering and access control
- Flask app → Auth routes: registers · Authentication routes are mounted into the app
- Flask app → Public routes: registers · Public pages are mounted into the app
- Flask app → Dashboards: registers · Role-specific dashboard routes are mounted into the app
- Flask app → Citas: registers · Appointment routes are mounted into the app
- Flask app → Ajustes: registers · Settings routes are mounted into the app
- Flask app → Doctor routes: registers · Doctor workflow routes are mounted into the app
- Flask app → Paciente routes: registers · Patient workflow routes are mounted into the app
- Flask app → Recepción routes: registers · Reception workflow routes are mounted into the app
- Flask app → Farmacia routes: registers · Pharmacy workflow routes are mounted into the app
- Flask app → Soporte routes: registers · Support routes are mounted into the app
- Auth routes → Route guards: protects · Login and role checks are enforced through shared decorators
- Dashboards → Templates: renders · Dashboards render server-side HTML views
- Public routes → Templates: renders · Public pages are rendered from Jinja templates
- Citas → Templates: renders · Appointment screens and receipts use templates
- Doctor routes → Templates: renders · Doctor-specific pages are server rendered
- Paciente routes → Templates: renders · Patient-specific pages are server rendered
- Recepción routes → Templates: renders · Reception workflows render operational pages
- Farmacia routes → Templates: renders · Pharmacy pages are server rendered
- Soporte routes → Templates: renders · Support pages are server rendered
- Flask app → Static assets: serves · The monolith serves shared and role-specific static assets
- Auth routes → Database: reads/writes · Authentication persists and verifies account/session data
- Citas → Database: reads/writes · Appointment workflows store and load scheduling data
- Doctor routes → Database: reads/writes · Doctor workflow uses persistence for clinical records
- Paciente routes → Database: reads/writes · Patient workflow accesses profile and history data
- Recepción routes → Database: reads/writes · Reception workflows manage master data and appointments
- Farmacia routes → Database: reads/writes · Pharmacy workflow validates prescriptions and history
- Soporte routes → Database: reads/writes · Support workflows access operational data
- Database → Bitácora: logs · Important actions are captured in the audit trail
- Fake DB → Auth routes: swap-in · Fake persistence can stand in for real data during local or test flows
