Skip to content

Commit 9422cd7

Browse files
committed
docs: standardize and enhance READMEs for all crates
1 parent 45ab57a commit 9422cd7

12 files changed

Lines changed: 304 additions & 511 deletions

File tree

crates/cargo-rustapi/README.md

Lines changed: 37 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,61 @@
11
# cargo-rustapi
22

3-
The official CLI tool for the RustAPI framework. Scaffold new projects, run development servers, and manage database migrations.
3+
**The official CLI tool for the RustAPI framework.**
44

5-
## Installation
5+
Use this tool to scaffold new projects, generate code, and fast-track your development workflow.
66

7-
`ash
7+
## 📦 Installation
8+
9+
```bash
810
cargo install cargo-rustapi
9-
`
11+
```
1012

11-
## Features
13+
## 🛠️ Usage
1214

13-
- **Project Scaffolding**: Create new projects with
14-
ew command, choosing from templates like pi, web, or ull.
15-
- **Development Server**: Run your project with un command, supporting hot-reloading (via cargo-watch integration if available).
16-
- **Code Generation**: Generate handlers, models, and CRUD operations with generate.
17-
- **Database Management**: (Planned) Simple wrappers around migration tools.
15+
### Creating a New Project
1816

19-
## Usage
17+
Use the `new` command to generate a project structure.
2018

21-
### Create a New Project
19+
```bash
20+
# Interactive mode (Recommended)
21+
cargo rustapi new my-app
2222

23-
`ash
24-
# Interactive mode
25-
cargo rustapi new my-project
23+
# Quick start with specific template
24+
cargo rustapi new my-app --template api
25+
```
2626

27-
# With template
28-
cargo rustapi new my-project --template api
27+
**Available Templates:**
28+
- `minimal`: Basic `main.rs` and `Cargo.toml`.
29+
- `api`: REST API structure with separated `handlers` and `models`.
30+
- `web`: Web application with HTML templates (`rustapi-view`).
31+
- `full`: Complete example with Database, Auth, and Docker support.
2932

30-
# With features
31-
cargo rustapi new my-project --features jwt,cors
32-
`
33+
### Running Development Server
3334

34-
### Run Development Server
35+
Run your application with hot-reloading (requires `cargo-watch`).
3536

36-
`ash
37-
# Run with auto-reload
37+
```bash
3838
cargo rustapi run
39+
```
3940

40-
# Run on specific port
41-
cargo rustapi run --port 8080
42-
`
41+
### Code Generation
4342

44-
### Generate Code
43+
Save time by generating boilerplate.
4544

46-
`ash
47-
# Generate a new handler
45+
```bash
46+
# Generate a handler function and register it
4847
cargo rustapi generate handler users
4948

50-
# Generate a model
49+
# Generate a database model
5150
cargo rustapi generate model User
5251

53-
# Generate CRUD endpoints (Handlers + Models + Tests)
54-
cargo rustapi generate crud users
55-
`
56-
57-
## Templates
58-
59-
- minimal: Bare bones setup.
60-
- pi: REST API structure with handlers and models.
61-
- web: Includes ustapi-view and emplates folder.
62-
- ull: Complete setup with Auth, DB (SQLx), and more.
52+
# Generate a full CRUD resource (Model + Handlers + Tests)
53+
cargo rustapi generate crud product
54+
```
6355

64-
## License
56+
### Managing Migrations (Planned)
6557

66-
MIT OR Apache-2.0
58+
```bash
59+
cargo rustapi migrate run
60+
cargo rustapi migrate revert
61+
```

crates/rustapi-core/README.md

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,37 @@
11
# RustAPI Core
22

3-
The core engine for the RustAPI framework.
3+
**The internal engine of the RustAPI framework.**
44

5-
> **Note**: This is an internal crate. You should depend on `rustapi-rs` instead.
5+
> ⚠️ **Warning**: Most users should depend on `rustapi-rs` instead of using this crate directly. This crate's API is subject to change to support the higher-level facade.
66
7-
## Responsibilities
7+
## Overview
88

9-
- **HTTP Server**: Wraps `hyper` 1.0.
10-
- **Routing**: Implements radix-tree routing via `matchit`.
11-
- **Glue Code**: Connects extractors, handlers, and responses.
12-
- **Middleware Integration**: Provides `tower` compatibility (internal).
9+
`rustapi-core` handles the low-level HTTP mechanics, leveraging the best-in-class Rust async ecosystem:
1310

14-
## Architecture
11+
- **Hyper 1.0**: For robust, correct HTTP/1 and HTTP/2 implementation.
12+
- **Matchit**: For extremely fast URL routing (radix tree based).
13+
- **Tower**: For middleware composition (Service, Layer).
14+
- **Tokio**: For the async runtime.
1515

16-
This crate provides the `RustApi` builder and the `Handler` trait system that powers the framework's ergonomics.
16+
## Key Concepts
17+
18+
### The `RustApi` Builder
19+
Responsible for assembling routes, middleware, and starting the Hyper server.
20+
21+
### The `Handler` Trait
22+
The magic that allows functions with arbitrary arguments (extractors) to be used as request handlers.
23+
24+
```rust
25+
// This function...
26+
async fn my_handler(Json(body): Json<MyData>) -> impl Responder { ... }
27+
28+
// ...is converted into a Tower Service via the Handler trait.
29+
```
30+
31+
### Extractors
32+
`FromRequest` and `FromRequestParts` traits are defined here. They allow type-safe extraction of data from HTTP requests.
33+
34+
- `Json<T>`
35+
- `Query<T>`
36+
- `Path<T>`
37+
- `State<T>`

crates/rustapi-extras/README.md

Lines changed: 25 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,48 @@
1-
# rustapi-extras
1+
# RustAPI Extras
22

3-
Optional security and utility features for the RustAPI framework.
3+
**Production-ready middleware and utilities for RustAPI.**
44

5-
## Features
5+
This crate provides optional "batteries" that you can enable to build robust applications.
66

7-
This crate provides production-ready middleware and utilities that are opt-in via Cargo feature flags to minimize binary size when not needed.
7+
## Feature Flags
88

9-
### Available Features
9+
Enable these in your `Cargo.toml`.
1010

11-
- `jwt` - JWT authentication middleware and `AuthUser<T>` extractor
12-
- `cors` - CORS middleware with builder pattern configuration
13-
- `rate-limit` - IP-based rate limiting middleware
14-
- `config` - Configuration management with `.env` file support
15-
- `cookies` - Cookie parsing extractor
16-
- `extras` - Meta feature enabling jwt, cors, and rate-limit
17-
- `full` - All features enabled
11+
| Feature | Description | Dependencies |
12+
|---------|-------------|--------------|
13+
| `jwt` | JSON Web Token authentication extractor & middleware | `jsonwebtoken` |
14+
| `cors` | Cross-Origin Resource Sharing middleware | `tower-http` |
15+
| `rate-limit` | IP-based rate limiting | `governor` / `dashmap` |
16+
| `sqlx` | Database integration helpers | `sqlx` |
17+
| `config` | Typed configuration loading from env/files | `config`, `dotenvy` |
18+
| `otel` | OpenTelemetry observability integration | `opentelemetry` |
1819

19-
## Usage
20-
21-
Add to your `Cargo.toml`:
22-
23-
```toml
24-
[dependencies]
25-
rustapi-extras = { version = "0.1", features = ["jwt", "cors"] }
26-
```
27-
28-
## Examples
20+
## Usage Examples
2921

3022
### JWT Authentication
3123

3224
```rust
33-
use rustapi_extras::jwt::{JwtLayer, AuthUser};
34-
use serde::Deserialize;
25+
use rustapi_rs::prelude::*;
26+
use rustapi_extras::jwt::{JwtAuth, AuthUser};
3527

36-
#[derive(Deserialize)]
28+
#[derive(Serialize, Deserialize)]
3729
struct Claims {
3830
sub: String,
39-
exp: u64,
31+
exp: usize,
4032
}
4133

42-
async fn protected(AuthUser(claims): AuthUser<Claims>) -> String {
43-
format!("Hello, {}", claims.sub)
34+
#[get("/protected")]
35+
async fn protected_route(auth: AuthUser<Claims>) -> impl Responder {
36+
format!("Hello user {}", auth.sub)
4437
}
4538
```
4639

47-
### CORS Configuration
40+
### CORS
4841

4942
```rust
5043
use rustapi_extras::cors::CorsLayer;
51-
use http::Method;
5244

53-
let cors = CorsLayer::new()
54-
.allow_origins(["https://example.com"])
55-
.allow_methods([Method::GET, Method::POST])
56-
.allow_credentials(true);
45+
RustApi::new()
46+
.layer(CorsLayer::permissive())
47+
// ...
5748
```
58-
59-
### Rate Limiting
60-
61-
```rust
62-
use rustapi_extras::rate_limit::RateLimitLayer;
63-
use std::time::Duration;
64-
65-
// Allow 100 requests per minute per IP
66-
let rate_limit = RateLimitLayer::new(100, Duration::from_secs(60));
67-
```
68-
69-
## License
70-
71-
Licensed under either of Apache License, Version 2.0 or MIT license at your option.

crates/rustapi-jobs/README.md

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,37 @@
11
# RustAPI Jobs
22

3-
Robust background job processing for the RustAPI framework.
3+
**Background job processing for RustAPI.**
44

5-
## Features
5+
Offload heavy tasks (emails, report generation, webhooks) to background workers.
66

7-
- **Multiple Backends**: Support for Redis and PostgreSQL backends.
8-
- **Reliable Processing**: At-least-once delivery guarantees.
9-
- **Retries**: Configurable retry policies with exponential backoff.
10-
- **Scheduled Tasks**: Cron-like scheduling for recurring jobs.
11-
- **Async Processing**: Fully async/await based on Tokio.
7+
## Key Features
128

13-
## Usage
9+
- **Backend Agnostic**: Drivers for **Redis** (recommended for speed) and **PostgreSQL** (for transactional reliability).
10+
- **At-Least-Once Delivery**: Jobs are not lost if a worker crashes.
11+
- **Retries**: Configurable exponential backoff policies.
12+
- **Scheduling**: Cron-like recurring tasks.
1413

15-
Add to your `Cargo.toml`:
16-
17-
```toml
18-
[dependencies]
19-
rustapi-jobs = { version = "0.1", features = ["redis"] }
20-
```
21-
22-
### Defining a Job
14+
## Quick Start
2315

2416
```rust
2517
use rustapi_jobs::{Job, JobContext};
26-
use serde::{Serialize, Deserialize};
2718

2819
#[derive(Serialize, Deserialize)]
29-
struct EmailJob {
20+
struct SendEmail {
3021
to: String,
31-
subject: String,
32-
body: String,
22+
content: String,
3323
}
3424

3525
#[async_trait]
36-
impl Job for EmailJob {
26+
impl Job for SendEmail {
3727
const NAME: &'static str = "send_email";
3828

39-
async fn run(&self, _ctx: JobContext) -> Result<(), Error> {
40-
// Send email...
29+
async fn run(&self, _ctx: JobContext) -> Result<()> {
30+
// Send the email...
4131
Ok(())
4232
}
4333
}
44-
```
45-
46-
### Enqueueing Jobs
4734

48-
```rust
49-
let queue = RedisQueue::new("redis://localhost:6379").await?;
50-
queue.push(EmailJob {
51-
to: "user@example.com".to_string(),
52-
subject: "Welcome!".to_string(),
53-
body: "Hello...".to_string(),
54-
}).await?;
35+
// Enqueue
36+
queue.push(SendEmail { ... }).await?;
5537
```

crates/rustapi-macros/README.md

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,38 @@
11
# RustAPI Macros
22

3-
Internal procedural macros for the RustAPI framework.
3+
**Procedural macros that power the RustAPI developer experience.**
44

5-
> **Note**: This is an internal crate. You should depend on `rustapi-rs` instead.
5+
> ℹ️ **Note**: These macros are re-exported by `rustapi-rs`. You do not need to add this crate manually.
66
7-
## Features
7+
## Attribute Macros
88

9-
- `#[rustapi::main]`: Async runtime entry point.
10-
- `#[rustapi::get]`: GET handler definition.
11-
- `#[rustapi::post]`: POST handler definition.
12-
- `#[rustapi::put]`: PUT handler definition.
13-
- `#[rustapi::patch]`: PATCH handler definition.
14-
- `#[rustapi::delete]`: DELETE handler definition.
15-
- `#[rustapi::tag]`: OpenAPI tag metadata.
16-
- `#[rustapi::summary]`: OpenAPI summary metadata.
17-
- `#[rustapi::description]`: OpenAPI description metadata.
9+
### `#[rustapi::main]`
10+
Replaces `#[tokio::main]`. Sets up the runtime, tracing subscriber, and other framework essentials.
1811

19-
## Usage
12+
### HTTP Method Handlers
13+
Registers a function as a route handler.
2014

21-
These are automatically exported via the `rustapi` prefix when using `rustapi-rs`.
15+
- `#[rustapi::get("/users/{id}")]`
16+
- `#[rustapi::post("/users")]`
17+
- `#[rustapi::put("/users/{id}")]`
18+
- `#[rustapi::delete("/users/{id}")]`
19+
- `#[rustapi::patch("/users/{id}")]`
20+
- `#[rustapi::head("/health")]`
21+
- `#[rustapi::options("/cors")]`
2222

23-
```rust
24-
use rustapi_rs::prelude::*;
23+
### OpenAPI Metadata
24+
Enrich your auto-generated documentation.
2525

26-
#[rustapi::get("/hello")]
27-
#[rustapi::summary("Hello Endpoint")]
28-
async fn hello() -> &'static str {
29-
"Hello World"
30-
}
31-
```
26+
- `#[rustapi::tag("Auth")]`: Groups endpoints.
27+
- `#[rustapi::summary("Logs in a user")]`: Brief summary.
28+
- `#[rustapi::description("Full markdown description...")]`: Detailed docs.
29+
30+
## Derive Macros
31+
32+
### `#[derive(Schema)]`
33+
Generates a JSON Schema for the struct, used by `rustapi-openapi`.
34+
*Wraps `utoipa::ToSchema` via `rustapi-openapi` integration.*
35+
36+
### `#[derive(Validate)]`
37+
Generates validation logic.
38+
*Wraps `validator::Validate` via `rustapi-validate` integration.*

0 commit comments

Comments
 (0)