# venopyx/apispark architecture

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

- Interactive diagram: https://gitdiagram.com/venopyx/apispark
- Repository: https://github.com/venopyx/apispark

## Overview

##### Main Components

A. Core Framework Layer
- FastAPI Base (as the foundation)
- ApiSpark Core (main application container)

B. Authentication Module
- API Key Authentication
- Basic Authentication
- JWT Authentication
- OAuth2 Authentication

C. Middleware Layer
- Logging Middleware
- Rate Limiting Middleware
- Secure Header Middleware

D. Supporting Components
- Router Management
- Exception Handling
- Utility Helpers

**┌─────────────────────────────────────────────────────┐**
- Client Applications                 │
- ┘
- ↓
**┌─────────────────────────────────────────────────────┐**
- Middleware Layer                    │
- ┌─────────────┐  ┌──────────────┐  ┌───────────┐  │
- Logging   │  │Rate Limiting  │  │  Secure   │  │
- Middleware │  │  Middleware   │  │  Headers  │  │
- ┘  └──────────────┘  └───────────┘  │
- ┘
- ↓
**┌─────────────────────────────────────────────────────┐**
- Authentication Layer                   │
- ┌─────────┐  ┌────────┐  ┌─────┐  ┌──────────┐   │
- API Key │  │ Basic  │  │ JWT │  │ OAuth2   │   │
- Auth   │  │  Auth  │  │Auth │  │  Auth    │   │
- ┘  └────────┘  └─────┘  └──────────┘   │
- ┘
- ↓
**┌─────────────────────────────────────────────────────┐**
- Router Layer                      │
- (Request Routing and Endpoint Handling)      │
- ┘
- ↓
**┌─────────────────────────────────────────────────────┐**
- Exception Handler Layer               │
- (Centralized Error Handling System)         │
- ┘
- ↓
**┌─────────────────────────────────────────────────────┐**
- FastAPI Core                    │
- ┘

##### Important Elements to Highlight

a. Flow Direction:
- Request flow from client through each layer
- Response flow back through the layers

b. Component Interactions:
- How authentication modules interact with the core
- Middleware chain execution order
- Demonstrate exception handling flow

c. Extension Points:
- Where future features (from README) could be integrated
- Potential integration points for databases and admin panels

##### Technical Details

- FastAPI dependency
- Python version compatibility
- Authentication flow specifics
- Middleware execution order
- Exception handling patterns

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client["Client Applications"]
        CA[Client Apps]
    end

    subgraph Middleware["Middleware Layer"]
        LM["Logging Middleware"]:::middleware
        RL["Rate Limiting Middleware"]:::middleware
        SH["Secure Headers Middleware"]:::middleware
    end

    subgraph Auth["Authentication Layer"]
        AK["API Key Auth"]:::auth
        BA["Basic Auth"]:::auth
        JA["JWT Auth"]:::auth
        OA["OAuth2 Auth"]:::auth
    end

    subgraph Router["Router Layer"]
        RM["Router Management"]:::router
    end

    subgraph Exception["Exception Handler Layer"]
        EH["Exception Handler"]:::exception
    end

    subgraph Core["Core Framework Layer"]
        FC["FastAPI Core"]:::core
        AC["ApiSpark Core"]:::core
    end

    %% Connections
    CA --> LM
    LM --> RL
    RL --> SH
    SH --> AK
    
    AK --> BA
    BA --> JA
    JA --> OA
    OA --> RM
    
    RM --> EH
    EH --> AC
    AC --> FC

    %% Click Events
    click LM "https://github.com/venopyX/apispark/blob/main/apispark/middleware/logging_middleware.py"
    click RL "https://github.com/venopyX/apispark/blob/main/apispark/middleware/rate_limiting_middleware.py"
    click SH "https://github.com/venopyX/apispark/blob/main/apispark/middleware/secure_header_middleware.py"
    click AK "https://github.com/venopyX/apispark/blob/main/apispark/auth/api_key_auth.py"
    click BA "https://github.com/venopyX/apispark/blob/main/apispark/auth/basic_auth.py"
    click JA "https://github.com/venopyX/apispark/blob/main/apispark/auth/jwt_auth.py"
    click OA "https://github.com/venopyX/apispark/blob/main/apispark/auth/oauth2_auth.py"
    click RM "https://github.com/venopyX/apispark/blob/main/apispark/routers/router.py"
    click EH "https://github.com/venopyX/apispark/blob/main/apispark/exceptions/exception_handler.py"
    click AC "https://github.com/venopyX/apispark/blob/main/apispark/app.py"

    %% Styles
    classDef core fill:#3498db,stroke:#2980b9,color:white
    classDef auth fill:#2ecc71,stroke:#27ae60,color:white
    classDef middleware fill:#e67e22,stroke:#d35400,color:white
    classDef router fill:#f1c40f,stroke:#f39c12,color:black
    classDef exception fill:#e74c3c,stroke:#c0392b,color:white

    %% Legend
    subgraph Legend
        L1["Core Components"]:::core
        L2["Authentication"]:::auth
        L3["Middleware"]:::middleware
        L4["Routing"]:::router
        L5["Exception Handling"]:::exception
    end
```
