# joseegarciaa/kryotec-admin architecture

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

- Interactive diagram: https://gitdiagram.com/joseegarciaa/kryotec-admin
- Repository: https://github.com/joseegarciaa/kryotec-admin

## Overview

##### Project Type and Purpose
- Full-stack web application following the MVC pattern.
- Frontend: React + TypeScript + Vite + TailwindCSS
- Backend: Node.js + Express
- Data storage: relational database (configured in src/server/config/db.js)
- Special feature: Excel import/export workflow for “Inventario Prospectos.”

##### File Structure
- Top-level config: Vite, Tailwind, ESLint, TypeScript, Railway deploy config.
- src/views: Presentation (React Views, UI components, routing, contexts).
- src/controllers: Client-side controllers tying models to views, plus React hooks.
- src/models: Business logic & types.
- src/services/api.ts: Frontend HTTP client to backend.
- src/server: Express application
- config (db.js), index.js (server bootstrap), db.js (connection helper)
- routes (Express routers)
- services (business logic on server side)
- utils (cache.js)
- Misc: assets, utils (date, excel template), package.json, .env.production

##### Key Insights from README
- MVC structure is explicit: Model, View, Controller separation.
- Data-flow: View → Controller → Model → API → Server routes → Services → DB.
- Excel import on prospectos with a dedicated backend endpoint.
- React Contexts (AuthContext, ThemeContext) for cross-cutting state.

##### Main Components & Their Relationships
A. Frontend (Browser)
1. UI Layer (Views & Components)
- src/views/… (LoginView, DashboardView, subviews + shared UI)
- Layout & navigation components under src/components/layout & navigation
2. Presentation Logic (React Contexts & Hooks)
- AuthContext, ThemeContext under src/views/contexts
- useXController hooks under src/controllers/hooks
3. Controller Layer (src/controllers/*.ts)
- AuthController, ThemeController, ProspectoController, etc.
- Coordinates view events with model calls.
4. Model Layer (src/models/*.ts)
- Defines business logic & data structures.
5. API Client (src/services/api.ts)
- Wraps fetch/axios, exposes REST methods for entities.

B. Backend (Node/Express)
1. HTTP Server (src/server/index.js)
2. Routing Layer (src/server/routes/*.js)
- clientesProspectosRoutes, sugerenciasRoutes, etc.
3. Service Layer (src/server/*Service.js)
- clientesProspectosService, userService, tenantService, etc.
- Implements business logic, enforces validation and Excel import logic.
4. Data Access Layer
- src/server/config/db.js + src/server/db.js for DB connection
5. Utilities
- src/server/utils/cache.js for in-memory caching
6. Database
- Relational DB (PostgreSQL or similar)

C. External/Deployment
- Railway deployment (railway.json)
- Excel file I/O (via src/utils/excelTemplate.ts)

##### Architectural Patterns and Principles
- MVC (clear separation of concerns)
- Layered Architecture (UI → Controllers → Models → API → Server → DB)
- Context/Provider pattern for cross-cutting state (Auth, Theme)
- Hook-based controllers for view integration
- RESTful API design with modular Express routers
- Utility-based caching for performance

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend
    subgraph "React App"
        direction TB
        UI["UI Layer\n(src/views + src/components)"]:::frontend
        Contexts["React Contexts\n(src/views/contexts)"]:::frontend
        Hooks["Presentation Hooks\n(src/controllers/hooks)"]:::frontend
        ControllersFE["Frontend Controllers\n(src/controllers)"]:::frontend
        ModelsFE["Frontend Models\n(src/models)"]:::frontend
        APIClient["API Client\n(src/services/api.ts)"]:::frontend
    end

    %% Backend
    subgraph "Express Server"
        direction TB
        HTTPServer["HTTP Server\n(src/server/index.js)"]:::backend
        Routes["Routing Layer\n(src/server/routes)"]:::backend
        ServicesBE["Service Layer\n(src/server/*.js)"]:::backend
        DBConfig["DB Config & Connection\n(src/server/config/db.js\nsrc/server/db.js)"]:::backend
        UtilsBE["Server Utils\n(src/server/utils/cache.js)"]:::backend
    end

    %% Database
    Database["Relational Database\n(PostgreSQL)"]:::database

    %% External
    subgraph "External/Deployment"
        direction TB
        Railway["Railway Config\n(railway.json)"]:::external
        Env["Env Config\n(.env.production)"]:::external
        BuildTools["Vite & Tailwind\n(vite.config.ts, tailwind.config.js)"]:::external
        ExcelUtil["Excel Templates\n(src/utils/excelTemplate.ts)"]:::external
    end

    %% Data flow
    UI -->|"uses"| Contexts
    UI -->|"dispatches events"| ControllersFE
    Contexts -->|"provides state to"| UI
    ControllersFE -->|"calls"| ModelsFE
    ModelsFE -->|"invokes"| APIClient
    APIClient -->|"HTTP requests"| HTTPServer
    HTTPServer -->|"routes to"| Routes
    Routes -->|"calls"| ServicesBE
    ServicesBE -->|"queries"| DBConfig
    DBConfig -->|"connects to"| Database
    ServicesBE -->|"caches via"| UtilsBE
    ServicesBE -->|"imports/exports via"| ExcelUtil
    Database -->|"returns data"| ServicesBE
    ServicesBE -->|"responds"| Routes
    Routes -->|"sends HTTP responses"| HTTPServer
    HTTPServer -->|"responds"| APIClient
    APIClient -->|"provides data to"| ModelsFE
    ModelsFE -->|"returns results to"| ControllersFE
    ControllersFE -->|"updates"| UI

    %% Click events - Frontend
    click UI "https://github.com/joseegarciaa/kryotec-admin/blob/main/src/views/auth/LoginView.tsx"
    click UI "https://github.com/joseegarciaa/kryotec-admin/blob/main/src/views/dashboard/DashboardView.tsx"
    click UI "https://github.com/joseegarciaa/kryotec-admin/blob/main/src/views/dashboard/CredocubesView.tsx"
    click UI "https://github.com/joseegarciaa/kryotec-admin/blob/main/src/views/dashboard/SettingsView.tsx"
    click UI "https://github.com/joseegarciaa/kryotec-admin/blob/main/src/views/dashboard/TenantsView.tsx"
    click UI "https://github.com/joseegarciaa/kryotec-admin/blob/main/src/views/dashboard/UsersView.tsx"
    click UI "https://github.com/joseegarciaa/kryotec-admin/blob/main/src/views/dashboard/prospectos/ProspectosView.tsx"
    click UI "https://github.com/joseegarciaa/kryotec-admin/blob/main/src/components/layout/MainLayout.tsx"
    click UI "https://github.com/joseegarciaa/kryotec-admin/blob/main/src/components/layout/ResponsiveLayout.tsx"
    click UI "https://github.com/joseegarciaa/kryotec-admin/blob/main/src/components/navigation/MobileNavigation.tsx"
    click UI "https://github.com/joseegarciaa/kryotec-admin/blob/main/src/components/ui/Input.tsx"
    click UI "https://github.com/joseegarciaa/kryotec-admin/blob/main/src/components/ui/ResponsiveTable.tsx"
    click Contexts "https://github.com/joseegarciaa/kryotec-admin/blob/main/src/views/contexts/AuthContext.tsx"
    click Contexts "https://github.com/joseegarciaa/kryotec-admin/blob/main/src/views/contexts/ThemeContext.tsx"
    click Hooks "https://github.com/joseegarciaa/kryotec-admin/blob/main/src/controllers/hooks/useClienteProspectoController.ts"
    click Hooks "https://github.com/joseegarciaa/kryotec-admin/blob/main/src/controllers/hooks/useInventarioProspectoController.ts"
    click Hooks "https://github.com/joseegarciaa/kryotec-admin/blob/main/src/controllers/hooks/useSugerenciasController.ts"
    click ControllersFE "https://github.com/joseegarciaa/kryotec-admin/blob/main/src/controllers/AuthController.ts"
    click ControllersFE "https://github.com/joseegarciaa/kryotec-admin/blob/main/src/controllers/ThemeController.ts"
    click ControllersFE "https://github.com/joseegarciaa/kryotec-admin/blob/main/src/controllers/ProspectoController.ts"
    click ControllersFE "https://github.com/joseegarciaa/kryotec-admin/blob/main/src/controllers/ClienteProspectoController.ts"
    click ControllersFE "https://github.com/joseegarciaa/kryotec-admin/blob/main/src/controllers/SugerenciasController.ts"
    click ControllersFE "https://github.com/joseegarciaa/kryotec-admin/blob/main/src/controllers/InventarioProspectoController.ts"
    click ControllersFE "https://github.com/joseegarciaa/kryotec-admin/blob/main/src/controllers/InventarioCredocubeController.ts"
    click ControllersFE "https://github.com/joseegarciaa/kryotec-admin/blob/main/src/controllers/CredocubeController.ts"
    click ControllersFE "https://github.com/joseegarciaa/kryotec-admin/blob/main/src/controllers/TenantController.ts"
    click ControllersFE "https://github.com/joseegarciaa/kryotec-admin/blob/main/src/controllers/UserController.ts"
    click ModelsFE "https://github.com/joseegarciaa/kryotec-admin/blob/main/src/models/AuthModel.ts"
    click ModelsFE "https://github.com/joseegarciaa/kryotec-admin/blob/main/src/models/ThemeModel.ts"
    click ModelsFE "https://github.com/joseegarciaa/kryotec-admin/blob/main/src/models/ProspectoModel.ts"
    click ModelsFE "https://github.com/joseegarciaa/kryotec-admin/blob/main/src/models/ClienteProspectoModel.ts"
    click ModelsFE "https://github.com/joseegarciaa/kryotec-admin/blob/main/src/models/SugerenciasModel.ts"
    click ModelsFE "https://github.com/joseegarciaa/kryotec-admin/blob/main/src/models/InventarioProspectoModel.ts"
    click ModelsFE "https://github.com/joseegarciaa/kryotec-admin/blob/main/src/models/InventarioCredocubeModel.ts"
    click ModelsFE "https://github.com/joseegarciaa/kryotec-admin/blob/main/src/models/CredocubeModel.ts"
    click ModelsFE "https://github.com/joseegarciaa/kryotec-admin/blob/main/src/models/TenantModel.ts"
    click ModelsFE "https://github.com/joseegarciaa/kryotec-admin/blob/main/src/models/UserModel.ts"
    click ModelsFE "https://github.com/joseegarciaa/kryotec-admin/blob/main/src/models/types/auth.ts"
    click ModelsFE "https://github.com/joseegarciaa/kryotec-admin/blob/main/src/models/types/theme.ts"
    click APIClient "https://github.com/joseegarciaa/kryotec-admin/blob/main/src/services/api.ts"

    %% Click events - Backend
    click HTTPServer "https://github.com/joseegarciaa/kryotec-admin/blob/main/src/server/index.js"
    click Routes "https://github.com/joseegarciaa/kryotec-admin/blob/main/src/server/routes/clientesProspectosRoutes.js"
    click Routes "https://github.com/joseegarciaa/kryotec-admin/blob/main/src/server/routes/sugerenciasRoutes.js"
    click Routes "https://github.com/joseegarciaa/kryotec-admin/blob/main/src/server/routes/tenantRoutes.js"
    click Routes "https://github.com/joseegarciaa/kryotec-admin/blob/main/src/server/routes/userRoutes.js"
    click Routes "https://github.com/joseegarciaa/kryotec-admin/blob/main/src/server/routes/credocubeRoutes.js"
    click Routes "https://github.com/joseegarciaa/kryotec-admin/blob/main/src/server/routes/inventarioProspectosRoutes.js"
    click ServicesBE "https://github.com/joseegarciaa/kryotec-admin/blob/main/src/server/authService.js"
    click ServicesBE "https://github.com/joseegarciaa/kryotec-admin/blob/main/src/server/clientesProspectosService.js"
    click ServicesBE "https://github.com/joseegarciaa/kryotec-admin/blob/main/src/server/sugerenciasService.js"
    click ServicesBE "https://github.com/joseegarciaa/kryotec-admin/blob/main/src/server/tenantService.js"
    click ServicesBE "https://github.com/joseegarciaa/kryotec-admin/blob/main/src/server/userService.js"
    click ServicesBE "https://github.com/joseegarciaa/kryotec-admin/blob/main/src/server/credocubeService.js"
    click ServicesBE "https://github.com/joseegarciaa/kryotec-admin/blob/main/src/server/inventarioProspectosService.js"
    click DBConfig "https://github.com/joseegarciaa/kryotec-admin/blob/main/src/server/config/db.js"
    click DBConfig "https://github.com/joseegarciaa/kryotec-admin/blob/main/src/server/db.js"
    click UtilsBE "https://github.com/joseegarciaa/kryotec-admin/blob/main/src/server/utils/cache.js"
    click ExcelUtil "https://github.com/joseegarciaa/kryotec-admin/blob/main/src/utils/excelTemplate.ts"

    %% Click events - External
    click Railway "https://github.com/joseegarciaa/kryotec-admin/blob/main/railway.json"
    click Env "https://github.com/joseegarciaa/kryotec-admin/blob/main/.env.production"
    click BuildTools "https://github.com/joseegarciaa/kryotec-admin/blob/main/vite.config.ts"
    click BuildTools "https://github.com/joseegarciaa/kryotec-admin/blob/main/tailwind.config.js"

    %% Styles
    classDef frontend fill:#E0F7FA,stroke:#006064,color:#000
    classDef backend fill:#E8F5E9,stroke:#1B5E20,color:#000
    classDef database fill:#FFF3E0,stroke:#E65100,color:#000
    classDef external fill:#ECEFF1,stroke:#455A64,color:#000
```
