# afnanlabs/afnkit-core architecture

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

- Interactive diagram: https://gitdiagram.com/afnanlabs/afnkit-core
- Repository: https://github.com/afnanlabs/afnkit-core

## Overview

Afnkit is a typed, Express-inspired HTTP framework built on Node.js HTTP. An application created through the public factory accepts middleware and method-specific routes, listens for requests, and dispatches each request through ordered middleware and matching route handlers to a response. Error handlers and terminal handling produce deliberate error responses. The graph focuses on the TypeScript implementation; the chapter directories are tutorial references, not runtime subsystems. Relationships reflect the sampled source and README; unsampled details are not expanded.

Main entry points: [`src/application/application.ts`](https://github.com/afnanlabs/afnkit-core/blob/master/src/application/application.ts) (Application), [`src/router/router.ts`](https://github.com/afnanlabs/afnkit-core/blob/master/src/router/router.ts) (Router), [`src/router/layer.ts`](https://github.com/afnanlabs/afnkit-core/blob/master/src/router/layer.ts) (Handler Layer), [`src/errors/final-handler.ts`](https://github.com/afnanlabs/afnkit-core/blob/master/src/errors/final-handler.ts) (Final Handler)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Application API"]
  node_express["express Factory<br/>[index.ts]"]
  node_application["Application<br/>[application.ts]"]
  node_middleware["Middleware Setup<br/>[init.ts]"]
end

subgraph group_dispatch["Request Dispatch"]
  node_router["Router<br/>[router.ts]"]
  node_route["Route Handlers<br/>[route.ts]"]
  node_layer["Handler Layer<br/>[layer.ts]"]
end

subgraph group_http["HTTP Extensions"]
  node_request["Request Extensions<br/>[request.ts]"]
  node_response["Response Helpers<br/>[response.ts]"]
end

subgraph group_errors["Error Handling"]
  node_errorhandler["Error Middleware<br/>[layer.ts]"]
  node_http_error["HttpError<br/>[http-error.ts]"]
  node_final["Final Handler<br/>[final-handler.ts]"]
end

node_developer(("Application Developer"))
node_nodehttp["Node HTTP Server"]

node_developer -->|"creates app"| node_express
node_express -->|"creates"| node_application
node_developer -->|"registers routes"| node_application
node_application -->|"registers and dispatches"| node_router
node_application -->|"installs"| node_middleware
node_application -->|"extends prototype"| node_request
node_application -->|"extends prototype"| node_response
node_application -->|"creates server"| node_nodehttp
node_nodehttp -->|"passes requests"| node_application
node_router -->|"dispatches matching"| node_route
node_router -->|"runs layers"| node_layer
node_route -->|"dispatches handlers"| node_layer
node_layer -->|"runs error handlers"| node_errorhandler
node_router -->|"finishes unmatched"| node_final
node_router -->|"signals method mismatch"| node_http_error
node_final -->|"formats status"| node_http_error
node_errorhandler -.->|"forwards errors"| node_final

click node_express "https://github.com/afnanlabs/afnkit-core/blob/master/src/index.ts"
click node_application "https://github.com/afnanlabs/afnkit-core/blob/master/src/application/application.ts"
click node_middleware "https://github.com/afnanlabs/afnkit-core/blob/master/src/middleware/init.ts"
click node_router "https://github.com/afnanlabs/afnkit-core/blob/master/src/router/router.ts"
click node_route "https://github.com/afnanlabs/afnkit-core/blob/master/src/router/route.ts"
click node_layer "https://github.com/afnanlabs/afnkit-core/blob/master/src/router/layer.ts"
click node_request "https://github.com/afnanlabs/afnkit-core/blob/master/src/request/request.ts"
click node_response "https://github.com/afnanlabs/afnkit-core/blob/master/src/response/response.ts"
click node_errorhandler "https://github.com/afnanlabs/afnkit-core/blob/master/src/router/layer.ts"
click node_http_error "https://github.com/afnanlabs/afnkit-core/blob/master/src/errors/http-error.ts"
click node_final "https://github.com/afnanlabs/afnkit-core/blob/master/src/errors/final-handler.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_express,node_application,node_middleware toneBlue
class node_router,node_route,node_layer toneAmber
class node_request,node_response,node_nodehttp toneMint
class node_errorhandler,node_http_error,node_final toneRose
class node_developer toneIndigo
```

## Components

### Application API

- [express Factory](https://github.com/afnanlabs/afnkit-core/blob/master/src/index.ts): `src/index.ts`
- [Application](https://github.com/afnanlabs/afnkit-core/blob/master/src/application/application.ts): `src/application/application.ts`
- [Middleware Setup](https://github.com/afnanlabs/afnkit-core/blob/master/src/middleware/init.ts): `src/middleware/init.ts`

### Request Dispatch

- [Router](https://github.com/afnanlabs/afnkit-core/blob/master/src/router/router.ts): `src/router/router.ts`
- [Route Handlers](https://github.com/afnanlabs/afnkit-core/blob/master/src/router/route.ts): `src/router/route.ts`
- [Handler Layer](https://github.com/afnanlabs/afnkit-core/blob/master/src/router/layer.ts): `src/router/layer.ts`

### HTTP Extensions

- [Request Extensions](https://github.com/afnanlabs/afnkit-core/blob/master/src/request/request.ts): `src/request/request.ts`
- [Response Helpers](https://github.com/afnanlabs/afnkit-core/blob/master/src/response/response.ts): `src/response/response.ts`

### Error Handling

- [Error Middleware](https://github.com/afnanlabs/afnkit-core/blob/master/src/router/layer.ts): `src/router/layer.ts`
- [HttpError](https://github.com/afnanlabs/afnkit-core/blob/master/src/errors/http-error.ts): `src/errors/http-error.ts`
- [Final Handler](https://github.com/afnanlabs/afnkit-core/blob/master/src/errors/final-handler.ts): `src/errors/final-handler.ts`

### Other components

- **Application Developer**
- **Node HTTP Server**

## Connections

- Application Developer → express Factory: creates app (evidence: `README.md`)
- express Factory → Application: creates (evidence: `src/index.ts`)
- Application Developer → Application: registers routes (evidence: `README.md`)
- Application → Router: registers and dispatches (evidence: `src/application/application.ts`)
- Application → Middleware Setup: installs (evidence: `src/application/application.ts`)
- Application → Request Extensions: extends prototype (evidence: `src/application/application.ts`)
- Application → Response Helpers: extends prototype (evidence: `src/application/application.ts`)
- Application → Node HTTP Server: creates server (evidence: `src/application/application.ts`)
- Node HTTP Server → Application: passes requests (evidence: `src/application/application.ts`)
- Router → Route Handlers: dispatches matching (evidence: `src/router/router.ts`)
- Router → Handler Layer: runs layers (evidence: `src/router/router.ts`)
- Route Handlers → Handler Layer: dispatches handlers (evidence: `src/router/route.ts`)
- Handler Layer → Error Middleware: runs error handlers (evidence: `src/router/layer.ts`)
- Router → Final Handler: finishes unmatched (evidence: `src/router/router.ts`)
- Router → HttpError: signals method mismatch (evidence: `src/router/router.ts`)
- Final Handler → HttpError: formats status (evidence: `src/errors/final-handler.ts`)
- Error Middleware → Final Handler: forwards errors
