# Enterprise Codebase Organization Analysis
Comparison of top GitHub repositories and recommendations for universal-crypto-mcp.
## π Top Repository Patterns Analyzed
### 1. **MCP Servers** (modelcontextprotocol/servers)
- **Stars**: High visibility official repo
- **Structure**: Monorepo with individual servers in `src/`
```
src/
βββ filesystem/ # Individual MCP server
β βββ index.ts # Main entry point
β βββ lib.ts # Core functionality
β βββ path-utils.ts # Utilities
β βββ __tests__/ # Tests co-located
β βββ README.md # Server-specific docs
βββ everything/
β βββ index.ts
β βββ docs/ # Comprehensive documentation
β βββ tools/ # Feature modules
β βββ resources/
β βββ prompts/
β βββ server/
βββ memory/
βββ ...
```
**Key Patterns**:
- β
**Flat server structure** - each MCP server is self-contained
- β
**Co-located tests** (`__tests__` next to code)
- β
**Feature-based modules** (tools/, resources/, prompts/)
- β
**Extensive documentation** per server
- β
**Shared root tsconfig.json**
### 2. **Uniswap V3** (uniswap/v3-core)
- **Stars**: 4.3k+ (DeFi standard)
- **Structure**: Clean contract-first architecture
```
contracts/
βββ interfaces/ # All interfaces
βββ libraries/ # Shared logic
β βββ math/
β βββ helpers/
β βββ ...
βββ test/ # Test contracts
βββ UniswapV3Pool.sol # Main contracts at root
test/
βββ shared/ # Test utilities
β βββ fixtures.ts
β βββ utilities.ts
β βββ expect.ts
βββ UniswapV3Pool.spec.ts
βββ Oracle.spec.ts
audits/
βββ tob/ # Trail of Bits audit
βββ contracts/
βββ README.md
```
**Key Patterns**:
- β
**Interfaces separated** from implementations
- β
**Libraries organized by category** (math, helpers)
- β
**Test utilities in shared/**
- β
**Audits tracked** in repo
- β
**Minimal nesting** - contracts at root level
### 3. **Aave V3** (aave/aave-v3-core)
- **Stars**: 900+ (Enterprise DeFi)
- **Structure**: Professional multi-layer architecture
```
contracts/
βββ protocol/
β βββ pool/ # Core pool logic
β βββ libraries/ # Business logic
β β βββ logic/ # Complex operations
β β βββ math/ # Math libraries
β β βββ types/ # Type definitions
β β βββ helpers/ # Utility functions
β βββ tokenization/ # Token contracts
β βββ configuration/ # Config contracts
βββ interfaces/ # All interfaces
βββ dependencies/ # External dependencies
β βββ openzeppelin/
β βββ weth/
βββ mocks/ # Test mocks
βββ misc/ # Utilities
test-suites/
βββ helpers/
β βββ make-suite.ts
β βββ actions.ts
β βββ utils/
βββ pool.spec.ts
βββ atoken.spec.ts
certora/ # Formal verification
βββ specs/
βββ scripts/
helpers/ # Deployment helpers
βββ types.ts
βββ contracts-helpers.ts
```
**Key Patterns**:
- β
**Deep logical organization** (protocol/libraries/logic/)
- β
**Separated concerns** (protocol vs interfaces vs dependencies)
- β
**Test suites** not just tests
- β
**Formal verification** included
- β
**Helper utilities** for deployment
## π Pattern Comparison Matrix
| Pattern | MCP Servers | Uniswap V3 | Aave V3 | Your Current |
|---------|-------------|------------|---------|--------------|
| **Monorepo** | β
Lerna-style | β Single | β Single | β
pnpm workspaces |
| **Test Location** | Co-located | Separate /test | Separate test-suites | Mixed |
| **Docs Location** | Per-package | Root + contracts | Root | Scattered |
| **Interface Separation** | Mixed | β
Yes | β
Yes | β No |
| **Utilities Organization** | lib.ts files | shared/ | helpers/ | Inconsistent |
| **Type Definitions** | Inline | shared/utilities.ts | helpers/types.ts | Mixed |
| **Nesting Depth** | 2-3 levels | 2 levels | 4-5 levels | 3-4 levels |
| **Config Files** | Root | Root | Root | Root |
## π― Recommended Organization for Universal-Crypto-MCP
Based on analysis of top repos, here's the ideal structure:
```
universal-crypto-mcp/
β
βββ π¦ packages/
β βββ core/ # β
Keep (foundation)
β βββ shared/ # β
Keep (utilities)
β β βββ types/ # π Centralize all TypeScript types
β β βββ utils/ # π Common utilities
β β βββ interfaces/ # π All interfaces
β β βββ constants/ # π Shared constants
β β
β βββ agents/ # Group by FEATURE, not tech
β β βββ trading/ # MCP server for trading
β β β βββ src/
β β β β βββ index.ts
β β β β βββ tools/ # Trading tools
β β β β βββ resources/
β β β β βββ lib/ # Trading utilities
β β β βββ __tests__/ # Co-located tests
β β β βββ docs/ # Server-specific docs
β β β βββ package.json
β β β βββ README.md
β β βββ defi/
β β βββ wallets/
β β
β βββ market-data/ # β
Good grouping
β β βββ coingecko/
β β βββ dune-analytics/
β β βββ defillama/
β β
β βββ payments/ # β
Good grouping
β β βββ x402/
β β β βββ facilitator/ # Your well-organized service
β β β βββ protocol/
β β β βββ sdk/
β β βββ stripe-mcp/
β β
β βββ defi/ # Protocols & integrations
β β βββ uniswap/
β β βββ aave/
β β βββ curve/
β β
β βββ infrastructure/ # DevOps & tooling
β βββ monitoring/
β βββ logging/
β βββ metrics/
β
βββ π contracts/ # Smart contracts (if any)
β βββ interfaces/
β βββ libraries/
β βββ mocks/
β βββ tests/
β
βββ π§ͺ tests/ # Integration & E2E tests
β βββ integration/
β βββ e2e/
β βββ fixtures/
β
βββ π docs/ # Centralized documentation
β βββ guides/
β βββ api/
β βββ architecture/
β βββ examples/
β
βββ π οΈ scripts/ # Build & deployment scripts
β βββ build/
β βββ deploy/
β βββ test/
β
βββ π examples/ # Usage examples
β βββ basic-mcp-server/
β βββ trading-bot/
β βββ full-deployment/
β
βββ βοΈ Configuration (Root)
β βββ package.json
β βββ pnpm-workspace.yaml
β βββ tsconfig.json
β βββ tsconfig.test.json
β βββ vitest.config.ts
β βββ eslint.config.js
β βββ .prettierrc
β βββ .gitignore
β
βββ π Documentation (Root)
βββ README.md
βββ CONTRIBUTING.md
βββ ARCHITECTURE.md
βββ CHANGELOG.md
βββ LICENSE
```
## π§ Key Improvements Needed
### 1. **Flatten Package Structure** (Like MCP Servers)
**Current** (Too deep):
```
packages/market-data/data-aggregator/sdk/typescript/
packages/market-data/data-aggregator/mcp/
```
**Recommended**:
```
packages/market-data/aggregator/ # Main package
packages/market-data/aggregator-sdk/ # SDK if large enough
```
### 2. **Centralize Types** (Like Aave)
**Create**: `packages/shared/types/`
```typescript
// packages/shared/types/src/index.ts
export * from './chains';
export * from './tokens';
export * from './defi';
export * from './mcp';
```
All packages import from `@nirholas/universal-crypto-mcp-types`
### 3. **Separate Interfaces** (Like Uniswap)
**Create**: `packages/shared/interfaces/`
```typescript
// packages/shared/interfaces/src/ITrading.ts
export interface ITrading {
swap(...): Promise<...>;
quote(...): Promise<...>;
}
```
### 4. **Standardize Test Location** (Choose One)
**Option A**: Co-located (MCP Servers style) - **RECOMMENDED**
```
packages/payments/x402/facilitator/
βββ src/
β βββ services/
β β βββ fees.ts
β β βββ __tests__/
β β βββ fees.test.ts
```
**Option B**: Separate (Aave style)
```
packages/payments/x402/facilitator/
βββ src/
β βββ services/
β βββ fees.ts
βββ test/
βββ services/
βββ fees.test.ts
```
### 5. **Consolidate Documentation** (Like all elite repos)
**Move all docs to**: `docs/`
```
docs/
βββ README.md # Entry point
βββ getting-started/
β βββ installation.md
β βββ quick-start.md
β βββ first-mcp-server.md
βββ guides/
β βββ trading.md
β βββ payments.md
β βββ defi.md
βββ api/
β βββ agents.md
β βββ market-data.md
β βββ payments.md
βββ architecture/
β βββ overview.md
β βββ packages.md
β βββ patterns.md
βββ examples/
βββ ...
```
### 6. **Remove Redundancy**
**Duplicates found**:
- `src/` AND `packages/` at root (choose one)
- `test/` AND `tests/` (consolidate)
- `x402/` AND `x402-deploy/` (should be in packages/)
- `website/` AND `website-unified/` (consolidate)
## π Migration Plan
### Phase 1: Foundation (Week 1)
```bash
# 1. Create shared packages
mkdir -p packages/shared/{types,interfaces,utils,constants}
# 2. Initialize them
cd packages/shared/types && pnpm init
cd packages/shared/interfaces && pnpm init
cd packages/shared/utils && pnpm init
# 3. Move types
# Extract all interface/type definitions to shared/
```
### Phase 2: Flatten Structure (Week 2)
```bash
# 1. Flatten deep nesting
mv packages/market-data/data-aggregator/sdk/typescript \
packages/market-data/aggregator-sdk
# 2. Standardize test locations
# Choose co-located and move all tests
```
### Phase 3: Consolidate Docs (Week 3)
```bash
# 1. Create docs structure
mkdir -p docs/{guides,api,architecture,examples}
# 2. Move scattered docs
mv packages/*/README.md docs/guides/
mv *.md docs/
# 3. Create doc index
```
### Phase 4: Clean Root (Week 4)
```bash
# 1. Remove duplicates
rm -rf src/ # Use packages/ only
rm -rf tests/ # Consolidate to test/
# 2. Move workspace-specific items
mv x402-deploy packages/payments/x402/deploy
```
## π¨ Package Naming Convention
**Current**: Inconsistent
```
packages/market-data/coingecko/
packages/wallets/armor/
packages/defi/uniswap/
```
**Recommended** (All elite repos use this):
```
@nirholas/universal-crypto-{category}-{name}
Examples:
@nirholas/universal-crypto-market-coingecko
@nirholas/universal-crypto-wallet-armor
@nirholas/universal-crypto-defi-uniswap
@nirholas/universal-crypto-agent-trading
@nirholas/universal-crypto-payment-x402
```
## ποΈ Directory Structure Best Practices
### Per-Package Structure (MCP Server Pattern)
```
packages/market-data/coingecko/
βββ src/
β βββ index.ts # Main entry (server)
β βββ tools/ # MCP tools
β β βββ index.ts
β β βββ get-price.ts
β β βββ get-trending.ts
β βββ resources/ # MCP resources
β βββ prompts/ # MCP prompts
β βββ lib/ # Utilities
β β βββ api-client.ts
β β βββ cache.ts
β βββ types/ # Local types
β βββ coingecko.ts
βββ __tests__/ # Co-located tests
β βββ tools/
β βββ lib/
βββ docs/ # Package docs
β βββ README.md
β βββ API.md
βββ examples/ # Usage examples
βββ package.json
βββ tsconfig.json
βββ README.md # Quick start
```
### Configuration Hierarchy
```
Root:
βββ tsconfig.json # Base config
βββ tsconfig.test.json # Test config
βββ vitest.config.ts # Shared test config
βββ eslint.config.js # Shared linting
Package:
βββ tsconfig.json # Extends root
βββ vitest.config.ts # Extends root (if needed)
```
## π Comparison Summary
### What Your Project Does WELL (Keep!)
β
**x402/facilitator** - Exceptionally organized:
- Clear service separation
- Comprehensive documentation
- Professional structure
- Good use of tools & scripts
β
**Monorepo with workspaces** - Industry standard
β
**Category-based grouping** - market-data/, payments/, agents/
β
**TypeScript + modern tooling** - vitest, eslint, prettier
### What Needs Improvement
β **Too much nesting** - Some packages 5+ levels deep
β **Inconsistent test location** - Some co-located, some separate
β **Scattered documentation** - READMEs everywhere, no central docs/
β **Duplicate directories** - src/ and packages/, test/ and tests/
β **No interface separation** - Mix interfaces with implementations
β **Missing shared utilities** - Each package reimplements common code
## π Quick Wins (Do These First)
1. **Create `packages/shared/types`** - Centralize all TypeScript types
2. **Create `docs/` directory** - Move all markdown files here
3. **Standardize tests** - Choose co-located, move all tests
4. **Remove `src/` at root** - Use only `packages/`
5. **Flatten deep packages** - Max 3 levels of nesting
6. **Add ARCHITECTURE.md** - Document your structure
## π Resources from Elite Repos
### MCP Servers
- Clean per-server structure
- Excellent documentation per server
- Co-located tests
### Uniswap V3
- Minimal nesting
- Separated interfaces
- Shared test utilities
### Aave V3
- Professional layering
- Helper utilities
- Formal verification setup
- Test suites organization
---
**Bottom Line**: Your x402/facilitator shows you know how to organize well. Apply that same structure across the entire monorepo, flatten the nesting, centralize common code, and you'll have an elite-tier repository.