# maadhu938/neuroweave architecture

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

- Interactive diagram: https://gitdiagram.com/maadhu938/neuroweave
- Repository: https://github.com/maadhu938/neuroweave

## Overview

1. **High-level shape**
   - Neuroweave is a split architecture: a **React/Vite single-page frontend** in `src/` and a **FastAPI backend** in `backend/app/`.
   - The frontend handles interaction and visualization; the backend owns all domain logic, AI calls, graph processing, and persistence.

2. **Frontend presentation layer**
   - `src/pages/` defines the main user surfaces: **Dashboard, Brain Map, Ask Your Brain, Upload Knowledge, Study Planner, Insights, Settings, Login, Landing**.
   - `src/components/` contains reusable UI tied to core product features, especially the knowledge/memory visualizations such as **AI insight cards, memory heatmap, memory decay chart, review quiz, sidebar, top bar**.
   - This layer is mostly a client-side orchestration and rendering layer, not where business logic lives.

3. **Frontend-to-backend boundary**
   - The frontend talks to the backend through `src/lib/api.ts` and the `useApi` hook.
   - Authentication is handled separately through Firebase client setup in `src/lib/firebase.ts` and the `useAuth` hook, so the app has a distinct **identity boundary** before API access.
   - The frontend appears to be a pure client app; the backend is the source of truth for learning state, graph data, and memory scoring.

4. **Backend API surface**
   - `backend/app/api/` is organized by domain, not by generic CRUD: `ask`, `dashboard`, `insights`, `knowledge_graph`, `memory`, `metrics`, `review`, `settings`, `study_planner`, `upload`.
   - This implies the backend is a **feature-oriented API**, where each router returns data shaped for a specific product surface rather than exposing low-level tables.
   - `backend/app/main.py` likely assembles these routers and applies middleware/CORS/auth.

5. **Core domain services**
   - `backend/app/services/` contains the real architecture center:
     - `ingestion.py` for turning source material into structured knowledge
     - `embedding.py` for vectorization
     - `graph.py` for knowledge graph construction/updates
     - `retrieval.py` for semantic and graph-aware lookup
     - `llm.py` for model interaction
     - `nama.py` for the memory-strength algorithm
     - `planner.py` for study scheduling
     - `insights.py` for analytics generation
   - These services are the main computational layer between API endpoints and the database.

6. **Knowledge ingestion pipeline**
   - The `upload` API feeds the ingestion service, which likely parses documents, extracts chunks, generates embeddings, and stores graph-relevant entities/relations.
   - `PyMuPDF` is listed in the stack, so PDF handling is a material part of ingestion.
   - The output of ingestion is not just files in storage; it becomes **structured graph + vector data** used by retrieval, planning, and analytics.

7. **Knowledge graph and retrieval path**
   - The `knowledge_graph` API plus `graph.py` represent the system’s canonical “brain map” model.
   - `retrieval.py` likely combines **pgvector semantic search** with **graph neighborhood/context expansion** so Ask Your Brain can answer in context, not from embeddings alone.
   - This is the main path for the “Ask Your Brain” experience: user query → retrieval → LLM → grounded answer.

8. **Memory model and adaptive learning loop**
   - `nama.py` implements the proprietary **NAMA Algorithm**, which updates memory strength from review history, performance, connectivity, and time decay.
   - The `memory` and `review` APIs likely drive this loop by accepting quiz/review outcomes and writing updated memory state back to the database.
   - This loop is what differentiates the app from a static knowledge base: user interactions continuously reshape future review priority.

9. **Study planning and prioritization**
   - `planner.py` and the `study_planner` API turn memory state into a schedule or prioritized queue of study actions.
   - The planner depends on the memory model and graph context, so scheduling is an output of accumulated usage history, not just fixed calendar rules.
   - This subsystem sits between analytics and action: it translates learning state into next steps.

10. **Analytics and dashboarding**
   - `insights.py`, `metrics`, and `dashboard` provide higher-level summaries such as retention, decay, coverage, and learning progress.
   - The frontend charts in `MemoryDecayChart`, `MemoryHeatmap`, and `AIInsightCards` are visual consumers of these aggregated outputs.
   - This layer is read-heavy and optimizes for quick interpretation rather than raw data entry.

11. **Persistence model**
   - `backend/app/database.py` and `backend/app/models/models.py` indicate a SQLAlchemy-backed relational schema.
   - PostgreSQL with **pgvector** is a key architectural choice: it stores both normal relational state and vector embeddings in the same system.
   - That means the core data store supports three concerns together: user/content records, graph/memory state, and semantic retrieval.

12. **External services and deployment boundaries**
   - The backend integrates with **Groq** for Llama-class LLM access and likely **Hugging Face embeddings** for vector generation, so model inference is external to the app runtime.
   - Firebase is used on the frontend for auth identity.
   - The repo layout and config files suggest a typical split deployment: **frontend on Vercel**, **backend on Render/Railway**, and **Postgres on Supabase or similar managed Postgres**.

13. **What to show in an architecture diagram**
   - Draw the main flow as: **User/UI → Frontend pages/components → API client → FastAPI routers → domain services → Postgres/pgvector + external AI services**.
   - Then show feedback loops from **review/quiz interactions back into memory/NAMA/planner**, and from **upload/ingestion into graph/retrieval/insights**.
   - The most important boundaries are: **presentation vs backend**, **API routing vs domain services**, **domain services vs persistence**, and **internal logic vs external model providers**.

Main entry points: [`backend/app/api`](https://github.com/maadhu938/neuroweave/tree/main/backend/app/api) (API Routers), [`backend/app/database.py`](https://github.com/maadhu938/neuroweave/blob/main/backend/app/database.py) (Database), [`src/pages`](https://github.com/maadhu938/neuroweave/tree/main/src/pages) (Pages), [`backend/app/services/retrieval.py`](https://github.com/maadhu938/neuroweave/blob/main/backend/app/services/retrieval.py) (Retrieval)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_pages["Pages<br/>ui surfaces"]
  node_components["UI Components<br/>shared widgets"]
  node_api_client["API Client<br/>client boundary<br/>[api.ts]"]
  node_auth_client["Auth Client<br/>identity<br/>[firebase.ts]"]
  node_use_api["useApi<br/>hook<br/>[useApi.ts]"]
  node_use_auth["useAuth<br/>hook<br/>[useAuth.tsx]"]
  node_main_app["App Shell<br/>[App.tsx]"]
end

subgraph group_backend["Backend"]
  node_api_main["FastAPI App<br/>server entry<br/>[main.py]"]
  node_api_routes["API Routers<br/>feature api"]
  node_ingestion["Ingestion<br/>pipeline<br/>[ingestion.py]"]
  node_retrieval["Retrieval<br/>search<br/>[retrieval.py]"]
  node_graph_service["Graph Service<br/>knowledge graph<br/>[graph.py]"]
  node_embedding["Embedding<br/>vectorization<br/>[embedding.py]"]
  node_llm["LLM Service<br/>model integration<br/>[llm.py]"]
  node_nama["NAMA Engine<br/>memory model<br/>[nama.py]"]
  node_planner["Planner<br/>scheduling<br/>[planner.py]"]
  node_insights_service["Insights Service<br/>analytics<br/>[insights.py]"]
  node_database[("Database<br/>persistence<br/>[database.py]")]
  node_models["Data Models<br/>schema<br/>[models.py]"]
end

subgraph group_external["External"]
  node_firebase["Firebase<br/>external auth"]
  node_groq["Groq<br/>external llm"]
  node_hf["Hugging Face<br/>external embeddings"]
  node_postgres[("Postgres/pgvector<br/>external data store")]
end

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

node_user -->|"uses"| node_pages
node_pages -->|"renders"| node_components
node_pages -->|"queries"| node_use_api
node_pages -->|"auth gates"| node_use_auth
node_use_api -->|"calls"| node_api_client
node_use_auth -->|"uses"| node_auth_client
node_auth_client -->|"authenticates"| node_firebase
node_api_client -->|"requests"| node_api_main
node_api_main -->|"mounts"| node_api_routes
node_api_routes -->|"upload"| node_ingestion
node_api_routes -->|"ask"| node_retrieval
node_api_routes -->|"brain map"| node_graph_service
node_api_routes -->|"memory"| node_nama
node_api_routes -->|"study plan"| node_planner
node_api_routes -->|"insights"| node_insights_service
node_api_routes -->|"stores"| node_database
node_ingestion -->|"vectorizes"| node_embedding
node_ingestion -->|"extracts graph"| node_graph_service
node_retrieval -->|"expands context"| node_graph_service
node_retrieval -->|"searches vectors"| node_embedding
node_retrieval -->|"grounds reply"| node_llm
node_nama -->|"updates state"| node_database
node_planner -->|"depends on"| node_nama
node_planner -->|"uses context"| node_graph_service
node_insights_service -->|"aggregates"| node_database
node_database -->|"maps to"| node_models
node_embedding -->|"calls"| node_hf
node_llm -->|"calls"| node_groq
node_database -->|"backed by"| node_postgres

click node_pages "https://github.com/maadhu938/neuroweave/tree/main/src/pages"
click node_components "https://github.com/maadhu938/neuroweave/tree/main/src/components"
click node_api_client "https://github.com/maadhu938/neuroweave/blob/main/src/lib/api.ts"
click node_auth_client "https://github.com/maadhu938/neuroweave/blob/main/src/lib/firebase.ts"
click node_use_api "https://github.com/maadhu938/neuroweave/blob/main/src/hooks/useApi.ts"
click node_use_auth "https://github.com/maadhu938/neuroweave/blob/main/src/hooks/useAuth.tsx"
click node_main_app "https://github.com/maadhu938/neuroweave/blob/main/src/app/App.tsx"
click node_api_main "https://github.com/maadhu938/neuroweave/blob/main/backend/app/main.py"
click node_api_routes "https://github.com/maadhu938/neuroweave/tree/main/backend/app/api"
click node_ingestion "https://github.com/maadhu938/neuroweave/blob/main/backend/app/services/ingestion.py"
click node_retrieval "https://github.com/maadhu938/neuroweave/blob/main/backend/app/services/retrieval.py"
click node_graph_service "https://github.com/maadhu938/neuroweave/blob/main/backend/app/services/graph.py"
click node_embedding "https://github.com/maadhu938/neuroweave/blob/main/backend/app/services/embedding.py"
click node_llm "https://github.com/maadhu938/neuroweave/blob/main/backend/app/services/llm.py"
click node_nama "https://github.com/maadhu938/neuroweave/blob/main/backend/app/services/nama.py"
click node_planner "https://github.com/maadhu938/neuroweave/blob/main/backend/app/services/planner.py"
click node_insights_service "https://github.com/maadhu938/neuroweave/blob/main/backend/app/services/insights.py"
click node_database "https://github.com/maadhu938/neuroweave/blob/main/backend/app/database.py"
click node_models "https://github.com/maadhu938/neuroweave/blob/main/backend/app/models/models.py"

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_pages,node_components,node_api_client,node_auth_client,node_use_api,node_use_auth,node_main_app toneBlue
class node_api_main,node_api_routes,node_ingestion,node_retrieval,node_graph_service,node_embedding,node_llm,node_nama,node_planner,node_insights_service,node_database,node_models toneAmber
class node_firebase,node_groq,node_hf,node_postgres toneMint
class node_user toneNeutral
```

## Components

### Frontend

React/Vite client for interaction, visualization, and auth gating.

- [Pages](https://github.com/maadhu938/neuroweave/tree/main/src/pages): ui surfaces · Main product screens: dashboard, brain map, ask, upload, planner, insights, settings, login, landing. · `src/pages`
- [UI Components](https://github.com/maadhu938/neuroweave/tree/main/src/components): shared widgets · Reusable presentation pieces for insight cards, charts, quizzes, and shell navigation. · `src/components`
- [API Client](https://github.com/maadhu938/neuroweave/blob/main/src/lib/api.ts): client boundary · Typed browser API access used by hooks and pages. · `src/lib/api.ts`
- [Auth Client](https://github.com/maadhu938/neuroweave/blob/main/src/lib/firebase.ts): identity · Firebase-backed frontend authentication and session state. · `src/lib/firebase.ts`
- [useApi](https://github.com/maadhu938/neuroweave/blob/main/src/hooks/useApi.ts): hook · Frontend hook that wraps backend requests and shared loading/error state. · `src/hooks/useApi.ts`
- [useAuth](https://github.com/maadhu938/neuroweave/blob/main/src/hooks/useAuth.tsx): hook · Frontend hook for login state and auth gating. · `src/hooks/useAuth.tsx`
- [App Shell](https://github.com/maadhu938/neuroweave/blob/main/src/app/App.tsx): shell · Top-level React composition and routing entrypoint. · `src/app/App.tsx`

### Backend

FastAPI app with routers, domain services, and persistence.

- [FastAPI App](https://github.com/maadhu938/neuroweave/blob/main/backend/app/main.py): server entry · Assembles routers, middleware, and application-wide backend setup. · `backend/app/main.py`
- [API Routers](https://github.com/maadhu938/neuroweave/tree/main/backend/app/api): feature api · Domain-oriented endpoints for ask, dashboard, insights, knowledge graph, memory, metrics, review, settings, study planner, and upload. · `backend/app/api`
- [Ingestion](https://github.com/maadhu938/neuroweave/blob/main/backend/app/services/ingestion.py): pipeline · Parses uploads, extracts structure, chunks content, and prepares graph/vector inputs. · `backend/app/services/ingestion.py`
- [Retrieval](https://github.com/maadhu938/neuroweave/blob/main/backend/app/services/retrieval.py): search · Combines semantic search with graph-aware context expansion for grounded answers. · `backend/app/services/retrieval.py`
- [Graph Service](https://github.com/maadhu938/neuroweave/blob/main/backend/app/services/graph.py): knowledge graph · Builds and updates the canonical knowledge graph used by the brain map. · `backend/app/services/graph.py`
- [Embedding](https://github.com/maadhu938/neuroweave/blob/main/backend/app/services/embedding.py): vectorization · Generates vector representations for semantic retrieval and similarity. · `backend/app/services/embedding.py`
- [LLM Service](https://github.com/maadhu938/neuroweave/blob/main/backend/app/services/llm.py): model integration · Handles model prompts and response generation for assistant-style features. · `backend/app/services/llm.py`
- [NAMA Engine](https://github.com/maadhu938/neuroweave/blob/main/backend/app/services/nama.py): memory model · Computes adaptive memory strength from reviews, time decay, and connectivity. · `backend/app/services/nama.py`
- [Planner](https://github.com/maadhu938/neuroweave/blob/main/backend/app/services/planner.py): scheduling · Turns memory state and graph context into study priorities and schedules. · `backend/app/services/planner.py`
- [Insights Service](https://github.com/maadhu938/neuroweave/blob/main/backend/app/services/insights.py): analytics · Produces retention, decay, coverage, and progress summaries. · `backend/app/services/insights.py`
- [Database](https://github.com/maadhu938/neuroweave/blob/main/backend/app/database.py): persistence · SQLAlchemy-backed relational store for app state and domain records. · `backend/app/database.py`
- [Data Models](https://github.com/maadhu938/neuroweave/blob/main/backend/app/models/models.py): schema · ORM models defining persisted users, knowledge, memory, and review state. · `backend/app/models/models.py`

### External

Third-party identity, model, and data services.

- **Firebase**: external auth · External identity provider used by the frontend.
- **Groq**: external llm · External model provider for LLM inference.
- **Hugging Face**: external embeddings · External embedding provider used for vector generation.
- **Postgres/pgvector**: external data store · Primary database layer with relational tables plus vector search support.

### Other components

- **User**: actor · Learner using the app to ask, upload, review, and plan.

## Connections

- User → Pages: uses · Interacts with product screens.
- Pages → UI Components: renders · Composes reusable UI widgets.
- Pages → useApi: queries · Fetches product data through the API hook.
- Pages → useAuth: auth gates · Checks session state for protected views.
- useApi → API Client: calls · Delegates network requests to the client layer.
- useAuth → Auth Client: uses · Reads and updates frontend auth state.
- Auth Client → Firebase: authenticates · Relies on Firebase identity services.
- API Client → FastAPI App: requests · Sends browser requests to the backend app.
- FastAPI App → API Routers: mounts · Registers feature-oriented routers.
- API Routers → Ingestion: upload · Turns source material into structured knowledge.
- API Routers → Retrieval: ask · Serves contextual question answering.
- API Routers → Graph Service: brain map · Exposes graph views and updates.
- API Routers → NAMA Engine: memory · Reads and writes adaptive memory state.
- API Routers → Planner: study plan · Produces prioritized study actions.
- API Routers → Insights Service: insights · Returns analytics and summaries.
- API Routers → Database: stores · Persists domain state and reads it back.
- Ingestion → Embedding: vectorizes · Creates embeddings for uploaded content.
- Ingestion → Graph Service: extracts graph · Converts content into entities and relations.
- Retrieval → Graph Service: expands context · Uses graph neighborhoods to ground answers.
- Retrieval → Embedding: searches vectors · Finds semantically related content.
- Retrieval → LLM Service: grounds reply · Builds contextual answers from retrieved evidence.
- NAMA Engine → Database: updates state · Persists memory scores and review history.
- Planner → NAMA Engine: depends on · Uses memory strength and decay signals.
- Planner → Graph Service: uses context · Factors in knowledge connectivity and structure.
- Insights Service → Database: aggregates · Reads persisted records to compute metrics.
- Database → Data Models: maps to · Implements the relational schema through ORM models.
- Embedding → Hugging Face: calls · Uses external embedding models.
- LLM Service → Groq: calls · Uses external LLM inference.
- Database → Postgres/pgvector: backed by · Primary persistent store with pgvector support.
