Skip to content

docs: add ARCHITECTURE.md with mermaid diagrams#4

Open
agaonker wants to merge 1 commit into
mainfrom
docs/architecture-mermaid
Open

docs: add ARCHITECTURE.md with mermaid diagrams#4
agaonker wants to merge 1 commit into
mainfrom
docs/architecture-mermaid

Conversation

@agaonker

@agaonker agaonker commented May 18, 2026

Copy link
Copy Markdown
Owner

Summary

What's in it

  1. Layered architecture flowchart — network → connection → protocol → command → store, with planned Phase 2.6-4 additions (ZSet, expiry sweeper, transactions, RDB, compat stubs) drawn dashed-yellow so the shape of what's coming is visible.
  2. Per-command sequence diagram — autonumbered walk through one SET k v from raw TCP bytes to +OK\r\n, showing the Connection task, parser, dispatch, tokio mutex acquire, handler, MutexGuard release, and serialize back.
  3. State + ownership flowchart — splits state into three lifetimes (process-wide / per-connection / per-command) so the lock semantics are unambiguous.

Plus a file-map table at the bottom mapping each layer to its source files.

Test plan

  • GitHub renders mermaid natively — open the file on github.com after merging to verify
  • All three blocks valid mermaid (no syntax errors); HTML entities used for <, >, & inside labels
  • Cross-references to redis-rust-design.md and TODOS.md are correct

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Documentation
    • Updated architecture documentation with comprehensive system design details, including control flow diagrams and component organization. Enhanced with execution sequence documentation and architectural patterns to support development and maintenance.

Review Change Stack

Three diagrams covering the as-built system (through PR #3, Phase 2 step 0):

1. Layered architecture — network -> connection -> protocol -> command -> store,
   with planned Phase 2.6-4 additions shown in dashed yellow
2. Per-command sequence — autonumbered walk through one SET k v from raw TCP
   bytes to "+OK\r\n", showing the Connection task, parser, dispatch,
   tokio::sync::Mutex acquire, handler, and serialize back
3. State + ownership — splits state into three lifetimes (process-wide,
   per-connection, per-command) so the lock semantics are unambiguous

Also includes a file-map table mapping each layer to its source files.

Renders natively in the GitHub markdown preview.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented May 18, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

This PR adds ARCHITECTURE.md, a comprehensive documentation file that describes the current "Phase 2 step 0" Redis-Rust server architecture. The document explains the layered design (network, protocol, command dispatch, mutex-guarded store), visualizes per-command execution flow, details state ownership across process, connection, and command lifetimes, and provides a file map linking architecture layers to source code locations.

Changes

Architecture Documentation

Layer / File(s) Summary
Architecture Overview, Sequences, and State Lifecycle
ARCHITECTURE.md
Documentation of the layered server model with Mermaid diagrams showing control flow, per-command sequence (e.g., SET parsing and dispatch), process/connection/command-scope state ownership with mutex guard lifetimes, and a table mapping architecture layers to source files and test locations.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 A rabbit wrote down all the layers so clear—
Network, protocol, dispatch, all here!
State scopes and lifetimes, diagrams too,
Architecture mapped fresh, brand new!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'docs: add ARCHITECTURE.md with mermaid diagrams' directly and accurately summarizes the primary change: adding documentation via ARCHITECTURE.md with mermaid diagrams.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch docs/architecture-mermaid

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c7ce84f493

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread ARCHITECTURE.md
Comment on lines +123 to +124
CO->>D: dispatch(cmd, &store).await
D->>M: lock().await

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Correct the lock path described here

This sequence documents a non-existent async dispatch/tokio-mutex path: dispatch is a synchronous function (redis-clone/src/command/dispatch.rs:22) and SharedStore is Arc<std::sync::Mutex<Store>> (redis-clone/src/store/mod.rs:2-6), with handlers calling store.lock().unwrap() themselves. Because this doc is presented as the as-built architecture, the current wording puts guard ownership in the wrong layer and will mislead anyone implementing transactions or auditing lock scope from it.

Useful? React with 👍 / 👎.

Comment thread ARCHITECTURE.md
```mermaid
flowchart TB
subgraph Process["Process-wide (one per server)"]
NEXT["static NEXT_CLIENT_ID: AtomicU64"]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Remove the nonexistent client-id state

This state diagram shows a process-wide NEXT_CLIENT_ID and per-connection IDs as existing state, but the current code has no such static and handle_connection only receives (TcpStream, SharedStore) (redis-clone/src/server/connection.rs:10). Since the document says it describes what has actually been built, this makes connection identity look available to future CLIENT/WATCH work when it is not implemented yet.

Useful? React with 👍 / 👎.

Comment thread ARCHITECTURE.md

| Layer | Files |
|---|---|
| Network | `src/server/listener.rs` |

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Prefix the source paths with the crate directory

The file map starts with root-relative src/... paths, but the repository has no root src directory; the actual files are under redis-clone/src/... (for example redis-clone/src/server/listener.rs). As written, the navigation table sends readers and tooling to paths that do not exist in this repo.

Useful? React with 👍 / 👎.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@ARCHITECTURE.md`:
- Line 169: The diagram's arrow "guard --> Process" is misleading about
ownership; update the diagram to either remove that arrow or replace it with a
clarifying annotation such as "guard dropped → lock released" that explains that
MutexGuard (the per-command guard) is dropped at end of the command lifetime
which releases the lock on the process-wide Mutex<Store>; make the change where
the "guard" and "Process" nodes are defined so readers see the correct lifecycle
relationship for MutexGuard and Mutex<Store>.
- Around line 185-194: Update the table so every filepath entry is prefixed with
"redis-clone/" (e.g., change "src/server/listener.rs" to
"redis-clone/src/server/listener.rs") for all layers (Network, Per-conn,
Protocol, Command, Store, Errors, Entry, Tests) and also add the missing module
files by including "redis-clone/src/server/mod.rs",
"redis-clone/src/protocol/mod.rs", and "redis-clone/src/command/mod.rs"
alongside the existing specific files (e.g., keep
"redis-clone/src/server/listener.rs", "redis-clone/src/server/connection.rs"
which contains the Connection struct and handle_connection wrapper, and the
protocol/command files listed).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2399a08a-e859-479d-b182-6bd811177a94

📥 Commits

Reviewing files that changed from the base of the PR and between 892f232 and c7ce84f.

📒 Files selected for processing (1)
  • ARCHITECTURE.md

Comment thread ARCHITECTURE.md
NEXT -- fetch_add(1) --> cid
STORE_ARC -- "Arc::clone()" --> sharehandle
sharehandle -- "lock().await" --> guard
guard --> Process

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Clarify or remove the guard --> Process arrow.

The arrow from guard back to Process is semantically unclear. The MutexGuard doesn't "point to" the Process scope; it's dropped at the end of the per-command lifetime, which releases the lock on the process-wide Mutex<Store>. This arrow might confuse readers about ownership semantics.

Consider removing this arrow or replacing it with a note like "guard dropped → lock released" to clarify the relationship.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@ARCHITECTURE.md` at line 169, The diagram's arrow "guard --> Process" is
misleading about ownership; update the diagram to either remove that arrow or
replace it with a clarifying annotation such as "guard dropped → lock released"
that explains that MutexGuard (the per-command guard) is dropped at end of the
command lifetime which releases the lock on the process-wide Mutex<Store>; make
the change where the "guard" and "Process" nodes are defined so readers see the
correct lifecycle relationship for MutexGuard and Mutex<Store>.

Comment thread ARCHITECTURE.md
Comment on lines +185 to +194
| Layer | Files |
|---|---|
| Network | `src/server/listener.rs` |
| Per-conn | `src/server/connection.rs` (`Connection` struct + `handle_connection` wrapper) |
| Protocol | `src/protocol/{types,parser,serializer}.rs` |
| Command | `src/command/{types,dispatch}.rs` + `src/command/handlers/{ping,echo,set,get,del,exists,list,hash,set_cmd}.rs` |
| Store | `src/store/mod.rs` |
| Errors | `src/error.rs` |
| Entry | `src/main.rs`, `src/lib.rs` |
| Tests | `tests/phase1.rs` (integration), inline `#[cfg(test)]` modules in each handler file |

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check existence of files mentioned in the file map

echo "=== Checking individual files ==="
for file in \
  "src/server/listener.rs" \
  "src/server/connection.rs" \
  "src/protocol/types.rs" \
  "src/protocol/parser.rs" \
  "src/protocol/serializer.rs" \
  "src/command/types.rs" \
  "src/command/dispatch.rs" \
  "src/store/mod.rs" \
  "src/error.rs" \
  "src/main.rs" \
  "src/lib.rs" \
  "tests/phase1.rs"
do
  if [ -f "$file" ]; then
    echo "$file"
  else
    echo "✗ MISSING: $file"
  fi
done

echo -e "\n=== Checking handler files directory ==="
if [ -d "src/command/handlers" ]; then
  echo "✓ src/command/handlers/ directory exists"
  echo "Handler files found:"
  fd -e rs . src/command/handlers/
else
  echo "✗ MISSING: src/command/handlers/ directory"
fi

Repository: agaonker/redis-rust

Length of output: 548


🏁 Script executed:

#!/bin/bash
# Discover actual repository structure

echo "=== Top-level files and directories ==="
ls -la | head -20

echo -e "\n=== src/ directory structure (if exists) ==="
if [ -d "src" ]; then
  find src -type f -name "*.rs" | head -20
  echo "---"
  find src -type d | sort
else
  echo "src/ directory does not exist"
fi

echo -e "\n=== tests/ directory structure (if exists) ==="
if [ -d "tests" ]; then
  find tests -type f -name "*.rs" | head -20
else
  echo "tests/ directory does not exist"
fi

echo -e "\n=== Total Rust files in repository ==="
find . -name "*.rs" -type f | wc -l
echo "Rust files found:"
find . -name "*.rs" -type f

Repository: agaonker/redis-rust

Length of output: 1733


Update file paths in the file map table to include the redis-clone/ directory prefix.

All files referenced in the table exist, but each path is missing the redis-clone/ directory prefix. Paths should be relative to the repository root and must start with redis-clone/ (e.g., redis-clone/src/server/listener.rs instead of src/server/listener.rs). This affects all entries in the table: Network, Per-conn, Protocol, Command, Store, Errors, Entry, and Tests layers. Additionally, the table omits the module files (src/server/mod.rs, src/protocol/mod.rs, src/command/mod.rs) which do exist in the codebase.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@ARCHITECTURE.md` around lines 185 - 194, Update the table so every filepath
entry is prefixed with "redis-clone/" (e.g., change "src/server/listener.rs" to
"redis-clone/src/server/listener.rs") for all layers (Network, Per-conn,
Protocol, Command, Store, Errors, Entry, Tests) and also add the missing module
files by including "redis-clone/src/server/mod.rs",
"redis-clone/src/protocol/mod.rs", and "redis-clone/src/command/mod.rs"
alongside the existing specific files (e.g., keep
"redis-clone/src/server/listener.rs", "redis-clone/src/server/connection.rs"
which contains the Connection struct and handle_connection wrapper, and the
protocol/command files listed).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant