This document outlines the architecture of the Neuron AI + Symfony Company Research Application, a web application that leverages Symfony framework and Neuron AI to provide comprehensive company research capabilities.
- System Overview
- Architectural Patterns
- Component Architecture
- Data Flow
- Technology Stack
- Integration Architecture
- Deployment Architecture
- Security Considerations
- References & Resources
The Company Research Application is a web application that enables users to:
- Search and research companies by name, industry, or keyword
- Import company data from financial data sources
- Gather and analyze financial data (quarterly reports, 10K)
- Identify and profile company leadership
- Generate competitive analyses
- Provide industry segment analysis
- Export reports to PDF or Excel
The system leverages Neuron AI to automate data gathering, analysis, and report generation, making it faster and more efficient to perform comprehensive company research.
The application follows these architectural patterns:
- Model-View-Controller (MVC) - Implemented through Symfony's framework pattern
- Service-Oriented Architecture - Business logic encapsulated in service classes
- Repository Pattern - Data access through Doctrine ORM repositories
- Client-Server Architecture - Web application serving HTML/JS clients
- Cloud-Native Design - Built for deployment to Cloud Foundry with service binding support
- Dependency Injection - Symfony's DI container for service management
- Event-Driven Components - For handling certain application events
- Command Query Responsibility Segregation (CQRS) - For financial data operations
graph TD
User[User] --> WebUI[Web UI]
WebUI --> SymfonyController[Symfony Controller Layer]
subgraph "Application"
SymfonyController --> CompanyController[Company Controller]
SymfonyController --> ReportController[Report Controller]
SymfonyController --> FinancialController[Financial Controller]
SymfonyController --> SecurityController[Security Controller]
CompanyController --> CompanyService[Company Service]
CompanyController --> NeuronAiService[Neuron AI Service]
ReportController --> ReportService[Report Service]
ReportController --> ReportExportService[Report Export Service]
FinancialController --> StockDataService[Stock Data Service]
FinancialController --> FinancialAnalysisService[Financial Analysis Service]
CompanyService --> CompanyRepository[Company Repository]
ReportService --> ReportRepository[Report Repository]
StockDataService --> ExternalAPI[External Financial APIs]
NeuronAiService --> GenAIAdapter[GenAI Adapter]
end
CompanyRepository --> Database[(Database)]
ReportRepository --> Database
GenAIAdapter --> LLMService[LLM Service]
subgraph "External Services"
ExternalAPI
LLMService
end
-
Web UI Layer
- Symfony Twig templates
- Bootstrap framework for styling
- JavaScript for asynchronous requests
- Form handling for user inputs
- Dynamic data display
-
Controller Layer
- Route handling and request processing
- Input validation
- Response generation
- Session management
- Error handling
-
Service Layer
- Business logic implementation
- Integration with external services
- Data transformation and manipulation
- Background processing
-
Repository Layer
- Data access abstractions
- Query building and execution
- Entity management
- Data persistence
-
Entity Layer
- Domain models and object-relational mapping
- Business rules and validation
- Relationships between entities
-
Neuron AI Integration
- GenAI service client
- Prompt engineering and response parsing
- Context management for AI requests
- Error recovery and fallback mechanisms
-
External API Integration
- Financial data providers
- Stock market information
- News and press releases
- Company profiles and information
- SEC filings and reports
sequenceDiagram
participant User
participant Controller as CompanyController
participant StockService as StockDataService
participant AI as NeuronAiService
participant DB as Database
participant External as External APIs
User->>Controller: Search for company
Controller->>DB: Search existing companies
DB->>Controller: Return database results
alt No results in database
Controller->>StockService: Search external sources
StockService->>External: API request for company info
External->>StockService: Return company data
StockService->>Controller: Return API results
Controller->>User: Display combined results
opt User imports company
User->>Controller: Select import
Controller->>StockService: Import company data
StockService->>External: Fetch detailed company data
External->>StockService: Return detailed data
StockService->>DB: Save company entity
opt AI Enhancement
Controller->>AI: Request additional company info
AI->>External: Query LLM service
External->>AI: Return enhanced data
AI->>DB: Update company with AI data
end
DB->>Controller: Return saved company
Controller->>User: Display company details
end
else Results found in database
Controller->>User: Display database results
end
sequenceDiagram
participant User
participant Controller as FinancialController
participant StockService as StockDataService
participant AI as NeuronAiService
participant DB as Database
participant External as External APIs
User->>Controller: Request financial analysis
Controller->>StockService: Fetch current stock data
StockService->>External: Request financial data
External->>StockService: Return financial data
StockService->>DB: Store historical data
Controller->>AI: Generate financial analysis
AI->>External: Query LLM service with financial context
External->>AI: Return analysis
AI->>Controller: Return structured analysis data
Controller->>DB: Save financial analysis
Controller->>User: Display financial data and analysis
sequenceDiagram
participant User
participant Controller as ReportController
participant ReportService
participant AI as NeuronAiService
participant ExportService
participant DB as Database
User->>Controller: Request company report
Controller->>ReportService: Generate report
ReportService->>DB: Fetch company data
DB->>ReportService: Return company data
ReportService->>AI: Generate report sections
AI->>ReportService: Return AI-generated content
ReportService->>DB: Save report draft
ReportService->>Controller: Return report data
Controller->>User: Display report preview
opt Export Report
User->>Controller: Request export (PDF/Excel)
Controller->>ExportService: Generate export file
ExportService->>Controller: Return file
Controller->>User: Download report file
end
- Symfony 6.3+: PHP web application framework
- PHP 8.3+: Programming language
- Doctrine ORM: Object-relational mapping for database interactions
- Neuron AI SDK: PHP library for LLM interactions
- Twig: Template engine for views
- Symfony Messenger: For asynchronous processing
- Symfony Security: For authentication and authorization
- Symfony Form: For form handling and validation
- Symfony Validator: For data validation
- MySQL/PostgreSQL/SQLite: Database options
- HTML/CSS/JavaScript: Standard web technologies
- Bootstrap 5: CSS framework for responsive design
- Chart.js: For financial data visualization
- Fetch API: For asynchronous requests
- FontAwesome: Icon library
- LLM API: Configurable LLM endpoint (compatible with OpenAI API)
- Financial Data APIs: Stock market and company data
- SEC Filing APIs: For regulatory filing information
- News APIs: For company news and press releases
- Cloud Foundry: Platform for deployment
- Symfony Env: Environment variable management
- Composer: Dependency management
- Git: Version control
- GitHub Actions: CI/CD pipeline
The application integrates with Large Language Model (LLM) services through a GenAI adapter:
// NeuronAiService class excerpt
public function __construct(
private string $apiKey,
private string $baseUrl = null,
private string $model = 'gpt-4o-mini'
) {
// Initialize the service with credentials
}
public function generateCompanyInfo(string $companyName): array
{
$prompt = $this->buildCompanyInfoPrompt($companyName);
try {
$response = $this->callLlmApi($prompt);
return $this->parseCompanyInfoResponse($response);
} catch (\Exception $e) {
return ['error' => 'Failed to generate company information: ' . $e->getMessage()];
}
}The application uses financial data APIs to fetch real-time and historical company data:
// StockDataService class excerpt
public function getCompanyNews(string $symbol, int $limit = 10): array
{
try {
$response = $this->apiClient->get("/company/news/{$symbol}", [
'query' => ['limit' => $limit]
]);
return $this->processNewsResponse($response);
} catch (\Exception $e) {
$this->logger->error('Failed to fetch company news', [
'symbol' => $symbol,
'error' => $e->getMessage()
]);
return [];
}
}When deployed to Cloud Foundry, the application can automatically bind to LLM services:
// Service configuration example
if (isset($_ENV['VCAP_SERVICES'])) {
$vcapServices = json_decode($_ENV['VCAP_SERVICES'], true);
// Look for GenAI service binding
if (isset($vcapServices['genai'])) {
$genaiService = $vcapServices['genai'][0];
$apiKey = $genaiService['credentials']['api_key'] ?? null;
$baseUrl = $genaiService['credentials']['base_url'] ?? null;
$model = $genaiService['credentials']['model'] ?? 'gpt-4o-mini';
// Configure the NeuronAiService with these credentials
}
}The application is designed for deployment to Tanzu Platform for Cloud Foundry:
graph TD
Internet[Internet] --> CF[Cloud Foundry Router]
CF --> App[Company Research App]
App --> DB[(Database)]
App --> GenAI[GenAI Service]
App --> FinAPI[Financial APIs]
App --> SEC[SEC Filing APIs]
App --> NewsAPI[News APIs]
subgraph "Tanzu Platform"
CF
App
DB
GenAI
end
subgraph "External Services"
FinAPI
SEC
NewsAPI
end
The application uses the following deployment strategy:
- Application Code: PHP Symfony application deployed as a Cloud Foundry app
- Database: Bound database service (MySQL, PostgreSQL, or SQLite)
- LLM Service: Bound GenAI service for AI capabilities
- Environment Variables: Configuration via environment variables
- Service Discovery: Automatic discovery of bound services
- Scaling: Horizontal scaling via instance count
- Form-based authentication for users
- Role-based access control for different user types
- Session management with secure cookies
- CSRF protection for form submissions
- API keys stored in environment variables
- Sensitive data encrypted in the database
- No hardcoded credentials in source code
- Proper input validation and sanitization
- Rate limiting for external API calls
- Secure communication over HTTPS
- Proper error handling to prevent information leakage
- API key rotation mechanisms
- Secure service binding for credentials
- Network isolation between applications
- Security groups for outbound access control
- Encrypted communication between components