Files
asepharyana-hub-llm-api/src/presentation/router.rs
T
asepharyanaandClaude Code e351d74fa4 refactor(llm-api): implement clean architecture following scraper pattern
Split monolithic 1012-line main.rs into layered hexagonal architecture:
- Domain: entity types and LlmError enum
- Application: prompt building, sampler construction, tool call parsing
- Infrastructure: LlamaEngine wrapping llama-cpp-2 with isolated unsafe transmute
- Presentation: Axum handlers, middleware (auth), error chain, router
- Config: type-safe AppConfig with LazyLock
- Bootstrap: Application struct with build() + run()

Resolves build_sampler/build_sampler_params duplication.
Adds simple web chat UI at GET /.

Co-Authored-By: Claude Code <noreply@anthropic.com>
2026-07-25 15:07:19 +07:00

28 lines
909 B
Rust

//! Axum router assembly.
use std::sync::Arc;
use axum::middleware;
use axum::routing::{get, post};
use axum::Router;
use tower_http::cors::CorsLayer;
use super::handler::{chat, chat_ui, health, models};
use crate::presentation::middleware::auth::auth_middleware;
use crate::presentation::state::AppState;
/// Build the main application router with all routes and middleware.
pub fn build_router(state: Arc<AppState>) -> Router {
Router::new()
// Public routes (no auth)
.route("/", get(chat_ui::chat_ui))
.route("/health", get(health::health_check))
.route("/v1/models", get(models::list_models))
// Chat completions (auth-protected)
.route("/v1/chat/completions", post(chat::chat_completions))
.route_layer(middleware::from_fn(auth_middleware))
// Global middleware
.layer(CorsLayer::permissive())
.with_state(state)
}