Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: CI

on:
push:
branches: [main]
pull_request:

permissions:
contents: read

concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true

jobs:
backend:
name: API (build, test, image)
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
- uses: actions/setup-dotnet@v4
with:
dotnet-version: 10.0.x
# Testcontainers starts Postgres and Azurite on the runner's Docker.
- run: dotnet test backend --configuration Release
- name: Build the API image
run: docker build backend

web:
name: ${{ matrix.app }} (lint, test, build)
runs-on: ubuntu-latest
timeout-minutes: 20
strategy:
fail-fast: false
matrix:
app: [admin, storefront]
defaults:
run:
working-directory: ${{ matrix.app }}
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
with:
package_json_file: ${{ matrix.app }}/package.json
- uses: actions/setup-node@v4
with:
node-version: 24
cache: pnpm
cache-dependency-path: ${{ matrix.app }}/pnpm-lock.yaml
- run: pnpm install --frozen-lockfile
- run: pnpm lint
- run: pnpm check:brand
- if: matrix.app == 'storefront'
run: pnpm test:unit
# Every page renders on request, so the build needs no running API; these only satisfy the config.
- run: pnpm build
env:
API_URL: http://localhost:8080
API_KEY: ci
SITE_URL: http://localhost:3000
104 changes: 86 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,99 @@
# Ecom foundation

Headless e-commerce backend (.NET 10 Minimal API + Postgres 17) with a Next.js 16 admin and a Next.js 16 storefront.
[![CI](https://github.com/cvam29/TheEcomProject/actions/workflows/ci.yml/badge.svg)](https://github.com/cvam29/TheEcomProject/actions/workflows/ci.yml)

A headless e-commerce starter for Indian stores: a .NET API, an admin for running the store, and a storefront for
customers. Fork it, brand it, and go live.

| Part | Stack | Folder |
|---|---|---|
| API | .NET 10 Minimal API, EF Core, Postgres 17, Azure Blob Storage | [backend/](backend/) |
| Admin | Next.js 16, React 19, Tailwind 4 | [admin/](admin/) |
| Storefront | Next.js 16, React 19 | [storefront/](storefront/) |

**What it does:** catalog (product types, categories, variants, collections, images), carts, guest and account
checkout, discounts, payments by cash on delivery, bank transfer, UPI or card, order management with status history,
GST invoices as PDF, transactional emails, customer accounts, and staff roles (Owner, Manager, Staff).

## Run it locally

You need Docker, the .NET 10 SDK, Node 24 (what CI uses), and pnpm 10.

```sh
docker compose up -d --build # Postgres, Azurite, Mailpit and the API on :8080

```
docker compose up -d --build # postgres, azurite, mailpit (:8025), api on :8080 (key: dev-key)
cp admin/.env.local.example admin/.env.local
pnpm --dir admin install
pnpm --dir admin dev --port 3001 # admin on :3001
dotnet test backend # API tests (Testcontainers, needs Docker)
pnpm --dir admin test:e2e # UI tests on their own stack (API :18080, admin :3101); E2E_KEEP=1 keeps it up
pnpm --dir admin gen:api # regenerate admin/src/lib/schema.d.ts
pnpm --dir admin dev # admin on :3001

cp storefront/.env.local.example storefront/.env.local
pnpm --dir storefront install
pnpm --dir storefront dev # storefront on :3000
```

Storefront (the shop a customer sees, against the same dev stack):
On start the API applies migrations and seeds a demo store (the `supplements` preset) with these logins:

| Email | Role |
|---|---|
| `owner@demo.local` | Owner: everything |
| `manager@demo.local` | Manager: everything except staff |
| `staff@demo.local` | Staff: view the catalog and customers, manage orders |
| `customer@demo.local` | Storefront customer |

The password is `DemoPassword` in [Seeder.cs](backend/Ecom.Api/Data/Seed/Seeder.cs).

| What | Where |
|---|---|
| Storefront | http://localhost:3000 |
| Admin | http://localhost:3001 |
| API | http://localhost:8080 (API reference at `/scalar`, OpenAPI at `/openapi/v1.json`) |
| Emails sent by the API | Mailpit, http://localhost:8025 |

Every API route except `/health` needs the `X-Api-Key` header (`dev-key` in compose). The two Next.js apps read
`API_URL` and `API_KEY` on the server only; the key never reaches the browser.

## Tests

| Command | What it runs |
|---|---|
| `dotnet test backend` | API tests against Postgres and Azurite in Testcontainers (needs Docker) |
| `pnpm --dir storefront test:unit` | Variant resolver, money formatting, API error mapping |
| `pnpm --dir admin test:e2e` | Admin Playwright tests on their own stack (API :18080, admin :3101) |
| `pnpm --dir storefront test:e2e` | Storefront Playwright tests on their own stack (API :28080, storefront :3100) |
| `pnpm --dir <app> lint` | ESLint |
| `pnpm --dir <app> check:brand` | Contrast of the brand colour tokens |

The e2e suites start and remove their own Docker stacks, so they never touch your dev database. `E2E_KEEP=1` leaves
the stack running after the tests finish.

[CI](.github/workflows/ci.yml) runs on every pull request and every push to `main`. It runs the API tests, builds the
API's Docker image, and lints, checks, tests and builds both apps. The Playwright suites run locally only.

## Common tasks

**Change the API contract.** After changing an endpoint, start the API and regenerate the typed clients:

```sh
pnpm --dir admin gen:api
pnpm --dir storefront gen:api
```
cp storefront/.env.local.example storefront/.env.local
pnpm --dir storefront install
pnpm --dir storefront dev # storefront on :3000
pnpm --dir storefront test:unit # variant resolver, money formatting, API failure mapping
pnpm --dir storefront check:brand # contrast of the brand tokens
pnpm --dir storefront test:e2e # UI tests on their own stack (project ecom-sf-e2e, API :28080, storefront :3100); E2E_KEEP=1 keeps it up
pnpm --dir storefront gen:api # regenerate storefront/src/lib/schema.d.ts

**Add a migration.**

```sh
dotnet tool restore
dotnet ef migrations add <Name> --project backend/Ecom.Api --output-dir Data/Migrations
```

The storefront's server reads `API_URL` and `API_KEY` (never sent to the browser). The API's emails link to it through `Store__StorefrontUrl`, `Email__CustomerConfirmUrl` and `Email__CustomerResetUrl` (`http://localhost:3000/…` in compose). Emails land in Mailpit at http://localhost:8025. The API contract a storefront is built on: [docs/STOREFRONT.md](docs/STOREFRONT.md).
**Configure the store.** Name, currency, GSTIN, payment methods, UPI ID and shipping come from `Store__*` settings on
the API; see [docker-compose.yml](docker-compose.yml). Email links point at the storefront through
`Store__StorefrontUrl`, `Email__CustomerConfirmUrl` and `Email__CustomerResetUrl`.

Every API route except `/health` needs `X-Api-Key`. Module handovers live in `docs/handover/`.
## Docs

Branding a store fork: [admin/BRANDING.md](admin/BRANDING.md) and [storefront/BRANDING.md](storefront/BRANDING.md) (colours, font, store content, help pages, going live). Building admin screens: [admin/DESIGN.md](admin/DESIGN.md).
- [docs/STOREFRONT.md](docs/STOREFRONT.md): the store API a storefront is built on (catalog, cart, checkout, orders,
accounts, errors).
- [admin/BRANDING.md](admin/BRANDING.md) and [storefront/BRANDING.md](storefront/BRANDING.md): colours, font, store
content, help pages and going live.
- [admin/DESIGN.md](admin/DESIGN.md): how admin screens are built.
- [docs/handover/](docs/handover/): one handover note per module, covering what was built and how to check it.
Loading