# cot-rs/cot architecture

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

- Interactive diagram: https://gitdiagram.com/cot-rs/cot
- Repository: https://github.com/cot-rs/cot

## Overview

##### Project type and purpose
- From the README and file tree, this is a batteries-included Rust web framework (“Cot”), modeled after Django, built on top of axum.
- It ships as:
- A CLI tool (`cot-cli`) that scaffolds new projects and generates migrations,
- A codegen crate (`cot-codegen`) and a set of procedural macros (`cot-macros`) for compile-time code generation,
- The core runtime library (`cot/`) which implements HTTP routing, ORM, template rendering, admin panel, middleware, etc.

##### File structure
- Top-level workspace with four main members:
- `cot-cli/` – CLI app and project templates
- `cot-codegen/` – code-generation utilities (model, symbol resolution, AST)
- `cot-macros/` – procedural macros for deriving models, queries, handlers, admin, form, main_fn
- `cot/` – core web framework (HTTP, router, middleware, ORM, templates, admin UI)
- There are shared config files (Cargo.toml, CI, lint, compose.yml), example apps under `examples/`, and tests everywhere.
- The core runtime (`cot/src`) subdivides into modules: `router`, `request`, `response`, `db` (drivers, migrations, queries), `auth`, `form`, `openapi`, `middleware`, `error_page`, `static_files`, `session`, `templates`, etc.

##### README for additional insights
- Built on axum (so HTTP server uses tokio + hyper under the hood).
- ORM is integrated with automatic migrations.
- Admin panel, templates, static file serving all included by default.

## Diagram (Mermaid)

```mermaid
flowchart TD
  subgraph "Build & Codegen"
    A1["Developer CLI: cot-cli"] 
    A2["Project Templates"]
    A3["cot-codegen"]
    A4["cot-macros"]
  end

  subgraph "Runtime (cot core + App)"
    B1["HTTP Server\n(axum/tokio)"]
    B2["Router & Handlers"]
    B3["Middleware\n(auth, sessions, errors)"]
    B4["ORM + Migrations"]
    B5["Database Drivers\n(Postgres/MySQL/SQLite)"]
    B6["Template Engine\n& Admin UI"]
    B7["Static File Server"]
  end

  subgraph "External Systems"
    C1["Browser / API Client"]
    C2["Database"]
  end

  %% Build-time flows
  A1 -->|"cot new"| A2
  A1 -->|"compilation"| A3
  A3 -->|"codegen"| B2
  A4 -->|"procedural macros"| B2

  %% Runtime flows
  C1 -->|"HTTP Request"| B1
  B1 --> B2
  B2 --> B3
  B2 --> B4
  B4 --> B5
  B5 --> C2
  C2 --> B5
  B2 --> B6
  C1 --> B7

  %% Click Events
  click A1 "https://github.com/cot-rs/cot/tree/master/cot-cli/"
  click A2 "https://github.com/cot-rs/cot/tree/master/cot-cli/src/project_template/"
  click A3 "https://github.com/cot-rs/cot/tree/master/cot-codegen/"
  click A4 "https://github.com/cot-rs/cot/tree/master/cot-macros/"
  click B1 "https://github.com/cot-rs/cot/blob/master/cot/src/lib.rs"
  click B2 "https://github.com/cot-rs/cot/blob/master/cot/src/router.rs"
  click B3 "https://github.com/cot-rs/cot/blob/master/cot/src/middleware.rs"
  click B4 "https://github.com/cot-rs/cot/blob/master/cot/src/db.rs"
  click B5 "https://github.com/cot-rs/cot/tree/master/cot/src/db/"
  click B6 "https://github.com/cot-rs/cot/blob/master/cot/src/admin.rs"
  click B7 "https://github.com/cot-rs/cot/blob/master/cot/src/static_files.rs"

  %% Classes
  class A1,A2,A3,A4 build;
  class B1,B2,B3,B4,B5,B6,B7 runtime;
  class C1,C2 external;

  %% Styles
  classDef build fill:#D0E8FF,stroke:#3A7ECF;
  classDef runtime fill:#DFF7D8,stroke:#449944;
  classDef external fill:#FFE4B5,stroke:#CC8400;
```
