|
| 1 | +# **Detailed Architecture & Roadmap** |
| 2 | + |
| 3 | +*Note: This document outlines the conceptual architecture of KnowCode, some of which looks ahead to future phases.* |
| 4 | + |
| 5 | +--- |
| 6 | + |
| 7 | +## **1. Layered Architecture** |
| 8 | + |
| 9 | +KnowCode follows a multi-layer design to ensure extensibility, maintainability, and scalability. |
| 10 | + |
| 11 | +1. **Ingestion Layer**: Source Code scanning, Parsing (AST/Tree-sitter). |
| 12 | +2. **Analysis Layer**: Structural building, Semantic graph construction. |
| 13 | +3. **Storage Layer**: Graph persistence, Vector storage. |
| 14 | +4. **Retrieval Layer**: Hybrid search (Lexical + Semantic). |
| 15 | +5. **Intelligence Layer**: Context synthesis, RAG orchestration. |
| 16 | +6. **Interface Layer**: CLI, REST API (FastAPI). |
| 17 | + |
| 18 | +--- |
| 19 | + |
| 20 | +## **2. Component Interaction** |
| 21 | + |
| 22 | +```mermaid |
| 23 | +flowchart TB |
| 24 | + subgraph Ingestion |
| 25 | + L1[Layer 1: Source Ingestion] |
| 26 | + end |
| 27 | + |
| 28 | + subgraph Analysis |
| 29 | + L2[Layer 2: Structural Parsing] |
| 30 | + L3[Layer 3: Semantic Graph] |
| 31 | + L4[Layer 4: Behavioral Analysis] |
| 32 | + L5[Layer 5: Runtime Signals] |
| 33 | + L6[Layer 6: Intent Extraction] |
| 34 | + end |
| 35 | + |
| 36 | + subgraph Intelligence |
| 37 | + L7[Layer 7: Doc Synthesis] |
| 38 | + L8[Layer 8: Knowledge Store] |
| 39 | + L9[Layer 9: Context Synthesis] |
| 40 | + end |
| 41 | + |
| 42 | + subgraph Interface |
| 43 | + L10[Layer 10: LLM Interface] |
| 44 | + DEV[Developer] |
| 45 | + end |
| 46 | + |
| 47 | + subgraph Evolution |
| 48 | + L11[Layer 11: Feedback Loop] |
| 49 | + end |
| 50 | + |
| 51 | + subgraph Cross-Cutting |
| 52 | + SEC[Security] |
| 53 | + OBS[Observability] |
| 54 | + CFG[Configuration] |
| 55 | + end |
| 56 | + |
| 57 | + L1 --> L2 |
| 58 | + L2 --> L3 |
| 59 | + L3 --> L4 |
| 60 | + L3 --> L6 |
| 61 | + L4 --> L8 |
| 62 | + L5 -.-> L8 |
| 63 | + L6 --> L8 |
| 64 | + L8 --> L7 |
| 65 | + L8 --> L9 |
| 66 | + L9 --> L10 |
| 67 | + L10 --> DEV |
| 68 | + DEV --> L11 |
| 69 | + L11 --> L8 |
| 70 | + L11 --> L3 |
| 71 | + |
| 72 | + SEC -.-> L1 & L8 & L10 |
| 73 | + OBS -.-> L1 & L3 & L8 & L10 |
| 74 | + CFG -.-> L2 & L4 & L9 |
| 75 | +``` |
| 76 | + |
| 77 | +--- |
| 78 | + |
| 79 | +## **Implementation Status & Roadmap** |
| 80 | + |
| 81 | +### **Phase 1: Foundation (COMPLETED)** |
| 82 | +1. **[x] Source Scanning + Parsing (Layers 1-2)**: Scanner with gitignore support; parsers for Python (AST), JS/TS + Java (Tree-sitter), Markdown, YAML. |
| 83 | +2. **[x] Unified Semantic Graph (Layer 3)**: Entity/relationship model with reference resolution (calls/imports/contains/inherits). |
| 84 | +3. **[x] Local Knowledge Store (Layer 8)**: In-memory graph with JSON persistence and query helpers. |
| 85 | +4. **[x] Token-Budgeted Context Synthesis (Layer 9)**: Priority-ordered sections with truncation handling. |
| 86 | +5. **[x] Service Layer**: Shared business logic for CLI and API. |
| 87 | + |
| 88 | +### **Phase 2: Intelligence Server & RAG (COMPLETED)** |
| 89 | +6. **[x] FastAPI Server (Layer 10)**: Health, stats, search, context, semantic query, reload, entity details, callers/callees. |
| 90 | +7. **[x] Semantic Search & Indexing (Layer 4a)**: Chunker (module header/imports/entities), OpenAI embeddings, FAISS vector store, hybrid BM25+vector retrieval (RRF), reranking, dependency expansion. |
| 91 | +8. **[x] Indexer Persistence + CLI**: `index`/`semantic-search` commands with save/load. |
| 92 | +9. **[x] Watch Mode**: Background indexer + filesystem monitor for incremental re-indexing. |
| 93 | +10. **[x] CLI Workflows**: `analyze`, `query`, `context`, `export`, `stats`, `server`, `history`, `ask`. |
| 94 | + |
| 95 | +### **Phase 3: Temporal & Runtime Signals (COMPLETED)** |
| 96 | +11. **[x] Git History Ingestion (Temporal)**: Commit/author entities, authored/modified/changed_by relationships; surfaced via `--temporal` and `history`. |
| 97 | +12. **[x] Coverage Signals (Layer 5)**: Cobertura ingestion with coverage report entities and covers/executed_by relationships. |
| 98 | + |
| 99 | +### **Phase 4: Documentation Synthesis (PARTIAL)** |
| 100 | +13. **[x] Markdown Export (MVP)**: CLI `export` produces an index-style Markdown doc. |
| 101 | +14. **[ ] Multi-Level Doc Synthesis (Layer 7)**: Architecture/module/function narratives, change summaries, and freshness tracking. |
| 102 | + |
| 103 | +### **Phase 5: Deep Analysis (NEXT)** |
| 104 | +15. **[ ] Static Behavioral Analysis (Layer 4)**: Data flow, state transitions, side-effect classification. |
| 105 | +16. **[ ] Intent Extraction (Layer 6)**: ADR/PR/commit intent linking beyond commit metadata. |
| 106 | +17. **[ ] Confidence Scoring (Layer 3)**: Weighted edges/entities by evidence source. |
| 107 | + |
| 108 | +### **Phase 6: Enterprise (FUTURE)** |
| 109 | +18. **[ ] Security & RBAC**: Permissioned access and audit trails. |
| 110 | +19. **[ ] Scalability**: Large monorepo support and distributed processing. |
| 111 | +20. **[ ] Team Sharing**: Remote knowledge store sync and collaboration. |
0 commit comments