# billyledev/astro-hapijs-starter architecture

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

- Interactive diagram: https://gitdiagram.com/billyledev/astro-hapijs-starter
- Repository: https://github.com/billyledev/astro-hapijs-starter

## Overview

##### Main Components
- Frontend: Represented by the "packages/front" directory, this component uses Astro for static page generation, Vue for interactive components, and Tailwind CSS for theming. It manages user interfaces like sign-in, sign-up, landing pages, contact forms, and more.
- Backend API: Represented by the "packages/api" directory, the API is built on HapiJS. Key files include the server entry point (src/server.ts), plugins (e.g., betterAuthPlugin, captchaPlugin, contactPlugin, mailerPlugin), and utility functions for tasks like mailing.
- Authentication & Security: Highlight the usage of BetterAuth for managing authentication and Altcha for captcha integration. These are integrated into the backend via dedicated plugins.
- Email Service: The API has an "emails" folder containing HTML/text templates for contact and welcome emails, along with mailer utilities. External SMTP (e.g., MailHog for testing) is used to deliver emails.

##### Component Interactions
- External Services: Include the SMTP server (like MailHog) as an external service interacting with the backend’s mailer utility.

##### Architectural Patterns and Design Principles
- Modular Architecture: The separation of the project into two main packages ("api" and "front") indicates a modular design, fostering separation of concerns.
- Plugin-based Extensions: The backend uses plugins to add functionality (better authentication, captcha, email), showcasing an extensible system design.
- TypeScript: Both components use TypeScript, ensuring consistency and type safety across the codebase.
- API-First Design: The clear division suggests an API-first approach where the frontend interacts with the backend solely via defined endpoints.

## Diagram (Mermaid)

```mermaid
flowchart TD
    F["Frontend (Astro, Vue, Tailwind)"]:::front
    F -->|"APIRequest"| S("Server Entry Point (HapiJS, TypeScript)"):::backend

    subgraph "Backend API Plugins"
      direction TB
      Auth["Authentication Plugin (BetterAuth)"]:::plugin
      Captcha["Captcha Plugin (Altcha)"]:::plugin
      Contact["Contact Plugin (ContactForm)"]:::plugin
      Mailer["Mailer Plugin (Emails)"]:::plugin
    end

    S -->|"HandlesAuth"| Auth
    S -->|"ProcessesCaptcha"| Captcha
    S -->|"SubmitsContact"| Contact
    S -->|"TriggersEmails"| Mailer

    U["Mailing Utility"]:::utils
    E["Email Templates"]:::email
    Mailer -->|"UsesUtility"| U
    Mailer -->|"UsesTemplates"| E

    SMTP["MailHog (SMTP Server)"]:::external
    Mailer -->|"SendsEmail"| SMTP

    click F "https://github.com/billyledev/astro-hapijs-starter/tree/main/packages/front"
    click S "https://github.com/billyledev/astro-hapijs-starter/blob/main/packages/api/src/server.ts"
    click Auth "https://github.com/billyledev/astro-hapijs-starter/blob/main/packages/api/src/plugins/betterAuthPlugin.ts"
    click Captcha "https://github.com/billyledev/astro-hapijs-starter/blob/main/packages/api/src/plugins/captchaPlugin.ts"
    click Contact "https://github.com/billyledev/astro-hapijs-starter/blob/main/packages/api/src/plugins/contactPlugin.ts"
    click Mailer "https://github.com/billyledev/astro-hapijs-starter/blob/main/packages/api/src/plugins/mailerPlugin.ts"
    click U "https://github.com/billyledev/astro-hapijs-starter/blob/main/packages/api/src/utils/mailer.ts"
    click E "https://github.com/billyledev/astro-hapijs-starter/tree/main/packages/api/emails"

    classDef front fill:#FFF3CD,stroke:#FFB300,stroke-width:2px;
    classDef backend fill:#D1ECF1,stroke:#0C5460,stroke-width:2px;
    classDef plugin fill:#D4EDDA,stroke:#155724,stroke-width:2px;
    classDef utils fill:#F8D7DA,stroke:#721C24,stroke-width:2px;
    classDef email fill:#E2E3E5,stroke:#6C757D,stroke-width:2px;
    classDef external fill:#FEE2E2,stroke:#DC3545,stroke-width:2px;
```
