# mikelitom/personal_dacpa architecture

> Architecture diagram of the GitHub repository mikelitom/personal_dacpa, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mikelitom/personal_dacpa
- Repository: https://github.com/mikelitom/personal_dacpa

## Overview

##### Project Type and Purpose
- This is a full-stack web application built with Next.js (App Router).
- It offers a student dashboard for managing tuition payments, reporting, uniforms marketplace, and user/profile management.
- It exposes serverless API routes (under `src/app/api`) for CRUD operations on students (`alumnos`), parents (`padre-familia`), payment records (`pago-colegiatura`), reports (`reportes`), and integration points (MercadoPago, PDF generation).

##### File Structure Analysis
- **Frontend**:
- `src/app`: Next.js pages, layouts, global styling (`globals.css`), font config (`fonts.ts`), and middleware.
- `src/app/components` & `src/app/components/ui`: Reusable UI primitives and shared components (buttons, dialogs, form inputs).
- `src/app/dashboard` & `src/app/login`: Feature folders containing page entrypoints (`page.tsx`), layouts, hooks, and subcomponent trees.
- **Backend/API**:
- `src/app/api/...`: Route handlers for various resources, each with a `/route.ts` implementing GET/POST/PUT logic.
- `src/app/lib`: Client/server wrappers for Supabase, authentication helpers, type definitions, and utility functions.
- `src/app/services`: Business-logic services for database operations and report generation.
- **Configuration & Tooling**:
- Next.js config (`next.config.ts`), ESLint, Jest/Vitest, Tailwind, Storybook setups, TypeScript settings.

##### Key Architectural Patterns
- **App Router (File-based routing)**: Routes and API endpoints derived from folder structure.
- **Separation of Concerns**:
- UI components <-> feature pages <-> API routes <-> services <-> data layer.
- Shared context (`src/contexts/DashboardContext.tsx`) for cross‐cutting state.
- **Serverless Functions**: Each API folder’s `route.ts` is a Lambda‐style endpoint.
- **External Integrations**:
- Supabase as primary database + auth provider.
- MercadoPago for payment creation and webhooks.
- PDF generation endpoint for invoice/report creation.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "Frontend" 
        direction TB
        UI["Client (Next.js UI)"]:::frontend
        Dashboard["Dashboard Module"]:::frontend
        Login["Login Module"]:::frontend
        UIComponents["Shared UI Components"]:::frontend
        Uniformes["Uniforms Marketplace Components"]:::frontend
        GlobalLayout["Global Layout & Styles"]:::frontend
        Context["Shared Context"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend / Serverless"
        direction TB
        subgraph "API Routes" 
            direction TB
            API_Alumnos["API: /api/alumnos"]:::api
            API_Padre["API: /api/padre-familia"]:::api
            API_Pago["API: /api/pago-colegiatura"]:::api
            API_Reportes["API: /api/reportes"]:::api
            API_Usuario["API: /api/usuario"]:::api
            API_MP["API: /api/mercadopago"]:::api
            API_PDF["API: /api/generar-pdf"]:::api
        end
        subgraph "Services"
            direction TB
            DBService["dbService.ts"]:::service
            ReportesService["reportes-service.ts"]:::service
        end
        subgraph "Lib & Helpers"
            direction TB
            SupabaseClient["supabase.ts"]:::service
            AuthHelpers["auth.ts"]:::service
            ClientHelper["client.ts"]:::service
            ServerHelper["server.ts"]:::service
            Utils["utils.ts & reportes.tsx"]:::service
            Types["types.ts & mercadopago.d.ts"]:::service
        end
    end

    %% External Systems
    DB[(Supabase Database)]:::db
    MP(("MercadoPago API")):::external
    PDF(("PDF Generation Service")):::external
    Vercel["Vercel Hosting"]:::external

    %% Connections - Frontend
    UI --> Dashboard
    UI --> Login
    UI --> UIComponents
    UI --> Uniformes
    UI --> GlobalLayout
    UI --> Context
    Dashboard --> UIComponents
    Dashboard --> Context
    Login --> UIComponents
    Context --> API_Usuario

    Dashboard -->|"fetchAlumnos() GET"| API_Alumnos
    Dashboard -->|"fetchPagoColegiatura() GET"| API_Pago
    Dashboard -->|"fetchReportes() GET"| API_Reportes
    Login -->|"login/auth"| API_Usuario

    %% Connections - Backend
    API_Alumnos --> SupabaseClient
    API_Padre --> SupabaseClient
    API_Pago --> SupabaseClient
    API_Reportes --> ReportesService
    API_Reportes --> SupabaseClient
    API_Usuario --> AuthHelpers
    API_Usuario --> SupabaseClient
    API_MP --> MP
    API_MP --> SupabaseClient
    API_PDF --> PDF

    SupabaseClient --> DBService
    DBService --> DB
    ReportesService --> DB

    %% Webhook
    MP -->|"webhook POST"| API_MP

    %% Hosting
    Vercel --> API_Alumnos
    Vercel --> API_Padre
    Vercel --> API_Pago
    Vercel --> API_Reportes
    Vercel --> API_Usuario
    Vercel --> API_MP
    Vercel --> API_PDF

    %% Click Events
    click UI "https://github.com/mikelitom/personal_dacpa/tree/main/src/app"
    click Dashboard "https://github.com/mikelitom/personal_dacpa/tree/main/src/app/dashboard"
    click Login "https://github.com/mikelitom/personal_dacpa/tree/main/src/app/login"
    click UIComponents "https://github.com/mikelitom/personal_dacpa/tree/main/src/app/components/ui"
    click Uniformes "https://github.com/mikelitom/personal_dacpa/tree/main/src/app/components/uniformes"
    click GlobalLayout "https://github.com/mikelitom/personal_dacpa/blob/main/src/app/layout.tsx"
    click GlobalLayout "https://github.com/mikelitom/personal_dacpa/blob/main/src/app/globals.css"
    click GlobalLayout "https://github.com/mikelitom/personal_dacpa/blob/main/src/app/fonts.ts"
    click Context "https://github.com/mikelitom/personal_dacpa/blob/main/src/contexts/DashboardContext.tsx"
    click API_Alumnos "https://github.com/mikelitom/personal_dacpa/tree/main/src/app/api/alumnos"
    click API_Padre "https://github.com/mikelitom/personal_dacpa/tree/main/src/app/api/padre-familia"
    click API_Pago "https://github.com/mikelitom/personal_dacpa/tree/main/src/app/api/pago-colegiatura"
    click API_Reportes "https://github.com/mikelitom/personal_dacpa/tree/main/src/app/api/reportes"
    click API_Usuario "https://github.com/mikelitom/personal_dacpa/tree/main/src/app/api/usuario"
    click API_MP "https://github.com/mikelitom/personal_dacpa/tree/main/src/app/api/mercadopago"
    click API_PDF "https://github.com/mikelitom/personal_dacpa/blob/main/src/app/api/generar-pdf/route.ts"
    click SupabaseClient "https://github.com/mikelitom/personal_dacpa/blob/main/src/app/lib/supabase.ts"
    click AuthHelpers "https://github.com/mikelitom/personal_dacpa/blob/main/src/app/lib/auth.ts"
    click ClientHelper "https://github.com/mikelitom/personal_dacpa/blob/main/src/app/lib/client.ts"
    click ServerHelper "https://github.com/mikelitom/personal_dacpa/blob/main/src/app/lib/server.ts"
    click Utils "https://github.com/mikelitom/personal_dacpa/blob/main/src/app/lib/utils.ts"
    click Utils "https://github.com/mikelitom/personal_dacpa/blob/main/src/app/lib/utils/reportes.tsx"
    click Types "https://github.com/mikelitom/personal_dacpa/blob/main/src/app/lib/types.ts"
    click Types "https://github.com/mikelitom/personal_dacpa/blob/main/src/app/lib/mercadopago.d.ts"
    click DBService "https://github.com/mikelitom/personal_dacpa/blob/main/src/app/services/dbService.ts"
    click ReportesService "https://github.com/mikelitom/personal_dacpa/blob/main/src/app/services/reportes-service.ts"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#000,stroke-width:1px
    classDef api fill:#D5FFD0,stroke:#000,stroke-width:1px
    classDef service fill:#FFF4C1,stroke:#000,stroke-width:1px
    classDef db fill:#E0E0E0,stroke:#000,stroke-width:1px
    classDef external fill:#FFD8A8,stroke:#000,stroke-width:1px
```
