# safwanhasan120/synapse architecture

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

- Interactive diagram: https://gitdiagram.com/safwanhasan120/synapse
- Repository: https://github.com/safwanhasan120/synapse

## Overview

Synapse is a team knowledge-memory product: users authenticate, organize projects, propose context units, review them into accepted knowledge, then retrieve relevant accepted units through semantic search. The API owns those domain operations and persists them in PostgreSQL; accepted units are embedded through OpenAI. The repository also includes a web interface and an MCP server, but the available evidence does not establish their runtime connections to the API, so those links are left unverified.

Main entry points: [`apps/api/src/app.ts`](https://github.com/safwanhasan120/synapse/blob/main/apps/api/src/app.ts) (HTTP application), [`apps/api/src/db/index.ts`](https://github.com/safwanhasan120/synapse/blob/main/apps/api/src/db/index.ts) (Database access), [`apps/api/src/services/embeddings.ts`](https://github.com/safwanhasan120/synapse/blob/main/apps/api/src/services/embeddings.ts) (Embeddings and semantic search), [`apps/api/src/middleware/auth.ts`](https://github.com/safwanhasan120/synapse/blob/main/apps/api/src/middleware/auth.ts) (JWT authorization)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and identity"]
  node_app["HTTP application<br/>[app.ts]"]
  node_auth["GitHub authentication<br/>[auth.ts]"]
  node_authmw["JWT authorization<br/>[auth.ts]"]
  node_teams["Teams and projects<br/>[teams.ts]"]
  node_config["Runtime configuration<br/>[config.ts]"]
  node_logger["HTTP logging<br/>[logger.ts]"]
  node_errors["Error handling<br/>[error.ts]"]
  node_shared["Shared types<br/>[index.ts]"]
end

subgraph group_knowledge["Knowledge lifecycle"]
  node_context["Context unit workflow<br/>[context-units.ts]"]
  node_search["Search endpoint<br/>[search.ts]"]
  node_embed["Embeddings and semantic search<br/>[embeddings.ts]"]
end

subgraph group_storage["Persistence and search"]
  node_db["Database access<br/>[index.ts]"]
  node_postgres[("PostgreSQL")]
end

subgraph group_clients["Product clients"]
  node_web["Web interface"]
  node_webapi["Web API client<br/>[api.ts]"]
  node_mcp["MCP server<br/>[index.ts]"]
end

node_user(("Team user"))
node_openai{{"OpenAI embeddings"}}

node_user -->|"uses"| node_web
node_user -.->|"uses"| node_mcp
node_web -.->|"calls"| node_webapi
node_webapi -.->|"requests"| node_app
node_user -->|"authenticates"| node_app
node_app -->|"routes to"| node_auth
node_app -->|"routes to"| node_teams
node_app -->|"routes to"| node_search
node_app -->|"routes to"| node_context
node_app -->|"logs requests"| node_logger
node_app -->|"handles errors"| node_errors
node_auth -->|"redirects browser"| node_user
node_auth -->|"reads and writes"| node_db
node_auth -->|"protects profile"| node_authmw
node_teams -->|"requires token"| node_authmw
node_context -->|"requires token"| node_authmw
node_search -->|"requires token"| node_authmw
node_teams -->|"reads and writes"| node_db
node_context -->|"reads and writes"| node_db
node_search -->|"checks access"| node_db
node_context -->|"embeds approved unit"| node_embed
node_search -->|"searches semantically"| node_embed
node_embed -->|"requests vectors"| node_openai
node_embed -->|"stores and searches vectors"| node_db
node_db -->|"queries"| node_postgres
node_db -->|"reads connection settings"| node_config
node_authmw -->|"reads JWT secret"| node_config
node_logger -->|"reads log settings"| node_config
node_errors -->|"logs failures"| node_logger
node_embed -->|"logs embedding status"| node_logger

click node_app "https://github.com/safwanhasan120/synapse/blob/main/apps/api/src/app.ts"
click node_auth "https://github.com/safwanhasan120/synapse/blob/main/apps/api/src/routes/auth.ts"
click node_authmw "https://github.com/safwanhasan120/synapse/blob/main/apps/api/src/middleware/auth.ts"
click node_teams "https://github.com/safwanhasan120/synapse/blob/main/apps/api/src/routes/teams.ts"
click node_context "https://github.com/safwanhasan120/synapse/blob/main/apps/api/src/routes/context-units.ts"
click node_search "https://github.com/safwanhasan120/synapse/blob/main/apps/api/src/routes/search.ts"
click node_embed "https://github.com/safwanhasan120/synapse/blob/main/apps/api/src/services/embeddings.ts"
click node_db "https://github.com/safwanhasan120/synapse/blob/main/apps/api/src/db/index.ts"
click node_config "https://github.com/safwanhasan120/synapse/blob/main/apps/api/src/config.ts"
click node_logger "https://github.com/safwanhasan120/synapse/blob/main/apps/api/src/middleware/logger.ts"
click node_errors "https://github.com/safwanhasan120/synapse/blob/main/apps/api/src/middleware/error.ts"
click node_web "https://github.com/safwanhasan120/synapse/tree/main/apps/web/src/app"
click node_webapi "https://github.com/safwanhasan120/synapse/blob/main/apps/web/src/lib/api.ts"
click node_mcp "https://github.com/safwanhasan120/synapse/blob/main/apps/mcp-server/src/index.ts"
click node_shared "https://github.com/safwanhasan120/synapse/blob/main/packages/shared/src/index.ts"

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_auth,node_authmw,node_teams,node_config,node_logger,node_errors,node_shared,node_user toneBlue
class node_context,node_search,node_embed toneAmber
class node_db,node_postgres toneMint
class node_web,node_webapi,node_mcp toneRose
class node_openai toneIndigo
```

## Components

### API and identity

- [HTTP application](https://github.com/safwanhasan120/synapse/blob/main/apps/api/src/app.ts): `apps/api/src/app.ts`
- [GitHub authentication](https://github.com/safwanhasan120/synapse/blob/main/apps/api/src/routes/auth.ts): `apps/api/src/routes/auth.ts`
- [JWT authorization](https://github.com/safwanhasan120/synapse/blob/main/apps/api/src/middleware/auth.ts): `apps/api/src/middleware/auth.ts`
- [Teams and projects](https://github.com/safwanhasan120/synapse/blob/main/apps/api/src/routes/teams.ts): `apps/api/src/routes/teams.ts`
- [Runtime configuration](https://github.com/safwanhasan120/synapse/blob/main/apps/api/src/config.ts): `apps/api/src/config.ts`
- [HTTP logging](https://github.com/safwanhasan120/synapse/blob/main/apps/api/src/middleware/logger.ts): `apps/api/src/middleware/logger.ts`
- [Error handling](https://github.com/safwanhasan120/synapse/blob/main/apps/api/src/middleware/error.ts): `apps/api/src/middleware/error.ts`
- [Shared types](https://github.com/safwanhasan120/synapse/blob/main/packages/shared/src/index.ts): `packages/shared/src/index.ts`

### Knowledge lifecycle

- [Context unit workflow](https://github.com/safwanhasan120/synapse/blob/main/apps/api/src/routes/context-units.ts): `apps/api/src/routes/context-units.ts`
- [Search endpoint](https://github.com/safwanhasan120/synapse/blob/main/apps/api/src/routes/search.ts): `apps/api/src/routes/search.ts`
- [Embeddings and semantic search](https://github.com/safwanhasan120/synapse/blob/main/apps/api/src/services/embeddings.ts): `apps/api/src/services/embeddings.ts`

### Persistence and search

- [Database access](https://github.com/safwanhasan120/synapse/blob/main/apps/api/src/db/index.ts): `apps/api/src/db/index.ts`
- **PostgreSQL**

### Product clients

- [Web interface](https://github.com/safwanhasan120/synapse/tree/main/apps/web/src/app): `apps/web/src/app`
- [Web API client](https://github.com/safwanhasan120/synapse/blob/main/apps/web/src/lib/api.ts): `apps/web/src/lib/api.ts`
- [MCP server](https://github.com/safwanhasan120/synapse/blob/main/apps/mcp-server/src/index.ts): `apps/mcp-server/src/index.ts`

### Other components

- **Team user**
- **OpenAI embeddings**

## Connections

- Team user → Web interface: uses (evidence: `apps/web/src/app/page.tsx`)
- Team user → MCP server: uses
- Web interface → Web API client: calls
- Web API client → HTTP application: requests
- Team user → HTTP application: authenticates
- HTTP application → GitHub authentication: routes to (evidence: `apps/api/src/app.ts`)
- HTTP application → Teams and projects: routes to (evidence: `apps/api/src/app.ts`)
- HTTP application → Search endpoint: routes to (evidence: `apps/api/src/app.ts`)
- HTTP application → Context unit workflow: routes to (evidence: `apps/api/src/app.ts`)
- HTTP application → HTTP logging: logs requests (evidence: `apps/api/src/app.ts`)
- HTTP application → Error handling: handles errors (evidence: `apps/api/src/app.ts`)
- GitHub authentication → Team user: redirects browser (evidence: `apps/api/src/routes/auth.ts`)
- GitHub authentication → Database access: reads and writes (evidence: `apps/api/src/routes/auth.ts`)
- GitHub authentication → JWT authorization: protects profile (evidence: `apps/api/src/routes/auth.ts`)
- Teams and projects → JWT authorization: requires token (evidence: `apps/api/src/routes/teams.ts`)
- Context unit workflow → JWT authorization: requires token (evidence: `apps/api/src/routes/context-units.ts`)
- Search endpoint → JWT authorization: requires token (evidence: `apps/api/src/routes/search.ts`)
- Teams and projects → Database access: reads and writes (evidence: `apps/api/src/routes/teams.ts`)
- Context unit workflow → Database access: reads and writes (evidence: `apps/api/src/routes/context-units.ts`)
- Search endpoint → Database access: checks access (evidence: `apps/api/src/routes/search.ts`)
- Context unit workflow → Embeddings and semantic search: embeds approved unit (evidence: `apps/api/src/routes/context-units.ts`)
- Search endpoint → Embeddings and semantic search: searches semantically (evidence: `apps/api/src/routes/search.ts`)
- Embeddings and semantic search → OpenAI embeddings: requests vectors (evidence: `apps/api/src/services/embeddings.ts`)
- Embeddings and semantic search → Database access: stores and searches vectors (evidence: `apps/api/src/services/embeddings.ts`)
- Database access → PostgreSQL: queries (evidence: `apps/api/src/db/index.ts`)
- Database access → Runtime configuration: reads connection settings (evidence: `apps/api/src/db/index.ts`)
- JWT authorization → Runtime configuration: reads JWT secret (evidence: `apps/api/src/middleware/auth.ts`)
- HTTP logging → Runtime configuration: reads log settings (evidence: `apps/api/src/middleware/logger.ts`)
- Error handling → HTTP logging: logs failures (evidence: `apps/api/src/middleware/error.ts`)
- Embeddings and semantic search → HTTP logging: logs embedding status (evidence: `apps/api/src/services/embeddings.ts`)
