How nanoapi-io/napi works
Project type and purpose
• Type: A CLI‐driven “analysis & refactoring” application library (a modular monolith) with plugin support for multiple languages.
• Purpose:
• Provide commands (manifest generate, extract, etc.) that parse code, build an architectural manifest, extract symbols, and push data to a NanoAPI backend.
File structure
• Top‐level “src” modules:
• cli/ – CLI entrypoint, handlers, and middlewares
• apiService/ – HTTP client for remote NanoAPI backend
• helpers/ – Common utilities (filesystem, source‐code parsing, tree‐sitter integration)
• languagePlugins/ – One subfolder per language (c, csharp, java, python), each containing extractor, resolver, metrics, etc.
• symbolExtractor/ – Cross‐language symbol‐extraction orchestration
• manifest/ – Dependency‐manifest generator (language‐specific and generic)
• Support directories:
• examples/ – Sample projects in different languages demonstrating usage
• scripts/ – Utility scripts (versioning, Python stdlib list generation)
• install_scripts/ – OS‐specific install entrypoints
• CI/CD:
• .github/workflows/ – Lint, test, compile, and release pipelines
README for additional insights
• Core features: audit, refactor, build, integrate, live‐view architecture
• Stresses deterministic, open‐source approach, CI/CD compatibility, and plugin extensibility
• Mentions a separate UI (not part of this repo) that reads the manifest pushed by the CLI
Core components & interactions
1. CLI Layer
• Command parser
• Handlers (login, init, manifest, extract, etc.)
• Middlewares (auth check, config load, version check)
2. Core Services
• Manifest Generator (generic + language‐specific)
• Symbol Extractor
• Helpers (filesystem, tree‐sitter)
3. Language Plugins (for each supported language)
• Extractor, Resolver, Metrics, Dependency Formatter, Symbol Registry, etc.
4. API Client (apiService)
• HTTP/REST calls to NanoAPI backend
• Auth token management
5. External NanoAPI Backend (cloud service + UI)
• Authentication service
• Manifest storage & indexing
• UI & visualizer
6. CI/CD Pipeline (GitHub Actions)
• Lint, test, build, and release workflows
1. User → CLI Layer (issues commands)
2. CLI Layer → Core Services (invoke manifest generator or extractor)
3. Core Services ↔ Helpers (filesystem reads, Tree-sitter parse calls)
4. Core Services → Language Plugins (pass ASTs or source trees; receive symbols, metrics, dependency info)
5. Core Services → API Client (package up manifest or extraction payload)
6. API Client → NanoAPI Backend (push data; receive acknowledgments)
7. CI/CD → CLI Layer & Tests (automated on push/pull request)
c. Architectural Patterns & Principles
• Layered Architecture: Separation between presentation (CLI), application logic (core services), domain (language plugins), and infrastructure (helpers, API client).
• Plugin Architecture: Each language support lives in a self-contained module under languagePlugins/, enabling easy extension.
• Middleware Pattern: CLI processing chain applies cross-cutting concerns (config loading, auth validation) before invoking handlers.
• Adapter/Facade: apiService abstracts HTTP details from core logic.
• Test‐Driven: Each module has corresponding .test.ts verifying functionality.
d. Key Technologies & Frameworks
• TypeScript/Node (Deno compatibility via deno.json)
• Tree-sitter for parsing multiple languages
• REST over HTTPS for backend communication
• GitHub Actions for CI/CD
• Shell scripts for installation