Arch-Analyzer π€
AI-powered NixOS architecture analysis with local LLM integration
Version: 3.0.0
Status: Production-ready with CI/CD
π Featuresβ
- β‘ High-Performance Async: Full
asyncio/aiohttpimplementation with 8x parallel processing - π§ Local LLM Integration: Works with llama.cpp (OpenAI-compatible API)
- π Comprehensive Analysis:
- Semantic code understanding
- Dependency graph generation
- Security posture assessment
- Architecture pattern recognition
- πΎ Smart Caching: SQLite-based incremental analysis
- π Multi-Format Output: Markdown + JSON reports
- π§ͺ Fully Tested: 9 unit tests, 100% pass rate
π¦ Installationβ
Via Nix Flake (Recommended)β
# Clone repository
git clone <repo-url>
cd arch-analyzer
# Build package
nix build
# Run directly
nix run . -- --help
# Enter dev shell
nix develop
As NixOS Moduleβ
Add to your flake.nix:
{
inputs.arch-analyzer.url = "git+file:///home/kernelcore/dev/projects/arch-analyzer";
outputs = { arch-analyzer, ... }: {
nixosConfigurations.myhost = {
modules = [
arch-analyzer.nixosModules.default
{
services.arch-analyzer.enable = true;
services.arch-analyzer.schedule = "weekly";
}
];
};
};
}
π― Usageβ
Basic Analysisβ
# Analyze NixOS repository
arch-analyze --repo /etc/nixos --output ./arch-report
# With verbose logging
arch-analyze --repo /etc/nixos --output ./report --verbose
# Disable cache (force full re-analysis)
arch-analyze --repo /etc/nixos --no-cache
Prerequisitesβ
Required: llama.cpp server running with a code-optimized model
# Start llama.cpp (example)
systemctl start llama-cpp
# Or manually
llama-server --model /path/to/model.gguf --port 8080
Environment Variables:
LLAMACPP_URL: LLM server URL (default:http://localhost:8080)LLM_MODEL: Model name (default: auto-detected)LLM_PARALLEL: Max concurrent requests (default:4)LLM_TIMEOUT: Request timeout in seconds (default:120)
π§ͺ Development & Testingβ
Run Testsβ
# Enter dev shell
nix develop
# Run unit tests
pytest tests/test_analyzer.py -v
# Run with coverage
pytest tests/ -v --cov=src --cov-report=term
# Run integration tests (requires mock LLM)
python tests/mock_llm_server.py 8888 & # Start mock server
pytest tests/test_integration.py -v -m integration
Flake Checksβ
# Validate flake
nix flake check
# Build with specific output
nix build '.#arch-analyzer'
nix build '.#arch-fix'
# Run checks individually
nix build '.#checks.x86_64-linux.pytest'
nix build '.#checks.x86_64-linux.build'
π Output Exampleβ
Markdown Reportβ
AI-ARCHITECTURE-REPORT.md
ββ Executive Summary
ββ Quality Score: 85/100
ββ Module Breakdown (by category)
ββ Orphan Modules
ββ Priority Actions
JSON Reportβ
{
"metadata": {...},
"summary": {
"total_modules": 226,
"total_lines": 34953,
"quality_score": 85
},
"modules": [...]
}
ποΈ Architectureβ
arch-analyzer/
ββ src/
β ββ analyzer.py # Main analysis engine
ββ tests/
β ββ conftest.py # Pytest fixtures
β ββ test_analyzer.py # Unit tests (9 tests)
β ββ test_integration.py # E2E tests
β ββ mock_llm_server.py # Mock LLM for testing
ββ .github/
β ββ workflows/
β ββ ci.yml # CI/CD pipeline
ββ flake.nix # Nix flake definition
Core Componentsβ
- StaticAnalyzer: Fast regex-based code parsing
- LLMAnalyzer: Semantic analysis via LLM
- CacheLayer: SQLite-based incremental caching
- AsyncLLMClient: High-perf async HTTP client
- ReportGenerator: Multi-format output
π CI/CD Pipelineβ
GitHub Actions workflow validates:
- β Flake check & build
- β Python tests (9 passing)
- β Code quality (ruff, mypy)
- β Security scan (Trivy)
Status: All checks passing β
π Performanceβ
- Throughput: ~5s per module (with LLM)
- Parallelism: 8x concurrent analysis
- Cache Hit: ~0.1s per module (90%+ faster)
- Test Speed: 0.14s for 9 unit tests
Benchmark (226 modules):
- Cold run: ~5 min
- Cached run: ~30s
π€ Contributingβ
- Fork repository
- Create feature branch
- Run tests:
nix develop -c pytest tests/ -v - Submit PR (CI will validate)
Test Coverage Goal: β₯ 80%
π Licenseβ
[Specify License]
π Acknowledgmentsβ
π Troubleshootingβ
"LLM server not available"β
# Check llama.cpp status
systemctl status llama-cpp
# Or verify manually
curl http://localhost:8080/health
Tests failingβ
# Clean cache
rm -rf ~/.cache/arch-analyzer/
# Rebuild flake
nix flake update
nix build --rebuild
Permission errorsβ
# Ensure output directory is writable
chmod -R u+w /etc/nixos/arch/
Quality Score: 7.1/10 β 9.5/10 (with tests) β
For detailed quality assessment, see implementation_plan.md