8.1 KiB
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Project Overview
PMFlow / Neural Sync is an AI-native project management platform designed for small (10-50 person) AI/ML technical teams. The system has evolved into a multi-tenant, role-based PM operating system with:
- Multi-tenant Architecture: Complete data isolation with tenant_id filtering
- RBAC: Role-based access control with JWT authentication
- Event-Driven Architecture: Event bus with WebSocket real-time updates
- AI-Native Features: LangChain integration, skill management, intelligent task routing
Dual Frontend Architecture
The project maintains two frontends:
- Vue 3 (
frontend/): Legacy Signal Dashboard with Naive UI - React 18 (
frontend-react/): New PMFlow interface with shadcn/ui (recommended for new features)
Common Development Commands
Quick Start / Stop
# Start all services (backend + React frontend)
./start.sh
# Or use Python launcher (cross-platform)
python launcher.py
# Stop all services
./stop.sh
Backend Development
cd backend
# Install dependencies (use project venv)
source ../venv/bin/activate # On Windows: ../venv/Scripts/activate
pip install -r requirements.txt
# Run database migrations
alembic upgrade head
# Seed initial data (development)
python -m seed_projects.py
# Start backend server (dev mode with hot reload)
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000
# Run specific file
python -m app.main
Frontend Development
React (PMFlow - Recommended):
cd frontend-react
npm install
npm run dev # Port 5174
npm run build
npm run preview
Vue 3 (Legacy):
cd frontend
npm install
npm run dev -- --host # Port 5174
npm run build
Architecture
Backend Structure (backend/app/)
Core Architecture:
api/- API routes organized by module (auth, signals, users, sstc, etc.)core/- Configuration, logging, response formattingmodels/- SQLAlchemy ORM with multi-tenant base classesschemas/- Pydantic request/response modelsservices/- Business logic layerdependencies/- FastAPI dependency injection (auth, tenant filtering)config/- Configuration and AI promptsmain.py- FastAPI application entry point
Key Systems:
-
Multi-Tenancy (
models/base.py):- All models inherit from
Base(includestenant_id,created_at,updated_at) Tenantmodel usesBaseNoTenant(no tenant_id)- All queries must filter by tenant_id via dependency injection
- All models inherit from
-
Authentication (
services/auth.py,dependencies/auth.py):- JWT-based authentication with 24-hour expiration
- RBAC with roles: BOSS, ADMIN, AI, FE, BE
- Permission matrix for fine-grained access control
- Use
require_roles()andget_current_userdependencies
-
Event System (
events.py,websocket.py):- Event bus for pub/sub messaging
- WebSocket manager with real-time broadcasting
- Event types: signals, tasks, code reviews, audits, integrations
-
Role Dispatcher (
dispatcher.py):- Routes signals to appropriate roles (Boss, AI Engineer, Backend, Frontend)
- Keyword and pattern-based routing with confidence scoring
- Escalation logic for high-impact decisions
-
AI Services:
ai_service.py- LangChain integrationllm.py- Ollama/OpenAI client wrapperskill_service.py- User skill managementconfig/ai_prompts.py- Centralized prompt templates
-
Integration Services:
plane.py- Plane PM tool integrationlark.py- Lark/Feishu messagingauditor.py- Code audit workflowauto_merger.py- Auto-merge logic
Frontend Structure
React (frontend-react/src/):
pages/- Page components (Login, Dashboard, Projects, Users, Skills)components/- Reusable UI componentsapi/- API client wrappershooks/- Custom React hooks (useUserRole)- Uses React Router with HashRouter, Tailwind CSS, Zustand for state
Vue 3 (frontend/src/):
pages/- Vue pagescomponents/- Vue components with Naive UIapi/- API clientcomposables/- Vue composablesstores/- Pinia stores
Database Schema
Multi-Tenant Models:
User- User accounts with roles (BOSS, ADMIN, AI, FE, BE)Tenant- Tenant isolationProject- Projects with tenant_idSignal- External signals with strategic analysisTask- Tasks linked to signals and projectsSkill- User skills with proficiency levelsUserSkillBinding- Many-to-many user-skill relationshipsUserWorkload- Real-time workload tracking
Type Compatibility (models/types.py):
- PostgreSQL: JSONB, ARRAY, Vector (pgvector)
- SQLite: Fallback to JSON/text storage for development
Key Integration Points
Authentication Flow
- Login via
/auth/loginreturns JWT token - Include token in Authorization header:
Bearer <token> - Use
get_current_userdependency for protected routes - Use
require_roles("BOSS", "ADMIN")for role-gated endpoints
Multi-Tenant Queries
from app.dependencies import get_tenant_id
@router.get("/items")
async def list_items(
tenant_id: int = Depends(get_tenant_id),
db: AsyncSession = Depends(get_db)
):
result = await db.execute(
select(Item).where(Item.tenant_id == tenant_id)
)
Event Broadcasting
from app.events import get_event_bus, EventType
event_bus = get_event_bus()
await event_bus.publish(
EventType.TASK_ASSIGNED,
{"task_id": 123, "user_id": 456}
)
WebSocket Events
- Events are automatically bridged to WebSocket clients
- Clients subscribe to event types for filtering
- Message format:
{"type": "event", "event_type": "...", "data": {...}, "timestamp": ...}
Development Notes
- Database: PostgreSQL with pgvector recommended; SQLite fallback for development
- CORS: Currently allows all origins (
*) - restrict for production - Logging: Structured logging via
core/logging.py - API Response: Standardized format via
core/response.py - AI Caching: Redis-based caching for AI call results
- AI Logging: All AI calls logged to
ai_call_logstable
Ports and Endpoints
- Backend API: http://127.0.0.1:8000
- API Docs: http://127.0.0.1:8000/docs (Swagger UI)
- React Frontend: http://127.0.0.1:5174
- Vue Frontend: http://127.0.0.1:5173
Environment Variables
Key environment variables (see .env.example):
DATABASE_URL- PostgreSQL/SQLite connection stringSECRET_KEY- JWT signing keyOPENAI_API_KEY- OpenAI API key for LangChainREDIS_URL- Redis connection for cachingPLANE_API_*- Plane PM tool integration
File Conventions
- Pydantic Schemas: Request/Response models in
schemas/ - SQLAlchemy Models: Database models in
models/ - API Routes: Route handlers in
api/ - Business Logic: Services in
services/ - AI Prompts: Centralized in
config/ai_prompts.py