# datapeopleconnected/buttress-js architecture

> Architecture diagram of the GitHub repository datapeopleconnected/buttress-js, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/datapeopleconnected/buttress-js
- Repository: https://github.com/datapeopleconnected/buttress-js

## Overview

##### Main System Components

a) Core Services Layer:
- REST API Server (from app.sh)
- WebSocket Server (from app-socket.sh)
- Lambda Function Runner (from app-lambda.sh)

b) Data Layer:
- Multiple Datastore Adapters:
- MongoDB Adapter
- Buttress Adapter
- Empty Adapter
- Secure Store Component

c) Access Control Layer:
- Policy Management
- Conditions Handler
- Filtering System
- Projection System

d) Model Layer:
- Core Models (User, App, Token, etc.)
- Type System (Remote/Standard Types)

##### Component Relationships

a) External Interfaces:
- REST API Endpoints (→ Core Services)
- WebSocket Connections (→ Real-time Service)
- Lambda Function Endpoints (→ Lambda Runner)

b) Internal Flow:
- Access Control Layer ↔ Core Services
- Core Services ↔ Model Layer
- Model Layer ↔ Data Layer

##### Specific Implementation Details

Technical elements:

a) Service Communication:
- Federation capabilities between instances
- Data sharing pathways
- Real-time event propagation

b) Security Layer:
- Policy enforcement points
- Token validation flow
- Secure store interactions

**┌─ Client Layer ─────────────────────────┐**
- REST │ WebSocket │ Lambda │
- Access Control Layer ─────────────────┤
- Policies │ Conditions │ Filters │
- Core Services ────────────────────────┤
- REST API │ Socket Server │ Lambda Runner│
- Model Layer ──────────────────────────┤
- Core Models │ Type System │
- Data Layer ───────────────────────────┤
- MongoDB │ Buttress │ Empty │
- ┘

##### Important Notes

- Modular nature of the datastore adapters
- Federation capabilities between different ButtressJS instances
- Real-time aspects of the system
- Lambda execution environment isolation
- Schema-based routing system

## Diagram (Mermaid)

```mermaid
graph TB
    %% Client Layer
    subgraph Client
        REST[REST Client]:::client
        WS[WebSocket Client]:::client
        Lambda[Lambda Client]:::client
    end

    %% Access Control Layer
    subgraph AccessControl
        Policy["Policy Management"]:::security
        Conditions["Conditions Handler"]:::security
        Filters["Filtering System"]:::security
        Projections["Projection System"]:::security
    end

    %% Core Services Layer
    subgraph CoreServices
        APIServer["REST API Server"]:::service
        SocketServer["WebSocket Server"]:::service
        LambdaRunner["Lambda Function Runner"]:::service
    end

    %% Model Layer
    subgraph Models
        CoreModels["Core Models"]:::model
        TypeSystem["Type System"]:::model
        RemoteTypes["Remote Types"]:::model
        StandardTypes["Standard Types"]:::model
    end

    %% Data Layer
    subgraph DataLayer
        MongoDB["MongoDB Adapter"]:::database
        ButtressDB["Buttress Adapter"]:::database
        EmptyDB["Empty Adapter"]:::database
        SecureStore["Secure Store"]:::security
    end

    %% Relationships
    REST --> APIServer
    WS --> SocketServer
    Lambda --> LambdaRunner

    APIServer & SocketServer & LambdaRunner --> Policy
    Policy --> Conditions
    Policy --> Filters
    Policy --> Projections

    APIServer & SocketServer & LambdaRunner --> CoreModels
    CoreModels --> TypeSystem
    TypeSystem --> RemoteTypes
    TypeSystem --> StandardTypes

    CoreModels --> MongoDB & ButtressDB & EmptyDB
    CoreModels --> SecureStore

    %% Click Events
    click APIServer "https://github.com/datapeopleconnected/buttress-js/blob/main/src/bin/app.ts"
    click SocketServer "https://github.com/datapeopleconnected/buttress-js/blob/main/src/bin/app-socket.ts"
    click LambdaRunner "https://github.com/datapeopleconnected/buttress-js/blob/main/src/lambda/lambda-runner.ts"
    click MongoDB "https://github.com/datapeopleconnected/buttress-js/blob/main/src/datastore/adapters/mongodb.ts"
    click ButtressDB "https://github.com/datapeopleconnected/buttress-js/blob/main/src/datastore/adapters/buttress.ts"
    click EmptyDB "https://github.com/datapeopleconnected/buttress-js/blob/main/src/datastore/adapters/empty.ts"
    click SecureStore "https://github.com/datapeopleconnected/buttress-js/blob/main/src/model/core/secure-store.ts"
    click Policy "https://github.com/datapeopleconnected/buttress-js/blob/main/src/access-control/policy-match.ts"
    click Conditions "https://github.com/datapeopleconnected/buttress-js/blob/main/src/access-control/conditions.ts"
    click Filters "https://github.com/datapeopleconnected/buttress-js/blob/main/src/access-control/filter.ts"
    click Projections "https://github.com/datapeopleconnected/buttress-js/blob/main/src/access-control/projection.ts"
    click CoreModels "https://github.com/datapeopleconnected/buttress-js/tree/main/src/model/core/"
    click TypeSystem "https://github.com/datapeopleconnected/buttress-js/tree/main/src/model/type/"
    click RemoteTypes "https://github.com/datapeopleconnected/buttress-js/blob/main/src/model/type/remote.ts"
    click StandardTypes "https://github.com/datapeopleconnected/buttress-js/blob/main/src/model/type/standard.ts"

    %% Styles
    classDef client fill:#2374ab
    classDef security fill:#ff4d4d
    classDef service fill:#4CAF50
    classDef model fill:#9C27B0
    classDef database fill:#FFA726

    %% Legend
    subgraph Legend
        Client1[Client Interface]:::client
        Security1[Security Component]:::security
        Service1[Core Service]:::service
        Model1[Model Component]:::model
        DB1[Database]:::database
    end
```
