# grip-framework/grip architecture

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

- Interactive diagram: https://gitdiagram.com/grip-framework/grip
- Repository: https://github.com/grip-framework/grip

## Overview

##### Project Type and Purpose
- This is a Crystal-based “microframework” for building RESTful and WebSocket applications. Think of it as analogous to Express.js or Phoenix but in Crystal. Its goal is to provide:
- A request/response context object
- A pipeline of middleware (“pipes”)
- A router that dispatches to controller actions
- Built-in exception handling, parameter parsing, JSON serialization, WebSocket support

##### File Structure
- Top level
- shard.yml → dependency definition
- .github, LICENSE, README, specs folder → CI, tests, docs
- src/grip/
- application.cr → application bootstrap
- controllers/ → HTTP + WebSocket controller definitions
- handlers/ → pipeline handlers (logging, routing, exception catchers)
- middleware/ → context-modifying middleware components
- parsers/ → file upload, parameter extraction
- exceptions/ → HTTP exception types & factory
- extensions/ → core-type and Context extensions
- helpers/, support/, macros/ → DSL methods, routing macro, file downloads, singleton helpers, i18n, mime types
- minuscule/ → error pages for development
- version.cr → version metadata

##### Extract Insights from the README
- Emphasizes modularity and speed
- Pipeline architecture (“pipes”) to manipulate Context
- Router inspired by Phoenix’s DSL (scope, get/post, named routes)
- HTTP 1.1 & WebSocket RFC6455 support built in

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Server & Application Layer
    subgraph "Server & Application" 
        direction TB
        Server["HTTP/WebSocket Server"]:::server
        AppBootstrap["Application Bootstrap"]:::server
        Application["Application"]:::server
    end

    %% Pipeline Handlers & Middleware
    subgraph "Handler Pipeline" 
        direction TB
        LogHandler["Log Handler"]:::pipeline
        subgraph "Middleware Chain"
            direction TB
            ClientIP["Client IP Middleware"]:::pipeline
            PoweredBy["PoweredByGrip Middleware"]:::pipeline
        end
        ExceptionHandler["Exception Handler"]:::exception
        RouteHandler["Routing Handler"]:::pipeline
        WebSocketHandler["WebSocket Handler"]:::pipeline
    end

    %% Router & Controllers
    subgraph "Router & Controllers"
        direction TB
        RouterDSL["Router DSL"]:::router
        subgraph "Controllers"
            direction TB
            HTTPControllers["HTTP Controllers"]:::router
            WSControllers["WebSocket Controllers"]:::router
        end
    end

    %% Parsers, Extensions, Helpers, Support
    subgraph "Utilities & Extensions"
        direction TB
        subgraph Parsers
            direction TB
            FileUpload["File Upload Parser"]:::utils
            ParamBox["ParameterBox Parser"]:::utils
        end
        subgraph Extensions
            direction TB
            ContextExt["Context Extension"]:::utils
            StringExt["String Extension"]:::utils
            NumberExt["Number Extension"]:::utils
            ResponseExt["Response Extension"]:::utils
        end
        subgraph Helpers
            direction TB
            FileDownload["File Download Helper"]:::utils
            Singleton["Singleton Helper"]:::utils
        end
        subgraph Support
            direction TB
            MimeTypes["MIME Types"]:::utils
            LocaleFmt["Locale Formatting"]:::utils
        end
    end

    %% Error Pages & Version & JSON
    subgraph "Exception Pages & Metadata"
        direction TB
        Minuscule["Minuscule Error Page"]:::exception
        Version["Version Metadata"]:::utils
        JSONSer["JSON Serializer"]:::utils
    end

    %% Flow connections
    Server -->|"receive request"| AppBootstrap
    AppBootstrap -->|"bootstrap app"| Application
    Application -->|"run pipeline"| LogHandler
    LogHandler --> ClientIP
    ClientIP --> PoweredBy
    PoweredBy --> ExceptionHandler
    ExceptionHandler --> RouteHandler
    RouteHandler --> WebSocketHandler
    RouteHandler -->|"dispatch via DSL"| RouterDSL
    RouterDSL --> HTTPControllers
    RouterDSL --> WSControllers
    HTTPControllers -->|"parse params"| ParamBox
    HTTPControllers --> FileUpload
    HTTPControllers --> FileDownload
    HTTPControllers --> ContextExt
    HTTPControllers --> StringExt
    HTTPControllers --> NumberExt
    HTTPControllers --> Singleton
    HTTPControllers --> MimeTypes
    HTTPControllers --> LocaleFmt
    HTTPControllers --> JSONSer
    WSControllers -->|"parse handshake"| ParamBox
    WSControllers --> WebSocketHandler
    ExceptionHandler --> Minuscule
    JSONSer -->|"serialize response"| Server

    %% Click events
    click Server "https://github.com/grip-framework/grip/blob/core/src/grip/application.cr"
    click AppBootstrap "https://github.com/grip-framework/grip/blob/core/src/grip.cr"
    click LogHandler "https://github.com/grip-framework/grip/blob/core/src/grip/handlers/log.cr"
    click ClientIP "https://github.com/grip-framework/grip/blob/core/src/grip/middleware/client_ip.cr"
    click PoweredBy "https://github.com/grip-framework/grip/blob/core/src/grip/middleware/powered_by_grip.cr"
    click ExceptionHandler "https://github.com/grip-framework/grip/blob/core/src/grip/handlers/exception.cr"
    click RouteHandler "https://github.com/grip-framework/grip/blob/core/src/grip/handlers/route.cr"
    click WebSocketHandler "https://github.com/grip-framework/grip/blob/core/src/grip/handlers/websocket.cr"
    click RouterDSL "https://github.com/grip-framework/grip/blob/core/src/grip/macros/dsl.cr"
    click HTTPControllers "https://github.com/grip-framework/grip/blob/core/src/grip/controllers/http.cr"
    click WSControllers "https://github.com/grip-framework/grip/blob/core/src/grip/controllers/websocket.cr"
    click FileUpload "https://github.com/grip-framework/grip/blob/core/src/grip/parsers/file_upload.cr"
    click ParamBox "https://github.com/grip-framework/grip/blob/core/src/grip/parsers/parameter_box.cr"
    click ContextExt "https://github.com/grip-framework/grip/blob/core/src/grip/extensions/context.cr"
    click StringExt "https://github.com/grip-framework/grip/blob/core/src/grip/extensions/string.cr"
    click NumberExt "https://github.com/grip-framework/grip/blob/core/src/grip/extensions/number.cr"
    click ResponseExt "https://github.com/grip-framework/grip/blob/core/src/grip/extensions/response.cr"
    click FileDownload "https://github.com/grip-framework/grip/blob/core/src/grip/helpers/file_download.cr"
    click Singleton "https://github.com/grip-framework/grip/blob/core/src/grip/helpers/singleton.cr"
    click MimeTypes "https://github.com/grip-framework/grip/blob/core/src/grip/support/mime_types.cr"
    click LocaleFmt "https://github.com/grip-framework/grip/blob/core/src/grip/support/locale_format.cr"
    click Minuscule "https://github.com/grip-framework/grip/blob/core/src/grip/minuscule/exception_page.cr"
    click Version "https://github.com/grip-framework/grip/blob/core/src/grip/version.cr"

    %% Styles
    classDef server fill:#cce5ff,stroke:#004085,color:#004085
    classDef pipeline fill:#d4edda,stroke:#155724,color:#155724
    classDef router fill:#ffe5b4,stroke:#ff8c00,color:#8b4513
    classDef utils fill:#e2e3e5,stroke:#6c757d,color:#383d41
    classDef exception fill:#f8d7da,stroke:#721c24,color:#721c24
```
