# limense/front-crea-bienestar architecture

> Architecture diagram of the GitHub repository limense/front-crea-bienestar, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-11-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/limense/front-crea-bienestar
- Repository: https://github.com/limense/front-crea-bienestar

## Overview

##### Project Type & Purpose
- CREA Bienestar is a full-stack web application (Next.js 15 + React 19 + TypeScript) for managing student well-being, with authentication, role-based dashboards (Student, Professional, Tutor, Admin), appointment scheduling, resource library, and AI-driven dropout detection.
- Backend services are hosted on Supabase (PostgreSQL with RLS, Auth, Storage, Realtime) and planned integrations with Google Gemini API (AI chatbot) and Google Meet API.

##### File Structure Analysis
- **src/app/** – Next.js App Router layout and pages, segmented by route groups:
- (auth): login, registro, recuperar/actualizar contraseña
- (estudiante)/(profesional)/(tutor)/(admin): dashboards
- citas: appointment pages + server/client handlers + wizard
- recursos: resource library
- **src/components/** – Presentational React components organized by domain (citas, dashboard, ui, error-boundary)
- **src/lib/** – Business logic and data-access layers:
- supabase (cliente, servidor, middleware)
- citas (actions.ts for server actions, disponibilidad, validaciones)
- auth helpers, accessibility utils, generic utils
- **src/middleware.ts** – Global route protection by role
- **supabase/migrations/** – SQL migrations for DB schema

##### Key README Insights
- Authentication via Supabase Auth + middleware for route protection
- Server Actions for secure mutations (Next.js /app actions)
- Row-Level Security policies in Supabase for data isolation
- UI built with Tailwind CSS v4 + shadcn/ui components
- Accessibility (WCAG 2.1 AA) and professional UX patterns (skeletons, error boundaries)

##### Main Components & Interactions
a. Presentation Layer (Frontend)
- Browser → Next.js App (React Server + Client Components)
- Components: pages (app/routes), UI library (shadcn/ui), domain components (citas/calendar, dashboard sidebar)
- Middleware (src/middleware.ts) guards protected routes
b. Business Logic Layer
- Server Actions (src/lib/citas/actions.ts) invoked by React components for CRUD operations
- Client-side utilities (src/lib/citas/disponibilidad-client.ts) for real-time availability checks
- Auth helpers (src/lib/auth.ts) for session management
c. Data Layer & Services
- Supabase Client (src/lib/supabase/cliente.ts) used in Server Actions & middleware
- Supabase Server (src/lib/supabase/servidor.ts) for direct DB queries with RLS
- PostgreSQL database with tables for perfiles, citas, horarios_disponibilidad, conversaciones, mensajes, alertas, recursos, talleres, inscripciones_talleres, documentos_medicos, notificaciones, registros_auditoria
- Storage for medical documents & media
d. External APIs (future)
- Google Gemini API (AI chatbot)
- Google Meet API (virtual appointment links)

##### Architectural Patterns & Principles
- Layered Architecture: Presentation → Business Logic → Data Access → Database
- Next.js App Router with React Server Components for SSR/SSG & Client Components for interactive UI
- Server Actions for secure server-side mutations
- Row-Level Security in DB + middleware for zero-trust access control
- Domain-driven organization: “citas”, “recursos”, “auth”, “dashboards”
- Accessibility and UX patterns (error boundaries, skeleton loaders, ARIA compliance)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend (Blue)" 
        classDef frontend fill:#bbdefb,stroke:#1e88e5,color:#0d47a1
        Browser["Browser (Student/Professional/Tutor/Admin)"]:::frontend
        NextJS["Next.js App Router & Layout"]:::frontend
        click NextJS "https://github.com/limense/front-crea-bienestar/blob/main/src/app/layout.tsx"
        click NextJS "https://github.com/limense/front-crea-bienestar/blob/main/src/app/page.tsx"
        click NextJS "https://github.com/limense/front-crea-bienestar/blob/main/src/app/globals.css"

        subgraph "Auth Routes"
            Login["Login Page"]:::frontend
            click Login "https://github.com/limense/front-crea-bienestar/blob/main/src/app/(auth)/login/page.tsx"
            Registro["Registro Page"]:::frontend
            click Registro "https://github.com/limense/front-crea-bienestar/blob/main/src/app/(auth)/registro/page.tsx"
            RecuperarPwd["Recuperar Password Page"]:::frontend
            click RecuperarPwd "https://github.com/limense/front-crea-bienestar/blob/main/src/app/(auth)/recuperar-password/page.tsx"
            ActualizarPwd["Actualizar Password Page"]:::frontend
            click ActualizarPwd "https://github.com/limense/front-crea-bienestar/blob/main/src/app/(auth)/actualizar-password/page.tsx"
        end

        subgraph "Role-Based Dashboards"
            EstudianteDash["Student Dashboard"]:::frontend
            click EstudianteDash "https://github.com/limense/front-crea-bienestar/blob/main/src/app/(estudiante)/dashboard/page.tsx"
            ProfesionalDash["Professional Dashboard"]:::frontend
            click ProfesionalDash "https://github.com/limense/front-crea-bienestar/blob/main/src/app/(profesional)/profesional/page.tsx"
            TutorDash["Tutor Dashboard"]:::frontend
            click TutorDash "https://github.com/limense/front-crea-bienestar/blob/main/src/app/(tutor)/tutor/page.tsx"
            AdminDash["Admin Dashboard"]:::frontend
            click AdminDash "https://github.com/limense/front-crea-bienestar/blob/main/src/app/(admin)/admin/page.tsx"
        end

        subgraph "Citas (Appointments)"
            CitasPage["Citas Page"]:::frontend
            click CitasPage "https://github.com/limense/front-crea-bienestar/blob/main/src/app/citas/page.tsx"
            NuevaCita["Nueva Cita Page"]:::frontend
            click NuevaCita "https://github.com/limense/front-crea-bienestar/blob/main/src/app/citas/nueva/page.tsx"
            Wizard["Wizard Agendar Cita"]:::frontend
            click Wizard "https://github.com/limense/front-crea-bienestar/blob/main/src/app/citas/nueva/wizard-agendar-cita.tsx"
            Metadata["Citas Metadata"]:::frontend
            click Metadata "https://github.com/limense/front-crea-bienestar/blob/main/src/app/citas/metadata.ts"
            Handlers["Handlers Citas"]:::frontend
            click Handlers "https://github.com/limense/front-crea-bienestar/blob/main/src/app/citas/handlers-citas.tsx"
            ListaClient["Lista Citas Client"]:::frontend
            click ListaClient "https://github.com/limense/front-crea-bienestar/blob/main/src/app/citas/lista-citas-client.tsx"
        end

        RecursosPage["Recursos Page"]:::frontend
        click RecursosPage "https://github.com/limense/front-crea-bienestar/blob/main/src/app/recursos/page.tsx"
    end

    %% Business Logic Layer
    subgraph "Business Logic & Utilities (Green)"
        classDef backend fill:#c8e6c9,stroke:#43a047,color:#1b5e20
        Actions["Citas Server Actions\n(src/lib/citas/actions.ts)"]:::backend
        click Actions "https://github.com/limense/front-crea-bienestar/blob/main/src/lib/citas/actions.ts"
        DisponClient["Disponibilidad Client Util\n(src/lib/citas/disponibilidad-client.ts)"]:::backend
        click DisponClient "https://github.com/limense/front-crea-bienestar/blob/main/src/lib/citas/disponibilidad-client.ts"
        Dispon["Disponibilidad Logic"]:::backend
        click Dispon "https://github.com/limense/front-crea-bienestar/blob/main/src/lib/citas/disponibilidad.ts"
        Horarios["Horarios Logic"]:::backend
        click Horarios "https://github.com/limense/front-crea-bienestar/blob/main/src/lib/citas/horarios.ts"
        Validaciones["Validaciones Logic"]:::backend
        click Validaciones "https://github.com/limense/front-crea-bienestar/blob/main/src/lib/citas/validaciones.ts"
        AuthHelper["Auth Helpers\n(src/lib/auth.ts)"]:::backend
        click AuthHelper "https://github.com/limense/front-crea-bienestar/blob/main/src/lib/auth.ts"
        Accessibility["Accessibility Helpers\n(src/lib/accessibility.tsx)"]:::backend
        click Accessibility "https://github.com/limense/front-crea-bienestar/blob/main/src/lib/accessibility.tsx"
        Utils["Generic Utils\n(src/lib/utils/index.ts)"]:::backend
        click Utils "https://github.com/limense/front-crea-bienestar/blob/main/src/lib/utils/index.ts"
        Logger["Logger\n(src/lib/logger.ts)"]:::backend
        click Logger "https://github.com/limense/front-crea-bienestar/blob/main/src/lib/logger.ts"
    end

    %% Data Access Layer
    subgraph "Supabase Data Access (Green)"
        SupaClient["Supabase Client SDK\n(src/lib/supabase/cliente.ts)"]:::backend
        click SupaClient "https://github.com/limense/front-crea-bienestar/blob/main/src/lib/supabase/cliente.ts"
        SupaServer["Supabase Server SDK\n(src/lib/supabase/servidor.ts)"]:::backend
        click SupaServer "https://github.com/limense/front-crea-bienestar/blob/main/src/lib/supabase/servidor.ts"
        SupaMiddleware["Supabase Middleware\n(src/lib/supabase/middleware.ts)"]:::backend
        click SupaMiddleware "https://github.com/limense/front-crea-bienestar/blob/main/src/lib/supabase/middleware.ts"
        GlobalMiddleware["Global Middleware\n(src/middleware.ts)"]:::backend
        click GlobalMiddleware "https://github.com/limense/front-crea-bienestar/blob/main/src/middleware.ts"
    end

    %% Database Layer
    PostgreSQL["PostgreSQL DB\n(RLS Policies)"]:::backend
    supaStorage["Storage (Media & Docs)"]:::backend
    supaRealtime["Realtime API"]:::backend

    %% External Services
    subgraph "External APIs (Orange)"
        classDef external fill:#ffe0b2,stroke:#fb8c00,color:#e65100
        GoogleGemini["Google Gemini AI Chatbot"]:::external
        GoogleMeet["Google Meet API"]:::external
    end

    %% Data Flow
    Browser --> NextJS
    NextJS --> GlobalMiddleware
    GlobalMiddleware --> AuthHelper
    GlobalMiddleware --> SupaMiddleware
    NextJS --> Login
    NextJS --> Registro
    NextJS --> RecuperarPwd
    NextJS --> ActualizarPwd
    NextJS --> EstudianteDash
    NextJS --> ProfesionalDash
    NextJS --> TutorDash
    NextJS --> AdminDash
    NextJS --> CitasPage
    NextJS --> RecursosPage

    CitasPage --> Actions
    NuevaCita --> Actions
    Wizard --> Actions
    Handlers --> Actions
    ListaClient --> DisponClient

    Actions --> SupaClient
    Actions --> SupaServer
    AuthHelper --> SupaClient
    SupaMiddleware --> SupaClient

    SupaClient --> PostgreSQL
    SupaServer --> PostgreSQL
    SupaClient --> supaStorage
    supaRealtime --> NextJS

    Actions -.-> GoogleGemini
    Actions -.-> GoogleMeet
    supaRealtime --> Notifications["Notifications"]:::backend

    %% Types & Schema
    typesDB["DB Types\n(src/types/database.ts)"]:::backend
    typesCitas["Citas Types\n(src/types/citas.ts)"]:::backend
    click typesDB "https://github.com/limense/front-crea-bienestar/blob/main/src/types/database.ts"
    click typesCitas "https://github.com/limense/front-crea-bienestar/blob/main/src/types/citas.ts"
    PostgreSQL --> typesDB
    Actions --> typesCitas

    %% Migrations & Config
    migrations["SQL Migrations\n(supabase/migrations/)"]:::backend
    config["Next.js & Tooling"]:::backend
    click migrations "https://github.com/limense/front-crea-bienestar/tree/main/supabase/migrations/"
    click config "https://github.com/limense/front-crea-bienestar/blob/main/next.config.ts"
    click config "https://github.com/limense/front-crea-bienestar/blob/main/tsconfig.json"
    click config "https://github.com/limense/front-crea-bienestar/blob/main/postcss.config.mjs"
    click config "https://github.com/limense/front-crea-bienestar/blob/main/eslint.config.mjs"
    migrations --> PostgreSQL
    config --> NextJS

    %% Styles
    class Browser,NextJS,Login,Registro,RecuperarPwd,ActualizarPwd,EstudianteDash,ProfesionalDash,TutorDash,AdminDash,CitasPage,NuevaCita,Wizard,Metadata,Handlers,ListaClient,RecursosPage frontend
    class Actions,DisponClient,Dispon,Horarios,Validaciones,AuthHelper,Accessibility,Utils,Logger,SupaClient,SupaServer,SupaMiddleware,GlobalMiddleware,PostgreSQL,supaStorage,supaRealtime,typesDB,typesCitas,migrations,config backend
    class GoogleGemini,GoogleMeet external
```
