Skip to content

Commit 1c83874

Browse files
committed
improve: code clean up
1 parent 23f80f2 commit 1c83874

File tree

8 files changed

+309
-146
lines changed

8 files changed

+309
-146
lines changed

CONTRIBUTING.md

Lines changed: 24 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,42 @@
11
# Contributing to InferaDB
22

3-
Thank you for your interest in contributing to [InferaDB](https://inferadb.com)! We welcome contributions from the community and are grateful for any help you can provide.
3+
We welcome contributions! By participating, you agree to uphold the [Code of Conduct](CODE_OF_CONDUCT.md).
44

5-
## Code of Conduct
5+
## Reporting Issues
66

7-
This project and everyone participating in it is governed by the [Contributor Covenant Code of Conduct](CODE_OF_CONDUCT.md). By participating, you are expected to uphold this code. Please report unacceptable behavior to [open@inferadb.com](mailto:open@inferadb.com).
7+
- **Bugs**: Search existing issues first. Include version, steps to reproduce, expected vs actual behavior.
8+
- **Features**: Describe the use case and proposed solution.
9+
- **Security**: Email [security@inferadb.com](mailto:security@inferadb.com) — do not open public issues.
810

9-
## How to Contribute
11+
## Pull Requests
1012

11-
### Reporting Issues
13+
1. Fork and branch from `main`
14+
2. Run `just ci` to verify tests, linting, and formatting pass
15+
3. Follow [Conventional Commits](https://www.conventionalcommits.org/) for commit messages
16+
4. Update documentation if changing public APIs
17+
5. Submit PR with clear description
1218

13-
- **Bug Reports**: Search existing issues first to avoid duplicates. Include version information, steps to reproduce, expected vs actual behavior, and relevant logs.
14-
- **Feature Requests**: Describe the use case, proposed solution, and alternatives considered.
15-
- **Security Issues**: Do **not** open public issues for security vulnerabilities. Instead, email [security@inferadb.com](mailto:security@inferadb.com).
19+
## Development
1620

17-
### Pull Requests
21+
```bash
22+
mise trust && mise install # Setup tooling
23+
just ci # Run all checks before submitting
24+
```
1825

19-
1. **Fork the repository** and create your branch from `main`
20-
2. **Follow the development workflow** documented in the repository's [README.md](README.md)
21-
3. **Write clear commit messages** following [Conventional Commits](https://www.conventionalcommits.org/)
22-
4. **Ensure all tests pass** before submitting
23-
5. **Update documentation** if your changes affect public APIs or user-facing behavior
24-
6. **Submit a pull request** with a clear description of your changes
25-
26-
### Development Setup
27-
28-
Each repository has its own development setup and workflow. See the repository's [README.md](README.md) for prerequisites, build commands, and development workflow.
26+
See [README.md](README.md) for full development setup.
2927

3028
## Review Process
3129

32-
1. **Automated Checks**: CI will run tests, linters, and formatters
33-
2. **Peer Review**: At least one maintainer will review your contribution
34-
3. **Feedback**: Address any review comments
35-
4. **Approval**: Once approved, a maintainer will merge your contribution
30+
1. CI runs automated checks
31+
2. Maintainer reviews code
32+
3. Address feedback
33+
4. Maintainer merges on approval
3634

3735
## License
3836

39-
By contributing to [InferaDB](https://github.com/inferadb), you agree that your contributions will be dual-licensed under:
40-
41-
- [Apache License, Version 2.0](LICENSE-APACHE)
42-
- [MIT License](LICENSE-MIT)
37+
Contributions are dual-licensed under [MIT](LICENSE-MIT) and [Apache 2.0](LICENSE-APACHE).
4338

4439
## Questions?
4540

46-
If you have questions or need help:
47-
48-
- Join our [Discord server](https://discord.gg/inferadb) to chat with the community
49-
- Email us at [open@inferadb.com](mailto:open@inferadb.com)
50-
51-
Thank you for helping make InferaDB better!
41+
- [Discord](https://discord.gg/inferadb)
42+
- [open@inferadb.com](mailto:open@inferadb.com)

README.md

Lines changed: 29 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,10 @@ mise trust && mise install
2121
cargo run --bin inferadb-control
2222
```
2323

24-
Register and login:
25-
26-
```bash
27-
# Register
28-
curl -X POST http://localhost:9090/v1/auth/register \
29-
-H "Content-Type: application/json" \
30-
-d '{"email": "alice@example.com", "password": "securepass123", "name": "Alice"}'
31-
32-
# Login
33-
curl -X POST http://localhost:9090/v1/auth/login/password \
34-
-H "Content-Type: application/json" \
35-
-d '{"email": "alice@example.com", "password": "securepass123"}'
36-
```
37-
3824
| Endpoint | URL |
3925
| -------- | ------------------------------- |
4026
| REST API | `http://localhost:9090` |
4127
| gRPC API | `http://localhost:9091` |
42-
| Mesh API | `http://localhost:9092` |
4328
| Health | `http://localhost:9090/healthz` |
4429
| Metrics | `http://localhost:9090/metrics` |
4530

@@ -53,18 +38,6 @@ curl -X POST http://localhost:9090/v1/auth/login/password \
5338
| **Client Auth** | Ed25519 certificates, JWT assertions |
5439
| **Token Issuance** | Vault-scoped JWTs for Engine API |
5540

56-
## Key Concepts
57-
58-
| Entity | Description |
59-
| ------------ | --------------------------------------------- |
60-
| User | Account with auth methods (password, passkey) |
61-
| Organization | Workspace with members and roles |
62-
| Vault | Authorization policy container |
63-
| Client | Service identity with Ed25519 certs |
64-
| Team | Group-based vault access |
65-
66-
**Auth Flow:** User → Session → Vault access → JWT → Engine API
67-
6841
## Architecture
6942

7043
```mermaid
@@ -78,84 +51,48 @@ graph TD
7851
SharedStorage --> Memory[(Memory)]
7952
SharedStorage --> StorageLedger[inferadb-storage-ledger]
8053
StorageLedger --> Ledger[(InferaDB Ledger)]
81-
Core --> Engine[inferadb-control-engine-client]
8254
```
8355

84-
| Crate | Purpose |
85-
| ------------------------------ | ------------------------------ |
86-
| inferadb-control | Binary entrypoint |
87-
| inferadb-control-api | REST/gRPC handlers |
88-
| inferadb-control-config | Configuration loading |
89-
| inferadb-control-const | Shared constants |
90-
| inferadb-control-core | Business logic, entities |
91-
| inferadb-control-storage | Repositories + storage factory |
92-
| inferadb-control-types | Shared type definitions |
93-
| inferadb-control-engine-client | Engine API client |
94-
95-
### Shared Storage Crates
96-
97-
| Crate | Purpose |
98-
| ----------------------- | -------------------------------------------- |
99-
| inferadb-storage | Generic StorageBackend trait + MemoryBackend |
100-
| inferadb-storage-ledger | Ledger-backed StorageBackend implementation |
56+
| Crate | Purpose |
57+
| ------------------------ | ------------------------------ |
58+
| inferadb-control | Binary entrypoint |
59+
| inferadb-control-api | REST/gRPC handlers |
60+
| inferadb-control-config | Configuration loading |
61+
| inferadb-control-const | Shared constants |
62+
| inferadb-control-core | Business logic, entities |
63+
| inferadb-control-storage | Repositories + storage factory |
64+
| inferadb-control-types | Shared type definitions |
10165

10266
## Configuration
10367

104-
```yaml
105-
control:
106-
listen:
107-
http: "0.0.0.0:9090"
108-
grpc: "0.0.0.0:9091"
109-
mesh: "0.0.0.0:9092"
110-
111-
# Storage: "memory" (dev) or "ledger" (production)
112-
storage: "ledger"
113-
114-
# Ledger configuration (requires --features ledger)
115-
ledger:
116-
endpoint: "http://ledger.inferadb:50051"
117-
client_id: "control-prod-001"
118-
namespace_id: 1
119-
vault_id: 1 # optional
120-
121-
webauthn:
122-
party: "localhost"
123-
origin: "http://localhost:9090"
124-
```
125-
126-
### Environment Variables
127-
12868
Environment variables use `INFERADB_CTRL__` prefix with double underscores for nesting:
12969

130-
| Variable | Description | Example |
131-
| ------------------------------------- | -------------------------- | --------------------- |
132-
| `INFERADB_CTRL__LISTEN__HTTP` | HTTP listen address | `0.0.0.0:9090` |
133-
| `INFERADB_CTRL__STORAGE` | Storage backend | `ledger` |
134-
| `INFERADB_CTRL__LEDGER__ENDPOINT` | Ledger server URL | `http://ledger:50051` |
135-
| `INFERADB_CTRL__LEDGER__CLIENT_ID` | Client ID for idempotency | `control-001` |
136-
| `INFERADB_CTRL__LEDGER__NAMESPACE_ID` | Namespace for data scoping | `1` |
137-
| `INFERADB_CTRL__LEDGER__VAULT_ID` | Vault for finer scoping | `1` |
70+
| Variable | Description |
71+
| ------------------------------------- | --------------------------------------------- |
72+
| `INFERADB_CTRL__LISTEN__HTTP` | HTTP listen address (default: `0.0.0.0:9090`) |
73+
| `INFERADB_CTRL__STORAGE` | Storage backend: `memory` or `ledger` |
74+
| `INFERADB_CTRL__LEDGER__ENDPOINT` | Ledger server URL |
75+
| `INFERADB_CTRL__LEDGER__CLIENT_ID` | Client ID for idempotency |
76+
| `INFERADB_CTRL__LEDGER__NAMESPACE_ID` | Namespace for data scoping |
13877

13978
See [config.yaml](config.yaml) for all options.
14079

14180
## Development
14281

14382
```bash
144-
# Setup (one-time)
83+
# Setup
14584
mise trust && mise install
14685

147-
# Run the control plane
148-
cargo run --bin inferadb-control
149-
150-
# Run tests
151-
cargo test --all-targets
86+
# Common tasks (requires just)
87+
just test # Run tests
88+
just lint # Run clippy
89+
just fmt # Format code
90+
just ci # Run all checks
15291

153-
# Format and lint
92+
# Manual commands
93+
cargo nextest run
94+
cargo +1.92 clippy --workspace --all-targets -- -D warnings
15495
cargo +nightly fmt --all
155-
cargo clippy --workspace --all-targets --all-features -- -D warnings
156-
157-
# Build release
158-
cargo build --release
15996
```
16097

16198
## Deployment
@@ -166,19 +103,17 @@ cargo build --release
166103
docker run -p 9090:9090 inferadb/control:latest
167104
```
168105

169-
### Kubernetes (Helm)
106+
### Kubernetes
170107

171108
```bash
172109
helm install inferadb-control ./helm \
173110
--namespace inferadb \
174111
--create-namespace \
175112
--set config.storage=ledger \
176-
--set config.ledger.endpoint=http://ledger.inferadb:50051 \
177-
--set config.webauthn.party=example.com \
178-
--set config.webauthn.origin=https://app.example.com
113+
--set config.ledger.endpoint=http://ledger.inferadb:50051
179114
```
180115

181-
See [helm/README.md](helm/README.md) for full configuration options.
116+
See [helm/README.md](helm/README.md) for configuration options.
182117

183118
## Documentation
184119

@@ -191,7 +126,7 @@ See [helm/README.md](helm/README.md) for full configuration options.
191126

192127
## Community
193128

194-
Join us on [Discord](https://discord.gg/inferadb) for questions, discussions, and contributions.
129+
Join us on [Discord](https://discord.gg/inferadb) for questions and discussions.
195130

196131
## License
197132

crates/inferadb-control-config/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ pub struct WebAuthnConfig {
204204
pub party: String,
205205

206206
/// Origin URL for WebAuthn
207-
/// e.g., "https://app.inferadb.com" or "http://localhost:3000"
207+
/// e.g., `https://app.inferadb.com` or `http://localhost:3000`
208208
#[serde(default = "default_webauthn_origin")]
209209
#[builder(default = "http://localhost:3000".to_string())]
210210
pub origin: String,
@@ -315,7 +315,7 @@ impl Default for LimitsConfig {
315315
#[builder(on(String, into))]
316316
pub struct FrontendConfig {
317317
/// Base URL for email links (verification, password reset)
318-
/// Example: "https://app.inferadb.com" or "http://localhost:3000"
318+
/// Example: `https://app.inferadb.com` or `http://localhost:3000`
319319
#[serde(default = "default_frontend_url")]
320320
#[builder(default = "http://localhost:3000".to_string())]
321321
pub url: String,
@@ -352,7 +352,7 @@ impl Default for WebhookConfig {
352352
#[builder(on(String, into))]
353353
pub struct LedgerConfig {
354354
/// Ledger server endpoint URL
355-
/// e.g., "http://localhost:50051" or "https://ledger.inferadb.com:50051"
355+
/// e.g., `http://localhost:50051` or `https://ledger.inferadb.com:50051`
356356
pub endpoint: Option<String>,
357357

358358
/// Client ID for idempotency tracking

crates/inferadb-control-core/src/jobs.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,11 @@ impl<S: StorageBackend + Clone + Send + Sync + 'static> BackgroundJobs<S> {
243243
}
244244

245245
/// Cleanup expired email verification and password reset tokens
246+
///
247+
/// Token cleanup is handled by TTL on the storage layer, so this method
248+
/// is intentionally a no-op. The storage backend automatically expires
249+
/// tokens based on their TTL settings.
246250
async fn cleanup_expired_tokens(_storage: S) -> Result<()> {
247-
// Token cleanup is handled by TTL on the storage layer
248-
// This is a placeholder for future detailed cleanup if needed
249251
tracing::debug!("Token cleanup skipped (TTL-based expiry in storage layer)");
250252
Ok(())
251253
}

crates/inferadb-control-core/src/jwt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use crate::crypto::PrivateKeyEncryptor;
2020
/// Format matches the Engine specification.
2121
#[derive(Debug, Clone, Serialize, Deserialize)]
2222
pub struct VaultTokenClaims {
23-
/// Issuer: Management API URL (https://api.inferadb.com)
23+
/// Issuer: Management API URL (<https://api.inferadb.com>)
2424
pub iss: String,
2525
/// Subject: Format "client:<client_id>" for service accounts
2626
pub sub: String,

crates/inferadb-control-core/src/repository/audit_log.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use inferadb_control_types::{
55
error::{Error, Result},
66
};
77

8-
const PREFIX_AUDIT_LOG: &[u8] = b"audit_log:";
8+
const PREFIX_AUDIT_LOG: &str = "audit_log:";
99

1010
/// Query filters for audit logs
1111
#[derive(Debug, Clone, Default)]
@@ -72,8 +72,7 @@ impl<S: StorageBackend> AuditLogRepository<S> {
7272
// This is a simplified implementation that scans all logs
7373
// In a real implementation, we would use a secondary index on organization_id + created_at
7474

75-
let prefix = format!("{}{}", String::from_utf8_lossy(PREFIX_AUDIT_LOG), "");
76-
let start_key = prefix.as_bytes().to_vec();
75+
let start_key = PREFIX_AUDIT_LOG.as_bytes().to_vec();
7776
let end_key = {
7877
let mut key = start_key.clone();
7978
key.push(0xFF);
@@ -129,8 +128,7 @@ impl<S: StorageBackend> AuditLogRepository<S> {
129128
///
130129
/// Returns the number of logs deleted
131130
pub async fn delete_older_than(&self, cutoff_date: DateTime<Utc>) -> Result<usize> {
132-
let prefix = format!("{}{}", String::from_utf8_lossy(PREFIX_AUDIT_LOG), "");
133-
let start_key = prefix.as_bytes().to_vec();
131+
let start_key = PREFIX_AUDIT_LOG.as_bytes().to_vec();
134132
let end_key = {
135133
let mut key = start_key.clone();
136134
key.push(0xFF);
@@ -161,7 +159,7 @@ impl<S: StorageBackend> AuditLogRepository<S> {
161159
}
162160

163161
fn key(id: i64) -> Vec<u8> {
164-
format!("{}{}", String::from_utf8_lossy(PREFIX_AUDIT_LOG), id).into_bytes()
162+
format!("{PREFIX_AUDIT_LOG}{id}").into_bytes()
165163
}
166164
}
167165

0 commit comments

Comments
 (0)