|
| 1 | +# M365 Knowledge Assistant - Architecture |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +An AI-powered knowledge assistant that helps employees find information across Microsoft 365 services (SharePoint, Teams, OneDrive, Outlook) using the GitHub Copilot SDK. |
| 6 | + |
| 7 | +## System Architecture |
| 8 | + |
| 9 | +``` |
| 10 | +┌─────────────────────────────────────────────────────────────────────────────┐ |
| 11 | +│ CLIENT LAYER │ |
| 12 | +├─────────────────────────────────────────────────────────────────────────────┤ |
| 13 | +│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │ |
| 14 | +│ │ Teams Bot │ │ Web UI │ │ CLI Tool │ │ |
| 15 | +│ │ (Future) │ │ (React) │ │ (Current) │ │ |
| 16 | +│ └──────┬───────┘ └──────┬───────┘ └──────┬───────┘ │ |
| 17 | +│ │ │ │ │ |
| 18 | +│ └─────────────────┼─────────────────┘ │ |
| 19 | +│ ▼ │ |
| 20 | +├─────────────────────────────────────────────────────────────────────────────┤ |
| 21 | +│ API LAYER │ |
| 22 | +├─────────────────────────────────────────────────────────────────────────────┤ |
| 23 | +│ ┌─────────────────────────────────────────────────────────────────────┐ │ |
| 24 | +│ │ Express.js REST API │ │ |
| 25 | +│ │ /api/chat - Send messages, stream responses │ │ |
| 26 | +│ │ /api/sessions - Manage conversation sessions │ │ |
| 27 | +│ │ /api/health - Health checks and monitoring │ │ |
| 28 | +│ └─────────────────────────────────────────────────────────────────────┘ │ |
| 29 | +│ │ │ |
| 30 | +├───────────────────────────┼─────────────────────────────────────────────────┤ |
| 31 | +│ CORE LAYER │ |
| 32 | +├───────────────────────────┼─────────────────────────────────────────────────┤ |
| 33 | +│ ▼ │ |
| 34 | +│ ┌─────────────────────────────────────────────────────────────────────┐ │ |
| 35 | +│ │ Copilot SDK Client │ │ |
| 36 | +│ │ • Session Management │ │ |
| 37 | +│ │ • Tool Registration │ │ |
| 38 | +│ │ • Event Streaming │ │ |
| 39 | +│ │ • Custom Agents │ │ |
| 40 | +│ └─────────────────────────────────────────────────────────────────────┘ │ |
| 41 | +│ │ │ |
| 42 | +│ ┌─────────────────┼─────────────────┐ │ |
| 43 | +│ ▼ ▼ ▼ │ |
| 44 | +│ ┌────────────┐ ┌────────────┐ ┌────────────┐ │ |
| 45 | +│ │ M365 │ │ GitHub │ │ Custom │ │ |
| 46 | +│ │ Tools │ │ MCP │ │ Skills │ │ |
| 47 | +│ └────────────┘ └────────────┘ └────────────┘ │ |
| 48 | +│ │ |
| 49 | +├─────────────────────────────────────────────────────────────────────────────┤ |
| 50 | +│ INTEGRATION LAYER │ |
| 51 | +├─────────────────────────────────────────────────────────────────────────────┤ |
| 52 | +│ ┌────────────┐ ┌────────────┐ ┌────────────┐ ┌────────────┐ │ |
| 53 | +│ │ SharePoint │ │ Teams │ │ OneDrive │ │ Outlook │ │ |
| 54 | +│ │ Service │ │ Service │ │ Service │ │ Service │ │ |
| 55 | +│ └─────┬──────┘ └─────┬──────┘ └─────┬──────┘ └─────┬──────┘ │ |
| 56 | +│ │ │ │ │ │ |
| 57 | +│ └────────────────┴────────────────┴────────────────┘ │ |
| 58 | +│ │ │ |
| 59 | +│ ▼ │ |
| 60 | +│ ┌─────────────────────────────────────────────────────────────────────┐ │ |
| 61 | +│ │ Microsoft Graph Client │ │ |
| 62 | +│ │ • Authentication (MSAL) │ │ |
| 63 | +│ │ • Token Management │ │ |
| 64 | +│ │ • API Abstraction │ │ |
| 65 | +│ └─────────────────────────────────────────────────────────────────────┘ │ |
| 66 | +│ │ |
| 67 | +└─────────────────────────────────────────────────────────────────────────────┘ |
| 68 | +``` |
| 69 | + |
| 70 | +## Directory Structure |
| 71 | + |
| 72 | +``` |
| 73 | +demo/ |
| 74 | +├── ARCHITECTURE.md # This file |
| 75 | +├── TECH_STACK.md # Technology decisions |
| 76 | +├── PROJECT.md # Current tasks and roadmap |
| 77 | +├── STANDARDS.md # Coding standards |
| 78 | +│ |
| 79 | +├── backend/ |
| 80 | +│ ├── src/ |
| 81 | +│ │ ├── api/ # Express routes and controllers |
| 82 | +│ │ │ ├── routes/ |
| 83 | +│ │ │ │ ├── chat.routes.ts |
| 84 | +│ │ │ │ ├── session.routes.ts |
| 85 | +│ │ │ │ └── health.routes.ts |
| 86 | +│ │ │ ├── controllers/ |
| 87 | +│ │ │ │ ├── chat.controller.ts |
| 88 | +│ │ │ │ ├── session.controller.ts |
| 89 | +│ │ │ │ └── health.controller.ts |
| 90 | +│ │ │ └── middleware/ |
| 91 | +│ │ │ ├── auth.middleware.ts |
| 92 | +│ │ │ ├── error.middleware.ts |
| 93 | +│ │ │ └── validation.middleware.ts |
| 94 | +│ │ │ |
| 95 | +│ │ ├── core/ # Copilot SDK integration |
| 96 | +│ │ │ ├── copilot-client.ts # SDK client wrapper |
| 97 | +│ │ │ ├── session-manager.ts # Session lifecycle |
| 98 | +│ │ │ ├── tool-registry.ts # Tool registration |
| 99 | +│ │ │ └── agent-config.ts # Custom agent definitions |
| 100 | +│ │ │ |
| 101 | +│ │ ├── tools/ # Custom Copilot tools |
| 102 | +│ │ │ ├── index.ts # Tool exports |
| 103 | +│ │ │ ├── sharepoint.tool.ts |
| 104 | +│ │ │ ├── teams.tool.ts |
| 105 | +│ │ │ ├── onedrive.tool.ts |
| 106 | +│ │ │ └── outlook.tool.ts |
| 107 | +│ │ │ |
| 108 | +│ │ ├── services/ # Business logic & integrations |
| 109 | +│ │ │ ├── graph/ |
| 110 | +│ │ │ │ ├── graph-client.ts |
| 111 | +│ │ │ │ ├── sharepoint.service.ts |
| 112 | +│ │ │ │ ├── teams.service.ts |
| 113 | +│ │ │ │ ├── onedrive.service.ts |
| 114 | +│ │ │ │ └── outlook.service.ts |
| 115 | +│ │ │ └── auth/ |
| 116 | +│ │ │ ├── msal-client.ts |
| 117 | +│ │ │ └── token-cache.ts |
| 118 | +│ │ │ |
| 119 | +│ │ ├── config/ # Configuration |
| 120 | +│ │ │ ├── index.ts |
| 121 | +│ │ │ ├── copilot.config.ts |
| 122 | +│ │ │ └── graph.config.ts |
| 123 | +│ │ │ |
| 124 | +│ │ ├── utils/ # Shared utilities |
| 125 | +│ │ │ ├── logger.ts |
| 126 | +│ │ │ ├── errors.ts |
| 127 | +│ │ │ └── validators.ts |
| 128 | +│ │ │ |
| 129 | +│ │ └── index.ts # Application entry point |
| 130 | +│ │ |
| 131 | +│ ├── tests/ |
| 132 | +│ │ ├── unit/ |
| 133 | +│ │ ├── integration/ |
| 134 | +│ │ └── e2e/ |
| 135 | +│ │ |
| 136 | +│ ├── package.json |
| 137 | +│ ├── tsconfig.json |
| 138 | +│ └── Dockerfile |
| 139 | +│ |
| 140 | +├── common/ # Shared types and constants |
| 141 | +│ ├── types/ |
| 142 | +│ │ ├── api.types.ts |
| 143 | +│ │ ├── session.types.ts |
| 144 | +│ │ ├── tool.types.ts |
| 145 | +│ │ └── m365.types.ts |
| 146 | +│ └── constants/ |
| 147 | +│ └── index.ts |
| 148 | +│ |
| 149 | +├── skills/ # Copilot SDK skills |
| 150 | +│ └── enterprise-knowledge/ |
| 151 | +│ └── SKILL.md |
| 152 | +│ |
| 153 | +├── scripts/ # Build and deployment scripts |
| 154 | +│ ├── setup.sh |
| 155 | +│ └── deploy.sh |
| 156 | +│ |
| 157 | +├── .github/ |
| 158 | +│ └── workflows/ |
| 159 | +│ └── ci.yml |
| 160 | +│ |
| 161 | +├── .env.example |
| 162 | +├── docker-compose.yml |
| 163 | +└── README.md |
| 164 | +``` |
| 165 | + |
| 166 | +## Data Flow |
| 167 | + |
| 168 | +### 1. User Query Flow |
| 169 | +``` |
| 170 | +User Input → API Layer → Core Layer → Tool Execution → Graph API → Response |
| 171 | +``` |
| 172 | + |
| 173 | +### 2. Session Management |
| 174 | +``` |
| 175 | +Create Session → Register Tools → Configure Agent → Process Messages → Persist State |
| 176 | +``` |
| 177 | + |
| 178 | +### 3. Tool Invocation |
| 179 | +``` |
| 180 | +Copilot Decision → Tool Registry → Service Layer → Graph Client → External API |
| 181 | +``` |
| 182 | + |
| 183 | +## Key Components |
| 184 | + |
| 185 | +### 1. Copilot Client Wrapper (`/backend/src/core/copilot-client.ts`) |
| 186 | +- Manages SDK lifecycle (start/stop) |
| 187 | +- Handles connection to Copilot CLI |
| 188 | +- Provides singleton access |
| 189 | + |
| 190 | +### 2. Session Manager (`/backend/src/core/session-manager.ts`) |
| 191 | +- Creates and resumes sessions |
| 192 | +- Manages session persistence |
| 193 | +- Handles multi-user scenarios |
| 194 | + |
| 195 | +### 3. Tool Registry (`/backend/src/core/tool-registry.ts`) |
| 196 | +- Registers M365 tools with Copilot |
| 197 | +- Manages tool handlers |
| 198 | +- Provides type-safe tool definitions |
| 199 | + |
| 200 | +### 4. M365 Services (`/backend/src/services/graph/`) |
| 201 | +- Abstracts Microsoft Graph API |
| 202 | +- Handles authentication via MSAL |
| 203 | +- Provides typed responses |
| 204 | + |
| 205 | +## Security Boundaries |
| 206 | + |
| 207 | +1. **Authentication**: MSAL for M365, JWT for API |
| 208 | +2. **Authorization**: Graph permissions, role-based access |
| 209 | +3. **Data Flow**: All M365 data through Graph API only |
| 210 | +4. **Secrets**: Environment variables, never hardcoded |
| 211 | + |
| 212 | +## Extension Points |
| 213 | + |
| 214 | +1. Add new tools in `/backend/src/tools/` |
| 215 | +2. Add new services in `/backend/src/services/` |
| 216 | +3. Add new skills in `/skills/` |
| 217 | +4. Add new agents in `/backend/src/core/agent-config.ts` |
0 commit comments