# elisbanpaco/cognitive-hub architecture

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

- Interactive diagram: https://gitdiagram.com/elisbanpaco/cognitive-hub
- Repository: https://github.com/elisbanpaco/cognitive-hub

## Overview

1. **Repositorio monolítico con tres límites claros**
   - `client/`: interfaz de usuario en Next.js 16 + React 19 + TypeScript.
   - `api/`: backend de inferencia en FastAPI.
   - `ml_research/`: laboratorio de experimentación y entrenamiento, separado del runtime de producción.
   Esta separación es la decisión arquitectónica principal: investigación, serving e interfaz viven desacoplados.

2. **Flujo principal de producto**
   - El usuario interactúa con el frontend.
   - El frontend llama a la API HTTP.
   - La API valida la entrada, ejecuta lógica de inferencia o algoritmos y devuelve resultados.
   - Los experimentos del área de research generan artefactos/metrics que luego pueden alimentar el entorno de producción.

3. **Backend de inferencia (`api/`)**
   - `main.py` es el punto de entrada de FastAPI.
   - `routes/predict.py` expone la ruta de predicción.
   - `routes/AG.py` expone operaciones asociadas a “AG”/algoritmos genéticos.
   - `schemas/data_models.py` define los contratos de datos para requests y responses.
   - `core/` contiene la lógica de negocio y algoritmos: engine, feature selection, hyperparameter optimization y neuroevolution.

4. **Responsabilidad del backend**
   - No parece ser un backend CRUD generalista: está centrado en inferencia y experimentación algorítmica.
   - La capa `routes/` actúa como adaptador HTTP.
   - La capa `core/` concentra la computación pesada y la lógica de optimización.
   - Las `schemas/` aíslan el formato de entrada/salida del resto del sistema.

5. **Frontend de producto (`client/`)**
   - Usa el App Router de Next.js (`src/app/...`).
   - Tiene dos experiencias visibles: `AG/` y `mood/`.
   - `AG/useAG.ts`, `ConfigPanel.tsx` y `Dashboard.tsx` sugieren un flujo de configuración + ejecución + visualización de resultados.
   - `mood/MoodPredictor.tsx` apunta a una pantalla de inferencia orientada a usuario final.
   - `src/app/components/navbar.tsx` y `layout.tsx` muestran una shell compartida de navegación/UI.

6. **Cómo se conecta el frontend con la API**
   - La UI no parece hablar con una base de datos propia; su dependencia de datos es la API.
   - `client/src/app/AG/types.ts` y `config.ts` sugieren contratos locales alineados con el backend.
   - La separación de componentes y hook indica un patrón: UI → hook de dominio → llamadas HTTP → actualización de dashboard.

7. **Área de research (`ml_research/`)**
   - Es un sandbox de experimentación, no parte del camino crítico de producción.
   - Incluye subdominios por familia de algoritmos:
     - `genetic_algorithms/`
     - `swarm_algorithms/`
     - `predictive_poc/`
   - Cada subproyecto tiene su propio `pyproject.toml`, `uv.lock` y scripts de entrada, lo que refuerza el aislamiento experimental.

8. **Subproyectos de investigación y su rol**
   - `genetic_algorithms/` replica/expande ideas como feature selection, hyperparameter optimization y neuroevolution.
   - `swarm_algorithms/` explora alternativas como ABC, PSO y clustering.
   - `predictive_poc/` parece un proof of concept más cercano a producción, con `train.py`, `predict.py` y métricas guardadas.
   En conjunto, estas carpetas funcionan como generación de conocimiento y validación de enfoques.

9. **Artefactos y persistencia**
   - Hay `model_artifacts/` en la raíz y también dentro de `predictive_poc/`.
   - Los archivos `metrics.json` y `metrics_summary.csv` indican que el repo conserva resultados de experimentos, no solo código.
   - Esto sugiere un flujo típico: entrenamiento/benchmarking en research → publicación de métricas/artefactos → posible consumo por la API o por análisis offline.

10. **Infraestructura de ejecución**
   - Hay `Dockerfile` en `api/` y `client/`, además de `docker-compose.yml` en la raíz.
   - Eso indica que los dos servicios principales están pensados para levantarse como contenedores separados.
   - El backend usa Python/uvicorn; el frontend usa Node/pnpm.
   - El proyecto asume también un entorno de MLOps/CI con `.github/workflows/mlops.yml`.

11. **Boundaries importantes para el diagrama**
   - **Presentación:** `client/`
   - **Serving / inference:** `api/`
   - **Experimentación / training:** `ml_research/`
   - **Artefactos de modelo y métricas:** `model_artifacts/`
   Estas fronteras son las más importantes para representar correctamente el sistema.

12. **Lectura arquitectónica resumida**
   - CognitiveHub no es una sola app, sino un ecosistema: UI + API de inferencia + laboratorio ML.
   - El valor del diseño está en desacoplar experimentación de despliegue, mientras se comparte la temática de algoritmos cognitivos/genéticos.
   - Para un diagrama, la relación principal es: usuario → frontend → API → lógica core/artefactos, con research como flujo paralelo que produce nuevos modelos, métricas y técnicas.

Main entry points: [`api/core/AG_engine.py`](https://github.com/elisbanpaco/cognitive-hub/blob/main/api/core/AG_engine.py) (AG engine), [`ml_research/genetic_algorithms/main.py`](https://github.com/elisbanpaco/cognitive-hub/blob/main/ml_research/genetic_algorithms/main.py) (Genetic research), [`client/src/app/layout.tsx`](https://github.com/elisbanpaco/cognitive-hub/blob/main/client/src/app/layout.tsx) (App shell), [`api/routes/predict.py`](https://github.com/elisbanpaco/cognitive-hub/blob/main/api/routes/predict.py) (Predict route)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_client["client"]
  node_client_shell["App shell<br/>nextjs shell<br/>[layout.tsx]"]
  node_client_nav["Navbar<br/>ui component<br/>[navbar.tsx]"]
  node_client_ag["AG workspace<br/>domain UI<br/>[page.tsx]"]
  node_client_ag_hook["AG hook<br/>state hook<br/>[useAG.ts]"]
  node_client_ag_dashboard["Dashboard<br/>results UI<br/>[Dashboard.tsx]"]
  node_client_mood["Mood predictor<br/>domain UI<br/>[MoodPredictor.tsx]"]
end

subgraph group_group_api["api"]
  node_api_main["FastAPI app<br/>entrypoint<br/>[main.py]"]
  node_api_predict_route["Predict route<br/>http route<br/>[predict.py]"]
  node_api_ag_route["AG route<br/>http route<br/>[AG.py]"]
  node_api_schemas["Data models<br/>contracts<br/>[data_models.py]"]
  node_api_engine["AG engine<br/>core logic<br/>[AG_engine.py]"]
  node_api_feature_selection["Feature selection<br/>optimizer"]
  node_api_hpo["Hyperopt<br/>optimizer"]
  node_api_neuroevo["Neuroevolution<br/>optimizer"]
end

subgraph group_group_research["ml_research"]
  node_research_ga["Genetic research<br/>experiment suite<br/>[main.py]"]
  node_research_swarm["Swarm research<br/>experiment suite<br/>[main.py]"]
  node_research_poc["Predictive POC<br/>training pipeline<br/>[train.py]"]
  node_artifacts_poc[("POC artifacts<br/>stored outputs<br/>[metrics.json]")]
end

subgraph group_group_artifacts["artifacts"]
  node_artifacts_root[("Model artifacts<br/>stored outputs<br/>[metrics.json]")]
end

node_user(("User<br/>actor"))

node_user -->|"uses"| node_client_shell
node_client_shell -->|"includes"| node_client_nav
node_client_shell -->|"renders"| node_client_ag
node_client_shell -->|"renders"| node_client_mood
node_client_ag -->|"coordinates"| node_client_ag_hook
node_client_ag_hook -->|"calls"| node_api_ag_route
node_client_mood -->|"calls"| node_api_predict_route
node_api_main -->|"mounts"| node_api_predict_route
node_api_main -->|"mounts"| node_api_ag_route
node_api_predict_route -->|"validates"| node_api_schemas
node_api_ag_route -->|"validates"| node_api_schemas
node_api_predict_route -->|"delegates"| node_api_engine
node_api_ag_route -->|"delegates"| node_api_engine
node_api_engine -->|"uses"| node_api_feature_selection
node_api_engine -->|"uses"| node_api_hpo
node_api_engine -->|"uses"| node_api_neuroevo
node_research_ga -.->|"informs"| node_api_feature_selection
node_research_ga -.->|"informs"| node_api_hpo
node_research_ga -.->|"informs"| node_api_neuroevo
node_research_swarm -.->|"explores"| node_api_hpo
node_research_poc -->|"writes"| node_artifacts_poc
node_research_ga -.->|"produces"| node_artifacts_root
node_research_swarm -.->|"produces"| node_artifacts_root

click node_client_shell "https://github.com/elisbanpaco/cognitive-hub/blob/main/client/src/app/layout.tsx"
click node_client_nav "https://github.com/elisbanpaco/cognitive-hub/blob/main/client/src/app/components/navbar.tsx"
click node_client_ag "https://github.com/elisbanpaco/cognitive-hub/blob/main/client/src/app/AG/page.tsx"
click node_client_ag_hook "https://github.com/elisbanpaco/cognitive-hub/blob/main/client/src/app/AG/useAG.ts"
click node_client_ag_dashboard "https://github.com/elisbanpaco/cognitive-hub/blob/main/client/src/app/AG/_components/Dashboard.tsx"
click node_client_mood "https://github.com/elisbanpaco/cognitive-hub/blob/main/client/src/app/mood/_components/MoodPredictor.tsx"
click node_api_main "https://github.com/elisbanpaco/cognitive-hub/blob/main/api/main.py"
click node_api_predict_route "https://github.com/elisbanpaco/cognitive-hub/blob/main/api/routes/predict.py"
click node_api_ag_route "https://github.com/elisbanpaco/cognitive-hub/blob/main/api/routes/AG.py"
click node_api_schemas "https://github.com/elisbanpaco/cognitive-hub/blob/main/api/schemas/data_models.py"
click node_api_engine "https://github.com/elisbanpaco/cognitive-hub/blob/main/api/core/AG_engine.py"
click node_api_feature_selection "https://github.com/elisbanpaco/cognitive-hub/blob/main/api/core/AG_feature_selection.py"
click node_api_hpo "https://github.com/elisbanpaco/cognitive-hub/blob/main/api/core/AG_hyperparameter_optimization.py"
click node_api_neuroevo "https://github.com/elisbanpaco/cognitive-hub/blob/main/api/core/AG_neuroevolution.py"
click node_research_ga "https://github.com/elisbanpaco/cognitive-hub/blob/main/ml_research/genetic_algorithms/main.py"
click node_research_swarm "https://github.com/elisbanpaco/cognitive-hub/blob/main/ml_research/swarm_algorithms/main.py"
click node_research_poc "https://github.com/elisbanpaco/cognitive-hub/blob/main/ml_research/predictive_poc/train.py"
click node_artifacts_root "https://github.com/elisbanpaco/cognitive-hub/blob/main/model_artifacts/metrics.json"
click node_artifacts_poc "https://github.com/elisbanpaco/cognitive-hub/blob/main/ml_research/predictive_poc/model_artifacts/metrics.json"

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_client_shell,node_client_nav,node_client_ag,node_client_ag_hook,node_client_ag_dashboard,node_client_mood toneBlue
class node_api_main,node_api_predict_route,node_api_ag_route,node_api_schemas,node_api_engine,node_api_feature_selection,node_api_hpo,node_api_neuroevo toneAmber
class node_research_ga,node_research_swarm,node_research_poc,node_artifacts_poc toneMint
class node_artifacts_root toneRose
class node_user toneNeutral
```

## Components

### client

Next.js frontend for user interaction and dashboarding

- [App shell](https://github.com/elisbanpaco/cognitive-hub/blob/main/client/src/app/layout.tsx): nextjs shell · Shared layout and navigation for the frontend · `client/src/app/layout.tsx`
- [Navbar](https://github.com/elisbanpaco/cognitive-hub/blob/main/client/src/app/components/navbar.tsx): ui component · Top-level navigation component · `client/src/app/components/navbar.tsx`
- [AG workspace](https://github.com/elisbanpaco/cognitive-hub/blob/main/client/src/app/AG/page.tsx): domain UI · Configuration, execution, and results view for AG workflows · `client/src/app/AG/page.tsx`
- [AG hook](https://github.com/elisbanpaco/cognitive-hub/blob/main/client/src/app/AG/useAG.ts): state hook · Coordinates AG state and API calls · `client/src/app/AG/useAG.ts`
- [Dashboard](https://github.com/elisbanpaco/cognitive-hub/blob/main/client/src/app/AG/_components/Dashboard.tsx): results UI · Displays AG progress and outcomes · `client/src/app/AG/_components/Dashboard.tsx`
- [Mood predictor](https://github.com/elisbanpaco/cognitive-hub/blob/main/client/src/app/mood/_components/MoodPredictor.tsx): domain UI · User-facing prediction screen · `client/src/app/mood/_components/MoodPredictor.tsx`

### api

FastAPI serving layer for prediction and AG workflows

- [FastAPI app](https://github.com/elisbanpaco/cognitive-hub/blob/main/api/main.py): entrypoint · API application bootstrap and routing setup · `api/main.py`
- [Predict route](https://github.com/elisbanpaco/cognitive-hub/blob/main/api/routes/predict.py): http route · HTTP adapter for prediction requests · `api/routes/predict.py`
- [AG route](https://github.com/elisbanpaco/cognitive-hub/blob/main/api/routes/AG.py): http route · HTTP adapter for algorithmic AG operations · `api/routes/AG.py`
- [Data models](https://github.com/elisbanpaco/cognitive-hub/blob/main/api/schemas/data_models.py): contracts · Request and response schemas for the API · `api/schemas/data_models.py`
- [AG engine](https://github.com/elisbanpaco/cognitive-hub/blob/main/api/core/AG_engine.py): core logic · Orchestrates inference and algorithm execution · `api/core/AG_engine.py`
- [Feature selection](https://github.com/elisbanpaco/cognitive-hub/blob/main/api/core/AG_feature_selection.py): optimizer · Core feature-selection logic · `api/core/AG_feature_selection.py`
- [Hyperopt](https://github.com/elisbanpaco/cognitive-hub/blob/main/api/core/AG_hyperparameter_optimization.py): optimizer · Hyperparameter search and tuning logic · `api/core/AG_hyperparameter_optimization.py`
- [Neuroevolution](https://github.com/elisbanpaco/cognitive-hub/blob/main/api/core/AG_neuroevolution.py): optimizer · Evolutionary model search and training logic · `api/core/AG_neuroevolution.py`

### ml_research

Experimental ML and algorithm research sandbox

- [Genetic research](https://github.com/elisbanpaco/cognitive-hub/blob/main/ml_research/genetic_algorithms/main.py): experiment suite · Experimental implementations of genetic algorithms · `ml_research/genetic_algorithms/main.py`
- [Swarm research](https://github.com/elisbanpaco/cognitive-hub/blob/main/ml_research/swarm_algorithms/main.py): experiment suite · Experimental swarm and clustering algorithms · `ml_research/swarm_algorithms/main.py`
- [Predictive POC](https://github.com/elisbanpaco/cognitive-hub/blob/main/ml_research/predictive_poc/train.py): training pipeline · Train/predict proof of concept closer to production · `ml_research/predictive_poc/train.py`
- [POC artifacts](https://github.com/elisbanpaco/cognitive-hub/blob/main/ml_research/predictive_poc/model_artifacts/metrics.json): stored outputs · Artifacts and metrics from the predictive proof of concept · `ml_research/predictive_poc/model_artifacts/metrics.json`

### artifacts

Persisted model outputs and evaluation metrics

- [Model artifacts](https://github.com/elisbanpaco/cognitive-hub/blob/main/model_artifacts/metrics.json): stored outputs · Shared metrics and evaluation outputs · `model_artifacts/metrics.json`

### Other components

- **User**: actor · Interacts with the product through the web UI

## Connections

- User → App shell: uses · User accesses the application through the frontend
- App shell → Navbar: includes · Shared UI shell provides navigation
- App shell → AG workspace: renders · Shell hosts the AG experience
- App shell → Mood predictor: renders · Shell hosts the mood prediction experience
- AG workspace → AG hook: coordinates · AG page delegates state and execution flow to the hook
- AG hook → AG route: calls · Frontend workflow invokes AG HTTP endpoints
- Mood predictor → Predict route: calls · Prediction UI sends inference requests
- FastAPI app → Predict route: mounts · FastAPI app registers prediction route
- FastAPI app → AG route: mounts · FastAPI app registers AG route
- Predict route → Data models: validates · Prediction requests and responses use shared contracts
- AG route → Data models: validates · AG endpoints use shared contracts
- Predict route → AG engine: delegates · Route hands execution to core engine
- AG route → AG engine: delegates · Route hands algorithmic work to core engine
- AG engine → Feature selection: uses · Engine can invoke feature-selection logic
- AG engine → Hyperopt: uses · Engine can invoke hyperparameter optimization
- AG engine → Neuroevolution: uses · Engine can invoke neuroevolution logic
- Genetic research → Feature selection: informs · Research implementations feed corresponding production logic
- Genetic research → Hyperopt: informs · Research experiments inform tuning workflows
- Genetic research → Neuroevolution: informs · Research experiments inform neuroevolution workflows
- Swarm research → Hyperopt: explores · Swarm experiments explore optimization alternatives
- Predictive POC → POC artifacts: writes · POC training produces local artifacts and metrics
- Genetic research → Model artifacts: produces · Research and benchmarking can contribute shared outputs
- Swarm research → Model artifacts: produces · Research and benchmarking can contribute shared outputs
