# sharetribe/web-template architecture

> Architecture diagram of the GitHub repository sharetribe/web-template, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sharetribe/web-template
- Repository: https://github.com/sharetribe/web-template

## Overview

##### Main Components
a. Client/Frontend Application
- Located mainly in the “src” directory and “public” folder.
- Built with React (using create-react-app), including routing, components, containers, and a rich set of UI elements.
- Uses state management (e.g., ducks in “src/ducks”), and includes analytics, translations, and custom CSS.
b. Server/Backend Application
- Found in the “server” directory.
- Provides API endpoints, server-side rendering, middleware (authentication, data loading, etc.), and integration with external services.
- Contains configuration and utility files (e.g., “server/apiRouter.js”, “server/index.js”).
c. Transaction Process Modules
- In the “ext/transaction-processes” directory.
- These modules provide standardized workflows (booking, inquiry, purchase) with templates and configuration files.
d. External Services and Integrations
- Payment processing (Stripe integrations seen in containers like “StripeConnectAccountForm”, “StripePaymentAddress”, etc.)
- Social authentication providers (Facebook, Google, etc. under “server/api/auth”).
- Mapping and geocoding services (Google Maps and Mapbox integration in “src/components/Map” and “src/components/LocationAutocompleteInput”).
- Deployment and CI/CD services (CircleCI configuration, GitHub integration, and Heroku deployment instructions).

##### Relationships and Interactions
- The backend handles SSR for quicker initial loads and also serves static assets (from “public”).
- The server integrates with external services (authentication providers, payment gateways, maps) and the transaction-process modules.
- The “ext” folder modules can be seen as pluggable components that handle specific business workflows (e.g., booking or inquiry) which are invoked from the backend logic.
- Configuration files and environment setups are central for both development and production, showing a two-way configuration dependency.

##### Architectural Patterns and Design Principles
- Separation of concerns: clear separation between frontend (React components with client-side routing) and backend (API server with SSR).
- Modular design: lots of reusable components (present in “src/components”) and modular containers (pages, authentication, transaction, listing).
- Extensibility: The “ext” folder allows for custom transaction processes – a plug-in-like approach for adding or replacing business logic.
- Environment-specific configurations: use of multiple .env files, CircleCI, and patches ensures a consistent deployment pipeline.
- Integration with external libraries: payment (Stripe), maps (Google/Mapbox), and social login integrations (Facebook, Google).

##### Relevant Technologies and Frameworks
- Client: React, Redux (or ducks pattern), Webpack (via create-react-app), custom CSS modules.
- Server: Node.js (Express-like API structure), SSR techniques, custom middleware (for authentication, error handling, CSP).
- Continuous Integration/Deployment: CircleCI, Heroku.
- Third-party APIs: Social login providers, Stripe for payments, Mapbox/Google Maps for geographical data.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global User
    User("User (Browser)"):::user

    %% Client/Frontend Subgraph
    subgraph "Client/Frontend"
        FE("React Application"):::frontend
        Assets("Static Assets"):::frontend
        PaymentForm("StripeConnectAccountForm"):::external
        PaymentAddress("StripePaymentAddress"):::external
        MapComponent("Map"):::external
        Autocomplete("LocationAutocompleteInput"):::external
    end

    %% Server/Backend Subgraph
    subgraph "Server/Backend"
        Backend("Node.js API/SSR Server"):::backend
        SocialAuth("Social Auth Providers"):::external
    end

    %% Transaction Process Modules Subgraph
    subgraph "Transaction Processes"
        Transaction("Transaction Process Modules"):::transaction
    end

    %% External Services Subgraph
    subgraph "External Services"
        PaymentGateway("Payment Gateway (Stripe)"):::external
        MapsService("Mapping Service (Google/Mapbox)"):::external
    end

    %% Connections
    User -->|"initiates"| FE
    FE -->|"APIRequests"| Backend
    Backend -->|"AuthCalls"| SocialAuth
    Backend -->|"InvokeWorkflow"| Transaction
    Backend -->|"ProcessPayments"| PaymentGateway
    PaymentForm -->|"InitiatePayment"| PaymentGateway
    PaymentAddress -->|"UpdatePayment"| PaymentGateway
    MapComponent -->|"GetGeoData"| MapsService
    Autocomplete -->|"FetchSuggestions"| MapsService

    %% Click Events for Component Mapping
    click FE "https://github.com/sharetribe/web-template/tree/main/src"
    click Assets "https://github.com/sharetribe/web-template/tree/main/public"
    click Backend "https://github.com/sharetribe/web-template/tree/main/server"
    click Transaction "https://github.com/sharetribe/web-template/tree/main/ext/transaction-processes"
    click PaymentForm "https://github.com/sharetribe/web-template/tree/main/src/components/StripeConnectAccountForm"
    click PaymentAddress "https://github.com/sharetribe/web-template/tree/main/src/components/StripePaymentAddress"
    click SocialAuth "https://github.com/sharetribe/web-template/tree/main/server/api/auth"
    click MapComponent "https://github.com/sharetribe/web-template/tree/main/src/components/Map"
    click Autocomplete "https://github.com/sharetribe/web-template/tree/main/src/components/LocationAutocompleteInput"

    %% Styles
    classDef frontend fill:#f9e79f,stroke:#333,stroke-width:2px;
    classDef backend fill:#aed6f1,stroke:#333,stroke-width:2px;
    classDef transaction fill:#a9dfbf,stroke:#333,stroke-width:2px;
    classDef external fill:#f5b7b1,stroke:#333,stroke-width:2px;
    classDef user fill:#d5f5e3,stroke:#333,stroke-width:2px;
```
