# knowii-oss/knowii architecture

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

- Interactive diagram: https://gitdiagram.com/knowii-oss/knowii
- Repository: https://github.com/knowii-oss/knowii

## Overview

##### Main Components

a. Frontend Layer:
- React-based SPA (located in /apps/knowii)
- Key frontend modules:
- Authentication components
- Community management
- Resource management
- Profile management

b. Backend Layer:
- Laravel-based API (/app directory)
- Key modules:
- API Controllers (/app/Http/Controllers/API)
- Actions (/app/Actions)
- Models (/app/Models)
- Events system (/app/Events)

c. Database Layer:
- Supports multiple databases (MySQL/MariaDB/PostgreSQL)
- Key entities:
- Users
- Communities
- Resources
- ResourceCollections
- TextArticles

d. External Services:
- Email service (for invitations)
- Browserless service (indicated by browserless scripts)

##### Architecture Patterns to Highlight

- MVC pattern in the Laravel backend
- Demonstrate the Action pattern (/app/Actions)
- Event-driven architecture (/app/Events)
- Repository pattern for data access
- API-first design with versioning

##### Specific Elements

a. Client Side:
- Frontend components:
- Pages
- Components
- API client interface
- State management

b. Server Side:
- API Gateway layer
- Authentication middleware
- Business logic layer (Actions)
- Data access layer
- Event system

c. Data Flow:
- API request/response flow
- Event broadcasting
- Real-time updates
- Authentication flow

##### Integration Points

- API endpoints (/api/v1)
- Authentication mechanisms (both token and cookie-based)
- WebSocket connections for real-time features
- External service integrations

##### Security Layer
- Token-based authentication
- Cookie-based authentication
- CSRF protection
- API security middleware

**[Frontend Layer (React SPA)]**
- ↕
**[API Gateway Layer]**
- ↕
**[Business Logic Layer]**
- ↕
**[Data Access Layer]**
- ↕
**[Database Layer]**

- Blue: Frontend components
- Green: API/Backend services
- Yellow: Database components
- Red: Security components
- Purple: External services

- Component relationships
- Authentication flows
- Data flow directions
- Security boundaries
- External service integration points

Keep the abstraction level high enough to show the overall architecture while including enough detail to understand the system's core functionality around knowledge management, communities, and resources.

Remember to highlight the scalability aspects with the containerized architecture (Docker) and the separation of concerns between different services.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef backend fill:#2ecc71,stroke:#27ae60,color:white
    classDef database fill:#f1c40f,stroke:#f39c12,color:black
    classDef security fill:#e74c3c,stroke:#c0392b,color:white
    classDef external fill:#9b59b6,stroke:#8e44ad,color:white

    %% Frontend Layer
    subgraph Frontend
        SPA["React SPA"]:::frontend
        AuthComp["Authentication Components"]:::frontend
        CommComp["Community Management"]:::frontend
        ResComp["Resource Management"]:::frontend
        ProfComp["Profile Management"]:::frontend
        
        SPA --> AuthComp
        SPA --> CommComp
        SPA --> ResComp
        SPA --> ProfComp
    end

    %% API Gateway Layer
    subgraph APIGateway
        APIControllers["API Controllers"]:::backend
        APIMiddleware["API Security Middleware"]:::security
        APIAuth["Authentication Layer"]:::security
    end

    %% Business Logic Layer
    subgraph BusinessLogic
        Actions["Business Logic Actions"]:::backend
        Events["Events System"]:::backend
        ResourceActions["Resource Actions"]:::backend
    end

    %% Data Access Layer
    subgraph DataAccess
        Models["Data Models"]:::backend
        Repositories["Repositories"]:::backend
    end

    %% Database Layer
    subgraph Database
        DB[(Database)]:::database
        Migrations["Migrations"]:::database
        Factories["Database Factories"]:::database
    end

    %% External Services
    subgraph ExternalServices
        EmailService["Email Service"]:::external
        Browserless["Browserless Service"]:::external
    end

    %% Connections
    Frontend --> APIGateway
    APIGateway --> BusinessLogic
    BusinessLogic --> DataAccess
    DataAccess --> Database
    BusinessLogic --> ExternalServices

    %% Click Events
    click SPA "https://github.com/knowii-oss/knowii/tree/main/apps/knowii/src"
    click AuthComp "https://github.com/knowii-oss/knowii/tree/main/apps/knowii/src/Pages/Auth"
    click CommComp "https://github.com/knowii-oss/knowii/tree/main/apps/knowii/src/Components/Communities"
    click ResComp "https://github.com/knowii-oss/knowii/tree/main/apps/knowii/src/Components/Resources"
    click ProfComp "https://github.com/knowii-oss/knowii/tree/main/apps/knowii/src/Pages/Profile"
    click APIControllers "https://github.com/knowii-oss/knowii/tree/main/app/Http/Controllers/API"
    click Actions "https://github.com/knowii-oss/knowii/tree/main/app/Actions"
    click Events "https://github.com/knowii-oss/knowii/tree/main/app/Events"
    click Models "https://github.com/knowii-oss/knowii/tree/main/app/Models"
    click Migrations "https://github.com/knowii-oss/knowii/tree/main/database/migrations"
    click Factories "https://github.com/knowii-oss/knowii/tree/main/database/factories"
    click EmailService "https://github.com/knowii-oss/knowii/tree/main/app/Mail"
    click Browserless "https://github.com/knowii-oss/knowii/blob/main/browserless-create-container.sh"
    click APIAuth "https://github.com/knowii-oss/knowii/tree/main/app/Actions/Fortify"
    click APIMiddleware "https://github.com/knowii-oss/knowii/tree/main/app/Http/Middleware"
    click ResourceActions "https://github.com/knowii-oss/knowii/tree/main/app/Actions/Resources"

    %% Legend
    subgraph Legend
        Frontend_L["Frontend Component"]:::frontend
        Backend_L["Backend Component"]:::backend
        Database_L["Database Component"]:::database
        Security_L["Security Component"]:::security
        External_L["External Service"]:::external
    end
```
