$ show cot-rs/cot
Cot is a batteries-included web framework for Rust, heavily inspired by Django. It provides a full-stack application architecture with an ORM (SQLite, PostgreSQL, MySQL), automatic migration generation, an admin panel, form handling with validation, session management (multiple backends including file, database, Redis), caching (in-memory, Redis), email sending (console, SMTP), OpenAPI/Swagger documentation generation, static file serving, and a CLI for project scaffolding and migration management. The framework is built on top of tokio, axum, sea-query, sqlx, and tower, using trait-based designs and an extensive set of procedural macros (e.g., `#[model]`, `#[Form]`, `#[AdminModel]`, `#[IntoResponse]`, `query!`, `#[cot::main]`) to reduce boilerplate. Architecturally, Cot uses a type-safe phased bootstrapper (the `Bootstrapper` with six states from `Uninitialized` to `Initialized`) to configure the project in a guaranteed order. The central `Project` and `App` traits define the application composition, while the `Router` (trie-based) supports nested routing and reverse URL generation. The ORM layer features a query expression builder, migration engine with dependency-aware rollback, and backend-specific implementations. The macro system (`cot-macros` + `cot-codegen`) performs compile-time code generation for models, forms, queries, and admin interfaces, with UI compile-fail tests to validate error messages. The codebase demonstrates high craftsmanship with well-separated concerns, extensive test coverage (unit, integration, snapshot, UI compile-fail, and end-to-end WebDriver tests), and reusable patterns such as composable response modifiers, builder-pattern configuration, and a custom serde deserializer for path parameters. While the framework is relatively new and some features like workspace migration generation are incomplete, it is actively maintained with frequent releases and a healthy CI/CD pipeline.
The LLM identified 5 files worth highlighting for reuse:
Implements a phased type-state bootstrap pattern where the Bootstrapper struct uses generics sealed by a `BootstrapPhase` trait to represent six distinct states (Uninitialized, WithConfig, WithApps, WithDatabase, WithCache, Initialized). Each state transition consumes self and produces a new Bootstrapper with the next phase type, preventing access to uninitialized resources at compile time. This pattern is reusable in any application that requires a guaranteed initialization order of services.
Defines the `IntoResponse` trait with a set of composable modifier methods (`with_header`, `with_content_type`, `with_status`, `with_body`, `with_extension`) that each return a wrapper type implementing `IntoResponse`. This enables ergonomic, method-chain construction of HTTP responses without a full builder struct. The pattern is reusable in any Rust HTTP framework and demonstrates non-obvious use of newtype wrapping and trait implementations.
Implements a custom `serde::Deserializer` that extracts typed values from URL path parameters (a `HashMap<String, String>`). Supports deserializing into structs, tuples, maps, and enums, handling missing fields and type mismatches with proper error reporting. This is a non-trivial example of building a serde deserializer from scratch, reusable for any scenario where query/path parameters need typed extraction without an external library.
Provides the `sort_migrations` function that uses `petgraph`'s topological sort to order migration operations respecting foreign key dependencies. It also implements a `remove_cycles` function using a feedback arc set heuristic to break cycles in migration dependencies. This is a standalone, well-tested graph algorithm component that could be extracted for any domain requiring dependency-ordered execution with cycle resolution.
Implements a strongly-typed expression DSL for building SQL-like queries in Rust, including field references (`FieldRef<T>`), comparisons (`ExprEq`), ordering (`ExprOrd`), arithmetic (`ExprAdd/Sub/Mul/Div`), and string pattern matching (`ExprLike` with `contains`, `starts_with`, `ends_with`, `raw_like`). Each expression type carries phantom type parameters for compile-time type safety. The design is a clean example of a typed expression builder pattern reusable for any embedded DSL.