# trycatchlearn/restore architecture

> Architecture diagram of the GitHub repository trycatchlearn/restore, 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/trycatchlearn/restore
- Repository: https://github.com/trycatchlearn/restore

## Overview

##### Main Components
- Frontend (Client): Located in the "client" folder, this sub-project includes all React components, layout elements, hooks, state management, routing (with React Router), and feature-specific modules (catalog, basket, checkout, etc.). It also manages environment variables and uses various assets and static files.
- Backend (API): In the "API" folder, the project is organized into controllers (for handling endpoints such as accounts, basket, orders, etc.), DTOs (for data transfer), entities (domain models like User, Product, Order, etc.), data access with migrations (using Entity Framework Core for Postgres), services (for business logic such as payments, tokens, and image processing), and middleware (e.g., for exception handling).
- Database: Although the file system doesn’t show a physical database, the presence of migrations and a StoreContext class indicates that the application uses a relational database (likely Postgres, as suggested by migration filenames like “PostgresInitial”) to manage persistent data.
- External Services: There are service classes for payments and images, indicating integration with external APIs or third-party services.
- Configuration & Deployment: Files like Dockerfile, GitHub workflows, and fly.toml hint at containerization, continuous integration/deployment, and cloud deployment processes.

##### Relationships and Interactions
- The API uses controllers to expose RESTful endpoints, which in turn interact with various services (e.g., PaymentService, TokenService) for handling business logic.
- External integrations (payment gateways, image hosting services) can be depicted as additional nodes that the backend interacts with.

##### Architectural Patterns and Design Principles
- Separation of Concerns: Completely separate projects for the front and back ends.
- MVC-like Structure in API: With Controllers, DTOs, and Entities.
- Middleware Pipeline: Used for handling cross-cutting concerns like error handling (e.g., ExceptionMiddleware).
- Modular CSS/JS assets: In the client “assets” directory, showing that static file serving is part of the API’s role.
- Clear domain-driven design: Especially in the API with organized directories for Entities, Data, and Services.

##### Relevant Technologies
- Backend: .NET 7.0, ASP.NET Core Web API, Entity Framework Core (with migrations), and dependency injection.
- Frontend: React 18, React Router 6, TypeScript, and state management patterns.
- Deployment & DevOps: Docker (Dockerfile in API), GitHub Actions (workflows for docker-push), and Fly.io (fly.toml).

## Diagram (Mermaid)

```mermaid
graph TD
    %% Frontend Subgraph
    subgraph "Frontend"
        FE["React Frontend"]:::frontend
        subgraph "Frontend Modules"
            RT["Routing (Routes.tsx)"]:::frontend
            COMP["UI Components"]:::frontend
            SM_CONF["Configure Store"]:::frontend
            SM_CTX["Store Context"]:::frontend
        end
    end

    %% Backend API Subgraph
    subgraph "Backend API"
        MW["Exception Middleware"]:::backend
        CT["Controllers"]:::backend
        DTO["DTOs"]:::backend
        ENT["Entities"]:::backend
        DA["Data Access & Migrations"]:::backend
        SRV["Services"]:::backend
    end

    %% External Services Subgraph
    subgraph "External Services"
        PAY["Payment Gateway"]:::external
        IMG["Image Hosting"]:::external
    end

    %% Configuration & Deployment Subgraph
    subgraph "Configuration & Deployment"
        DEP_DOCKER["Dockerfile"]:::config
        DEP_GITHUB["GitHub Workflow (docker-push)"]:::config
        DEP_FLY["Fly.io Config"]:::config
    end

    %% Database Node
    DB["PostgreSQL Database"]:::database

    %% Connections
    FE -->|"HTTP Request"| MW
    MW -->|"Forward Request"| CT
    CT -->|"Uses"| DTO
    CT -->|"Uses"| ENT
    CT -->|"Invokes"| SRV
    SRV -->|"Data Persistence"| DA
    DA -->|"Read/Write"| DB
    SRV -->|"Integrates"| PAY
    SRV -->|"Integrates"| IMG

    %% Deployment connections to Frontend & Backend
    DEP_DOCKER -->|"Containerize"| FE
    DEP_DOCKER -->|"Containerize"| CT
    DEP_GITHUB -->|"CI/CD"| FE
    DEP_GITHUB -->|"CI/CD"| CT
    DEP_FLY -->|"Cloud Deploy"| CT

    %% Styles
    classDef frontend fill:#80bfff,stroke:#333,stroke-width:2px
    classDef backend fill:#ffcc66,stroke:#333,stroke-width:2px
    classDef database fill:#aaffaa,stroke:#333,stroke-dasharray: 5 5,stroke-width:2px
    classDef external fill:#ff9999,stroke:#333,stroke-width:2px
    classDef config fill:#ccccff,stroke:#333,stroke-width:2px

    %% Click Events
    click FE "https://github.com/trycatchlearn/restore/tree/main/client/"
    click RT "https://github.com/trycatchlearn/restore/blob/main/client/src/app/router/Routes.tsx"
    click COMP "https://github.com/trycatchlearn/restore/tree/main/client/src/app/components/"
    click SM_CONF "https://github.com/trycatchlearn/restore/blob/main/client/src/app/store/configureStore.ts"
    click SM_CTX "https://github.com/trycatchlearn/restore/blob/main/client/src/app/context/StoreContext.tsx"
    click CT "https://github.com/trycatchlearn/restore/tree/main/API/Controllers/"
    click DTO "https://github.com/trycatchlearn/restore/tree/main/API/DTOs/"
    click ENT "https://github.com/trycatchlearn/restore/tree/main/API/Entities/"
    click DA "https://github.com/trycatchlearn/restore/tree/main/API/Data/"
    click SRV "https://github.com/trycatchlearn/restore/tree/main/API/Services/"
    click MW "https://github.com/trycatchlearn/restore/blob/main/API/Middleware/ExceptionMiddleware.cs"
    click DEP_DOCKER "https://github.com/trycatchlearn/restore/tree/main/API/Dockerfile"
    click DEP_GITHUB "https://github.com/trycatchlearn/restore/blob/main/.github/workflows/docker-push.yml"
    click DEP_FLY "https://github.com/trycatchlearn/restore/blob/main/fly.toml"
```
