> ## Documentation Index
> Fetch the complete documentation index at: https://docs.corrdata.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Architecture Overview

> CorrData's multi-layer architecture for pipeline integrity management

## System Architecture

CorrData uses a modern, event-driven architecture designed for reliability, scalability, and real-time analytics.

```
┌─────────────────────────────────────────────────────────────────┐
│                        Client Layer                              │
├─────────────────┬─────────────────┬─────────────────────────────┤
│   Web Dashboard │   Mobile PWA    │   AI Assistants (MCP)       │
└────────┬────────┴────────┬────────┴─────────────┬───────────────┘
         │                 │                       │
         ▼                 ▼                       ▼
┌─────────────────────────────────────────────────────────────────┐
│                       API Gateway                                │
│                    (GraphQL / REST)                             │
└────────────────────────────┬────────────────────────────────────┘
                             │
         ┌───────────────────┼───────────────────┐
         ▼                   ▼                   ▼
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│  Asset Service  │ │ Analytics Svc   │ │ Compliance Svc  │
└────────┬────────┘ └────────┬────────┘ └────────┬────────┘
         │                   │                   │
         ▼                   ▼                   ▼
┌─────────────────────────────────────────────────────────────────┐
│                       Data Layer                                 │
├─────────────────┬─────────────────┬─────────────────────────────┤
│   PostgreSQL    │   TimescaleDB   │      Neo4j                  │
│   (Assets)      │   (Time-series) │      (Relationships)        │
└─────────────────┴─────────────────┴─────────────────────────────┘
```

## Core Components

### Client Layer

<CardGroup cols={3}>
  <Card title="Web Dashboard" icon="browser">
    React-based SPA for operators and managers. Real-time dashboards, compliance tracking, and reporting.
  </Card>

  <Card title="Mobile PWA" icon="mobile">
    Progressive Web App for field technicians. Offline-first design with GPS integration.
  </Card>

  <Card title="AI Assistants" icon="robot">
    MCP server enables Claude and other AI assistants to interact with pipeline data.
  </Card>
</CardGroup>

### API Layer

CorrData exposes a unified GraphQL API for all client applications:

* **Queries** - Read operations for assets, measurements, compliance status
* **Mutations** - Write operations for creating readings, updating assets
* **Subscriptions** - Real-time updates for dashboards and alerts

### Service Layer

| Service              | Responsibility                                                     |
| -------------------- | ------------------------------------------------------------------ |
| Asset Service        | CRUD operations for pipelines, segments, test stations, rectifiers |
| Analytics Service    | Risk scoring, trend analysis, anomaly detection                    |
| Compliance Service   | Regulation tracking, deadline management, reporting                |
| Import Service       | GIS data import from ArcGIS and Shapefiles                         |
| Notification Service | Alerts, emails, SMS for critical events                            |

### Data Layer

<AccordionGroup>
  <Accordion title="PostgreSQL + PostGIS">
    Primary relational database for asset data:

    * Asset metadata and attributes
    * Tenant isolation via row-level security
    * Geospatial queries with PostGIS extension
  </Accordion>

  <Accordion title="TimescaleDB">
    Time-series database for measurements:

    * Optimized for time-series queries
    * Automatic data compression
    * Continuous aggregates for dashboards
  </Accordion>

  <Accordion title="Neo4j">
    Graph database for relationships:

    * Asset topology (what protects what)
    * Impact analysis (cascade effects)
    * Visualization data for relationship graphs
  </Accordion>
</AccordionGroup>

## Deployment Architecture

CorrData is deployed on AWS using containerized services:

```
┌─────────────────────────────────────────────────────────────────┐
│                         AWS Cloud                                │
├─────────────────────────────────────────────────────────────────┤
│  ┌─────────────┐  ┌─────────────┐  ┌─────────────┐              │
│  │ CloudFront  │  │    ALB      │  │  API GW     │              │
│  │   (CDN)     │  │             │  │             │              │
│  └──────┬──────┘  └──────┬──────┘  └──────┬──────┘              │
│         │                │                │                      │
│         ▼                ▼                ▼                      │
│  ┌─────────────────────────────────────────────────────┐        │
│  │                  ECS Fargate                         │        │
│  │  ┌─────────┐  ┌─────────┐  ┌─────────┐              │        │
│  │  │ Web App │  │ GraphQL │  │ Workers │              │        │
│  │  └─────────┘  └─────────┘  └─────────┘              │        │
│  └─────────────────────────────────────────────────────┘        │
│                              │                                   │
│         ┌────────────────────┼────────────────────┐              │
│         ▼                    ▼                    ▼              │
│  ┌─────────────┐      ┌─────────────┐      ┌─────────────┐      │
│  │    RDS      │      │ ElastiCache │      │   Neptune   │      │
│  │ PostgreSQL  │      │   (Redis)   │      │  (Neo4j)    │      │
│  └─────────────┘      └─────────────┘      └─────────────┘      │
└─────────────────────────────────────────────────────────────────┘
```

## Security Architecture

### Multi-Tenant Isolation

CorrData uses PostgreSQL Row-Level Security (RLS) for tenant isolation:

* Every table has a `tenant_id` column
* RLS policies enforce tenant boundaries at the database level
* API tokens include tenant claims for automatic filtering

### Authentication Flow

```
User → Cognito → JWT Token → API Gateway → Service
                    │
                    └── Contains: user_id, tenant_id, roles
```

### Data Encryption

| Layer       | Encryption                                |
| ----------- | ----------------------------------------- |
| In Transit  | TLS 1.3 for all connections               |
| At Rest     | AES-256 for RDS and S3                    |
| Application | Field-level encryption for sensitive data |

## Scalability

CorrData scales horizontally to handle growing data volumes:

* **ECS Auto-Scaling** - Add containers based on CPU/memory
* **Read Replicas** - Scale database reads independently
* **TimescaleDB Partitioning** - Automatic time-based partitioning
* **CDN Caching** - Edge caching for static assets
