# tefosc/mi-tesis-v1 architecture

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

- Interactive diagram: https://gitdiagram.com/tefosc/mi-tesis-v1
- Repository: https://github.com/tefosc/mi-tesis-v1

## Overview

1. **System shape**
   - AcademIA is a **mobile-first React Native app** for UNC exam preparation.
   - The architecture is centered on a **client app** that orchestrates learning flows, backed by **Supabase/PostgreSQL** for persistent data and **Anthropic Claude** for personalized tutor messages and study-plan generation.

2. **Application shell**
   - `App.js` wires the global providers and root navigation.
   - The shell is built around two cross-cutting contexts: **AuthContext** for session/user state and **ThemeContext** for design tokens and theme helpers.
   - `AppNavigator` acts as the top-level gate: authenticated vs unauthenticated flows, with an animated splash/transition layer.

3. **Navigation boundaries**
   - Navigation is split into:
     - **Auth stack** for login/register/forgot password.
     - **Bottom-tab app** for the main product areas: Home, Practice, Exams, Progress, Profile.
     - **Nested stacks** per feature, so each module owns its own internal screen flow.
   - This makes the UI architecture feature-based rather than screen-by-screen.

4. **Core user journeys**
   - The main app paths are:
     - **Simulacros**: exam listing → detail → timed take-exam → results.
     - **Práctica rápida**: configurable practice session → results.
     - **Home**: summary of progress, target career, countdown, and Markov-based intake gauge.
     - **Progress**: accumulated stats and radar visualization.
     - **Profile**: account, avatar, notification settings, and app info.
   - These journeys all feed back into shared learning state.

5. **Learning engine boundary**
   - The key domain logic lives in `src/services/markovEngine.js`.
   - This module is intentionally **pure**: it computes states, transition matrices, and suggested progression without direct I/O.
   - `markovService.js` wraps that engine with persistence to Supabase, so the architecture cleanly separates **calculation** from **storage**.

6. **Markov-driven adaptation flow**
   - After an exam or practice session:
     - answers are recorded,
     - session performance is processed,
     - the user-topic Markov state is updated,
     - transition history is stored,
     - career affinity is recalculated,
     - downstream UI surfaces are refreshed.
   - The learning state moves through four domain states: **novato → aprendiendo → competente → experto**.

7. **Exam and practice subsystem**
   - `examService.js` manages the exam bank, sessions, answers, and results.
   - The exam UI is built from specialized components like question cards, timers, navigation grids, result summaries, topic breakdowns, and grace-period overlays.
   - Practice has a separate but related flow, allowing shorter sessions with different configuration and scoring behavior.
   - These two subsystems share domain entities but differ in session semantics and UX.

8. **AI and recommendation services**
   - `tutorMessageService.js` generates the post-session tutor message using Claude API.
   - `supabase/functions/generate-study-plan` provides server-side generation for study plans, keeping AI-related orchestration out of the mobile client.
   - `reviewNotificationService.js` turns learning state into a daily review reminder, so recommendations are not just visual but operational.

9. **Backend data model**
   - Supabase is the system of record for:
     - exam content: modules, topics, exams, questions, periods,
     - user profile and exam date,
     - exam/practice session history,
     - Markov topic states and transition history,
     - career predictions and their historical series,
     - AI-generated study plans,
     - milestone tracking.
   - This schema is what binds the learning model, UI dashboards, and longitudinal thesis analysis together.

10. **Local state, caching, and persistence**
   - `AsyncStorage` is used for session persistence, preferences, and lightweight cached state.
   - `cacheService.js` adds a SWR-style in-memory cache with TTL to reduce repeated reads and keep screens responsive.
   - This means the app uses a **hybrid state model**: local cache for immediate UX, Supabase for durable truth.

11. **Notification, milestone, and celebration layer**
   - `expo-notifications` handles daily reminder scheduling.
   - `milestoneService.js` detects learning milestones, which trigger celebration experiences.
   - The celebration subsystem has its own overlay and particle components, so feedback is a separate presentation layer rather than embedded in feature screens.

12. **Presentation system and shared UI**
   - Components are organized by domain: common, exam, home, progress, practice, tutor, celebration, notifications.
   - `theme/` provides colors, spacing, typography, and affinity zones used consistently across the app.
   - This shared UI layer is important because many screens are variations of the same learning dashboard vocabulary: cards, gauges, chips, metrics, and overlays.

13. **Tooling and data import pipeline**
   - `supabase/migrations` defines the backend schema evolution and RLS-related fixes.
   - `src/scripts/processExamData.js` and root `scripts/import-exam.js` support importing the exam bank.
   - Validation scripts in `/scripts` verify scoring, countdown logic, tutor behavior, and schema consistency, showing that data correctness is treated as part of the architecture.

14. **Repo structure as architecture documentation**
   - The `.planning/` tree is not runtime code, but it is a major architectural artifact: it captures roadmap phases, feature specs, validation, UAT, and debugging history.
   - For a diagram, you can treat it as the project’s **design and traceability layer**, adjacent to the production app and backend.

15. **High-level data flow to diagram**
   - User interaction starts in the React Native screens.
   - Screen actions call feature services.
   - Services read/write Supabase and update local cache.
   - Session outcomes feed the Markov engine and career predictions.
   - AI services generate tutor feedback and study plans.
   - Notifications and celebrations close the loop by reinforcing the next learning action.

Main entry points: [`src/services/examService.js`](https://github.com/tefosc/mi-tesis-v1/blob/main/src/services/examService.js) (ExamSvc), [`src/navigation/TabNavigator.js`](https://github.com/tefosc/mi-tesis-v1/blob/main/src/navigation/TabNavigator.js) (Tabs), [`src/services/markovService.js`](https://github.com/tefosc/mi-tesis-v1/blob/main/src/services/markovService.js) (MarkovSvc), [`src/navigation/StackNavigators.js`](https://github.com/tefosc/mi-tesis-v1/blob/main/src/navigation/StackNavigators.js) (Stacks)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app_shell["App Shell"]
  node_app_js["App.js<br/>root entry<br/>[App.js]"]
  node_auth_context(("Auth<br/>context<br/>[AuthContext.js]"))
  node_theme_context(("Theme<br/>context<br/>[ThemeContext.js]"))
  node_app_navigator["AppNav<br/>navigator<br/>[AppNavigator.js]"]
  node_stack_navigators["Stacks<br/>navigator<br/>[StackNavigators.js]"]
  node_tab_navigator["Tabs<br/>navigator<br/>[TabNavigator.js]"]
  node_home_screen["Home<br/>screen<br/>[HomeScreen.js]"]
  node_exams_screen["Exams<br/>screen<br/>[ExamsScreen.js]"]
  node_practice_screen["Practice<br/>screen<br/>[PracticeScreen.js]"]
  node_progress_screen["Progress<br/>screen<br/>[ProgressScreen.js]"]
  node_profile_screen["Profile<br/>screen<br/>[ProfileScreen.js]"]
end

subgraph group_learning_core["Learning Core"]
  node_exam_service[("ExamSvc<br/>domain service<br/>[examService.js]")]
  node_markov_engine{{"Markov<br/>pure engine<br/>[markovEngine.js]"}}
  node_markov_service[("MarkovSvc<br/>domain service<br/>[markovService.js]")]
  node_tutor_service[("Tutor AI<br/>ai service")]
  node_milestone_service[("Milestones<br/>domain service")]
  node_notification_service[("Review Reminders<br/>notification service")]
  node_cache_service["Cache<br/>[cacheService.js]"]
end

subgraph group_ui_domain["UI Domain"]
  node_app_card["Cards<br/>shared UI<br/>[AppCard.js]"]
  node_exam_components["Exam UI<br/>feature UI<br/>[QuestionCard.js]"]
  node_home_components["Home UI<br/>feature UI"]
  node_progress_components["Progress UI<br/>feature UI<br/>[RadarCard.js]"]
  node_celebration_components(("Celebration UI<br/>overlay UI"))
end

subgraph group_backend_ops["Backend & Ops"]
  node_supabase_config[("Supabase<br/>client config<br/>[supabase.js]")]
  node_supabase_function["Study Plan Fn<br/>edge function<br/>[index.ts]"]
  node_migrations["Migrations<br/>schema evolution<br/>[01-foundation.sql]"]
  node_import_script["Import Exam<br/>pipeline script<br/>[import-exam.js]"]
  node_planning_layer["Planning<br/>design traceability<br/>[PROJECT.md]"]
end

node_app_js -->|"provides"| node_auth_context
node_app_js -->|"provides"| node_theme_context
node_app_js -->|"boots"| node_app_navigator
node_app_navigator -->|"routes"| node_stack_navigators
node_app_navigator -->|"routes"| node_tab_navigator
node_stack_navigators -->|"contains"| node_home_screen
node_stack_navigators -->|"contains"| node_exams_screen
node_stack_navigators -->|"contains"| node_practice_screen
node_tab_navigator -->|"opens"| node_home_screen
node_tab_navigator -->|"opens"| node_exams_screen
node_tab_navigator -->|"opens"| node_practice_screen
node_tab_navigator -->|"opens"| node_progress_screen
node_tab_navigator -->|"opens"| node_profile_screen
node_exams_screen -->|"uses"| node_exam_service
node_practice_screen -->|"uses"| node_exam_service
node_exam_service -->|"updates"| node_markov_service
node_markov_service -->|"computes"| node_markov_engine
node_markov_service -->|"persists"| node_supabase_config
node_exam_service -->|"persists"| node_supabase_config
node_markov_service -->|"caches"| node_cache_service
node_exam_service -->|"caches"| node_cache_service
node_exam_service -->|"triggers"| node_tutor_service
node_exam_service -->|"triggers"| node_milestone_service
node_milestone_service -->|"surfaces"| node_celebration_components
node_markov_service -->|"informs"| node_notification_service
node_notification_service -->|"configures"| node_profile_screen
node_home_screen -->|"renders"| node_home_components
node_progress_screen -->|"renders"| node_progress_components
node_exams_screen -->|"renders"| node_exam_components
node_practice_screen -->|"renders"| node_app_card
node_supabase_function -->|"integrates"| node_supabase_config
node_migrations -->|"defines"| node_supabase_config
node_import_script -->|"loads"| node_migrations
node_planning_layer -.->|"documents"| node_migrations
node_planning_layer -.->|"documents"| node_markov_engine
node_planning_layer -.->|"documents"| node_exam_service

click node_app_js "https://github.com/tefosc/mi-tesis-v1/blob/main/App.js"
click node_auth_context "https://github.com/tefosc/mi-tesis-v1/blob/main/src/contexts/AuthContext.js"
click node_theme_context "https://github.com/tefosc/mi-tesis-v1/blob/main/src/contexts/ThemeContext.js"
click node_app_navigator "https://github.com/tefosc/mi-tesis-v1/blob/main/src/navigation/AppNavigator.js"
click node_stack_navigators "https://github.com/tefosc/mi-tesis-v1/blob/main/src/navigation/StackNavigators.js"
click node_tab_navigator "https://github.com/tefosc/mi-tesis-v1/blob/main/src/navigation/TabNavigator.js"
click node_home_screen "https://github.com/tefosc/mi-tesis-v1/blob/main/src/screens/home/HomeScreen.js"
click node_exams_screen "https://github.com/tefosc/mi-tesis-v1/blob/main/src/screens/exam/ExamsScreen.js"
click node_practice_screen "https://github.com/tefosc/mi-tesis-v1/blob/main/src/screens/practice/PracticeScreen.js"
click node_progress_screen "https://github.com/tefosc/mi-tesis-v1/blob/main/src/screens/progress/ProgressScreen.js"
click node_profile_screen "https://github.com/tefosc/mi-tesis-v1/blob/main/src/screens/profile/ProfileScreen.js"
click node_exam_service "https://github.com/tefosc/mi-tesis-v1/blob/main/src/services/examService.js"
click node_markov_engine "https://github.com/tefosc/mi-tesis-v1/blob/main/src/services/markovEngine.js"
click node_markov_service "https://github.com/tefosc/mi-tesis-v1/blob/main/src/services/markovService.js"
click node_tutor_service "https://github.com/tefosc/mi-tesis-v1/blob/main/src/services/tutorMessageService.js"
click node_milestone_service "https://github.com/tefosc/mi-tesis-v1/blob/main/src/services/milestoneService.js"
click node_notification_service "https://github.com/tefosc/mi-tesis-v1/blob/main/src/services/reviewNotificationService.js"
click node_cache_service "https://github.com/tefosc/mi-tesis-v1/blob/main/src/services/cacheService.js"
click node_app_card "https://github.com/tefosc/mi-tesis-v1/blob/main/src/components/common/AppCard.js"
click node_exam_components "https://github.com/tefosc/mi-tesis-v1/blob/main/src/components/exam/QuestionCard.js"
click node_home_components "https://github.com/tefosc/mi-tesis-v1/blob/main/src/components/home/HomeCompactHeader.js"
click node_progress_components "https://github.com/tefosc/mi-tesis-v1/blob/main/src/components/progress/RadarCard.js"
click node_celebration_components "https://github.com/tefosc/mi-tesis-v1/blob/main/src/components/celebration/CelebrationOverlay.js"
click node_supabase_config "https://github.com/tefosc/mi-tesis-v1/blob/main/src/config/supabase.js"
click node_supabase_function "https://github.com/tefosc/mi-tesis-v1/blob/main/supabase/functions/generate-study-plan/index.ts"
click node_migrations "https://github.com/tefosc/mi-tesis-v1/blob/main/supabase/migrations/01-foundation.sql"
click node_import_script "https://github.com/tefosc/mi-tesis-v1/blob/main/scripts/import-exam.js"
click node_planning_layer "https://github.com/tefosc/mi-tesis-v1/blob/main/.planning/PROJECT.md"

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_app_js,node_auth_context,node_theme_context,node_app_navigator,node_stack_navigators,node_tab_navigator,node_home_screen,node_exams_screen,node_practice_screen,node_progress_screen,node_profile_screen toneBlue
class node_exam_service,node_markov_engine,node_markov_service,node_tutor_service,node_milestone_service,node_notification_service,node_cache_service toneAmber
class node_app_card,node_exam_components,node_home_components,node_progress_components,node_celebration_components toneMint
class node_supabase_config,node_supabase_function,node_migrations,node_import_script,node_planning_layer toneRose
```

## Components

### App Shell

Root providers, navigation, and feature boundaries in the mobile client.

- [App.js](https://github.com/tefosc/mi-tesis-v1/blob/main/App.js): root entry · Wires global providers and launches the navigation shell. · `App.js`
- [Auth](https://github.com/tefosc/mi-tesis-v1/blob/main/src/contexts/AuthContext.js): context · Holds session and user state across the app. · `src/contexts/AuthContext.js`
- [Theme](https://github.com/tefosc/mi-tesis-v1/blob/main/src/contexts/ThemeContext.js): context · Provides tokens and theme helpers for consistent presentation. · `src/contexts/ThemeContext.js`
- [AppNav](https://github.com/tefosc/mi-tesis-v1/blob/main/src/navigation/AppNavigator.js): navigator · Top-level gate between authenticated and unauthenticated flows. · `src/navigation/AppNavigator.js`
- [Stacks](https://github.com/tefosc/mi-tesis-v1/blob/main/src/navigation/StackNavigators.js): navigator · Feature-owned stack navigation for auth and nested journeys. · `src/navigation/StackNavigators.js`
- [Tabs](https://github.com/tefosc/mi-tesis-v1/blob/main/src/navigation/TabNavigator.js): navigator · Bottom-tab shell for the main product areas. · `src/navigation/TabNavigator.js`
- [Home](https://github.com/tefosc/mi-tesis-v1/blob/main/src/screens/home/HomeScreen.js): screen · Summary dashboard for progress, target career, and intake gauge. · `src/screens/home/HomeScreen.js`
- [Exams](https://github.com/tefosc/mi-tesis-v1/blob/main/src/screens/exam/ExamsScreen.js): screen · Exam listing and entry point to the timed exam flow. · `src/screens/exam/ExamsScreen.js`
- [Practice](https://github.com/tefosc/mi-tesis-v1/blob/main/src/screens/practice/PracticeScreen.js): screen · Configurable rapid-practice entry and session start screen. · `src/screens/practice/PracticeScreen.js`
- [Progress](https://github.com/tefosc/mi-tesis-v1/blob/main/src/screens/progress/ProgressScreen.js): screen · Longitudinal stats and radar visualization for learning progress. · `src/screens/progress/ProgressScreen.js`
- [Profile](https://github.com/tefosc/mi-tesis-v1/blob/main/src/screens/profile/ProfileScreen.js): screen · Account, avatar, notifications, and app information screen. · `src/screens/profile/ProfileScreen.js`

### Learning Core

Domain services that compute adaptation, sessions, milestones, and recommendations.

- [ExamSvc](https://github.com/tefosc/mi-tesis-v1/blob/main/src/services/examService.js): domain service · Manages exam bank, sessions, answers, and results. · `src/services/examService.js`
- [Markov](https://github.com/tefosc/mi-tesis-v1/blob/main/src/services/markovEngine.js): pure engine · Pure state and transition logic for learning progression. · `src/services/markovEngine.js`
- [MarkovSvc](https://github.com/tefosc/mi-tesis-v1/blob/main/src/services/markovService.js): domain service · Wraps Markov calculations with Supabase persistence. · `src/services/markovService.js`
- [Tutor AI](https://github.com/tefosc/mi-tesis-v1/blob/main/src/services/tutorMessageService.js): ai service · Generates post-session tutor messages with Claude. · `src/services/tutorMessageService.js`
- [Milestones](https://github.com/tefosc/mi-tesis-v1/blob/main/src/services/milestoneService.js): domain service · Detects learning milestones and celebration triggers. · `src/services/milestoneService.js`
- [Review Reminders](https://github.com/tefosc/mi-tesis-v1/blob/main/src/services/reviewNotificationService.js): notification service · Turns learning state into daily review notifications. · `src/services/reviewNotificationService.js`
- [Cache](https://github.com/tefosc/mi-tesis-v1/blob/main/src/services/cacheService.js): state cache · In-memory TTL cache for responsive reads and SWR-style reuse. · `src/services/cacheService.js`

### UI Domain

Shared presentation components organized by product area.

- [Cards](https://github.com/tefosc/mi-tesis-v1/blob/main/src/components/common/AppCard.js): shared UI · Common card and metric vocabulary used across dashboards. · `src/components/common/AppCard.js`
- [Exam UI](https://github.com/tefosc/mi-tesis-v1/blob/main/src/components/exam/QuestionCard.js): feature UI · Question cards, timers, navigation grid, results, and breakdowns. · `src/components/exam/QuestionCard.js`
- [Home UI](https://github.com/tefosc/mi-tesis-v1/blob/main/src/components/home/HomeCompactHeader.js): feature UI · Home-specific chips, selectors, and countdown presentation. · `src/components/home/HomeCompactHeader.js`
- [Progress UI](https://github.com/tefosc/mi-tesis-v1/blob/main/src/components/progress/RadarCard.js): feature UI · Progress dashboard visualizations including the radar card. · `src/components/progress/RadarCard.js`
- [Celebration UI](https://github.com/tefosc/mi-tesis-v1/blob/main/src/components/celebration/CelebrationOverlay.js): overlay UI · Celebration overlay and particles for milestone feedback. · `src/components/celebration/CelebrationOverlay.js`

### Backend & Ops

Supabase schema, edge functions, scripts, and planning artifacts.

- [Supabase](https://github.com/tefosc/mi-tesis-v1/blob/main/src/config/supabase.js): client config · Client connection setup for the backend system of record. · `src/config/supabase.js`
- [Study Plan Fn](https://github.com/tefosc/mi-tesis-v1/blob/main/supabase/functions/generate-study-plan/index.ts): edge function · Server-side AI orchestration for generating study plans. · `supabase/functions/generate-study-plan/index.ts`
- [Migrations](https://github.com/tefosc/mi-tesis-v1/blob/main/supabase/migrations/01-foundation.sql): schema evolution · Supabase schema, RLS fixes, and seeded exam data. · `supabase/migrations/01-foundation.sql`
- [Import Exam](https://github.com/tefosc/mi-tesis-v1/blob/main/scripts/import-exam.js): pipeline script · Loads and processes exam bank content into the data model. · `scripts/import-exam.js`
- [Planning](https://github.com/tefosc/mi-tesis-v1/blob/main/.planning/PROJECT.md): design traceability · Roadmaps, validation notes, research, and architectural history. · `.planning/PROJECT.md`

## Connections

- App.js → Auth: provides · The root app mounts authentication state.
- App.js → Theme: provides · The root app mounts theme state.
- App.js → AppNav: boots · App.js starts the navigation shell.
- AppNav → Stacks: routes · App-level gating delegates to stack flows.
- AppNav → Tabs: routes · Authenticated users enter the tabbed product shell.
- Stacks → Home: contains · Feature stacks host screen flows for product areas.
- Stacks → Exams: contains · Exam flow screens live inside nested stacks.
- Stacks → Practice: contains · Practice flow screens live inside nested stacks.
- Tabs → Home: opens · Home is one of the primary tab destinations.
- Tabs → Exams: opens · Exams is one of the primary tab destinations.
- Tabs → Practice: opens · Practice is one of the primary tab destinations.
- Tabs → Progress: opens · Progress is one of the primary tab destinations.
- Tabs → Profile: opens · Profile is one of the primary tab destinations.
- Exams → ExamSvc: uses · Exam screens orchestrate listing, attempts, and results.
- Practice → ExamSvc: uses · Practice reuses the session and scoring domain.
- ExamSvc → MarkovSvc: updates · Session outcomes update adaptive learning state.
- MarkovSvc → Markov: computes · Persistence layer delegates calculation to the pure engine.
- MarkovSvc → Supabase: persists · Adaptive state is stored in Supabase.
- ExamSvc → Supabase: persists · Questions, sessions, and results are read and written in Supabase.
- MarkovSvc → Cache: caches · Recent reads can be served through the hybrid cache.
- ExamSvc → Cache: caches · Exam data and session state benefit from local caching.
- ExamSvc → Tutor AI: triggers · Completed sessions feed tutor message generation.
- ExamSvc → Milestones: triggers · Performance events are checked for milestones.
- Milestones → Celebration UI: surfaces · Milestones drive celebration overlays in the UI.
- MarkovSvc → Review Reminders: informs · Learning state drives review reminder logic.
- Review Reminders → Profile: configures · Notification settings are managed from profile.
- Home → Home UI: renders · Home uses shared feature-specific presentation components.
- Progress → Progress UI: renders · Progress visualization is built from dedicated components.
- Exams → Exam UI: renders · Exam and result flows use specialized exam UI.
- Practice → Cards: renders · Practice and dashboard surfaces reuse shared card vocabulary.
- Study Plan Fn → Supabase: integrates · The edge function complements the mobile client backend.
- Migrations → Supabase: defines · Schema evolution shapes the client data contract.
- Import Exam → Migrations: loads · Import pipeline depends on the schema and seed structure.
- Planning → Migrations: documents · Planning artifacts capture schema and product evolution.
- Planning → Markov: documents · Design notes and validation history describe the learning model.
- Planning → ExamSvc: documents · The planning layer traces exam-flow decisions and fixes.
