# thejuanjo1/bethlemitas architecture

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

- Interactive diagram: https://gitdiagram.com/thejuanjo1/bethlemitas
- Repository: https://github.com/thejuanjo1/bethlemitas

## Overview

1. This is a Laravel 11-style monolith for school/student support management, centered on academic administration, teacher workflows, psychoorientation, and PIAR case tracking. The app is server-rendered with Blade views, Eloquent models, and standard Laravel routing/controllers.

2. The repository is organized around role-based access rather than feature microservices. Middleware such as `RoleMiddleware`, `RoleDocenteMiddleware`, `RolePsicoorientadorMiddleware`, and the combined role middleware gate access to different areas of the system. This is the main architectural boundary between user types.

3. The core domain is educational structure management: degrees, periods, areas, groups, institution, and the assignment of teachers/students to those structures. The corresponding controllers in `app/Http/Controllers` and models like `Degree`, `Group`, `Area`, `Period`, `Institution`, and the `Users_load_*` / `Teachers_areas_groups` tables define the academic organizational layer.

4. User management is a separate subsystem from the academic structure. `AcademicUserService` and the `StoreUserRequest` / `UpdateUserRequest` classes suggest a dedicated workflow for creating and editing academic users, likely with validation and role assignment. The presence of `config/permission.php` and the `permission_tables` migration indicates role/permission management via a package such as Spatie Permission.

5. The student support workflow is driven by referrals and psychoorientation records. `Referral`, `Psychoorientation`, and related controllers (`CreateReferralController`, `PsicoController`) indicate a process where teachers or staff report a student, psychoorientation staff review it, and the case is tracked through status/state changes. Models like `State`, `Users_student`, and `Student_characteristics` support that lifecycle.

6. PIAR is the most specialized subsystem in the repo. It has its own models, migrations, controllers, and views: `Piar`, `PiarMinute`, `PiarCharacteristic`, `PiarAdjustment`, `PiarReport/Annual_Report`, `Agreement`, `Recommendation`, `Strategies`, and `Dua`. This suggests a formal multi-step intervention plan with meetings, observations, adjustments, recommendations, and periodic evaluations.

7. The PIAR workflow is period-based and document-heavy. There are dedicated Blade templates for `periodo1`, `periodo2`, `periodo3`, evaluation, editing adjustments, and PDFs, implying the app generates structured outputs for each review cycle. The `public/piars` directory and `resources/views/pdf/*` templates show that generated documents are stored and served as downloadable files.

8. Communication is integrated through email and notifications. `AcceptStudentMail`, `CreatedReferralMail`, and `StudentInPiarNotification` show asynchronous user-facing events tied to the support workflow. A notifications table migration exists, so the app persists notification history rather than relying only on transient mail delivery.

9. The presentation layer is split by audience: `resources/views/academic`, `teacher`, `psycho`, `piar`, `profile`, and `auth`. This mirrors the role boundaries and keeps each user journey isolated in the UI, with shared layout shells in `resources/views/layout*` and reusable email/PDF templates.

10. Client-side behavior is lightweight and targeted. The project uses `resources/js` plus a set of page-specific scripts in `public/scripts` for form interactions like user creation, area/degree/group management, and student acceptance. Styling is handled with Vite/Tailwind and custom CSS assets.

11. Persistence is centered on a relational database with many domain tables and join tables. The migrations show a normalized schema with reference data, user-to-structure assignments, referral/psychoorientation records, and PIAR-specific artifacts. This is the main data backbone of the system.

12. File storage is part of the architecture, not just an implementation detail. Profile images and PIAR-related PDFs are stored under `public/Imagenes_Perfil` and `public/piars`, while Laravel’s `storage` directories handle generated and internal files. This means documents are both produced and served by the application.

13. The routing entry point is conventional Laravel: web routes dispatch to controllers, which orchestrate validation, persistence, email/notification side effects, and view rendering. There is no sign of a separate API-first architecture; the system is primarily server-rendered with form submissions and document generation.

14. In diagram terms, the main containers are: authentication/authorization, academic administration, teacher referral handling, psychoorientation case management, PIAR case lifecycle, and document/notification output. The central database connects all of them, with email and file storage as the main external dependencies.

Main entry points: [`app/Http/Controllers/PiarController.php`](https://github.com/thejuanjo1/bethlemitas/blob/main/app/Http/Controllers/PiarController.php) (PIAR ctrl), [`routes/web.php`](https://github.com/thejuanjo1/bethlemitas/blob/main/routes/web.php) (Web routes), [`app/Http/Controllers/CreateReferralController.php`](https://github.com/thejuanjo1/bethlemitas/blob/main/app/Http/Controllers/CreateReferralController.php) (Referral ctrl), [`app/Http/Middleware/RoleMiddleware.php`](https://github.com/thejuanjo1/bethlemitas/blob/main/app/Http/Middleware/RoleMiddleware.php) (Role middleware)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_g_auth["Access & roles"]
  node_n_auth["Auth<br/>controller<br/>[AuthController.php]"]
  node_n_roles{{"Role middleware<br/>[RoleMiddleware.php]"}}
end

subgraph group_g_academic["Academic admin"]
  node_n_academic_service["User service"]
  node_n_academic_ctrl["Academic controllers"]
  node_n_user_req["User requests<br/>validation"]
  node_n_academic_models["Academic models<br/>domain models<br/>[Degree.php]"]
end

subgraph group_g_support["Support workflows"]
  node_n_referral_ctrl["Referral ctrl<br/>controller"]
  node_n_psico_ctrl["Psycho ctrl<br/>controller"]
  node_n_support_models["Support models<br/>domain models<br/>[Referral.php]"]
  node_n_teacher_views["Teacher UI<br/>views"]
end

subgraph group_g_piar["PIAR lifecycle"]
  node_n_piar_ctrl["PIAR ctrl<br/>controller<br/>[PiarController.php]"]
  node_n_piar_models["PIAR models<br/>domain models<br/>[Piar.php]"]
  node_n_piar_views["PIAR views<br/>[create.blade.php]"]
end

subgraph group_g_output["Documents & delivery"]
  node_n_pdf_views["PDF templates<br/>documents<br/>[piar.blade.php]"]
  node_n_mails["Mail templates<br/>email"]
  node_n_notifications(("Notifications<br/>delivery"))
  node_n_storage[("File storage<br/>assets")]
end

node_n_routes["Web routes<br/>router<br/>[web.php]"]
node_n_db[("Database<br/>relational db")]

node_n_routes -->|"auth routes"| node_n_auth
node_n_routes -->|"protected routes"| node_n_roles
node_n_routes -->|"admin routes"| node_n_academic_ctrl
node_n_routes -->|"teacher routes"| node_n_referral_ctrl
node_n_routes -->|"psycho routes"| node_n_psico_ctrl
node_n_routes -->|"piar routes"| node_n_piar_ctrl
node_n_roles -->|"gate"| node_n_academic_ctrl
node_n_roles -->|"gate"| node_n_referral_ctrl
node_n_roles -->|"gate"| node_n_psico_ctrl
node_n_roles -->|"gate"| node_n_piar_ctrl
node_n_academic_ctrl -->|"uses"| node_n_academic_service
node_n_academic_ctrl -->|"validates"| node_n_user_req
node_n_academic_ctrl -->|"persists"| node_n_academic_models
node_n_academic_service -->|"stores"| node_n_db
node_n_user_req -.->|"reads rules"| node_n_db
node_n_referral_ctrl -->|"creates"| node_n_support_models
node_n_referral_ctrl -->|"sends"| node_n_mails
node_n_referral_ctrl -->|"notifies"| node_n_notifications
node_n_referral_ctrl -->|"renders"| node_n_teacher_views
node_n_psico_ctrl -->|"updates"| node_n_support_models
node_n_psico_ctrl -->|"notifies"| node_n_notifications
node_n_psico_ctrl -.->|"shares"| node_n_teacher_views
node_n_piar_ctrl -->|"manages"| node_n_piar_models
node_n_piar_ctrl -->|"renders"| node_n_piar_views
node_n_piar_ctrl -->|"exports"| node_n_pdf_views
node_n_piar_ctrl -->|"stores files"| node_n_storage
node_n_piar_ctrl -->|"notifies"| node_n_notifications
node_n_piar_models -->|"persisted in"| node_n_db
node_n_support_models -->|"persisted in"| node_n_db
node_n_academic_models -->|"persisted in"| node_n_db
node_n_mails -.->|"attachments"| node_n_storage

click node_n_routes "https://github.com/thejuanjo1/bethlemitas/blob/main/routes/web.php"
click node_n_auth "https://github.com/thejuanjo1/bethlemitas/blob/main/app/Http/Controllers/auth/AuthController.php"
click node_n_roles "https://github.com/thejuanjo1/bethlemitas/blob/main/app/Http/Middleware/RoleMiddleware.php"
click node_n_academic_service "https://github.com/thejuanjo1/bethlemitas/blob/main/app/Services/AcademicUserService.php"
click node_n_academic_ctrl "https://github.com/thejuanjo1/bethlemitas/blob/main/app/Http/Controllers/CreateAreaController.php"
click node_n_user_req "https://github.com/thejuanjo1/bethlemitas/blob/main/app/Http/Requests/Academic/StoreUserRequest.php"
click node_n_academic_models "https://github.com/thejuanjo1/bethlemitas/blob/main/app/Models/Degree.php"
click node_n_referral_ctrl "https://github.com/thejuanjo1/bethlemitas/blob/main/app/Http/Controllers/CreateReferralController.php"
click node_n_psico_ctrl "https://github.com/thejuanjo1/bethlemitas/blob/main/app/Http/Controllers/PsicoController.php"
click node_n_support_models "https://github.com/thejuanjo1/bethlemitas/blob/main/app/Models/Referral.php"
click node_n_teacher_views "https://github.com/thejuanjo1/bethlemitas/blob/main/resources/views/teacher/studentReferral.blade.php"
click node_n_piar_ctrl "https://github.com/thejuanjo1/bethlemitas/blob/main/app/Http/Controllers/PiarController.php"
click node_n_piar_models "https://github.com/thejuanjo1/bethlemitas/blob/main/app/Models/Piar.php"
click node_n_piar_views "https://github.com/thejuanjo1/bethlemitas/blob/main/resources/views/piar/create.blade.php"
click node_n_pdf_views "https://github.com/thejuanjo1/bethlemitas/blob/main/resources/views/pdf/piar.blade.php"
click node_n_mails "https://github.com/thejuanjo1/bethlemitas/blob/main/resources/views/emails/createdReferral.blade.php"
click node_n_notifications "https://github.com/thejuanjo1/bethlemitas/blob/main/app/Notifications/StudentInPiarNotification.php"
click node_n_storage "https://github.com/thejuanjo1/bethlemitas/tree/main/public/piars"
click node_n_db "https://github.com/thejuanjo1/bethlemitas/blob/main/database/migrations/2024_10_01_155113_create_degrees_table.php"

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_n_auth,node_n_roles toneBlue
class node_n_academic_service,node_n_academic_ctrl,node_n_user_req,node_n_academic_models toneAmber
class node_n_referral_ctrl,node_n_psico_ctrl,node_n_support_models,node_n_teacher_views toneMint
class node_n_piar_ctrl,node_n_piar_models,node_n_piar_views toneRose
class node_n_pdf_views,node_n_mails,node_n_notifications,node_n_storage toneIndigo
class node_n_routes,node_n_db toneNeutral
```

## Components

### Access & roles

Authentication, authorization, and role gates for the app

- [Auth](https://github.com/thejuanjo1/bethlemitas/blob/main/app/Http/Controllers/auth/AuthController.php): controller · Login and password flows · `app/Http/Controllers/auth/AuthController.php`
- [Role middleware](https://github.com/thejuanjo1/bethlemitas/blob/main/app/Http/Middleware/RoleMiddleware.php): middleware · Role-based access gates for docent, psychoorientador, and combined access · `app/Http/Middleware/RoleMiddleware.php`

### Academic admin

School structure and user administration

- [User service](https://github.com/thejuanjo1/bethlemitas/blob/main/app/Services/AcademicUserService.php): service · Creates and updates academic users with role-aware workflow · `app/Services/AcademicUserService.php`
- [Academic controllers](https://github.com/thejuanjo1/bethlemitas/blob/main/app/Http/Controllers/CreateAreaController.php): controllers · Area, degree, group, and user administration controllers · `app/Http/Controllers/CreateAreaController.php`
- [User requests](https://github.com/thejuanjo1/bethlemitas/blob/main/app/Http/Requests/Academic/StoreUserRequest.php): validation · Validation for creating and editing academic users · `app/Http/Requests/Academic/StoreUserRequest.php`
- [Academic models](https://github.com/thejuanjo1/bethlemitas/blob/main/app/Models/Degree.php): domain models · Institution, degrees, areas, groups, and assignment tables · `app/Models/Degree.php`

### Support workflows

Referral, psychoorientation, and teacher-facing case handling

- [Referral ctrl](https://github.com/thejuanjo1/bethlemitas/blob/main/app/Http/Controllers/CreateReferralController.php): controller · Creates and routes student referrals into support workflows · `app/Http/Controllers/CreateReferralController.php`
- [Psycho ctrl](https://github.com/thejuanjo1/bethlemitas/blob/main/app/Http/Controllers/PsicoController.php): controller · Psychoorientation case review and student history handling · `app/Http/Controllers/PsicoController.php`
- [Support models](https://github.com/thejuanjo1/bethlemitas/blob/main/app/Models/Referral.php): domain models · Referral, psychoorientation, state, and student support records · `app/Models/Referral.php`
- [Teacher UI](https://github.com/thejuanjo1/bethlemitas/blob/main/resources/views/teacher/studentReferral.blade.php): views · Teacher-facing referral, minutes, and student list screens · `resources/views/teacher/studentReferral.blade.php`

### PIAR lifecycle

PIAR case management, periods, minutes, adjustments, and reports

- [PIAR ctrl](https://github.com/thejuanjo1/bethlemitas/blob/main/app/Http/Controllers/PiarController.php): controller · Orchestrates PIAR case creation, editing, and reporting · `app/Http/Controllers/PiarController.php`
- [PIAR models](https://github.com/thejuanjo1/bethlemitas/blob/main/app/Models/Piar.php): domain models · PIAR, minutes, characteristics, adjustments, agreements, and reports · `app/Models/Piar.php`
- [PIAR views](https://github.com/thejuanjo1/bethlemitas/blob/main/resources/views/piar/create.blade.php): views · Period-based PIAR screens and PDF templates · `resources/views/piar/create.blade.php`

### Documents & delivery

Email, notifications, PDFs, and stored artifacts

- [PDF templates](https://github.com/thejuanjo1/bethlemitas/blob/main/resources/views/pdf/piar.blade.php): documents · Printable PIAR and history documents · `resources/views/pdf/piar.blade.php`
- [Mail templates](https://github.com/thejuanjo1/bethlemitas/blob/main/resources/views/emails/createdReferral.blade.php): email · Referral and student acceptance email content · `resources/views/emails/createdReferral.blade.php`
- [Notifications](https://github.com/thejuanjo1/bethlemitas/blob/main/app/Notifications/StudentInPiarNotification.php): delivery · Persistent notification events for support workflows · `app/Notifications/StudentInPiarNotification.php`
- [File storage](https://github.com/thejuanjo1/bethlemitas/tree/main/public/piars): assets · Public PIAR PDFs and profile image storage · `public/piars`

### Other components

- [Web routes](https://github.com/thejuanjo1/bethlemitas/blob/main/routes/web.php): router · Laravel web entrypoint that dispatches requests to controllers · `routes/web.php`
- [Database](https://github.com/thejuanjo1/bethlemitas/blob/main/database/migrations/2024_10_01_155113_create_degrees_table.php): relational db · Shared relational persistence for users, structure, referrals, and PIAR data · `database/migrations/2024_10_01_155113_create_degrees_table.php`

## Connections

- Web routes → Auth: auth routes · Routes hand login and password flows to the auth controller
- Web routes → Role middleware: protected routes · Web routes are filtered through role middleware
- Web routes → Academic controllers: admin routes · Academic administration screens are routed to controllers
- Web routes → Referral ctrl: teacher routes · Teacher referral actions are routed here
- Web routes → Psycho ctrl: psycho routes · Psychoorientation screens are routed here
- Web routes → PIAR ctrl: piar routes · PIAR screens and actions are routed here
- Role middleware → Academic controllers: gate · Role checks protect administration areas
- Role middleware → Referral ctrl: gate · Teachers and staff must pass role checks
- Role middleware → Psycho ctrl: gate · Psychoorientation areas are role-restricted
- Role middleware → PIAR ctrl: gate · PIAR operations are role-restricted
- Academic controllers → User service: uses · Controllers delegate user workflows to the service
- Academic controllers → User requests: validates · User creation and update requests are validated here
- Academic controllers → Academic models: persists · Academic structure controllers operate on domain models
- User service → Database: stores · User and role updates are persisted in the database
- User requests → Database: reads rules · Validation is informed by existing records and constraints
- Referral ctrl → Support models: creates · Referrals and related records are written to support models
- Referral ctrl → Mail templates: sends · New referrals trigger email notifications
- Referral ctrl → Notifications: notifies · Referral events are persisted as notifications
- Referral ctrl → Teacher UI: renders · Teacher screens are rendered from referral actions
- Psycho ctrl → Support models: updates · Psychoorientation reviews update case and state records
- Psycho ctrl → Notifications: notifies · Support case status changes create notifications
- Psycho ctrl → Teacher UI: shares · Teacher-facing history and case views overlap with psycho workflows
- PIAR ctrl → PIAR models: manages · PIAR controller coordinates the PIAR domain objects
- PIAR ctrl → PIAR views: renders · PIAR pages are served through dedicated Blade views
- PIAR ctrl → PDF templates: exports · PIAR outputs are generated as printable PDFs
- PIAR ctrl → File storage: stores files · Generated PIAR documents are saved under public storage
- PIAR ctrl → Notifications: notifies · PIAR milestones can trigger student notifications
- PIAR models → Database: persisted in · PIAR entities are backed by relational tables
- Support models → Database: persisted in · Referral and psychoorientation data are stored in relational tables
- Academic models → Database: persisted in · Academic structure and assignment tables live in the database
- Mail templates → File storage: attachments · Documents and generated assets are served from file storage
