# mafo2017/dms_enterprise architecture

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

- Interactive diagram: https://gitdiagram.com/mafo2017/dms_enterprise
- Repository: https://github.com/mafo2017/dms_enterprise

## Overview

1. **Overall shape**
   - This is a **PHP 8.2+ monolith** built around a strict **MVC-style architecture**.
   - The codebase is split into a **browser-facing application** and a **separate REST API**, both sharing the same core, models, and database.

2. **Request entry points**
   - `public/index.php` is the main web entry point for the frontend.
   - `api/index.php` is the API entry point.
   - The `public/` directory is the web root, while `storage/` and `logs/` are kept outside normal public access and protected with `.htaccess`.

3. **Framework core**
   - The `core/` folder acts as a lightweight internal framework:
     - `Router.php` dispatches requests.
     - `Controller.php` and `View.php` support rendering and response handling.
     - `Model.php` and `Database.php` provide persistence access.
     - `Auth.php` and `Security.php` centralize authentication and security checks.
   - This suggests a custom framework rather than Laravel/Symfony.

4. **Frontend presentation layer**
   - Browser UI controllers live under `Controllers/frontend/`.
   - HTML rendering is handled by templates in `public/views/`, organized by feature:
     - `auth/`
     - `dashboard/`
     - `documents/`
     - `series/`
     - `users/`
     - `audit/`
     - shared `layouts/` and `partials/`
   - The frontend likely follows a classic server-rendered flow: controller → model → view.

5. **API layer**
   - API controllers live under `Controllers/api/v1/`, indicating explicit **versioning**.
   - The API has feature-specific endpoints for authentication, documents, users, audit, and series.
   - Responses are presumably JSON-based and used for integration with external systems.

6. **Domain subsystems**
   - The main business areas are:
     - **Document management** (`Document`, `DocumentVersion`, `DocumentMetadata`, `DocumentAccessLog`)
     - **User and role management** (`User`, `Role`)
     - **Authentication and recovery** (`RefreshToken`, `PasswordReset`)
     - **Audit and security** (`AuditLog`, `SecurityLog`)
     - **Retention/compliance** (`RetentionSchedule`, `RetentionAlert`)
     - **Notifications and settings** (`Notification`, `SystemSetting`)
   - `Series` appears to model document classification or filing structure.

7. **Persistence and data model**
   - The app uses **MySQL 8+** through the custom database layer in `core/Database.php`.
   - Each domain object has a corresponding model in `models/`, which likely encapsulates queries and business rules.
   - Database setup artifacts include `base.sql`, `datos.sql`, and import helpers like `import_db.php` and `execute_db.bat`.

8. **Security architecture**
   - The README indicates layered security: **sessions + JWT**, **2FA TOTP**, password reset, refresh tokens, and security logging.
   - `core/Security.php` and `core/Auth.php` likely enforce input validation, authorization, and session/token handling.
   - The presence of `logs/php_errors.log` and `SecurityLog` suggests runtime security events are tracked separately from application audit events.

9. **Audit and compliance**
   - Audit is a first-class subsystem, not an afterthought:
     - `AuditApiController.php` / `AuditController.php`
     - `AuditLog` and `DocumentAccessLog`
   - Retention management (`RetentionSchedule`, `RetentionAlert`) aligns with ISO 15489 document lifecycle requirements.
   - The repository also includes compliance checklists for ISO 15489, ISO 27001, and OWASP, which are supporting artifacts for governance and verification.

10. **Document lifecycle boundaries**
   - The document domain is more than CRUD: it includes **versions, metadata, access history, and retention rules**.
   - That implies a flow where documents are created/updated through controllers, persisted via models, and audited at each meaningful action.
   - The architecture is designed to preserve traceability and compliance, not just store files.

11. **Operational and deployment boundaries**
   - `.env` / `.ENV.EXAMPLE` and `config/config.php` / `config/database.php` separate environment configuration from code.
   - `storage/` and `logs/` are writable runtime areas, likely for files, generated artifacts, and error/audit logs.
   - `public/.htaccess` and `logs/.htaccess` indicate Apache-oriented hardening, though the app can also be hosted behind Nginx with equivalent routing.

12. **Supporting material in the repo**
   - The repository includes substantial documentation: installation, user manual, architecture notes, testing plan, and security characteristics.
   - Files like `CHECKLIST_*.txt`, `manual_instalacion.txt`, and `manual_usuario.txt` suggest the project is intended for audited enterprise deployment rather than a minimal prototype.

13. **Mental model for a diagram**
   - The cleanest diagram would show:
     - **Clients** entering through **web frontend** or **REST API**
     - Both routed through **front controllers / router**
     - Shared **core services** for auth, security, database, and view rendering
     - Feature controllers calling **domain models**
     - Models persisting to **MySQL**
     - Supporting stores for **logs, storage, and compliance/audit records**

Main entry points: [`Controllers/frontend`](https://github.com/mafo2017/dms_enterprise/tree/main/Controllers/frontend) (Frontend ctrls), [`Controllers/api/v1`](https://github.com/mafo2017/dms_enterprise/tree/main/Controllers/api/v1) (API v1 ctrls), [`models/Document.php`](https://github.com/mafo2017/dms_enterprise/blob/main/models/Document.php) (Document), [`core/Router.php`](https://github.com/mafo2017/dms_enterprise/blob/main/core/Router.php) (Router)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry points"]
  node_public_index["Web entry<br/>front controller<br/>[index.php]"]
  node_api_index["API entry<br/>front controller<br/>[index.php]"]
end

subgraph group_app["Application"]
  node_frontend_ctrls["Frontend ctrls<br/>web controllers"]
  node_api_ctrls["API v1 ctrls<br/>api controllers"]
  node_templates["Views<br/>templates"]
end

subgraph group_core["Core framework"]
  node_router{{"Router<br/>dispatch core<br/>[Router.php]"}}
  node_base_controller["Base ctl<br/>mvc base<br/>[Controller.php]"]
  node_view["View<br/>render core<br/>[View.php]"]
  node_auth{{"Auth<br/>security core<br/>[Auth.php]"}}
  node_security{{"Security<br/>[Security.php]"}}
  node_model_base["Model<br/>data base<br/>[Model.php]"]
  node_database[("Database<br/>mysql access<br/>[Database.php]")]
end

subgraph group_domain["Domain model"]
  node_user["User<br/>identity model<br/>[User.php]"]
  node_role["Role<br/>identity model<br/>[Role.php]"]
  node_document["Document<br/>content model<br/>[Document.php]"]
  node_doc_version["Versions<br/>content model"]
  node_doc_meta["Metadata<br/>content model"]
  node_doc_access["Access log<br/>audit model"]
  node_audit_log["Audit log<br/>audit model<br/>[AuditLog.php]"]
  node_security_log["Security log<br/>audit model<br/>[SecurityLog.php]"]
  node_retention["Retention<br/>compliance model"]
  node_refresh_token["Tokens<br/>auth model<br/>[RefreshToken.php]"]
end

subgraph group_ops["Runtime and config"]
  node_config["Config<br/>[config.php]"]
  node_env["Env<br/>runtime config<br/>[.env]"]
  node_storage[("Storage<br/>runtime store")]
  node_logs[("Logs<br/>runtime store")]
  node_sql["Schema<br/>db setup<br/>[base.sql]"]
end

node_public_index -->|"dispatches"| node_router
node_api_index -->|"dispatches"| node_router
node_router -->|"routes to"| node_frontend_ctrls
node_router -->|"routes to"| node_api_ctrls
node_frontend_ctrls -->|"extends"| node_base_controller
node_api_ctrls -->|"extends"| node_base_controller
node_frontend_ctrls -->|"renders"| node_templates
node_frontend_ctrls -->|"uses"| node_auth
node_frontend_ctrls -->|"uses"| node_security
node_api_ctrls -->|"uses"| node_auth
node_api_ctrls -->|"uses"| node_security
node_base_controller -->|"uses"| node_view
node_base_controller -->|"uses"| node_model_base
node_model_base -->|"persists via"| node_database
node_document -->|"has"| node_doc_version
node_document -->|"has"| node_doc_meta
node_document -->|"tracked by"| node_doc_access
node_frontend_ctrls -->|"manages"| node_document
node_api_ctrls -->|"exposes"| node_document
node_frontend_ctrls -->|"manages"| node_user
node_api_ctrls -->|"exposes"| node_user
node_frontend_ctrls -->|"reviews"| node_audit_log
node_api_ctrls -->|"exposes"| node_audit_log
node_auth -->|"stores"| node_refresh_token
node_auth -->|"verifies"| node_user
node_security -->|"records"| node_security_log
node_config -->|"configures"| node_database
node_env -->|"overrides"| node_config
node_sql -->|"initializes"| node_database
node_storage -->|"stores files"| node_document
node_logs -->|"stores"| node_security_log

click node_public_index "https://github.com/mafo2017/dms_enterprise/blob/main/public/index.php"
click node_api_index "https://github.com/mafo2017/dms_enterprise/blob/main/api/index.php"
click node_router "https://github.com/mafo2017/dms_enterprise/blob/main/core/Router.php"
click node_base_controller "https://github.com/mafo2017/dms_enterprise/blob/main/core/Controller.php"
click node_view "https://github.com/mafo2017/dms_enterprise/blob/main/core/View.php"
click node_auth "https://github.com/mafo2017/dms_enterprise/blob/main/core/Auth.php"
click node_security "https://github.com/mafo2017/dms_enterprise/blob/main/core/Security.php"
click node_model_base "https://github.com/mafo2017/dms_enterprise/blob/main/core/Model.php"
click node_database "https://github.com/mafo2017/dms_enterprise/blob/main/core/Database.php"
click node_frontend_ctrls "https://github.com/mafo2017/dms_enterprise/tree/main/Controllers/frontend"
click node_api_ctrls "https://github.com/mafo2017/dms_enterprise/tree/main/Controllers/api/v1"
click node_templates "https://github.com/mafo2017/dms_enterprise/tree/main/public/views"
click node_user "https://github.com/mafo2017/dms_enterprise/blob/main/models/User.php"
click node_role "https://github.com/mafo2017/dms_enterprise/blob/main/models/Role.php"
click node_document "https://github.com/mafo2017/dms_enterprise/blob/main/models/Document.php"
click node_doc_version "https://github.com/mafo2017/dms_enterprise/blob/main/models/DocumentVersion.php"
click node_doc_meta "https://github.com/mafo2017/dms_enterprise/blob/main/models/DocumentMetadata.php"
click node_doc_access "https://github.com/mafo2017/dms_enterprise/blob/main/models/DocumentAccessLog.php"
click node_audit_log "https://github.com/mafo2017/dms_enterprise/blob/main/models/AuditLog.php"
click node_security_log "https://github.com/mafo2017/dms_enterprise/blob/main/models/SecurityLog.php"
click node_retention "https://github.com/mafo2017/dms_enterprise/blob/main/models/RetentionSchedule.php"
click node_refresh_token "https://github.com/mafo2017/dms_enterprise/blob/main/models/RefreshToken.php"
click node_config "https://github.com/mafo2017/dms_enterprise/blob/main/config/config.php"
click node_env "https://github.com/mafo2017/dms_enterprise/blob/main/.env"
click node_storage "https://github.com/mafo2017/dms_enterprise/tree/main/storage"
click node_logs "https://github.com/mafo2017/dms_enterprise/tree/main/logs"
click node_sql "https://github.com/mafo2017/dms_enterprise/blob/main/base.sql"

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_public_index,node_api_index toneBlue
class node_frontend_ctrls,node_api_ctrls,node_templates toneAmber
class node_router,node_base_controller,node_view,node_auth,node_security,node_model_base,node_database toneMint
class node_user,node_role,node_document,node_doc_version,node_doc_meta,node_doc_access,node_audit_log,node_security_log,node_retention,node_refresh_token toneRose
class node_config,node_env,node_storage,node_logs,node_sql toneIndigo
```

## Components

### Entry points

Browser and API front controllers

- [Web entry](https://github.com/mafo2017/dms_enterprise/blob/main/public/index.php): front controller · Main browser-facing entry point · `public/index.php`
- [API entry](https://github.com/mafo2017/dms_enterprise/blob/main/api/index.php): front controller · REST API entry point · `api/index.php`

### Application

Frontend, API controllers, and views

- [Frontend ctrls](https://github.com/mafo2017/dms_enterprise/tree/main/Controllers/frontend): web controllers · Browser-facing controllers for auth, dashboard, documents, series, users, and audit · `Controllers/frontend`
- [API v1 ctrls](https://github.com/mafo2017/dms_enterprise/tree/main/Controllers/api/v1): api controllers · Versioned REST controllers for auth, documents, series, users, and audit · `Controllers/api/v1`
- [Views](https://github.com/mafo2017/dms_enterprise/tree/main/public/views): templates · Server-rendered pages and layouts · `public/views`

### Core framework

Shared routing, controller, auth, security, and persistence primitives

- [Router](https://github.com/mafo2017/dms_enterprise/blob/main/core/Router.php): dispatch core · Central request dispatcher · `core/Router.php`
- [Base ctl](https://github.com/mafo2017/dms_enterprise/blob/main/core/Controller.php): mvc base · Shared controller behavior · `core/Controller.php`
- [View](https://github.com/mafo2017/dms_enterprise/blob/main/core/View.php): render core · Template rendering and response output · `core/View.php`
- [Auth](https://github.com/mafo2017/dms_enterprise/blob/main/core/Auth.php): security core · Authentication and session/token handling · `core/Auth.php`
- [Security](https://github.com/mafo2017/dms_enterprise/blob/main/core/Security.php): security core · Input validation and authorization checks · `core/Security.php`
- [Model](https://github.com/mafo2017/dms_enterprise/blob/main/core/Model.php): data base · Shared model persistence layer · `core/Model.php`
- [Database](https://github.com/mafo2017/dms_enterprise/blob/main/core/Database.php): mysql access · Database connection and queries · `core/Database.php`

### Domain model

Business entities and compliance-related records

- [User](https://github.com/mafo2017/dms_enterprise/blob/main/models/User.php): identity model · Users and profile data · `models/User.php`
- [Role](https://github.com/mafo2017/dms_enterprise/blob/main/models/Role.php): identity model · Authorization roles · `models/Role.php`
- [Document](https://github.com/mafo2017/dms_enterprise/blob/main/models/Document.php): content model · Core document aggregate · `models/Document.php`
- [Versions](https://github.com/mafo2017/dms_enterprise/blob/main/models/DocumentVersion.php): content model · Document revision history · `models/DocumentVersion.php`
- [Metadata](https://github.com/mafo2017/dms_enterprise/blob/main/models/DocumentMetadata.php): content model · Document classification and descriptive data · `models/DocumentMetadata.php`
- [Access log](https://github.com/mafo2017/dms_enterprise/blob/main/models/DocumentAccessLog.php): audit model · Document access history · `models/DocumentAccessLog.php`
- [Audit log](https://github.com/mafo2017/dms_enterprise/blob/main/models/AuditLog.php): audit model · Application activity audit trail · `models/AuditLog.php`
- [Security log](https://github.com/mafo2017/dms_enterprise/blob/main/models/SecurityLog.php): audit model · Security-relevant event records · `models/SecurityLog.php`
- [Retention](https://github.com/mafo2017/dms_enterprise/blob/main/models/RetentionSchedule.php): compliance model · Retention schedules and alerts · `models/RetentionSchedule.php`
- [Tokens](https://github.com/mafo2017/dms_enterprise/blob/main/models/RefreshToken.php): auth model · Refresh token storage · `models/RefreshToken.php`

### Runtime and config

Environment, storage, logs, and database setup

- [Config](https://github.com/mafo2017/dms_enterprise/blob/main/config/config.php): environment config · Application and database configuration · `config/config.php`
- [Env](https://github.com/mafo2017/dms_enterprise/blob/main/.env): runtime config · Environment variable settings · `.env`
- [Storage](https://github.com/mafo2017/dms_enterprise/tree/main/storage): runtime store · Protected writable files and generated artifacts · `storage`
- [Logs](https://github.com/mafo2017/dms_enterprise/tree/main/logs): runtime store · Protected log output area · `logs`
- [Schema](https://github.com/mafo2017/dms_enterprise/blob/main/base.sql): db setup · Database seed and setup artifacts · `base.sql`

## Connections

- Web entry → Router: dispatches · Web requests are routed into the shared dispatcher
- API entry → Router: dispatches · API requests are routed into the shared dispatcher
- Router → Frontend ctrls: routes to · Browser routes are handled by frontend controllers
- Router → API v1 ctrls: routes to · API routes are handled by versioned API controllers
- Frontend ctrls → Base ctl: extends · Frontend controllers share common controller behavior
- API v1 ctrls → Base ctl: extends · API controllers share common controller behavior
- Frontend ctrls → Views: renders · Frontend controllers render server-side views
- Frontend ctrls → Auth: uses · Authentication and session checks
- Frontend ctrls → Security: uses · Authorization and validation checks
- API v1 ctrls → Auth: uses · Token/session based API authentication
- API v1 ctrls → Security: uses · API request validation and protection
- Base ctl → View: uses · Controllers rely on view rendering helpers
- Base ctl → Model: uses · Controllers coordinate with models through the shared base
- Model → Database: persists via · Models execute database access through the shared database layer
- Document → Versions: has · Documents maintain version history
- Document → Metadata: has · Documents carry metadata and classification
- Document → Access log: tracked by · Document access is separately audited
- Frontend ctrls → Document: manages · Document lifecycle screens
- API v1 ctrls → Document: exposes · Document REST endpoints
- Frontend ctrls → User: manages · User administration and profile flows
- API v1 ctrls → User: exposes · User REST endpoints
- Frontend ctrls → Audit log: reviews · Audit screens inspect activity history
- API v1 ctrls → Audit log: exposes · Audit REST endpoints
- Auth → Tokens: stores · Refresh token lifecycle support
- Auth → User: verifies · Authentication resolves user identities
- Security → Security log: records · Security events are written to dedicated logs
- Config → Database: configures · Database settings feed the persistence layer
- Env → Config: overrides · Environment values supplement static config
- Schema → Database: initializes · Schema and seed artifacts prepare the database
- Storage → Document: stores files · Writable storage holds document assets and generated content
- Logs → Security log: stores · Runtime logs complement security audit records
