# ak-ram/magic-box-assessment architecture

> Architecture diagram of the GitHub repository ak-ram/magic-box-assessment, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ak-ram/magic-box-assessment
- Repository: https://github.com/ak-ram/magic-box-assessment

## Overview

Magic Box is an Angular gift-box purchase app. A visitor fills out and validates a purchase form; authenticated users submit it, while unauthenticated users have the form saved as a session draft and are sent to login. After login, the app returns them to purchasing with the draft restored. The README also documents remember-me token persistence and expiry. The graph captures the documented flow and relationships visible in sampled source; it does not assume an unsampled payment backend.

Main entry points: [`src/pages/purchase/purchase.component.ts`](https://github.com/ak-ram/magic-box-assessment/blob/master/src/pages/purchase/purchase.component.ts) (Purchase Form), [`src/services/auth.service.ts`](https://github.com/ak-ram/magic-box-assessment/blob/master/src/services/auth.service.ts) (Auth Service), [`src/app/app.routes.ts`](https://github.com/ak-ram/magic-box-assessment/blob/master/src/app/app.routes.ts) (Route Config), [`src/pages/login/login.component.ts`](https://github.com/ak-ram/magic-box-assessment/blob/master/src/pages/login/login.component.ts) (Login Page)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_navigation["App Navigation"]
  node_app["App Shell<br/>[app.ts]"]
  node_routing["Route Config<br/>[app.routes.ts]"]
  node_config["Router Setup<br/>[app.config.ts]"]
  node_landing["Landing Page"]
end

subgraph group_purchase["Purchase Flow"]
  node_purchaseform["Purchase Form"]
  node_draftservice["Draft Service"]
  node_draftstorage[("Session Storage")]
end

subgraph group_identity["Authentication"]
  node_login["Login Page<br/>[login.component.ts]"]
  node_guard["Login Guard<br/>[login.guard.ts]"]
  node_authservice["Auth Service<br/>[auth.service.ts]"]
  node_tokenstorage[("Token Storage")]
  node_models["Auth and Form Models<br/>[auth.model.ts]"]
end

subgraph group_shared["Shared UI"]
  node_summary["Summary Card"]
  node_header["Header"]
end

node_user(("Visitor"))
node_dummyjson["DummyJSON Auth"]

node_user -->|"uses"| node_app
node_app -->|"renders routes"| node_routing
node_config -->|"provides routes"| node_routing
node_routing -->|"loads"| node_landing
node_routing -->|"loads"| node_purchaseform
node_routing -->|"loads"| node_login
node_routing -->|"guards login"| node_guard
node_app -->|"renders"| node_header
node_purchaseform -->|"uses"| node_summary
node_purchaseform -->|"loads and saves draft"| node_draftservice
node_draftservice -->|"reads and writes"| node_draftstorage
node_purchaseform -->|"checks authentication"| node_authservice
node_purchaseform -->|"redirects unauthenticated"| node_login
node_login -->|"submits credentials"| node_authservice
node_login -->|"returns after login"| node_purchaseform
node_authservice -->|"calls auth endpoints"| node_dummyjson
node_authservice -->|"persists tokens"| node_tokenstorage
node_guard -->|"checks authentication"| node_authservice
node_header -->|"loads profile and logs out"| node_authservice
node_header -->|"clears draft on logout"| node_draftservice
node_authservice -->|"uses auth types"| node_models
node_login -->|"uses login form"| node_models
node_purchaseform -->|"uses purchase form"| node_models

click node_app "https://github.com/ak-ram/magic-box-assessment/blob/master/src/app/app.ts"
click node_routing "https://github.com/ak-ram/magic-box-assessment/blob/master/src/app/app.routes.ts"
click node_config "https://github.com/ak-ram/magic-box-assessment/blob/master/src/app/app.config.ts"
click node_landing "https://github.com/ak-ram/magic-box-assessment/blob/master/src/pages/landing/landing.component.ts"
click node_purchaseform "https://github.com/ak-ram/magic-box-assessment/blob/master/src/pages/purchase/purchase.component.ts"
click node_summary "https://github.com/ak-ram/magic-box-assessment/blob/master/src/components/summary-card/summary-card.component.ts"
click node_draftservice "https://github.com/ak-ram/magic-box-assessment/blob/master/src/services/purchase.service.ts"
click node_login "https://github.com/ak-ram/magic-box-assessment/blob/master/src/pages/login/login.component.ts"
click node_guard "https://github.com/ak-ram/magic-box-assessment/blob/master/src/guards/login.guard.ts"
click node_authservice "https://github.com/ak-ram/magic-box-assessment/blob/master/src/services/auth.service.ts"
click node_header "https://github.com/ak-ram/magic-box-assessment/blob/master/src/components/header/header.component.ts"
click node_models "https://github.com/ak-ram/magic-box-assessment/blob/master/src/models/auth.model.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_app,node_routing,node_config,node_landing toneBlue
class node_purchaseform,node_draftservice,node_draftstorage toneAmber
class node_login,node_guard,node_authservice,node_tokenstorage,node_models toneMint
class node_summary,node_header toneRose
class node_user,node_dummyjson toneIndigo
```

## Components

### App Navigation

- [App Shell](https://github.com/ak-ram/magic-box-assessment/blob/master/src/app/app.ts): `src/app/app.ts`
- [Route Config](https://github.com/ak-ram/magic-box-assessment/blob/master/src/app/app.routes.ts): `src/app/app.routes.ts`
- [Router Setup](https://github.com/ak-ram/magic-box-assessment/blob/master/src/app/app.config.ts): `src/app/app.config.ts`
- [Landing Page](https://github.com/ak-ram/magic-box-assessment/blob/master/src/pages/landing/landing.component.ts): `src/pages/landing/landing.component.ts`

### Purchase Flow

- [Purchase Form](https://github.com/ak-ram/magic-box-assessment/blob/master/src/pages/purchase/purchase.component.ts): `src/pages/purchase/purchase.component.ts`
- [Draft Service](https://github.com/ak-ram/magic-box-assessment/blob/master/src/services/purchase.service.ts): `src/services/purchase.service.ts`
- **Session Storage**

### Authentication

- [Login Page](https://github.com/ak-ram/magic-box-assessment/blob/master/src/pages/login/login.component.ts): `src/pages/login/login.component.ts`
- [Login Guard](https://github.com/ak-ram/magic-box-assessment/blob/master/src/guards/login.guard.ts): `src/guards/login.guard.ts`
- [Auth Service](https://github.com/ak-ram/magic-box-assessment/blob/master/src/services/auth.service.ts): `src/services/auth.service.ts`
- **Token Storage**
- [Auth and Form Models](https://github.com/ak-ram/magic-box-assessment/blob/master/src/models/auth.model.ts): `src/models/auth.model.ts`

### Shared UI

- [Summary Card](https://github.com/ak-ram/magic-box-assessment/blob/master/src/components/summary-card/summary-card.component.ts): `src/components/summary-card/summary-card.component.ts`
- [Header](https://github.com/ak-ram/magic-box-assessment/blob/master/src/components/header/header.component.ts): `src/components/header/header.component.ts`

### Other components

- **Visitor**
- **DummyJSON Auth**

## Connections

- Visitor → App Shell: uses
- App Shell → Route Config: renders routes (evidence: `src/app/app.ts`)
- Router Setup → Route Config: provides routes (evidence: `src/app/app.config.ts`)
- Route Config → Landing Page: loads (evidence: `src/app/app.routes.ts`)
- Route Config → Purchase Form: loads (evidence: `src/app/app.routes.ts`)
- Route Config → Login Page: loads (evidence: `src/app/app.routes.ts`)
- Route Config → Login Guard: guards login (evidence: `src/app/app.routes.ts`)
- App Shell → Header: renders (evidence: `src/app/app.ts`)
- Purchase Form → Summary Card: uses (evidence: `src/pages/purchase/purchase.component.ts`)
- Purchase Form → Draft Service: loads and saves draft (evidence: `src/pages/purchase/purchase.component.ts`)
- Draft Service → Session Storage: reads and writes (evidence: `src/services/purchase.service.ts`)
- Purchase Form → Auth Service: checks authentication (evidence: `src/pages/purchase/purchase.component.ts`)
- Purchase Form → Login Page: redirects unauthenticated (evidence: `src/pages/purchase/purchase.component.ts`)
- Login Page → Auth Service: submits credentials (evidence: `src/pages/login/login.component.ts`)
- Login Page → Purchase Form: returns after login (evidence: `README.md`)
- Auth Service → DummyJSON Auth: calls auth endpoints (evidence: `src/services/auth.service.ts`)
- Auth Service → Token Storage: persists tokens (evidence: `src/services/auth.service.ts`)
- Login Guard → Auth Service: checks authentication (evidence: `src/guards/login.guard.ts`)
- Header → Auth Service: loads profile and logs out (evidence: `src/components/header/header.component.ts`)
- Header → Draft Service: clears draft on logout (evidence: `src/components/header/header.component.ts`)
- Auth Service → Auth and Form Models: uses auth types (evidence: `src/services/auth.service.ts`)
- Login Page → Auth and Form Models: uses login form (evidence: `src/pages/login/login.component.ts`)
- Purchase Form → Auth and Form Models: uses purchase form (evidence: `src/pages/purchase/purchase.component.ts`)
