# markbmag/ncode architecture

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

- Interactive diagram: https://gitdiagram.com/markbmag/ncode
- Repository: https://github.com/markbmag/ncode

## Overview

Ncode is a web app for searching text across connected relational databases. A user signs in, selects a connection and search scope, submits a phrase, follows task progress, and views highlighted matching rows or exports them. The backend also manages connections, user permissions, sessions, and search auditing. The graph preserves documented connection management, table scoping, CSV export, and team features; some backend internals are represented at module level because their source was not excerpted.

Main entry points: [`frontend/src/Workspace.tsx`](https://github.com/markbmag/ncode/blob/main/frontend/src/Workspace.tsx) (Workspace), [`backend/app/api.py`](https://github.com/markbmag/ncode/blob/main/backend/app/api.py) (API routes), [`frontend/src/hooks/useSearch.ts`](https://github.com/markbmag/ncode/blob/main/frontend/src/hooks/useSearch.ts) (Search progress), [`frontend/src/api.ts`](https://github.com/markbmag/ncode/blob/main/frontend/src/api.ts) (HTTP and session client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Web workspace"]
  node_app["Session gate<br/>[App.tsx]"]
  node_login["Login<br/>[Login.tsx]"]
  node_workspace["Workspace<br/>[Workspace.tsx]"]
  node_connections_ui["Connection editor"]
  node_scope_ui["Search scope<br/>[ScopeModal.tsx]"]
  node_search_ui["Search controls<br/>[SearchBar.tsx]"]
  node_search_hook["Search progress<br/>[useSearch.ts]"]
  node_results["Results and export<br/>[ResultsPanel.tsx]"]
  node_highlight["Match highlighting<br/>[Highlight.tsx]"]
  node_api_client["HTTP and session client<br/>[api.ts]"]
end

subgraph group_api["API and access"]
  node_routes["API routes<br/>[api.py]"]
  node_security["Authentication<br/>[security.py]"]
end

subgraph group_search["Search runtime"]
  node_search_engine["Database search<br/>[search.py]"]
  node_task_store["Search tasks<br/>[tasks.py]"]
  node_database_adapters["Database access<br/>[db.py]"]
end

subgraph group_data["Configuration and state"]
  node_connection_config["Connection registry<br/>[config.py]"]
  node_app_database[("Users, sessions, audit<br/>[appdb.py]")]
  node_crypto["Credential encryption<br/>[crypto.py]"]
end

node_user(("User"))
node_search_databases[("Connected databases")]

node_user -->|"opens"| node_app
node_app -->|"prompts"| node_login
node_app -->|"shows"| node_workspace
node_login -->|"authenticates via"| node_api_client
node_workspace -->|"loads and manages"| node_api_client
node_workspace -->|"opens"| node_connections_ui
node_workspace -->|"opens"| node_scope_ui
node_workspace -->|"renders"| node_search_ui
node_workspace -->|"starts and tracks"| node_search_hook
node_workspace -->|"renders"| node_results
node_search_ui -->|"submits parameters"| node_search_hook
node_search_hook -->|"starts and cancels"| node_api_client
node_search_hook -->|"opens task socket"| node_routes
node_results -->|"renders matches"| node_highlight
node_results -->|"exports CSV"| node_user
node_api_client -->|"sends API requests"| node_routes
node_routes -->|"checks access"| node_security
node_routes -->|"reads and writes"| node_app_database
node_routes -->|"loads connection settings"| node_connection_config
node_routes -->|"creates and serves tasks"| node_task_store
node_routes -->|"dispatches searches"| node_search_engine
node_search_engine -->|"queries tables"| node_database_adapters
node_search_engine -->|"updates progress and results"| node_task_store
node_database_adapters -.->|"connects and reads"| node_search_databases
node_app_database -->|"encrypts credentials"| node_crypto
node_app_database -->|"stores access and audit records"| node_user
node_connection_config -->|"defines connections"| node_search_databases

click node_app "https://github.com/markbmag/ncode/blob/main/frontend/src/App.tsx"
click node_login "https://github.com/markbmag/ncode/blob/main/frontend/src/Login.tsx"
click node_workspace "https://github.com/markbmag/ncode/blob/main/frontend/src/Workspace.tsx"
click node_connections_ui "https://github.com/markbmag/ncode/blob/main/frontend/src/components/ConnectionModal.tsx"
click node_scope_ui "https://github.com/markbmag/ncode/blob/main/frontend/src/components/ScopeModal.tsx"
click node_search_ui "https://github.com/markbmag/ncode/blob/main/frontend/src/components/SearchBar.tsx"
click node_search_hook "https://github.com/markbmag/ncode/blob/main/frontend/src/hooks/useSearch.ts"
click node_results "https://github.com/markbmag/ncode/blob/main/frontend/src/components/ResultsPanel.tsx"
click node_highlight "https://github.com/markbmag/ncode/blob/main/frontend/src/components/Highlight.tsx"
click node_api_client "https://github.com/markbmag/ncode/blob/main/frontend/src/api.ts"
click node_routes "https://github.com/markbmag/ncode/blob/main/backend/app/api.py"
click node_security "https://github.com/markbmag/ncode/blob/main/backend/app/security.py"
click node_search_engine "https://github.com/markbmag/ncode/blob/main/backend/app/search.py"
click node_task_store "https://github.com/markbmag/ncode/blob/main/backend/app/tasks.py"
click node_database_adapters "https://github.com/markbmag/ncode/blob/main/backend/app/db.py"
click node_connection_config "https://github.com/markbmag/ncode/blob/main/backend/app/config.py"
click node_app_database "https://github.com/markbmag/ncode/blob/main/backend/app/appdb.py"
click node_crypto "https://github.com/markbmag/ncode/blob/main/backend/app/crypto.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_app,node_login,node_workspace,node_connections_ui,node_scope_ui,node_search_ui,node_search_hook,node_results,node_highlight,node_api_client,node_user toneBlue
class node_routes,node_security,node_search_databases toneAmber
class node_search_engine,node_task_store,node_database_adapters toneMint
class node_connection_config,node_app_database,node_crypto toneRose
```

## Components

### Web workspace

- [Session gate](https://github.com/markbmag/ncode/blob/main/frontend/src/App.tsx): `frontend/src/App.tsx`
- [Login](https://github.com/markbmag/ncode/blob/main/frontend/src/Login.tsx): `frontend/src/Login.tsx`
- [Workspace](https://github.com/markbmag/ncode/blob/main/frontend/src/Workspace.tsx): `frontend/src/Workspace.tsx`
- [Connection editor](https://github.com/markbmag/ncode/blob/main/frontend/src/components/ConnectionModal.tsx): `frontend/src/components/ConnectionModal.tsx`
- [Search scope](https://github.com/markbmag/ncode/blob/main/frontend/src/components/ScopeModal.tsx): `frontend/src/components/ScopeModal.tsx`
- [Search controls](https://github.com/markbmag/ncode/blob/main/frontend/src/components/SearchBar.tsx): `frontend/src/components/SearchBar.tsx`
- [Search progress](https://github.com/markbmag/ncode/blob/main/frontend/src/hooks/useSearch.ts): `frontend/src/hooks/useSearch.ts`
- [Results and export](https://github.com/markbmag/ncode/blob/main/frontend/src/components/ResultsPanel.tsx): `frontend/src/components/ResultsPanel.tsx`
- [Match highlighting](https://github.com/markbmag/ncode/blob/main/frontend/src/components/Highlight.tsx): `frontend/src/components/Highlight.tsx`
- [HTTP and session client](https://github.com/markbmag/ncode/blob/main/frontend/src/api.ts): `frontend/src/api.ts`

### API and access

- [API routes](https://github.com/markbmag/ncode/blob/main/backend/app/api.py): `backend/app/api.py`
- [Authentication](https://github.com/markbmag/ncode/blob/main/backend/app/security.py): `backend/app/security.py`

### Search runtime

- [Database search](https://github.com/markbmag/ncode/blob/main/backend/app/search.py): `backend/app/search.py`
- [Search tasks](https://github.com/markbmag/ncode/blob/main/backend/app/tasks.py): `backend/app/tasks.py`
- [Database access](https://github.com/markbmag/ncode/blob/main/backend/app/db.py): `backend/app/db.py`

### Configuration and state

- [Connection registry](https://github.com/markbmag/ncode/blob/main/backend/app/config.py): `backend/app/config.py`
- [Users, sessions, audit](https://github.com/markbmag/ncode/blob/main/backend/app/appdb.py): `backend/app/appdb.py`
- [Credential encryption](https://github.com/markbmag/ncode/blob/main/backend/app/crypto.py): `backend/app/crypto.py`

### Other components

- **User**
- **Connected databases**

## Connections

- User → Session gate: opens
- Session gate → Login: prompts (evidence: `frontend/src/App.tsx`)
- Session gate → Workspace: shows (evidence: `frontend/src/App.tsx`)
- Login → HTTP and session client: authenticates via (evidence: `frontend/src/Login.tsx`)
- Workspace → HTTP and session client: loads and manages (evidence: `frontend/src/Workspace.tsx`)
- Workspace → Connection editor: opens (evidence: `frontend/src/Workspace.tsx`)
- Workspace → Search scope: opens (evidence: `frontend/src/Workspace.tsx`)
- Workspace → Search controls: renders (evidence: `frontend/src/Workspace.tsx`)
- Workspace → Search progress: starts and tracks (evidence: `frontend/src/Workspace.tsx`)
- Workspace → Results and export: renders (evidence: `frontend/src/Workspace.tsx`)
- Search controls → Search progress: submits parameters (evidence: `frontend/src/Workspace.tsx`)
- Search progress → HTTP and session client: starts and cancels (evidence: `frontend/src/hooks/useSearch.ts`)
- Search progress → API routes: opens task socket
- Results and export → Match highlighting: renders matches (evidence: `frontend/src/components/ResultsPanel.tsx`)
- Results and export → User: exports CSV
- HTTP and session client → API routes: sends API requests (evidence: `frontend/src/api.ts`)
- API routes → Authentication: checks access (evidence: `backend/app/api.py`)
- API routes → Users, sessions, audit: reads and writes (evidence: `backend/app/api.py`)
- API routes → Connection registry: loads connection settings (evidence: `backend/app/api.py`)
- API routes → Search tasks: creates and serves tasks (evidence: `backend/app/api.py`)
- API routes → Database search: dispatches searches (evidence: `backend/app/api.py`)
- Database search → Database access: queries tables (evidence: `backend/app/search.py`)
- Database search → Search tasks: updates progress and results (evidence: `backend/app/search.py`)
- Database access → Connected databases: connects and reads
- Users, sessions, audit → Credential encryption: encrypts credentials (evidence: `backend/app/appdb.py`)
- Users, sessions, audit → User: stores access and audit records
- Connection registry → Connected databases: defines connections
