# hhs/head-start-ttadp architecture

> Architecture diagram of the GitHub repository hhs/head-start-ttadp, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hhs/head-start-ttadp
- Repository: https://github.com/hhs/head-start-ttadp

## Overview

##### Core Components
- Frontend: Located in the “frontend” directory. This is a React-based Single Page Application (SPA) that runs on localhost:3000 (when deployed locally) and proxies API calls to the backend.
- Backend API: The primary business logic is in the “src” directory. It contains routes, middleware, models, services, migrations, and tests. This layer handles authentication, validation, business rules, and data transformation.
- Similarity Microservice: The “similarity_api” directory is a separate Python service (complete with its own Dockerfile, runtime.txt, and routes) that likely handles specialized similarity computations.
- Database: PostgreSQL is used as the persistent datastore. The numerous migration scripts (in “src/migrations”) and seeders indicate a strong focus on maintaining and version‑managing the relational schema.
- File Storage: Minio (S3‑compatible file storage) is integrated. The README shows that minio runs on localhost:9000 and is used for file uploads.
- Automation & Infrastructure: There are automation scripts (in directories like “automation/…”), CI configurations (.circleci), Terraform files (in “terraform/…”), and deployment manifests. These underpin testing, continuous integration (via CircleCI), and deployments (Cloud.gov-based environments).
- Additional Tools/Integrations: There are scripts for tasks like running tests, linting, backups, and data processing. There’s also evidence for integration with external services through Cloud.gov and possibly Redis for caching (inferred from binding to common ports and the existence of “automation/ci/scripts” and “bin” scripts).

##### Relationships and Interactions
- The Frontend sends HTTP requests to the Backend via REST APIs. Note that the frontend uses proxying (as per the README) so that unknown paths are forwarded.
- The Backend communicates directly with the PostgreSQL database for CRUD operations, applies migrations on startup, and maintains transactional integrity.
- The Backend also uses external file storage (minio) for handling uploads and downloads.
- Specialized requests may be routed (or a backend service call may be made) to the Similarity API for computations.
- CI/CD is handled by CircleCI using Docker containers that build, test, and deploy the application across different environments (sandbox, dev, staging, prod), and Terraform configuration files define the persistent infrastructure (for the database, etc.).
- Automated scripts for testing, backups, and pre‑commit hooks (e.g., linting and Terraform formatting) run locally or in the CI pipelines.
- The application also integrates with monitoring (NewRelic), authentication services (as indicated by AUTH_CLIENT_ID/SECRET and HSES integrations in middleware), and various messaging/email services (via “src/lib/mailer”).

##### Architectural Patterns and Design Principles
- Separation of Concerns: The project clearly separates presentation (frontend), business logic (backend services, middleware, and routes), data access (models, migrations), and external integrations.
- Microservices: The existence of the “similarity_api” as a separate service emphasizes a microservice approach for specialized tasks.
- Containerization: Dockerfiles, docker-compose configurations, and scripts (e.g., “yarn docker:reset”, “yarn docker:start”) reflect a containerized deployment strategy.
- CI/CD and Infrastructure as Code: CircleCI pipelines and Terraform scripts underline modern DevOps practices.
- Testing and Quality: Extensive directories for unit, integration, and e2e tests show that the project uses a strategy to keep each component well‑tested via isolation, snapshots (for database state), and linting processes.
- Extensibility: With clearly demarcated modules (such as controllers, middleware, services, and helpers), adding new features or replacement components is straightforward.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Cloud.gov Environment"
        subgraph "Ephemeral Infrastructure"
            FE["Frontend (React SPA)"]:::frontend
            BE["Backend API (Node.js)"]:::backend
            SM["Similarity Microservice (Python)"]:::microservice
        end
        subgraph "Persistent Infrastructure"
            DB["PostgreSQL Database"]:::database
            MINIO["Minio (File Storage)"]:::filestorage
        end
        subgraph "Automation & CI/CD"
            CI["CI/CD & Terraform"]:::automation
        end
    end

    %% Connections
    FE -->|"HTTP_API_Calls"| BE
    BE -->|"CRUD/Migrations/Seeders"| DB
    BE -->|"FileUploads/Downloads"| MINIO
    BE -->|"Compute_Similarity"| SM
    CI -->|"Deploys"| FE
    CI -->|"Deploys"| BE
    CI -->|"Manages"| DB
    CI -->|"Manages"| MINIO

    %% Click Events
    click FE "https://github.com/hhs/head-start-ttadp/tree/main/frontend/"
    click BE "https://github.com/hhs/head-start-ttadp/tree/main/src/"
    click DB "https://github.com/hhs/head-start-ttadp/tree/main/src/migrations/"
    click SM "https://github.com/hhs/head-start-ttadp/tree/main/similarity_api/"
    click CI "https://github.com/hhs/head-start-ttadp/tree/main/.circleci/"

    %% Styles
    classDef frontend fill:#add8e6,stroke:#333,stroke-width:2px;
    classDef backend fill:#90ee90,stroke:#333,stroke-width:2px;
    classDef microservice fill:#ffb6c1,stroke:#333,stroke-width:2px;
    classDef database fill:#ffe4b5,stroke:#333,stroke-width:2px;
    classDef filestorage fill:#dda0dd,stroke:#333,stroke-width:2px;
    classDef automation fill:#fafad2,stroke:#333,stroke-width:2px;
```
