# roytineo/dashboard_adminsgd architecture

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

- Interactive diagram: https://gitdiagram.com/roytineo/dashboard_adminsgd
- Repository: https://github.com/roytineo/dashboard_adminsgd

## Overview

##### Project type and purpose
- This is a full-stack web application built with Next.js (App Router) and React, using TypeScript.
- It’s a document management/dashboard portal featuring user auth (NextAuth), CRUD operations (cargos, usuarios, documentos, plantillas, guías, etc.), and server-side data handling.

##### High-level file structure
- src/app: Next.js App Router routes, pages, layouts, server components, client components.
- /api/auth/[...nextauth]/route.ts – authentication API route using NextAuth.
- /dashboard, /login, etc. – page-level routes and containers.
- src/components: shared React UI components (layout, dialogs, tables, forms).
- src/actions: server-side “action” modules that encapsulate business logic and database calls.
- src/lib: database connection (db.ts), encryption/decryption helpers, general utilities.
- src/utils: domain-specific helpers (e.g., guia.ts) and Zod schemas for validation.
- public/guias & public/logos: static assets for document templates and branding.
- Dockerfile & compose-generator.py: containerization support.

##### README
- Confirms Next.js default setup, run/dev commands, Vercel deployment.
- Doesn’t describe custom architecture, so we infer from files.

##### Main components to model
a. Client Layer
- Browser UI – React components (src/components & page components under src/app)
- Next.js SSR/SSG – server components, layouts, CSS via Tailwind (tailwind.config.ts)
b. Application Layer
- Next.js App Router – route handlers, server & client components.
- API Routes – NextAuth route module for authentication.
- “Actions” modules – server functions that process requests, validate via Zod, call db.
- Auth module – NextAuth configuration (auth.config.ts), session store.
c. Data Layer
- Database – connected via src/lib/db.ts (e.g., PostgreSQL, MySQL, etc.).
- ORM/Query tool – implied by db.ts (could be Prisma, Drizzle, or raw queries).
- Zod schemas for input validation.
d. Static Assets & Docs
- /public/guias – document templates served by Next.js static routes.
- /public/logos – branding/logos.
e. Infrastructure & Deployment
- Docker – Dockerfile for containerizing the app.
- compose-generator.py – generates docker-compose definitions for multi-container setups (app, DB).
- CI/CD on Vercel – automatic builds/deploys from Git repo.

##### Relationships and data flows
- Browser → Next.js frontend (CSR & SSR) → App Router pages →
- Calls “actions” directly using React Server Actions or via fetch to API routes.
- Calls NextAuth API routes for sign-in/sign-out.
- “Actions” modules → Zod validation → Database driver (db.ts) → Database.
- API routes (NextAuth) → 3rd-party OAuth providers or credentials → session store in DB.
- Next.js serves static assets from /public.

##### Architectural patterns & principles
- Separation of concerns:
- UI components vs business-logic actions vs data-access layer.
- Routes (presentation) vs actions (application logic) vs lib/db (persistence).
- React Server Components & Client Components pattern (Next.js App Router).
- Use of strong typing and schema validation (TypeScript + Zod).
- 12-factor app principles for config and secrets (via env vars).
- Containerization (Docker) for environment parity.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Layer"
        Browser["Browser UI"]:::ui
        UI["Page Components & Routes"]:::ui
    end

    %% Application Layer
    subgraph "Application Layer"
        NextApp["Next.js App Router<br/>Pages/Layouts"]:::app
        API["API Routes (NextAuth)"]:::logic
        Actions["Server Actions<br/>(src/actions)"]:::logic
        AuthCfg["Auth Configuration"]:::logic
    end

    %% Data Layer
    subgraph "Data Layer"
        DBConn["DB Connection<br/>src/lib/db.ts"]:::db
        DB["Database"]:::db
        Helpers["Helpers<br/>src/lib/decript.ts & utils.ts"]:::db
        Zod["Validation Schemas<br/>src/utils/zod/schemas.ts"]:::db
        Domain["Domain Helpers<br/>src/utils/guia.ts"]:::db
    end

    %% Static Assets
    subgraph "Static Assets"
        Templates["Document Templates"]:::static
        Logos["Logos & Branding"]:::static
    end

    %% Infrastructure
    subgraph "Infrastructure"
        DockerfileNode["Dockerfile"]:::infra
        Compose["compose-generator.py"]:::infra
        Vercel["Vercel (CI/CD)"]:::external
        OAuth["OAuth Providers"]:::external
    end

    %% Connections
    Browser -->|uses| UI
    UI -->|renders| NextApp
    NextApp -->|calls| Actions
    NextApp -->|fetches| API
    NextApp -->|serves| Templates
    NextApp -->|serves| Logos
    API -->|auth flow| OAuth
    API -->|stores sessions| DBConn
    Actions -->|queries| DBConn
    DBConn -->|connects to| DB
    Actions -->|uses schemas| Zod
    Actions -->|uses helpers| Helpers
    Actions -->|uses domain utils| Domain
    DockerfileNode -->|builds| NextApp
    Compose -->|generates| DockerfileNode
    Vercel -->|deploys| NextApp

    %% Click Events
    click Browser "https://github.com/roytineo/dashboard_adminsgd/tree/main/src/components"
    click UI "https://github.com/roytineo/dashboard_adminsgd/tree/main/src/app"
    click NextApp "https://github.com/roytineo/dashboard_adminsgd/tree/main/src/app"
    click API "https://github.com/roytineo/dashboard_adminsgd/blob/main/src/app/api/auth/[...nextauth]/route.ts"
    click Actions "https://github.com/roytineo/dashboard_adminsgd/tree/main/src/actions"
    click AuthCfg "https://github.com/roytineo/dashboard_adminsgd/blob/main/src/auth.config.ts"
    click DBConn "https://github.com/roytineo/dashboard_adminsgd/blob/main/src/lib/db.ts"
    click Helpers "https://github.com/roytineo/dashboard_adminsgd/blob/main/src/lib/decript.ts"
    click Helpers "https://github.com/roytineo/dashboard_adminsgd/blob/main/src/lib/utils.ts"
    click Zod "https://github.com/roytineo/dashboard_adminsgd/blob/main/src/utils/zod/schemas.ts"
    click Domain "https://github.com/roytineo/dashboard_adminsgd/blob/main/src/utils/guia.ts"
    click Templates "https://github.com/roytineo/dashboard_adminsgd/tree/main/public/guias"
    click Logos "https://github.com/roytineo/dashboard_adminsgd/tree/main/public/logos"
    click DockerfileNode "https://github.com/roytineo/dashboard_adminsgd/tree/main/Dockerfile"
    click Compose "https://github.com/roytineo/dashboard_adminsgd/blob/main/compose-generator.py"

    %% Styles
    classDef ui fill:#E0F7FA,stroke:#0288D1,color:#000
    classDef app fill:#BBDEFB,stroke:#1976D2,color:#000
    classDef logic fill:#C8E6C9,stroke:#388E3C,color:#000
    classDef db fill:#FFE0B2,stroke:#F57C00,color:#000
    classDef static fill:#E0E0E0,stroke:#9E9E9E,color:#000
    classDef infra fill:#CFD8DC,stroke:#455A64,color:#000
    classDef external fill:#F0F4C3,stroke:#AFB42B,color:#000
```
