# norri/rust-examples architecture

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

- Interactive diagram: https://gitdiagram.com/norri/rust-examples
- Repository: https://github.com/norri/rust-examples

## Overview

##### axum-postgres System Design

- HTTP Server Layer (Axum Framework)
- Domain Layer
- Data Access Layer
- PostgreSQL Database

b. Internal Structure:
- Server Component:
- Routes (/server/routes.rs)
- Handlers (todos_create, todos_list, todos_update, todos_delete)
- Extractors (auth_basic, request_json)
- OpenAPI Documentation

- Domain Layer:
- Todo Domain Logic
- Error Handling
- Common Types

- Data Sources:
- PostgreSQL Implementation
- Memory Database (for testing)
- Database Models

c. Flow Directions:
- HTTP requests flow from client → server → domain → data layer → database
- Error handling flow back through the layers

##### axum-prometheus System Design

a. Main Components:
- Axum Web Server
- Prometheus Metrics Collector
- Prometheus Server
- Grafana Dashboard

b. Monitoring Flow:
- Metrics Collection Path
- Data Scraping Flow
- Visualization Pipeline

##### Key Relationships to Highlight

For axum-postgres:
- Authentication flow through extractors
- CRUD operations flow for todos
- Database abstraction layer with both Postgres and in-memory implementations
- Migration handling

For axum-prometheus:
- Metrics collection points
- Prometheus scraping endpoints
- Grafana dashboard data flow

##### Technical Details

Annotations showing:
- Technology stack: Rust, Axum, PostgreSQL
- Key dependencies and versions
- Configuration sources
- Docker container boundaries
- Network ports and protocols

##### Deployment Context

A separate deployment view showing:
- Docker container organization
- Network isolation
- Volume mounts
- Service discovery

Remember to:
- Use consistent styling and naming
- Version information
- Document any assumptions or constraints

This architecture should emphasize the clean separation of concerns in both examples while showing how they implement different aspects of modern web service architecture: one focusing on data persistence and API design, the other on observability and monitoring.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph RustExamples["Rust Examples Collection"]
        direction TB
        
        subgraph AxumPostgres["Axum Postgres Example"]
            direction TB
            
            subgraph ServerLayer["HTTP Server Layer"]
                Routes["Routes Handler"]:::server
                Handlers["CRUD Handlers"]:::server
                Auth["Authentication Extractors"]:::server
                OpenAPI["OpenAPI Documentation"]:::server
            end
            
            subgraph DomainLayer["Domain Layer"]
                TodoLogic["Todo Domain Logic"]:::domain
                ErrorHandling["Error Handling"]:::domain
                CommonTypes["Common Types"]:::domain
            end
            
            subgraph DataLayer["Data Access Layer"]
                DataAccess["Data Access Interface"]:::data
                PostgresImpl["PostgreSQL Implementation"]:::data
                MemoryImpl["Memory Database"]:::data
                DBModels["Database Models"]:::data
                Migrations["Database Migrations"]:::data
            end
            
            DB[(PostgreSQL Database)]:::database
        end
        
        subgraph AxumPrometheus["Axum Prometheus Example"]
            direction TB
            
            MetricsCollector["Metrics Collector"]:::monitoring
            MetricsRoutes["Metrics Routes"]:::monitoring
            PrometheusServer{{"Prometheus Server"}}:::external
            GrafanaDashboard{{"Grafana Dashboard"}}:::external
            PrometheusConfig["Prometheus Config"]:::config
            GrafanaDashboards["Grafana Dashboards"]:::config
        end
    end
    
    %% Relationships
    Routes --> Handlers
    Handlers --> Auth
    Handlers --> TodoLogic
    TodoLogic --> DataAccess
    DataAccess --> PostgresImpl
    DataAccess --> MemoryImpl
    PostgresImpl --> DB
    MemoryImpl --> DBModels
    PostgresImpl --> DBModels
    
    MetricsRoutes --> MetricsCollector
    MetricsCollector --> PrometheusServer
    PrometheusServer --> GrafanaDashboard
    PrometheusConfig --> PrometheusServer
    GrafanaDashboards --> GrafanaDashboard
    
    %% Styles
    classDef server fill:#2374ab
    classDef domain fill:#48a9a6
    classDef data fill:#4ea5d9
    classDef database fill:#44cf6c
    classDef monitoring fill:#e4a0ae
    classDef external fill:#cccccc
    classDef config fill:#e8dab2
    
    %% Click Events
    click Routes "https://github.com/norri/rust-examples/blob/main/axum-postgres/app/src/server/routes.rs"
    click Handlers "https://github.com/norri/rust-examples/tree/main/axum-postgres/app/src/server/handlers/"
    click Auth "https://github.com/norri/rust-examples/tree/main/axum-postgres/app/src/server/extractors/"
    click OpenAPI "https://github.com/norri/rust-examples/blob/main/axum-postgres/app/src/server/openapi.rs"
    click DomainLayer "https://github.com/norri/rust-examples/tree/main/axum-postgres/app/src/server/domain/"
    click DataLayer "https://github.com/norri/rust-examples/tree/main/axum-postgres/app/src/datasources/"
    click DBModels "https://github.com/norri/rust-examples/blob/main/axum-postgres/app/src/datasources/database/models.rs"
    click PostgresImpl "https://github.com/norri/rust-examples/blob/main/axum-postgres/app/src/datasources/database/postgres_db.rs"
    click MemoryImpl "https://github.com/norri/rust-examples/blob/main/axum-postgres/app/src/datasources/database/memory_db.rs"
    click Migrations "https://github.com/norri/rust-examples/tree/main/axum-postgres/app/migrations/"
    click MetricsCollector "https://github.com/norri/rust-examples/blob/main/axum-prometheus/app/src/metrics.rs"
    click PrometheusConfig "https://github.com/norri/rust-examples/blob/main/axum-prometheus/prometheus/prometheus.yml"
    click GrafanaDashboards "https://github.com/norri/rust-examples/tree/main/axum-prometheus/grafana/provisioning/dashboards/"
    click MetricsRoutes "https://github.com/norri/rust-examples/blob/main/axum-prometheus/app/src/routes.rs"
```
