- AI-Powered: Intelligent task management using LangGraph and LLM orchestration
- Self-Hosted: Complete data ownership and control
- Lightweight: Minimal dependencies, fast startup, low resource usage
- Scalable: Horizontal scaling support via Docker Swarm/Kubernetes
- Maintainable: Clean separation of concerns, modular architecture
- Developer-Friendly: Comprehensive documentation, clear structure
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Frontend β
β (Vanilla JS + HTML5 + CSS3 + Nginx) β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ β
β β Task UI β β Chat UI β β Auth UI β β
β ββββββββ¬ββββββββ ββββββββ¬ββββββββ ββββββββ¬ββββββββ β
βββββββββββΌβββββββββββββββββββΌβββββββββββββββββββΌββββββββββββββ
β β β
β REST API β REST API β REST API
β β β
βββββββββββΌβββββββββββββββββββΌβββββββββββββββββββΌββββββββββββββ
β Backend (FastAPI) β
β ββββββββββββββ ββββββββββββββ ββββββββββββββββββββββ β
β β Auth β β Task β β Automated β β
β β Router β β Router β β Process Scheduler β β
β βββββββ¬βββββββ βββββββ¬βββββββ βββββββββββ¬βββββββββββ β
β β β β β
β βββββββΌββββββββββββββββΌββββββββββββββββββββββΌβββββββββββ β
β β Database Service Layer β β
β β (Auth, Task, Chat, Process Services) β β
β βββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββ β
ββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββ
β
ββββββββββββββΌβββββββββββββ
β β β
βββββββββΌβββββββ βββΌββββββββββ β
β PostgreSQL β β Agent β β
β Database β β Service β β
β β β(LangGraph)β β
ββββββββββββββββ βββββ¬ββββββββ β
β β
ββββββΌββββββ β
β LLM β β
βProviders β β
ββββββββββββ β
Technology: Vanilla JavaScript, HTML5, CSS3, Nginx
Responsibilities:
- User interface for task management
- AI chat interface
- Authentication flows
- Theme management (dark/light)
- State management via LocalStorage
Key Files:
index.html- Main applicationapp.js- Task and chat logiclogin.js/register.js- Authenticationtheme.js- Theme switchingstyles.css- Atom One Dark Pro theme
Communication:
- REST API calls to backend
- Token-based authentication
- Real-time updates (planned: WebSocket)
Technology: FastAPI, Python 3.11+, Uvicorn
Responsibilities:
- RESTful API endpoints
- Business logic orchestration
- Authentication and authorization
- Database operations
- Background task scheduling
- Integration with AI agent
API Routers:
/register - User registration
/login - User authentication
/me - Current user info
/api/v1/tasks - Task CRUD operations
/api/v1/chat - AI chat interactions
/api/v1/processes - Automated processes
/health - Health check
Services:
AuthService- User managementTaskService- Task operationsChatService- Chat sessionsAutomatedProcessService- Process management
Middleware:
- CORS handling
- Error handling
- Request logging
- Rate limiting (optional)
Technology: PostgreSQL 15+, SQLAlchemy ORM
Schema:
users- User accountstasks- Task storagechat_sessions- Chat sessionschat_messages- Message historyautomated_processes- Process definitionsautomated_process_executions- Execution logs
Features:
- Connection pooling
- Transaction management
- Migration support (Alembic)
- Timezone-aware timestamps
- JSONB for flexible data
Technology: LangGraph, LangChain, OpenAI/Anthropic
Responsibilities:
- Natural language understanding
- Intent classification
- Tool execution
- Response generation
- Context management
Graph Nodes:
- Entry Node - Initialize conversation
- Intent Classification - Understand user request
- Tool Execution - Execute actions
- Response Generation - Generate natural language response
Tools:
add_task- Create new tasksupdate_task- Modify existing taskslist_tasks- Query tasksdelete_task- Remove tasks
State Management:
- Conversation history
- User context
- Active tasks
- Pending actions
Technology: APScheduler
Responsibilities:
- Time-based process execution
- Cron-like scheduling
- Job monitoring
- Error handling and retries
Processes:
- Task rescheduling
- Session cleanup
- Reminder notifications
- Analytics generation
User β Frontend β Backend β Database
β β β β
β β β Create User
β β ββββββββββββ€
β β Return Token β
β βββββββββββ€ β
β Display Successβ β
βββββββββ€ β β
User β Frontend β Backend β Agent β LLM Provider
β β β β β
β "Create task" β β β
ββββββββΊβ β β β
β β POST /chat β β
β ββββββββββΊβ β β
β β β Invoke β β
β β ββββββββββΊβ β
β β β β Analyze
β β β ββββββββββΊβ
β β β βββββββββββ
β β β β β
β β β add_task() β
β β βββββββββββ β
β β β β
β β β Save to DB β
β β ββββββββΊ Database β
β β Response with task β
β βββββββββββ€ β
β Show task card β β
βββββββββ€ β β
Scheduler β AutomatedProcessService β Process Executor β Database
β β β β
Trigger β β β
ββββββββββββββββΊβ β β
β β Get Process Config β β
β βββββββββββββββββββββββββΊβ β
β β β β
β β Execute β β
β ββββββββββββββββββββββββββ β
β β β β
β β Update Tasks β
β β ββββββββββββββββΊβ
β β Log Execution β β
β ββββββββββββββββββββββββββββββββββββββββββΊβ
/ (repo root)
ββ docs/ # π Comprehensive documentation
β ββ architecture.md # System architecture (this file)
β ββ API.md # REST API documentation
β ββ AGENT.md # AI agent system guide
β ββ DATABASE.md # Database schema & services
β ββ FRONTEND.md # Frontend architecture
β ββ INTEGRATION.md # Integration guide
β ββ DEPLOYMENT.md # Deployment strategies
β ββ CONFIGURATION.md # Configuration options
β ββ TESTING.md # Testing guide
β ββ automated_processes.md # Process automation
β ββ README.md # Documentation index
ββ src/
β ββ frontend/ # π Static frontend
β β ββ index.html # Main app page
β β ββ login.html # Authentication
β β ββ app.js # Task & chat logic
β β ββ theme.js # Theme management
β β ββ styles.css # Styling
β β ββ nginx.conf # Server config
β β ββ Dockerfile # Container definition
β ββ backend/ # π₯ FastAPI backend
β β ββ app/
β β β ββ api/
β β β β ββ routers/ # API endpoints
β β β β β ββ auth.py # Authentication routes
β β β β β ββ chat.py # Chat routes
β β β β ββ models/ # Request/response models
β β β ββ database/
β β β β ββ models.py # SQLAlchemy models
β β β β ββ database.py # Connection management
β β β β ββ auth_service.py # User operations
β β β β ββ task_service.py # Task operations
β β β β ββ chat_service.py # Chat operations
β β β β ββ automated_process_service.py
β β β ββ main.py # FastAPI app
β β β ββ scheduler.py # Background scheduler
β β ββ requirements.txt # Python dependencies
β β ββ Dockerfile
β ββ behflow_agent/ # π€ AI Agent service
β β ββ nodes/
β β β ββ graph_nodes.py # LangGraph nodes
β β ββ models/
β β β ββ task.py # Task model
β β β ββ automated_process.py
β β β ββ models.py # Agent state
β β ββ agent.py # Main agent class
β β ββ builder.py # Agent factory
β β ββ tools.py # LangChain tools
β β ββ llm_config.py # LLM configuration
β β ββ users.py # User context
β β ββ utils.py # Utilities
β ββ shared/
β ββ logger.py # Logging utilities
ββ tests/ # π§ͺ Test suites
β ββ backend/ # Backend unit tests
β ββ frontend/ # Frontend tests
β ββ agent/ # Agent tests
ββ infra/
β ββ docker-compose.yml # Local development
β ββ migrations/ # Database migrations
ββ .github/
β ββ workflows/ # CI/CD pipelines
ββ .env.example # Environment template
ββ README.md # Project overview
ββ LICENSE # MIT License
1. User provides credentials
2. Backend validates against database
3. Generate JWT token with expiration
4. Client stores token in LocalStorage
5. Include token in Authorization header for API requests
6. Backend validates token on each request
- Password Hashing: BCrypt with salt
- JWT Tokens: Short expiration (24h default)
- HTTPS Only: TLS 1.2+ in production
- CORS Protection: Whitelisted origins
- SQL Injection Prevention: Parameterized queries
- Rate Limiting: Per-IP and per-user limits
- Input Validation: Pydantic models
- Secret Management: Environment variables, never hardcoded
1. CREATE: User creates task via chat or form
β
2. STORE: Save to database with NOT_STARTED status
β
3. UPDATE: Status changes (IN_PROGRESS, COMPLETED, BLOCKED)
β
4. NOTIFY: Trigger webhooks/notifications
β
5. ARCHIVE/DELETE: Cleanup or permanent removal
1. INITIATE: User sends first message
β
2. CREATE SESSION: Generate session_id
β
3. PROCESS: Agent analyzes and responds
β
4. STORE: Save messages to database
β
5. CONTINUE: Maintain context across messages
β
6. EXPIRE: Auto-cleanup after inactivity
Backend:
- Stateless design
- Load balancing with Nginx/Traefik
- Auto-scaling based on CPU/memory
Database:
- Read replicas for queries
- Connection pooling
- Query optimization
Agent Service:
- Async/await for concurrency
- LLM request batching
- Response caching
- Increase container resources
- Optimize database indices
- Cache frequently accessed data
| Component | Technology | Purpose |
|---|---|---|
| Frontend | Vanilla JS + HTML5 + CSS3 | Lightweight UI |
| Backend | FastAPI + Python 3.11 | REST API |
| Database | PostgreSQL 15 | Data persistence |
| Agent | LangGraph + LangChain | AI orchestration |
| LLM | OpenAI/Anthropic | Natural language |
| Scheduler | APScheduler | Background jobs |
| Server | Nginx | Static files + proxy |
| Container | Docker + Docker Compose | Deployment |
| Orchestration | K8s / Docker Swarm | Scaling |
- Separation of Concerns: Clear boundaries between layers
- Single Responsibility: Each component has one job
- Dependency Injection: Loose coupling via interfaces
- Configuration Over Code: Environment-based settings
- Fail Fast: Validate early, fail gracefully
- Idempotency: Safe to retry operations
- Observability: Comprehensive logging and monitoring
# 1. Start infrastructure
docker-compose up -d db
# 2. Run backend
cd src/backend
python -m uvicorn app.main:app --reload
# 3. Serve frontend
cd src/frontend
python -m http.server 8080
# 4. Access application
open http://localhost:8080# Run unit tests
pytest tests/
# Run with coverage
pytest --cov=src tests/
# Run integration tests
pytest tests/integration/
# Run end-to-end tests
pytest tests/e2e/# 1. Build images
docker build -t behflow/backend:latest ./src/backend
docker build -t behflow/frontend:latest ./src/frontend
# 2. Push to registry
docker push behflow/backend:latest
docker push behflow/frontend:latest
# 3. Deploy to production
kubectl apply -f k8s/
# OR
docker stack deploy -c docker-stack.yml behflow- WebSocket support for real-time updates
- Voice interface integration
- Multi-agent collaboration
- Vector database for long-term memory
- Mobile app (React Native/Flutter)
- Browser extension
- Offline mode with sync
- Analytics dashboard
- Custom LLM integration
- Plugin system
- GraphQL API alongside REST
- Event sourcing for audit trail
- CQRS pattern for scalability
- Redis caching layer
- Elasticsearch for full-text search
- Prometheus metrics
- Distributed tracing (Jaeger)
- API versioning
- Rate limiting per user
- Multi-tenancy support
For detailed information about each component, see:
- API Documentation - REST API endpoints and usage
- Agent Documentation - AI agent system details
- Database Documentation - Schema and services
- Frontend Documentation - UI architecture
- Integration Guide - External integrations
- Deployment Guide - Deployment strategies
- Configuration Guide - Configuration options
- Testing Guide - Testing strategies
This architecture is designed to be simple, scalable, and maintainable. It prioritizes developer experience while maintaining production-readiness.