socrates-ai 0.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
app/__init__.py
ADDED
app/main.py
ADDED
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Main FastAPI application.
|
|
3
|
+
|
|
4
|
+
Socrates2 - AI-Powered Specification Assistant
|
|
5
|
+
Phase 7.0+: Pluggifiable Domain Architecture (COMPLETE)
|
|
6
|
+
Phase 7.2: Domain API Integration (IN PROGRESS)
|
|
7
|
+
"""
|
|
8
|
+
import logging
|
|
9
|
+
from contextlib import asynccontextmanager
|
|
10
|
+
from typing import Callable, Optional
|
|
11
|
+
|
|
12
|
+
from fastapi import FastAPI
|
|
13
|
+
from fastapi.exceptions import RequestValidationError
|
|
14
|
+
from fastapi.middleware.cors import CORSMiddleware
|
|
15
|
+
from starlette.exceptions import HTTPException
|
|
16
|
+
|
|
17
|
+
from .api import (
|
|
18
|
+
admin,
|
|
19
|
+
analytics,
|
|
20
|
+
auth,
|
|
21
|
+
billing,
|
|
22
|
+
code_generation,
|
|
23
|
+
collaboration,
|
|
24
|
+
conflicts,
|
|
25
|
+
documents,
|
|
26
|
+
domains,
|
|
27
|
+
export,
|
|
28
|
+
export_endpoints,
|
|
29
|
+
github_endpoints,
|
|
30
|
+
insights,
|
|
31
|
+
jobs,
|
|
32
|
+
llm_endpoints,
|
|
33
|
+
notifications,
|
|
34
|
+
projects,
|
|
35
|
+
quality,
|
|
36
|
+
resources,
|
|
37
|
+
search,
|
|
38
|
+
sessions,
|
|
39
|
+
teams,
|
|
40
|
+
templates,
|
|
41
|
+
workflows,
|
|
42
|
+
)
|
|
43
|
+
from .api.error_handlers import (
|
|
44
|
+
general_exception_handler,
|
|
45
|
+
http_exception_handler,
|
|
46
|
+
validation_error_handler,
|
|
47
|
+
)
|
|
48
|
+
from .core.action_logger import initialize_action_logger
|
|
49
|
+
from .core.config import settings
|
|
50
|
+
from .core.database import close_db_connections
|
|
51
|
+
from .core.sentry_config import init_sentry
|
|
52
|
+
|
|
53
|
+
# Configure logging
|
|
54
|
+
logging.basicConfig(
|
|
55
|
+
level=getattr(logging, settings.LOG_LEVEL),
|
|
56
|
+
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
|
57
|
+
)
|
|
58
|
+
logger = logging.getLogger(__name__)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def _register_default_agents():
|
|
62
|
+
"""
|
|
63
|
+
Register all agents with the orchestrator.
|
|
64
|
+
This is the default startup behavior.
|
|
65
|
+
"""
|
|
66
|
+
from .agents.orchestrator import initialize_default_agents
|
|
67
|
+
initialize_default_agents()
|
|
68
|
+
logger.info("AgentOrchestrator initialized with default agents")
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def _initialize_job_scheduler():
|
|
72
|
+
"""
|
|
73
|
+
Initialize the background job scheduler.
|
|
74
|
+
Registers all scheduled tasks.
|
|
75
|
+
"""
|
|
76
|
+
from .jobs import aggregate_daily_analytics, cleanup_old_sessions
|
|
77
|
+
from .services.job_scheduler import get_scheduler
|
|
78
|
+
|
|
79
|
+
scheduler = get_scheduler()
|
|
80
|
+
scheduler.start()
|
|
81
|
+
|
|
82
|
+
# Register jobs
|
|
83
|
+
# Daily analytics aggregation at 2 AM UTC
|
|
84
|
+
scheduler.add_job(
|
|
85
|
+
aggregate_daily_analytics,
|
|
86
|
+
trigger="cron",
|
|
87
|
+
job_id="daily_analytics_aggregation",
|
|
88
|
+
name="Daily Analytics Aggregation",
|
|
89
|
+
hour=2,
|
|
90
|
+
minute=0,
|
|
91
|
+
timezone="UTC"
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
# Session cleanup at 3 AM UTC
|
|
95
|
+
scheduler.add_job(
|
|
96
|
+
cleanup_old_sessions,
|
|
97
|
+
trigger="cron",
|
|
98
|
+
job_id="cleanup_old_sessions",
|
|
99
|
+
name="Clean Up Old Sessions",
|
|
100
|
+
hour=3,
|
|
101
|
+
minute=0,
|
|
102
|
+
timezone="UTC"
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
logger.info("Background job scheduler initialized with registered jobs")
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def create_app(register_agents_fn: Optional[Callable] = None) -> FastAPI:
|
|
109
|
+
"""
|
|
110
|
+
Create FastAPI application with configurable agent registration.
|
|
111
|
+
|
|
112
|
+
This allows tests to inject custom agent registration logic without
|
|
113
|
+
modifying the main app or using mocks/patches.
|
|
114
|
+
|
|
115
|
+
Args:
|
|
116
|
+
register_agents_fn: Optional custom function to register agents.
|
|
117
|
+
If None, uses default agent registration.
|
|
118
|
+
|
|
119
|
+
Returns:
|
|
120
|
+
Configured FastAPI application
|
|
121
|
+
"""
|
|
122
|
+
# Initialize Sentry error tracking before creating the app
|
|
123
|
+
init_sentry()
|
|
124
|
+
|
|
125
|
+
@asynccontextmanager
|
|
126
|
+
async def lifespan(app: FastAPI):
|
|
127
|
+
"""
|
|
128
|
+
Application lifespan context manager.
|
|
129
|
+
Handles startup and shutdown events.
|
|
130
|
+
"""
|
|
131
|
+
# Startup
|
|
132
|
+
logger.info("Starting Socrates2 API...")
|
|
133
|
+
logger.info(f"Environment: {settings.ENVIRONMENT}")
|
|
134
|
+
logger.info(f"Debug mode: {settings.DEBUG}")
|
|
135
|
+
|
|
136
|
+
# Initialize action logging with configuration
|
|
137
|
+
initialize_action_logger(
|
|
138
|
+
enabled=settings.ACTION_LOGGING_ENABLED,
|
|
139
|
+
log_level=settings.ACTION_LOG_LEVEL
|
|
140
|
+
)
|
|
141
|
+
logger.info(f"Action logging: {'ENABLED' if settings.ACTION_LOGGING_ENABLED else 'DISABLED'}")
|
|
142
|
+
|
|
143
|
+
# Initialize background job scheduler
|
|
144
|
+
_initialize_job_scheduler()
|
|
145
|
+
|
|
146
|
+
# Initialize orchestrator and register agents
|
|
147
|
+
if register_agents_fn:
|
|
148
|
+
# Use injected agent registration function
|
|
149
|
+
register_agents_fn()
|
|
150
|
+
else:
|
|
151
|
+
# Use default agent registration
|
|
152
|
+
_register_default_agents()
|
|
153
|
+
|
|
154
|
+
yield
|
|
155
|
+
|
|
156
|
+
# Shutdown
|
|
157
|
+
logger.info("Shutting down Socrates2 API...")
|
|
158
|
+
|
|
159
|
+
# Shutdown job scheduler
|
|
160
|
+
from .services.job_scheduler import get_scheduler
|
|
161
|
+
scheduler = get_scheduler()
|
|
162
|
+
if scheduler.is_running:
|
|
163
|
+
scheduler.stop()
|
|
164
|
+
logger.info("Job scheduler stopped")
|
|
165
|
+
|
|
166
|
+
close_db_connections()
|
|
167
|
+
logger.info("Database connections closed")
|
|
168
|
+
|
|
169
|
+
# Create FastAPI application
|
|
170
|
+
app = FastAPI(
|
|
171
|
+
title="Socrates2 API",
|
|
172
|
+
description="AI-Powered Specification Assistant",
|
|
173
|
+
version="0.1.0",
|
|
174
|
+
lifespan=lifespan,
|
|
175
|
+
debug=settings.DEBUG
|
|
176
|
+
)
|
|
177
|
+
|
|
178
|
+
# Configure CORS
|
|
179
|
+
app.add_middleware(
|
|
180
|
+
CORSMiddleware, # type: ignore[arg-type] # Standard FastAPI middleware pattern, type checker limitation
|
|
181
|
+
allow_origins=settings.cors_origins_list,
|
|
182
|
+
allow_credentials=True,
|
|
183
|
+
allow_methods=["*"],
|
|
184
|
+
allow_headers=["*"],
|
|
185
|
+
)
|
|
186
|
+
|
|
187
|
+
# Include routers
|
|
188
|
+
app.include_router(auth.router)
|
|
189
|
+
app.include_router(admin.router)
|
|
190
|
+
app.include_router(projects.router)
|
|
191
|
+
app.include_router(sessions.router)
|
|
192
|
+
app.include_router(conflicts.router)
|
|
193
|
+
app.include_router(code_generation.router)
|
|
194
|
+
app.include_router(quality.router)
|
|
195
|
+
app.include_router(teams.router)
|
|
196
|
+
app.include_router(export_endpoints.router)
|
|
197
|
+
app.include_router(llm_endpoints.router)
|
|
198
|
+
app.include_router(github_endpoints.router)
|
|
199
|
+
app.include_router(search.router)
|
|
200
|
+
app.include_router(insights.router)
|
|
201
|
+
app.include_router(templates.router)
|
|
202
|
+
app.include_router(resources.router)
|
|
203
|
+
app.include_router(jobs.router)
|
|
204
|
+
app.include_router(billing.router)
|
|
205
|
+
app.include_router(documents.router)
|
|
206
|
+
app.include_router(notifications.router)
|
|
207
|
+
app.include_router(export.router)
|
|
208
|
+
app.include_router(collaboration.router)
|
|
209
|
+
app.include_router(domains.router)
|
|
210
|
+
app.include_router(workflows.router)
|
|
211
|
+
app.include_router(analytics.router)
|
|
212
|
+
|
|
213
|
+
# Register exception handlers for error tracking and proper response formatting
|
|
214
|
+
app.add_exception_handler(HTTPException, http_exception_handler)
|
|
215
|
+
app.add_exception_handler(RequestValidationError, validation_error_handler)
|
|
216
|
+
app.add_exception_handler(Exception, general_exception_handler)
|
|
217
|
+
|
|
218
|
+
return app
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
# Create default app instance (used by uvicorn in production)
|
|
222
|
+
app = create_app()
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
@app.get("/")
|
|
226
|
+
def root():
|
|
227
|
+
"""
|
|
228
|
+
Root endpoint.
|
|
229
|
+
|
|
230
|
+
Returns:
|
|
231
|
+
Welcome message with API info
|
|
232
|
+
"""
|
|
233
|
+
return {
|
|
234
|
+
"message": "Socrates2 API",
|
|
235
|
+
"version": "0.1.0",
|
|
236
|
+
"phase": "Phase 7.4 - Advanced Analytics System",
|
|
237
|
+
"domains_infrastructure": "Phase 7.0 (Complete - 197 tests passing)",
|
|
238
|
+
"domains_api": "Phase 7.2 (Complete)",
|
|
239
|
+
"workflows": "Phase 7.3 (Complete - 29 tests passing)",
|
|
240
|
+
"analytics": "Phase 7.4 (In Development)",
|
|
241
|
+
"docs": "/docs",
|
|
242
|
+
"domains_endpoint": "/api/v1/domains",
|
|
243
|
+
"workflows_endpoint": "/api/v1/workflows",
|
|
244
|
+
"analytics_endpoint": "/api/v1/analytics",
|
|
245
|
+
"health": "/api/v1/admin/health"
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
@app.get("/api/v1/info")
|
|
250
|
+
def api_info():
|
|
251
|
+
"""
|
|
252
|
+
API information endpoint.
|
|
253
|
+
|
|
254
|
+
Returns:
|
|
255
|
+
Detailed API information
|
|
256
|
+
"""
|
|
257
|
+
from .agents.orchestrator import get_orchestrator
|
|
258
|
+
|
|
259
|
+
orchestrator = get_orchestrator()
|
|
260
|
+
agent_info = orchestrator.get_all_agents()
|
|
261
|
+
|
|
262
|
+
return {
|
|
263
|
+
"api": {
|
|
264
|
+
"title": "Socrates2 API",
|
|
265
|
+
"version": "0.1.0",
|
|
266
|
+
"environment": settings.ENVIRONMENT,
|
|
267
|
+
"phase": "Phase 7.4 - Advanced Analytics System",
|
|
268
|
+
"domains": {
|
|
269
|
+
"infrastructure": "Phase 7.0 (COMPLETE - 197 tests)",
|
|
270
|
+
"api_integration": "Phase 7.2 (COMPLETE)",
|
|
271
|
+
"workflows": "Phase 7.3 (COMPLETE - 29 tests)",
|
|
272
|
+
"analytics": "Phase 7.4 (IN PROGRESS)",
|
|
273
|
+
"total_tests": "226 passing"
|
|
274
|
+
}
|
|
275
|
+
},
|
|
276
|
+
"agents": {
|
|
277
|
+
"total": len(agent_info),
|
|
278
|
+
"registered": [agent['agent_id'] for agent in agent_info]
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
if __name__ == "__main__":
|
|
284
|
+
import uvicorn
|
|
285
|
+
|
|
286
|
+
uvicorn.run(
|
|
287
|
+
"app.main:app",
|
|
288
|
+
host="0.0.0.0",
|
|
289
|
+
port=8000,
|
|
290
|
+
reload=settings.DEBUG,
|
|
291
|
+
log_level=settings.LOG_LEVEL.lower()
|
|
292
|
+
)
|
|
@@ -0,0 +1,605 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: socrates-ai
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: AI-Powered Specification Assistant using Socratic Method
|
|
5
|
+
Author-email: Socrates2 Team <info@socrates2.io>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/socrates2/socrates2
|
|
8
|
+
Project-URL: Documentation, https://github.com/socrates2/socrates2/blob/main/backend/README.md
|
|
9
|
+
Project-URL: Repository, https://github.com/socrates2/socrates2
|
|
10
|
+
Project-URL: Issues, https://github.com/socrates2/socrates2/issues
|
|
11
|
+
Project-URL: Changelog, https://github.com/socrates2/socrates2/blob/main/backend/CHANGELOG.md
|
|
12
|
+
Keywords: ai,specifications,assistant,socratic-method,multi-domain,workflows,analytics
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Environment :: Web Environment
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
17
|
+
Classifier: Operating System :: OS Independent
|
|
18
|
+
Classifier: Programming Language :: Python
|
|
19
|
+
Classifier: Programming Language :: Python :: 3
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
23
|
+
Classifier: Topic :: Office/Business
|
|
24
|
+
Classifier: Framework :: FastAPI
|
|
25
|
+
Requires-Python: >=3.12
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
Requires-Dist: fastapi==0.121.0
|
|
28
|
+
Requires-Dist: uvicorn[standard]==0.34.0
|
|
29
|
+
Requires-Dist: sqlalchemy==2.0.44
|
|
30
|
+
Requires-Dist: alembic==1.14.0
|
|
31
|
+
Requires-Dist: psycopg2-binary==2.9.10
|
|
32
|
+
Requires-Dist: pydantic==2.12.3
|
|
33
|
+
Requires-Dist: pydantic-settings==2.7.0
|
|
34
|
+
Requires-Dist: python-dotenv==1.0.1
|
|
35
|
+
Requires-Dist: passlib[bcrypt]==1.7.4
|
|
36
|
+
Requires-Dist: python-jose[cryptography]==3.3.0
|
|
37
|
+
Requires-Dist: python-multipart==0.0.20
|
|
38
|
+
Requires-Dist: anthropic==0.43.0
|
|
39
|
+
Requires-Dist: click==8.1.7
|
|
40
|
+
Requires-Dist: httpx==0.28.1
|
|
41
|
+
Provides-Extra: dev
|
|
42
|
+
Requires-Dist: pytest==8.3.4; extra == "dev"
|
|
43
|
+
Requires-Dist: pytest-asyncio==0.25.0; extra == "dev"
|
|
44
|
+
Requires-Dist: pytest-cov==6.0.0; extra == "dev"
|
|
45
|
+
Requires-Dist: pytest-mock==3.14.0; extra == "dev"
|
|
46
|
+
Requires-Dist: black==24.10.0; extra == "dev"
|
|
47
|
+
Requires-Dist: ruff==0.8.4; extra == "dev"
|
|
48
|
+
Requires-Dist: mypy==1.13.0; extra == "dev"
|
|
49
|
+
Requires-Dist: faker==33.1.0; extra == "dev"
|
|
50
|
+
Requires-Dist: factory-boy==3.3.1; extra == "dev"
|
|
51
|
+
|
|
52
|
+
# Socrates2 Backend
|
|
53
|
+
|
|
54
|
+
AI-Powered Specification Assistant using Socratic Method
|
|
55
|
+
|
|
56
|
+
**Current Version:** 0.1.0
|
|
57
|
+
**Status:** Phase 7.4 - Advanced Analytics & Multi-Domain Workflows
|
|
58
|
+
**Build Status:** 274 tests passing ✅
|
|
59
|
+
|
|
60
|
+
## Overview
|
|
61
|
+
|
|
62
|
+
Socrates2 is a comprehensive AI system for building and validating specifications across multiple knowledge domains using the Socratic method. It provides:
|
|
63
|
+
|
|
64
|
+
- **Multi-Domain System:** 7 pre-configured domains (Programming, Data Engineering, Architecture, Testing, Business, Security, DevOps)
|
|
65
|
+
- **Workflow Management:** Orchestrate specifications across multiple domains with unified validation
|
|
66
|
+
- **Analytics Engine:** Track domain usage, workflow quality, and system health
|
|
67
|
+
- **REST API:** Complete API for programmatic access to all features
|
|
68
|
+
- **CLI Interface:** Command-line tools for domain and workflow management
|
|
69
|
+
- **Template Engine:** Customizable question, export, rule, and analyzer engines
|
|
70
|
+
|
|
71
|
+
## Quick Start
|
|
72
|
+
|
|
73
|
+
### Installation
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
cd backend
|
|
77
|
+
|
|
78
|
+
# Install in editable mode (recommended for development)
|
|
79
|
+
pip install -e ".[dev]"
|
|
80
|
+
|
|
81
|
+
# Or production installation
|
|
82
|
+
pip install -e .
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Configuration
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
# Copy environment template
|
|
89
|
+
cp .env.example .env
|
|
90
|
+
|
|
91
|
+
# Edit with your settings
|
|
92
|
+
export ANTHROPIC_API_KEY="your-key-here"
|
|
93
|
+
export SECRET_KEY=$(python -c "import secrets; print(secrets.token_urlsafe(32))")
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Setup Database
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
# Run migrations
|
|
100
|
+
alembic upgrade head
|
|
101
|
+
|
|
102
|
+
# Verify setup
|
|
103
|
+
pytest tests/ -v --tb=short
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### Run Server
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
# Development server with auto-reload
|
|
110
|
+
python -m uvicorn app.main:app --reload
|
|
111
|
+
|
|
112
|
+
# Access API docs: http://localhost:8000/docs
|
|
113
|
+
# Access ReDoc: http://localhost:8000/redoc
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## Key Features
|
|
117
|
+
|
|
118
|
+
### 1. Multi-Domain System
|
|
119
|
+
|
|
120
|
+
Seven pre-configured domains with complete question sets, exporters, conflict rules, and quality analyzers:
|
|
121
|
+
|
|
122
|
+
- **Programming** - Language design, patterns, frameworks
|
|
123
|
+
- **Data Engineering** - Data pipelines, databases, ETL
|
|
124
|
+
- **Architecture** - System design, scalability, performance
|
|
125
|
+
- **Testing** - Test strategy, coverage, automation
|
|
126
|
+
- **Business** - Market analysis, GTM, financials
|
|
127
|
+
- **Security** - Compliance, encryption, threats
|
|
128
|
+
- **DevOps** - Infrastructure, automation, monitoring
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
# List all available domains
|
|
132
|
+
socrates domains list
|
|
133
|
+
|
|
134
|
+
# Get details about a domain
|
|
135
|
+
socrates domains info programming
|
|
136
|
+
|
|
137
|
+
# Get all questions in a domain
|
|
138
|
+
socrates domains questions data_engineering
|
|
139
|
+
|
|
140
|
+
# Get exporters for a domain
|
|
141
|
+
socrates domains exporters architecture
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### 2. REST API
|
|
145
|
+
|
|
146
|
+
Complete API with 40+ endpoints organized by resource:
|
|
147
|
+
|
|
148
|
+
#### Domains
|
|
149
|
+
```bash
|
|
150
|
+
# List all domains
|
|
151
|
+
curl http://localhost:8000/api/v1/domains
|
|
152
|
+
|
|
153
|
+
# Get domain details
|
|
154
|
+
curl http://localhost:8000/api/v1/domains/programming
|
|
155
|
+
|
|
156
|
+
# Get domain questions
|
|
157
|
+
curl http://localhost:8000/api/v1/domains/programming/questions
|
|
158
|
+
|
|
159
|
+
# Get export formats
|
|
160
|
+
curl http://localhost:8000/api/v1/domains/programming/exporters
|
|
161
|
+
|
|
162
|
+
# Get validation rules
|
|
163
|
+
curl http://localhost:8000/api/v1/domains/programming/rules
|
|
164
|
+
|
|
165
|
+
# Validate specification
|
|
166
|
+
curl -X POST http://localhost:8000/api/v1/domains/programming/validate-specification \
|
|
167
|
+
-H "Content-Type: application/json" \
|
|
168
|
+
-d '{"field1": "value1", "field2": "value2"}'
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
#### Workflows
|
|
172
|
+
```bash
|
|
173
|
+
# Create workflow combining multiple domains
|
|
174
|
+
curl -X POST http://localhost:8000/api/v1/workflows?workflow_id=my_project
|
|
175
|
+
|
|
176
|
+
# Add domain to workflow
|
|
177
|
+
curl -X POST http://localhost:8000/api/v1/workflows/my_project/add-domain \
|
|
178
|
+
-d '{"domain_id": "programming"}'
|
|
179
|
+
|
|
180
|
+
# Validate workflow specifications
|
|
181
|
+
curl http://localhost:8000/api/v1/workflows/my_project/validate
|
|
182
|
+
|
|
183
|
+
# Get cross-domain conflicts
|
|
184
|
+
curl http://localhost:8000/api/v1/workflows/my_project/conflicts
|
|
185
|
+
|
|
186
|
+
# Export workflow
|
|
187
|
+
curl -X POST http://localhost:8000/api/v1/workflows/my_project/export \
|
|
188
|
+
-d '{"format_id": "json"}'
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
#### Analytics
|
|
192
|
+
```bash
|
|
193
|
+
# Get overall analytics report
|
|
194
|
+
curl http://localhost:8000/api/v1/analytics
|
|
195
|
+
|
|
196
|
+
# Get domain-specific analytics
|
|
197
|
+
curl http://localhost:8000/api/v1/analytics/domains/programming
|
|
198
|
+
|
|
199
|
+
# Get workflow quality metrics
|
|
200
|
+
curl http://localhost:8000/api/v1/analytics/quality-summary
|
|
201
|
+
|
|
202
|
+
# Get most used domains
|
|
203
|
+
curl http://localhost:8000/api/v1/analytics/domains/top/10
|
|
204
|
+
|
|
205
|
+
# Export analytics data
|
|
206
|
+
curl -X POST http://localhost:8000/api/v1/analytics/export?format_id=json
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
### 3. CLI Interface
|
|
210
|
+
|
|
211
|
+
Command-line tools for all features:
|
|
212
|
+
|
|
213
|
+
```bash
|
|
214
|
+
# Domain commands
|
|
215
|
+
socrates domains list # List all domains
|
|
216
|
+
socrates domains info <domain_id> # Domain details
|
|
217
|
+
socrates domains questions <domain_id> # Get questions
|
|
218
|
+
socrates domains exporters <domain_id> # Get exporters
|
|
219
|
+
|
|
220
|
+
# Workflow commands
|
|
221
|
+
socrates workflows create <workflow_id> # Create workflow
|
|
222
|
+
socrates workflows list # List workflows
|
|
223
|
+
socrates workflows show <workflow_id> # Workflow details
|
|
224
|
+
socrates workflows add <workflow_id> <domain> # Add domain
|
|
225
|
+
socrates workflows validate <workflow_id> # Validate specs
|
|
226
|
+
socrates workflows export <workflow_id> # Export workflow
|
|
227
|
+
socrates workflows delete <workflow_id> # Delete workflow
|
|
228
|
+
|
|
229
|
+
# Analytics commands
|
|
230
|
+
socrates analytics report # Overall report
|
|
231
|
+
socrates analytics quality # Quality summary
|
|
232
|
+
socrates analytics domains # Domain ranking
|
|
233
|
+
socrates analytics export <format> # Export data
|
|
234
|
+
|
|
235
|
+
# Auth commands
|
|
236
|
+
socrates auth login # User login
|
|
237
|
+
socrates auth logout # User logout
|
|
238
|
+
socrates auth token --generate # Generate API token
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
## Project Structure
|
|
242
|
+
|
|
243
|
+
```
|
|
244
|
+
backend/
|
|
245
|
+
├── app/ # Main application package
|
|
246
|
+
│ ├── api/ # FastAPI endpoints (40+ routes)
|
|
247
|
+
│ │ ├── domains.py # Domain management (11 endpoints)
|
|
248
|
+
│ │ ├── workflows.py # Workflow management (11 endpoints)
|
|
249
|
+
│ │ ├── analytics.py # Analytics reporting (8 endpoints)
|
|
250
|
+
│ │ ├── auth.py # Authentication
|
|
251
|
+
│ │ ├── admin.py # Admin endpoints
|
|
252
|
+
│ │ └── ... # Other endpoints
|
|
253
|
+
│ │
|
|
254
|
+
│ ├── domains/ # Multi-domain system
|
|
255
|
+
│ │ ├── base.py # BaseDomain abstract class
|
|
256
|
+
│ │ ├── registry.py # DomainRegistry singleton
|
|
257
|
+
│ │ ├── programming/ # Programming domain (14 Q's, 8 exports)
|
|
258
|
+
│ │ ├── data_engineering/ # Data Engineering domain
|
|
259
|
+
│ │ ├── architecture/ # Architecture domain
|
|
260
|
+
│ │ ├── testing/ # Testing domain
|
|
261
|
+
│ │ ├── business/ # Business domain
|
|
262
|
+
│ │ ├── security/ # Security domain
|
|
263
|
+
│ │ ├── devops/ # DevOps domain
|
|
264
|
+
│ │ ├── questions.py # Question template engine
|
|
265
|
+
│ │ ├── exporters.py # Export format engine
|
|
266
|
+
│ │ ├── rules.py # Conflict rule engine
|
|
267
|
+
│ │ ├── analyzers.py # Quality analyzer engine
|
|
268
|
+
│ │ ├── workflows.py # Multi-domain workflow orchestration
|
|
269
|
+
│ │ ├── analytics.py # Domain analytics tracking
|
|
270
|
+
│ │ └── tests/ # Domain tests (80+ tests)
|
|
271
|
+
│ │
|
|
272
|
+
│ ├── cli/ # CLI interface
|
|
273
|
+
│ │ ├── main.py # CLI entry point
|
|
274
|
+
│ │ ├── commands/
|
|
275
|
+
│ │ │ ├── domains.py # Domain commands
|
|
276
|
+
│ │ │ ├── workflows.py # Workflow commands
|
|
277
|
+
│ │ │ ├── analytics.py # Analytics commands
|
|
278
|
+
│ │ │ └── auth.py # Auth commands
|
|
279
|
+
│ │ └── tests.py # CLI tests (21 tests)
|
|
280
|
+
│ │
|
|
281
|
+
│ ├── core/ # Core functionality
|
|
282
|
+
│ │ ├── database.py # SQLAlchemy setup (2 databases)
|
|
283
|
+
│ │ ├── config.py # Settings management
|
|
284
|
+
│ │ ├── security.py # JWT auth
|
|
285
|
+
│ │ ├── dependencies.py # Dependency injection
|
|
286
|
+
│ │ └── ... # Other utilities
|
|
287
|
+
│ │
|
|
288
|
+
│ ├── models/ # SQLAlchemy models
|
|
289
|
+
│ │ ├── base.py # BaseModel with UUID, timestamps
|
|
290
|
+
│ │ ├── user.py # User model
|
|
291
|
+
│ │ ├── project.py # Project model
|
|
292
|
+
│ │ ├── specification.py # Specification model
|
|
293
|
+
│ │ └── ... # Other models
|
|
294
|
+
│ │
|
|
295
|
+
│ ├── agents/ # Agent system
|
|
296
|
+
│ │ ├── base.py # BaseAgent abstract class
|
|
297
|
+
│ │ ├── orchestrator.py # AgentOrchestrator
|
|
298
|
+
│ │ └── ... # Specialized agents
|
|
299
|
+
│ │
|
|
300
|
+
│ ├── services/ # Business logic services
|
|
301
|
+
│ │ └── ...
|
|
302
|
+
│ │
|
|
303
|
+
│ └── main.py # FastAPI application factory
|
|
304
|
+
│
|
|
305
|
+
├── tests/ # Test suite (274+ tests)
|
|
306
|
+
│ ├── test_domains/ # Domain tests
|
|
307
|
+
│ ├── test_workflows.py # Workflow tests (29 tests)
|
|
308
|
+
│ ├── test_analytics.py # Analytics tests (27 tests)
|
|
309
|
+
│ ├── test_cli.py # CLI tests (21 tests)
|
|
310
|
+
│ └── ... # Other test files
|
|
311
|
+
│
|
|
312
|
+
├── alembic/ # Database migrations
|
|
313
|
+
│ └── versions/ # Migration scripts
|
|
314
|
+
│
|
|
315
|
+
├── pyproject.toml # Package configuration
|
|
316
|
+
├── requirements.txt # Production dependencies
|
|
317
|
+
├── requirements-dev.txt # Development dependencies
|
|
318
|
+
└── README.md # This file
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
## Testing
|
|
322
|
+
|
|
323
|
+
### Run All Tests
|
|
324
|
+
|
|
325
|
+
```bash
|
|
326
|
+
# Install dev dependencies
|
|
327
|
+
pip install -e ".[dev]"
|
|
328
|
+
|
|
329
|
+
# Run all tests with verbose output
|
|
330
|
+
pytest tests/ -v
|
|
331
|
+
|
|
332
|
+
# Run with coverage report
|
|
333
|
+
pytest tests/ -v --cov=app --cov-report=html
|
|
334
|
+
|
|
335
|
+
# Run specific test module
|
|
336
|
+
pytest tests/test_workflows.py -v
|
|
337
|
+
|
|
338
|
+
# Run tests matching pattern
|
|
339
|
+
pytest tests/ -k "workflow" -v
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
### Test Coverage
|
|
343
|
+
|
|
344
|
+
- **Domain System:** 80+ tests
|
|
345
|
+
- 14 domain tests (per-domain functionality)
|
|
346
|
+
- Question engine tests
|
|
347
|
+
- Export engine tests
|
|
348
|
+
- Rule engine tests
|
|
349
|
+
- Analyzer engine tests
|
|
350
|
+
|
|
351
|
+
- **Workflows:** 29 tests
|
|
352
|
+
- Multi-domain workflow creation and validation
|
|
353
|
+
- Cross-domain conflict detection
|
|
354
|
+
- Specification export
|
|
355
|
+
|
|
356
|
+
- **Analytics:** 27 tests
|
|
357
|
+
- Metrics tracking
|
|
358
|
+
- Domain analytics
|
|
359
|
+
- Workflow analytics
|
|
360
|
+
- Quality summary
|
|
361
|
+
|
|
362
|
+
- **CLI:** 21 tests
|
|
363
|
+
- Domain commands
|
|
364
|
+
- Workflow commands
|
|
365
|
+
- Analytics commands
|
|
366
|
+
- Help text
|
|
367
|
+
|
|
368
|
+
- **Infrastructure:** 100+ tests
|
|
369
|
+
- Database persistence
|
|
370
|
+
- Authentication
|
|
371
|
+
- API endpoints
|
|
372
|
+
- Agent system
|
|
373
|
+
- Service integration
|
|
374
|
+
|
|
375
|
+
**Total: 274+ tests, all passing ✅**
|
|
376
|
+
|
|
377
|
+
## Development
|
|
378
|
+
|
|
379
|
+
### Code Quality
|
|
380
|
+
|
|
381
|
+
```bash
|
|
382
|
+
# Format code with black (100 char line length)
|
|
383
|
+
black app/ tests/
|
|
384
|
+
|
|
385
|
+
# Lint with ruff
|
|
386
|
+
ruff check app/ tests/
|
|
387
|
+
|
|
388
|
+
# Type check with mypy
|
|
389
|
+
mypy app/ --explicit-package-bases
|
|
390
|
+
|
|
391
|
+
# Run all checks
|
|
392
|
+
black app/ && ruff check app/ && mypy app/
|
|
393
|
+
```
|
|
394
|
+
|
|
395
|
+
### Common Development Tasks
|
|
396
|
+
|
|
397
|
+
```bash
|
|
398
|
+
# Start development server with auto-reload
|
|
399
|
+
python -m uvicorn app.main:app --reload --port 8000
|
|
400
|
+
|
|
401
|
+
# Run tests continuously while editing
|
|
402
|
+
pytest-watch tests/
|
|
403
|
+
|
|
404
|
+
# Create new database migration
|
|
405
|
+
alembic revision --autogenerate -m "description"
|
|
406
|
+
|
|
407
|
+
# Apply migrations
|
|
408
|
+
alembic upgrade head
|
|
409
|
+
|
|
410
|
+
# Rollback migration
|
|
411
|
+
alembic downgrade -1
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
## Configuration
|
|
415
|
+
|
|
416
|
+
### Environment Variables
|
|
417
|
+
|
|
418
|
+
Create `.env` file with:
|
|
419
|
+
|
|
420
|
+
```env
|
|
421
|
+
# Database URLs (PostgreSQL)
|
|
422
|
+
DATABASE_URL_AUTH=postgresql://postgres:password@localhost:5432/socrates_auth
|
|
423
|
+
DATABASE_URL_SPECS=postgresql://postgres:password@localhost:5432/socrates_specs
|
|
424
|
+
|
|
425
|
+
# Security
|
|
426
|
+
SECRET_KEY=your-secret-key-here
|
|
427
|
+
ALGORITHM=HS256
|
|
428
|
+
ACCESS_TOKEN_EXPIRE_MINUTES=30
|
|
429
|
+
|
|
430
|
+
# LLM API
|
|
431
|
+
ANTHROPIC_API_KEY=your-api-key-here
|
|
432
|
+
|
|
433
|
+
# Application
|
|
434
|
+
DEBUG=True
|
|
435
|
+
ENVIRONMENT=development
|
|
436
|
+
LOG_LEVEL=DEBUG
|
|
437
|
+
|
|
438
|
+
# CORS
|
|
439
|
+
CORS_ORIGINS=http://localhost:3000,http://localhost:5173
|
|
440
|
+
```
|
|
441
|
+
|
|
442
|
+
### Generate Secret Key
|
|
443
|
+
|
|
444
|
+
```bash
|
|
445
|
+
python -c "import secrets; print(secrets.token_urlsafe(32))"
|
|
446
|
+
```
|
|
447
|
+
|
|
448
|
+
## API Documentation
|
|
449
|
+
|
|
450
|
+
Once the server is running:
|
|
451
|
+
|
|
452
|
+
- **Swagger UI:** http://localhost:8000/docs
|
|
453
|
+
- **ReDoc:** http://localhost:8000/redoc
|
|
454
|
+
- **OpenAPI JSON:** http://localhost:8000/openapi.json
|
|
455
|
+
|
|
456
|
+
All endpoints are documented with:
|
|
457
|
+
- Request/response examples
|
|
458
|
+
- Parameter descriptions
|
|
459
|
+
- Error codes and messages
|
|
460
|
+
- Authentication requirements
|
|
461
|
+
|
|
462
|
+
## Architecture
|
|
463
|
+
|
|
464
|
+
### Multi-Database Design
|
|
465
|
+
|
|
466
|
+
**socrates_auth database:**
|
|
467
|
+
- Users table (authentication)
|
|
468
|
+
- Refresh tokens table (JWT management)
|
|
469
|
+
|
|
470
|
+
**socrates_specs database:**
|
|
471
|
+
- Projects table (specification metadata)
|
|
472
|
+
- Sessions table (conversation history)
|
|
473
|
+
- And future: specifications, questions, conflicts, metrics
|
|
474
|
+
|
|
475
|
+
### Domain System Architecture
|
|
476
|
+
|
|
477
|
+
```
|
|
478
|
+
DomainRegistry (singleton)
|
|
479
|
+
├── ProgrammingDomain
|
|
480
|
+
├── DataEngineeringDomain
|
|
481
|
+
├── ArchitectureDomain
|
|
482
|
+
├── TestingDomain
|
|
483
|
+
├── BusinessDomain
|
|
484
|
+
├── SecurityDomain
|
|
485
|
+
└── DevOpsDomain
|
|
486
|
+
|
|
487
|
+
Each Domain contains:
|
|
488
|
+
├── Questions (via QuestionTemplateEngine)
|
|
489
|
+
├── Export Formats (via ExportTemplateEngine)
|
|
490
|
+
├── Conflict Rules (via ConflictRuleEngine)
|
|
491
|
+
└── Quality Analyzers (via QualityAnalyzerEngine)
|
|
492
|
+
```
|
|
493
|
+
|
|
494
|
+
### Workflow System
|
|
495
|
+
|
|
496
|
+
```
|
|
497
|
+
WorkflowManager (singleton)
|
|
498
|
+
└── MultiDomainWorkflow
|
|
499
|
+
├── DomainSpec (per domain)
|
|
500
|
+
├── CrossDomainConflict detection
|
|
501
|
+
│ ├── Architecture ↔ Testing
|
|
502
|
+
│ ├── Performance ↔ Testing
|
|
503
|
+
│ └── Data ↔ Architecture
|
|
504
|
+
└── Unified validation & export
|
|
505
|
+
```
|
|
506
|
+
|
|
507
|
+
### Analytics System
|
|
508
|
+
|
|
509
|
+
```
|
|
510
|
+
DomainAnalytics (singleton)
|
|
511
|
+
├── Domain access tracking
|
|
512
|
+
├── Question answer tracking
|
|
513
|
+
├── Export generation tracking
|
|
514
|
+
├── Conflict detection tracking
|
|
515
|
+
├── Workflow analytics
|
|
516
|
+
├── Quality metrics
|
|
517
|
+
└── Custom reporting
|
|
518
|
+
```
|
|
519
|
+
|
|
520
|
+
## Troubleshooting
|
|
521
|
+
|
|
522
|
+
### "ModuleNotFoundError: No module named 'app'"
|
|
523
|
+
|
|
524
|
+
```bash
|
|
525
|
+
cd backend
|
|
526
|
+
pip install -e .
|
|
527
|
+
```
|
|
528
|
+
|
|
529
|
+
### "Connection refused" on PostgreSQL
|
|
530
|
+
|
|
531
|
+
```bash
|
|
532
|
+
# Check if PostgreSQL is running
|
|
533
|
+
sudo systemctl status postgresql # Linux
|
|
534
|
+
# or Services app on Windows
|
|
535
|
+
|
|
536
|
+
# Start PostgreSQL if stopped
|
|
537
|
+
sudo systemctl start postgresql # Linux
|
|
538
|
+
|
|
539
|
+
# Verify databases exist
|
|
540
|
+
psql -U postgres -l | grep socrates
|
|
541
|
+
```
|
|
542
|
+
|
|
543
|
+
### API returns 404 for domains
|
|
544
|
+
|
|
545
|
+
```bash
|
|
546
|
+
# Ensure domains are registered
|
|
547
|
+
python -c "from app.domains import get_domain_registry; r = get_domain_registry(); print([d for d in r.list_domain_ids()])"
|
|
548
|
+
|
|
549
|
+
# Check that domain JSON files exist
|
|
550
|
+
ls -la app/domains/*/domain.json
|
|
551
|
+
```
|
|
552
|
+
|
|
553
|
+
### Tests fail with "domain not found"
|
|
554
|
+
|
|
555
|
+
```bash
|
|
556
|
+
# Domain registration might not have happened
|
|
557
|
+
# Delete any .pyc files and restart
|
|
558
|
+
find . -type d -name __pycache__ -exec rm -r {} + 2>/dev/null || true
|
|
559
|
+
|
|
560
|
+
# Run tests again
|
|
561
|
+
pytest tests/ -v
|
|
562
|
+
```
|
|
563
|
+
|
|
564
|
+
## Contributing
|
|
565
|
+
|
|
566
|
+
1. Install in editable mode: `pip install -e ".[dev]"`
|
|
567
|
+
2. Create feature branch: `git checkout -b feature/your-feature`
|
|
568
|
+
3. Make changes
|
|
569
|
+
4. Run tests: `pytest tests/ -v`
|
|
570
|
+
5. Format code: `black app/ tests/`
|
|
571
|
+
6. Commit with descriptive message
|
|
572
|
+
7. Push and create pull request
|
|
573
|
+
|
|
574
|
+
## Phase Status
|
|
575
|
+
|
|
576
|
+
- ✅ **Phase 0:** Documentation - Complete
|
|
577
|
+
- ✅ **Phase 1:** Infrastructure - Complete (user/project/session models)
|
|
578
|
+
- ✅ **Phase 2:** Authentication - Complete (JWT, roles)
|
|
579
|
+
- ✅ **Phase 3:** Agents - Complete (BaseAgent, Orchestrator)
|
|
580
|
+
- ✅ **Phase 4:** Core APIs - Complete (domain/project endpoints)
|
|
581
|
+
- ✅ **Phase 5:** Questions & Exporters - Complete (7 domains, 100+ questions)
|
|
582
|
+
- ✅ **Phase 6:** Specification Validation - Complete (conflict rules, quality analyzers)
|
|
583
|
+
- ✅ **Phase 7:** Advanced Features - Complete
|
|
584
|
+
- ✅ Phase 7.1: Advanced Domains (Business, Security, DevOps)
|
|
585
|
+
- ✅ Phase 7.2: Template Engines
|
|
586
|
+
- ✅ Phase 7.3: Multi-Domain Workflows
|
|
587
|
+
- ✅ Phase 7.4: Analytics System & CLI
|
|
588
|
+
- ⏳ **Phase 8:** Production Hardening
|
|
589
|
+
|
|
590
|
+
## License
|
|
591
|
+
|
|
592
|
+
MIT
|
|
593
|
+
|
|
594
|
+
## Support
|
|
595
|
+
|
|
596
|
+
For issues, questions, or contributions:
|
|
597
|
+
1. Check existing documentation in `/docs`
|
|
598
|
+
2. Review test files for usage examples
|
|
599
|
+
3. Check API docs at `/docs` endpoint
|
|
600
|
+
4. Create issue with detailed description
|
|
601
|
+
|
|
602
|
+
---
|
|
603
|
+
|
|
604
|
+
**Last Updated:** November 11, 2025
|
|
605
|
+
**Maintained by:** Socrates2 Team
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
app/__init__.py,sha256=ZciT_mF8G9Un0rY26noEwUBAJu3Cpe100MfQrhhvf94,96
|
|
2
|
+
app/main.py,sha256=_gpKegnnp_xczDgE7kDfcKg6Tuh6tpRbi0ms92Vyv9E,8437
|
|
3
|
+
socrates_ai-0.2.0.dist-info/METADATA,sha256=dL_YBW5Y1_A0dRhxZJqTA77LIVnlx6Kt4inUnx5ayG0,18514
|
|
4
|
+
socrates_ai-0.2.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
5
|
+
socrates_ai-0.2.0.dist-info/entry_points.txt,sha256=BLb5fpQqDTSt6KT3PjBFv8Hv_HhZ1dzZ1Z6VyycjJ6k,42
|
|
6
|
+
socrates_ai-0.2.0.dist-info/top_level.txt,sha256=io9g7LCbfmTG1SFKgEOGXmCFB9uMP2H5lerm0HiHWQE,4
|
|
7
|
+
socrates_ai-0.2.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
app
|