# raahuldaksh/ec2--last-server-standing architecture

> Architecture diagram of the GitHub repository raahuldaksh/ec2--last-server-standing, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/raahuldaksh/ec2--last-server-standing
- Repository: https://github.com/raahuldaksh/ec2--last-server-standing

## Overview

Last Server Standing is a high-concurrency flash-sale shop API. Clients send HTTP requests to the Fastify server; routes validate product, purchase, and order-history requests, services perform the domain operations, and SQLite persists product and order state. Product reads and stock updates also use an in-memory cache. The graph includes the server’s worker startup and route-registration layers. The README documents health checks and the API capabilities; unsampled schema details and other implementation relationships are not inferred.

Main entry points: [`src/app.js`](https://github.com/raahuldaksh/ec2--last-server-standing/blob/main/src/app.js) (Fastify app), [`src/utils/errors.js`](https://github.com/raahuldaksh/ec2--last-server-standing/blob/main/src/utils/errors.js) (Domain errors), [`src/services/productService.js`](https://github.com/raahuldaksh/ec2--last-server-standing/blob/main/src/services/productService.js) (Product operations), [`src/services/orderService.js`](https://github.com/raahuldaksh/ec2--last-server-standing/blob/main/src/services/orderService.js) (Order operations)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Server runtime"]
  node_server["Worker startup<br/>[server.js]"]
  node_app["Fastify app<br/>[app.js]"]
end

subgraph group_api["HTTP API"]
  node_health["Health endpoint<br/>[health.js]"]
  node_products_route["Product routes<br/>[products.js]"]
  node_orders_route["Order route<br/>[orders.js]"]
  node_users_route["User history route<br/>[users.js]"]
end

subgraph group_domain["Shop operations"]
  node_product_service["Product operations<br/>[productService.js]"]
  node_order_service["Order operations<br/>[orderService.js]"]
  node_errors["Domain errors<br/>[errors.js]"]
end

subgraph group_persistence["State and configuration"]
  node_product_cache["Product cache<br/>[productCache.js]"]
  node_category_cache["Category cache<br/>[productService.js]"]
  node_db_connection["SQLite connection<br/>[connection.js]"]
  node_sqlite[("Shop database<br/>[schema.sql]")]
  node_config["Runtime config<br/>[env.js]"]
end

node_client(("API client"))

node_client -->|"sends HTTP"| node_server
node_server -->|"builds app"| node_app
node_server -->|"initializes database"| node_db_connection
node_server -->|"reads settings"| node_config
node_app -->|"registers route"| node_health
node_app -->|"registers route"| node_products_route
node_app -->|"registers route"| node_orders_route
node_app -->|"registers route"| node_users_route
node_app -->|"handles errors"| node_errors
node_products_route -->|"calls"| node_product_service
node_products_route -->|"validates with"| node_errors
node_orders_route -->|"calls"| node_order_service
node_orders_route -->|"validates with"| node_errors
node_users_route -->|"reads history via"| node_order_service
node_users_route -->|"validates with"| node_errors
node_product_service -->|"queries through"| node_db_connection
node_product_service -->|"reads and updates"| node_product_cache
node_product_service -->|"reads and updates"| node_category_cache
node_product_service -->|"raises"| node_errors
node_order_service -->|"queries through"| node_db_connection
node_order_service -->|"updates stock"| node_product_cache
node_order_service -->|"raises"| node_errors
node_db_connection -->|"initializes schema"| node_sqlite
node_db_connection -->|"reads database path"| node_config
node_product_cache -->|"reads cache TTL"| node_config

click node_server "https://github.com/raahuldaksh/ec2--last-server-standing/blob/main/src/server.js"
click node_app "https://github.com/raahuldaksh/ec2--last-server-standing/blob/main/src/app.js"
click node_health "https://github.com/raahuldaksh/ec2--last-server-standing/blob/main/src/routes/health.js"
click node_products_route "https://github.com/raahuldaksh/ec2--last-server-standing/blob/main/src/routes/products.js"
click node_orders_route "https://github.com/raahuldaksh/ec2--last-server-standing/blob/main/src/routes/orders.js"
click node_users_route "https://github.com/raahuldaksh/ec2--last-server-standing/blob/main/src/routes/users.js"
click node_product_service "https://github.com/raahuldaksh/ec2--last-server-standing/blob/main/src/services/productService.js"
click node_order_service "https://github.com/raahuldaksh/ec2--last-server-standing/blob/main/src/services/orderService.js"
click node_errors "https://github.com/raahuldaksh/ec2--last-server-standing/blob/main/src/utils/errors.js"
click node_product_cache "https://github.com/raahuldaksh/ec2--last-server-standing/blob/main/src/cache/productCache.js"
click node_category_cache "https://github.com/raahuldaksh/ec2--last-server-standing/blob/main/src/services/productService.js"
click node_db_connection "https://github.com/raahuldaksh/ec2--last-server-standing/blob/main/src/db/connection.js"
click node_sqlite "https://github.com/raahuldaksh/ec2--last-server-standing/blob/main/src/db/schema.sql"
click node_config "https://github.com/raahuldaksh/ec2--last-server-standing/blob/main/src/config/env.js"

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_server,node_app,node_client toneBlue
class node_health,node_products_route,node_orders_route,node_users_route toneAmber
class node_product_service,node_order_service,node_errors toneMint
class node_product_cache,node_category_cache,node_db_connection,node_sqlite,node_config toneRose
```

## Components

### Server runtime

- [Worker startup](https://github.com/raahuldaksh/ec2--last-server-standing/blob/main/src/server.js): `src/server.js`
- [Fastify app](https://github.com/raahuldaksh/ec2--last-server-standing/blob/main/src/app.js): `src/app.js`

### HTTP API

- [Health endpoint](https://github.com/raahuldaksh/ec2--last-server-standing/blob/main/src/routes/health.js): `src/routes/health.js`
- [Product routes](https://github.com/raahuldaksh/ec2--last-server-standing/blob/main/src/routes/products.js): `src/routes/products.js`
- [Order route](https://github.com/raahuldaksh/ec2--last-server-standing/blob/main/src/routes/orders.js): `src/routes/orders.js`
- [User history route](https://github.com/raahuldaksh/ec2--last-server-standing/blob/main/src/routes/users.js): `src/routes/users.js`

### Shop operations

- [Product operations](https://github.com/raahuldaksh/ec2--last-server-standing/blob/main/src/services/productService.js): `src/services/productService.js`
- [Order operations](https://github.com/raahuldaksh/ec2--last-server-standing/blob/main/src/services/orderService.js): `src/services/orderService.js`
- [Domain errors](https://github.com/raahuldaksh/ec2--last-server-standing/blob/main/src/utils/errors.js): `src/utils/errors.js`

### State and configuration

- [Product cache](https://github.com/raahuldaksh/ec2--last-server-standing/blob/main/src/cache/productCache.js): `src/cache/productCache.js`
- [Category cache](https://github.com/raahuldaksh/ec2--last-server-standing/blob/main/src/services/productService.js): `src/services/productService.js`
- [SQLite connection](https://github.com/raahuldaksh/ec2--last-server-standing/blob/main/src/db/connection.js): `src/db/connection.js`
- [Shop database](https://github.com/raahuldaksh/ec2--last-server-standing/blob/main/src/db/schema.sql): `src/db/schema.sql`
- [Runtime config](https://github.com/raahuldaksh/ec2--last-server-standing/blob/main/src/config/env.js): `src/config/env.js`

### Other components

- **API client**

## Connections

- API client → Worker startup: sends HTTP (evidence: `README.md`)
- Worker startup → Fastify app: builds app (evidence: `src/server.js`)
- Worker startup → SQLite connection: initializes database (evidence: `src/server.js`)
- Worker startup → Runtime config: reads settings (evidence: `src/server.js`)
- Fastify app → Health endpoint: registers route (evidence: `src/app.js`)
- Fastify app → Product routes: registers route (evidence: `src/app.js`)
- Fastify app → Order route: registers route (evidence: `src/app.js`)
- Fastify app → User history route: registers route (evidence: `src/app.js`)
- Fastify app → Domain errors: handles errors (evidence: `src/app.js`)
- Product routes → Product operations: calls (evidence: `src/routes/products.js`)
- Product routes → Domain errors: validates with (evidence: `src/routes/products.js`)
- Order route → Order operations: calls (evidence: `src/routes/orders.js`)
- Order route → Domain errors: validates with (evidence: `src/routes/orders.js`)
- User history route → Order operations: reads history via (evidence: `src/routes/users.js`)
- User history route → Domain errors: validates with (evidence: `src/routes/users.js`)
- Product operations → SQLite connection: queries through (evidence: `src/services/productService.js`)
- Product operations → Product cache: reads and updates (evidence: `src/services/productService.js`)
- Product operations → Category cache: reads and updates (evidence: `src/services/productService.js`)
- Product operations → Domain errors: raises (evidence: `src/services/productService.js`)
- Order operations → SQLite connection: queries through (evidence: `src/services/orderService.js`)
- Order operations → Product cache: updates stock (evidence: `src/services/orderService.js`)
- Order operations → Domain errors: raises (evidence: `src/services/orderService.js`)
- SQLite connection → Shop database: initializes schema (evidence: `src/db/connection.js`)
- SQLite connection → Runtime config: reads database path (evidence: `src/db/connection.js`)
- Product cache → Runtime config: reads cache TTL (evidence: `src/cache/productCache.js`)
