System Architecture Deep Dive
Core Architecture Principles
1. Microservices Architecture
- Frontend: Next.js 15 with App Router (SSR/SSG)
- Backend: API Routes + External Services
- AI Services: Separate Python services (LangGraph, Document Processing)
- Database: Supabase (PostgreSQL) with RLS
2. Technology Stack Details
| Layer | Technology | Version | Purpose |
|---|---|---|---|
| Frontend | Next.js | 15.2.5 | React framework with App Router |
| React | 19.1.0 | UI library | |
| TypeScript | 5.5+ | Type safety | |
| Zustand | Latest | State management | |
| shadcn/ui | Latest | Component library | |
| Backend | Node.js | 20.12+ | Runtime |
| Supabase | Latest | Database & Auth | |
| Redis | Latest | Caching layer | |
| SQLite | Latest | Local caching | |
| AI/ML | OpenAI | Latest | GPT models |
| Anthropic | Latest | Claude models | |
| LangChain | Latest | AI orchestration | |
| Python | 3.11+ | AI services | |
| Infrastructure | Azure | - | Cloud platform |
| Kubernetes | Latest | Container orchestration | |
| Docker | Latest | Containerization |
Data Flow Architecture
Database Architecture
Supabase Schema Overview
- Users & Authentication: Managed by Supabase Auth
- Organizations: Multi-tenant support
- Files & Documents: File management with embeddings
- Opportunities: Pipeline management
- Chats & Messages: Conversation history
- Knowledge Base: Categorized content
Key Database Features
- Row Level Security (RLS): All tables have RLS policies
- Embeddings: Vector storage for semantic search
- Materialized Views: Performance optimization
- Triggers: Automated data maintenance
Deployment Architecture
Environments
- Development: Local development
- QA Commercial: qa-commercial.awardedai.com
- QA Government: qa-government.awardedai.com
- Production Commercial: *.awardedai.com
- Production Government: *.awardedai.com (Azure Gov)
- Sandbox: Testing environment
CI/CD Pipeline
GitHub Push → GitHub Actions → Docker Build → Azure Container Registry → AKS Deployment
Container Services
- web: Main Next.js application
- ai: Python AI services
- nest: Shared services API
- doc-pipeline: Document processing
- workflows: LangGraph workflows
- agenting: Agent services
Future Architecture: LangGraph Platform
The strategic migration to LangGraph Platform will consolidate our AI services:
Benefits:
- Unified Development: One way to build AI features
- Built-in Evaluations: Move from tests to observations
- Native Observability: LangSmith integration out of the box
- Improved DevEx: Faster development cycles
Security Architecture
Authentication & Authorization
- Supabase Auth: Primary authentication
- NextAuth: Session management
- RLS Policies: Database-level security
- API Keys: Service-to-service auth
Data Security
- Encryption at Rest: Azure Storage
- Encryption in Transit: HTTPS/TLS
- Secrets Management: 1Password + Azure Key Vault
- RBAC: Role-based access control
Performance Architecture
Caching Strategy
- SQLite: Primary cache (always available)
- Redis: Secondary cache (distributed)
- In-Memory: Fallback cache
- CDN: Static asset caching
Optimization Techniques
- Code Splitting: Dynamic imports
- Image Optimization: Next.js Image component
- API Caching: 30-minute default TTL
- Database Indexes: HNSW for vector search
Monitoring & Observability
Tools & Services
- Sentry: Error tracking
- PostHog: Analytics & feature flags
- OpenTelemetry: Distributed tracing
- Custom Logging: Structured JSON logs
Key Metrics
- API response times
- Error rates
- Cache hit rates
- AI model performance
- User engagement
Scalability Considerations
Current Scale
- Users: ~1000+ active users
- Data: 1.38M lines of code
- Files: Millions of documents
- API Calls: Thousands per minute
Scaling Strategy
- Horizontal Scaling: Kubernetes pods
- Database Sharding: Future consideration
- CDN Expansion: Global distribution
- AI Model Optimization: Response caching
Technical Debt Areas
Identified Issues
- Test Coverage: Currently at 38.48%
- TODO/FIXME: 313 files with markers
- Type Safety: Some
anytypes remain - Documentation: Needs expansion
- Performance: Cache optimization needed
Recommended Actions
- Implement comprehensive testing strategy
- Address technical debt systematically
- Improve type safety across codebase
- Enhance documentation coverage
- Optimize caching mechanisms