# acad-ia/frontend architecture

> Architecture diagram of the GitHub repository acad-ia/frontend, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/acad-ia/frontend
- Repository: https://github.com/acad-ia/frontend

## Overview

1. **What this app is**
   - This is a client-side TanStack React application for managing **study plans (`planes`)** and **subjects (`asignaturas`)**, with supporting flows for bibliography and AI-assisted content generation.
   - The repository is organized as a **frontend-only SPA** that talks to Supabase and edge/API functions rather than hosting its own business backend.

2. **Application shell and navigation**
   - The visual shell is centered around `src/routes/__root.tsx`, `src/components/layout/*`, and route-level layouts.
   - Navigation is file-based via **TanStack Router**; `src/routeTree.gen.ts` is the generated route graph.
   - The root layout provides shared UI such as the header/sidebar, while route outlets render the active page inside that shell.

3. **Primary domain boundaries**
   - The main domain split is:
     - **Plans**: `src/routes/planes/*`, `src/components/planes/*`, `src/features/planes/*`
     - **Subjects**: `src/routes/planes/$planId/asignaturas/*`, `src/components/asignaturas/*`, `src/features/asignaturas/*`
     - **Authentication**: `src/components/auth/*`
   - This is a strong signal that the app is structured around a parent entity (`plan`) and child entities (`asignaturas`), with detail views and nested subroutes.

4. **Route hierarchy and page composition**
   - Plans have both list and detail flows:
     - list/index routes under `src/routes/planes/_lista.tsx`
     - create flow under `src/routes/planes/_lista/nuevo.tsx`
     - plan detail sections under `src/routes/planes/$planId/_detalle/*`
   - Subject detail routes are nested under a plan and subject ID, with separate tabs/pages for:
     - main subject view
     - content (`contenido`)
     - document (`documento`)
     - history (`historial`)
     - AI assistant view (`iaasignatura`)
     - bibliography (`bibliografia`)
   - The route structure maps almost one-to-one with domain tabs in the UI.

5. **Wizard-driven creation flows**
   - New plans and new subjects are created through multi-step wizards rather than single forms.
   - The wizard subsystem lives in `src/components/*/wizard/*` and `src/features/*/nuevo/*`.
   - These flows are split into reusable steps like:
     - basic data entry
     - source selection / cloning
     - details panel
     - method/mode selection
     - summary/confirmation
   - This suggests a guided creation experience with branching behavior depending on whether the user is cloning, editing, or generating from AI.

6. **Data access layer and server boundary**
   - `src/data/api/*` is the main boundary to the server side.
   - It contains focused API modules for:
     - AI
     - documents
     - files
     - metadata
     - notifications
     - repositories
     - plans
     - subjects
     - tasks
     - OpenAI-related file handling
   - `src/data/supabase/*` wraps the Supabase client, env access, and edge-function invocation.
   - `src/data/hooks/*` exposes domain-specific React hooks over those APIs, and `src/data/query/*` centralizes query keys and the TanStack Query client.

7. **AI-assisted and async workflows**
   - The presence of `ai.api.ts`, `openaiFiles.api.ts`, `useAI.ts`, and UI like `AIProgressLoader`, `IAAsignaturaTab`, and `planes/detalle/Ia/*` indicates AI is a first-class feature.
   - AI is not isolated to a single screen; it appears in both plan and subject workflows, likely for drafting, improving, or validating academic content.
   - `tasks`, `notifications`, and progress-related components suggest long-running operations are tracked asynchronously and surfaced in the UI.

8. **Bibliography and document formatting subsystem**
   - The repository includes citation assets under `public/csl/*` and fonts under `public/fonts/indivisa/*`.
   - That points to a document/bibliography rendering pipeline using **CSL styles** and localized citation data.
   - Components like `BibliographyItem`, `DocumentoSEPTab`, and `src/lib/asignaturaColumnParsers.ts` suggest the app can parse and present structured academic/document data, not just plain CRUD records.

9. **Shared UI foundation**
   - Most primitives come from `src/components/ui/*`, consistent with a **shadcn/ui-style** design system.
   - Custom higher-level widgets such as step indicators, progress indicators, motion tabs, dialogs, and cards are layered on top.
   - This separates the architectural boundary between low-level UI primitives and domain-specific screens.

10. **Shared domain types and utilities**
   - Canonical data contracts live in `src/types/*` and `src/data/types/domain.ts`.
   - Utility logic is kept outside components in `src/lib/*`, `src/utils/*`, and feature-specific helpers like file-size formatting and icon utilities.
   - This helps keep route and component layers thin while centralizing domain formatting and parsing rules.

11. **Static assets and application metadata**
   - `public/manifest.json`, `robots.txt`, `index.html`, and `public/fonts` indicate a deployable browser application with PWA-like metadata and branded typography.
   - `public/csl` is a meaningful content asset bundle for the bibliography/document subsystem.
   - `src/styles.css` is the global styling entry point, layered with Tailwind CSS and component-level styles.

12. **Build, deployment, and runtime shape**
   - The app is built with **Vite** and managed with **Bun**.
   - Production packaging is containerized via `Dockerfile` and served through `nginx.conf`, implying a static frontend build deployed behind Nginx.
   - `github/workflows/deploy.yaml` and `staticwebapp.config.json` show the repo is prepared for automated deployment, likely to a static hosting platform or container-based static serving.

13. **What to emphasize in an architecture diagram**
   - Draw the system as a **React SPA shell** with route-driven pages on top.
   - Show a clear split between:
     - UI/layout layer
     - domain feature modules for plans and subjects
     - shared data/query layer
     - Supabase + edge-function backend boundary
     - AI/file/document external services
   - The most important flows are: user navigation → route page → feature wizard/detail screen → data hooks/api layer → Supabase/edge services → query cache/UI updates.

Main entry points: [`src/components/asignaturas/detalle/AsignaturaDetailPage.tsx`](https://github.com/acad-ia/frontend/blob/main/src/components/asignaturas/detalle/AsignaturaDetailPage.tsx) (Subjects), [`src/components/planes/PlanEstudiosCard.tsx`](https://github.com/acad-ia/frontend/blob/main/src/components/planes/PlanEstudiosCard.tsx) (Plans), [`src/components/ui/button.tsx`](https://github.com/acad-ia/frontend/blob/main/src/components/ui/button.tsx) (UI primitives), [`src/data/hooks/usePlans.ts`](https://github.com/acad-ia/frontend/blob/main/src/data/hooks/usePlans.ts) (Domain hooks)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_shell["App shell"]
  node_node_root["Root app<br/>bootstrap/router<br/>[main.tsx]"]
  node_node_root_route["App shell<br/>route layout<br/>[__root.tsx]"]
  node_node_layout["Layout<br/>shell components<br/>[AppLayout.tsx]"]
  node_node_routes["Route tree<br/>file-based routes<br/>[routeTree.gen.ts]"]
  node_node_planes_routes["Plan routes<br/>route module<br/>[_lista.tsx]"]
  node_node_subject_routes["Subject routes<br/>route module<br/>[index.tsx]"]
end

subgraph group_group_domain["Domain features"]
  node_node_plan_features["Plans<br/>domain feature"]
  node_node_subject_features["Subjects<br/>domain feature"]
  node_node_biblio["Bibliography<br/>document feature"]
  node_node_ai_plan["Plan AI<br/>assistant workflow"]
  node_node_ai_subject["Subject AI<br/>assistant workflow"]
  node_node_plan_wizard["Plan wizard<br/>creation flow"]
  node_node_subject_wizard["Subject wizard<br/>creation flow"]
end

subgraph group_group_data["Data layer"]
  node_node_query["Query client<br/>state cache<br/>[queryClient.tsx]"]
  node_node_hooks["Domain hooks<br/>react hooks<br/>[usePlans.ts]"]
  node_node_api["API modules<br/>server boundary<br/>[plans.api.ts]"]
  node_node_supabase[("Supabase<br/>backend client<br/>[client.ts]")]
  node_node_types["Domain types<br/>contracts<br/>[domain.ts]"]
end

subgraph group_group_ui["Shared UI"]
  node_node_ui["UI primitives<br/>design system<br/>[button.tsx]"]
  node_node_assets["Static assets<br/>asset bundle<br/>[apa.csl]"]
end

node_node_root -->|"boots"| node_node_root_route
node_node_root_route -->|"uses"| node_node_layout
node_node_root -->|"loads"| node_node_routes
node_node_routes -->|"includes"| node_node_planes_routes
node_node_routes -->|"includes"| node_node_subject_routes
node_node_planes_routes -->|"renders"| node_node_plan_features
node_node_subject_routes -->|"renders"| node_node_subject_features
node_node_plan_features -->|"creates"| node_node_plan_wizard
node_node_subject_features -->|"creates"| node_node_subject_wizard
node_node_plan_features -->|"assists"| node_node_ai_plan
node_node_subject_features -->|"assists"| node_node_ai_subject
node_node_subject_features -->|"manages"| node_node_biblio
node_node_plan_features -->|"calls"| node_node_hooks
node_node_subject_features -->|"calls"| node_node_hooks
node_node_hooks -->|"wraps"| node_node_api
node_node_api -->|"invokes"| node_node_supabase
node_node_hooks -->|"caches"| node_node_query
node_node_api -->|"uses"| node_node_types
node_node_ui -->|"builds"| node_node_layout
node_node_ui -->|"supports"| node_node_plan_features
node_node_ui -->|"supports"| node_node_subject_features
node_node_assets -->|"feeds"| node_node_biblio
node_node_assets -->|"styles"| node_node_ui

click node_node_root "https://github.com/acad-ia/frontend/blob/main/src/main.tsx"
click node_node_root_route "https://github.com/acad-ia/frontend/blob/main/src/routes/__root.tsx"
click node_node_layout "https://github.com/acad-ia/frontend/blob/main/src/components/layout/AppLayout.tsx"
click node_node_routes "https://github.com/acad-ia/frontend/blob/main/src/routeTree.gen.ts"
click node_node_planes_routes "https://github.com/acad-ia/frontend/blob/main/src/routes/planes/_lista.tsx"
click node_node_subject_routes "https://github.com/acad-ia/frontend/blob/main/src/routes/planes/$planId/asignaturas/$asignaturaId/index.tsx"
click node_node_plan_features "https://github.com/acad-ia/frontend/blob/main/src/components/planes/PlanEstudiosCard.tsx"
click node_node_subject_features "https://github.com/acad-ia/frontend/blob/main/src/components/asignaturas/detalle/AsignaturaDetailPage.tsx"
click node_node_biblio "https://github.com/acad-ia/frontend/blob/main/src/features/bibliografia/nueva/NuevaBibliografiaModalContainer.tsx"
click node_node_ai_plan "https://github.com/acad-ia/frontend/blob/main/src/components/planes/detalle/Ia/ImprovementCard.tsx"
click node_node_ai_subject "https://github.com/acad-ia/frontend/blob/main/src/components/asignaturas/detalle/IAAsignaturaTab.tsx"
click node_node_plan_wizard "https://github.com/acad-ia/frontend/blob/main/src/features/planes/nuevo/hooks/useNuevoPlanWizard.ts"
click node_node_subject_wizard "https://github.com/acad-ia/frontend/blob/main/src/features/asignaturas/nueva/hooks/useNuevaAsignaturaWizard.ts"
click node_node_query "https://github.com/acad-ia/frontend/blob/main/src/data/query/queryClient.tsx"
click node_node_hooks "https://github.com/acad-ia/frontend/blob/main/src/data/hooks/usePlans.ts"
click node_node_api "https://github.com/acad-ia/frontend/blob/main/src/data/api/plans.api.ts"
click node_node_supabase "https://github.com/acad-ia/frontend/blob/main/src/data/supabase/client.ts"
click node_node_types "https://github.com/acad-ia/frontend/blob/main/src/data/types/domain.ts"
click node_node_ui "https://github.com/acad-ia/frontend/blob/main/src/components/ui/button.tsx"
click node_node_assets "https://github.com/acad-ia/frontend/blob/main/public/csl/styles/apa.csl"

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_node_root,node_node_root_route,node_node_layout,node_node_routes,node_node_planes_routes,node_node_subject_routes toneBlue
class node_node_plan_features,node_node_subject_features,node_node_biblio,node_node_ai_plan,node_node_ai_subject,node_node_plan_wizard,node_node_subject_wizard toneAmber
class node_node_query,node_node_hooks,node_node_api,node_node_supabase,node_node_types toneMint
class node_node_ui,node_node_assets toneRose
```

## Components

### App shell

SPA bootstrap, layout, and file-based routing.

- [Root app](https://github.com/acad-ia/frontend/blob/main/src/main.tsx): bootstrap/router · Application entry, root route, and generated route tree. · `src/main.tsx`
- [App shell](https://github.com/acad-ia/frontend/blob/main/src/routes/__root.tsx): route layout · Top-level route layout with shared navigation and outlet. · `src/routes/__root.tsx`
- [Layout](https://github.com/acad-ia/frontend/blob/main/src/components/layout/AppLayout.tsx): shell components · Header, sidebar, and overall page chrome. · `src/components/layout/AppLayout.tsx`
- [Route tree](https://github.com/acad-ia/frontend/blob/main/src/routeTree.gen.ts): file-based routes · Generated TanStack Router graph and page routes. · `src/routeTree.gen.ts`
- [Plan routes](https://github.com/acad-ia/frontend/blob/main/src/routes/planes/_lista.tsx): route module · List, detail, and nested plan subroutes. · `src/routes/planes/_lista.tsx`
- [Subject routes](https://github.com/acad-ia/frontend/blob/main/src/routes/planes/$planId/asignaturas/$asignaturaId/index.tsx): route module · Nested subject detail tabs under a plan. · `src/routes/planes/$planId/asignaturas/$asignaturaId/index.tsx`

### Domain features

Plans, subjects, bibliography, and AI-assisted creation flows.

- [Plans](https://github.com/acad-ia/frontend/blob/main/src/components/planes/PlanEstudiosCard.tsx): domain feature · Plan list, detail, AI, and creation flows. · `src/components/planes/PlanEstudiosCard.tsx`
- [Subjects](https://github.com/acad-ia/frontend/blob/main/src/components/asignaturas/detalle/AsignaturaDetailPage.tsx): domain feature · Subject detail pages, content editing, and wizards. · `src/components/asignaturas/detalle/AsignaturaDetailPage.tsx`
- [Bibliography](https://github.com/acad-ia/frontend/blob/main/src/features/bibliografia/nueva/NuevaBibliografiaModalContainer.tsx): document feature · Citation UI and bibliography creation flow. · `src/features/bibliografia/nueva/NuevaBibliografiaModalContainer.tsx`
- [Plan AI](https://github.com/acad-ia/frontend/blob/main/src/components/planes/detalle/Ia/ImprovementCard.tsx): assistant workflow · AI-assisted plan improvement and generation. · `src/components/planes/detalle/Ia/ImprovementCard.tsx`
- [Subject AI](https://github.com/acad-ia/frontend/blob/main/src/components/asignaturas/detalle/IAAsignaturaTab.tsx): assistant workflow · AI-assisted subject improvement and progress UI. · `src/components/asignaturas/detalle/IAAsignaturaTab.tsx`
- [Plan wizard](https://github.com/acad-ia/frontend/blob/main/src/features/planes/nuevo/hooks/useNuevoPlanWizard.ts): creation flow · Multi-step wizard for creating or cloning plans. · `src/features/planes/nuevo/hooks/useNuevoPlanWizard.ts`
- [Subject wizard](https://github.com/acad-ia/frontend/blob/main/src/features/asignaturas/nueva/hooks/useNuevaAsignaturaWizard.ts): creation flow · Multi-step wizard for creating or cloning subjects. · `src/features/asignaturas/nueva/hooks/useNuevaAsignaturaWizard.ts`

### Data layer

Query, API, Supabase, and domain contracts.

- [Query client](https://github.com/acad-ia/frontend/blob/main/src/data/query/queryClient.tsx): state cache · TanStack Query client and cache keys. · `src/data/query/queryClient.tsx`
- [Domain hooks](https://github.com/acad-ia/frontend/blob/main/src/data/hooks/usePlans.ts): react hooks · Typed hooks wrapping plans, subjects, AI, files, tasks, and notifications. · `src/data/hooks/usePlans.ts`
- [API modules](https://github.com/acad-ia/frontend/blob/main/src/data/api/plans.api.ts): server boundary · Focused API modules for plans, subjects, AI, documents, files, tasks, and metadata. · `src/data/api/plans.api.ts`
- [Supabase](https://github.com/acad-ia/frontend/blob/main/src/data/supabase/client.ts): backend client · Client setup, env access, and edge-function invocation. · `src/data/supabase/client.ts`
- [Domain types](https://github.com/acad-ia/frontend/blob/main/src/data/types/domain.ts): contracts · Canonical plan, subject, and Supabase type definitions. · `src/data/types/domain.ts`

### Shared UI

Reusable components, utilities, and static assets.

- [UI primitives](https://github.com/acad-ia/frontend/blob/main/src/components/ui/button.tsx): design system · Reusable shadcn-style components and base controls. · `src/components/ui/button.tsx`
- [Static assets](https://github.com/acad-ia/frontend/blob/main/public/csl/styles/apa.csl): asset bundle · Bibliography styles, fonts, manifest, and hosting metadata. · `public/csl/styles/apa.csl`

## Connections

- Root app → App shell: boots · The app entry renders the root route and route tree.
- App shell → Layout: uses · The root route composes the shared app shell.
- Root app → Route tree: loads · Generated routes power file-based navigation.
- Route tree → Plan routes: includes · Plan pages are part of the route graph.
- Route tree → Subject routes: includes · Subject tabs are nested under plan routes.
- Plan routes → Plans: renders · Plan routes mount plan list, detail, wizard, and AI screens.
- Subject routes → Subjects: renders · Subject routes mount detail tabs and editors.
- Plans → Plan wizard: creates · Plan creation uses a dedicated multi-step wizard.
- Subjects → Subject wizard: creates · Subject creation uses a dedicated multi-step wizard.
- Plans → Plan AI: assists · Plan screens include AI-driven improvement flows.
- Subjects → Subject AI: assists · Subject screens include AI-driven assistant flows.
- Subjects → Bibliography: manages · Subject detail includes bibliography management.
- Plans → Domain hooks: calls · Domain screens consume typed hooks for data access.
- Subjects → Domain hooks: calls · Subject screens consume typed hooks for data access.
- Domain hooks → API modules: wraps · Hooks are thin facades over API modules.
- API modules → Supabase: invokes · API modules call Supabase and edge functions.
- Domain hooks → Query client: caches · Hooks integrate with the shared query client.
- API modules → Domain types: uses · API modules are typed by domain contracts.
- UI primitives → Layout: builds · The shell uses shared UI primitives.
- UI primitives → Plans: supports · Plan screens are composed from shared primitives.
- UI primitives → Subjects: supports · Subject screens are composed from shared primitives.
- Static assets → Bibliography: feeds · CSL styles and fonts support bibliography rendering.
- Static assets → UI primitives: styles · Static typography and metadata support the UI layer.
