Skip to content

yasunchukandriy/ecom-pos-summary

Repository files navigation

🛒 POS Analytics API

REST API for aggregating e-commerce revenue across points of sale. Pass a date range — get back a summary: order count, total revenue, and average order value. Only active locations included.

PHP Symfony PostgreSQL Docker PHPUnit PHPStan


📋 Overview

POS Analytics API is a lightweight Symfony-based REST API designed for e-commerce platforms that operate across multiple physical or virtual points of sale. It provides instant revenue aggregation for any given date range — order counts, totals, and averages — filtered to active locations only.

Use cases:

  • Dashboard widgets showing daily/monthly revenue per store
  • Automated financial reporting across POS locations
  • Integration with ERP or BI systems

⚙️ Tech Stack

Layer Technology
Language PHP 8.3
Framework Symfony 7.2
Database PostgreSQL 16
ORM Doctrine
Containerization Docker / Docker Compose
Testing PHPUnit
Static Analysis PHPStan
Code Style PHP CS Fixer
CI/CD GitHub Actions

🗂️ Project Structure

ecom-pos-summary/
├── .github/workflows/    # GitHub Actions CI pipeline
├── bin/                  # Symfony console
├── config/               # App configuration
├── docker/               # Docker setup files
├── migrations/           # Database migrations
├── public/               # Entry point (index.php)
├── src/                  # Application source code
│   ├── Controller/       # API controllers
│   ├── Service/          # Business logic
│   └── Repository/       # Data access layer
├── tests/                # PHPUnit test suites
├── docker-compose.yml
├── composer.json
└── phpunit.dist.xml

🚀 Quick Start

Prerequisites

  • Docker & Docker Compose

1. Clone & configure

git clone https://github.com/yasunchukandriy/ecom-pos-summary.git
cd ecom-pos-summary
cp .env.example .env

2. Start containers

docker compose up -d

3. Run migrations

docker compose exec app php bin/console doctrine:migrations:migrate

4. Load fixtures (optional)

docker compose exec app php bin/console doctrine:fixtures:load

The API will be available at http://localhost:8080


📡 API Endpoints

GET /api/pos/summary

Revenue summary per point of sale for a given period.

Parameter Format Default
from YYYY-MM-DD First day of current month
to YYYY-MM-DD Last day of current month

Example request:

curl "http://localhost:8080/api/pos/summary?from=2025-01-01&to=2025-01-31"

Example response:

{
    "meta": {
        "period": { "from": "2025-01-01", "to": "2025-01-31" },
        "count": 3,
        "generatedAt": "2025-02-19T12:00:00+00:00"
    },
    "data": [
        {
            "id": 1,
            "name": "Berlin Flagship Store",
            "orderCount": 342,
            "totalRevenue": 28450.75,
            "averageOrderValue": 83.19
        }
    ]
}

Invalid dates return 400 with a detailed error description.


GET /api/health

Health check endpoint. Runs SELECT 1 against the database.

Status Meaning
200 OK App and database are healthy
503 Service Unavailable Database connection failed

🏗️ Architecture

The application follows a clean Controller → Service → Repository pattern:

  • Controller — handles HTTP request/response, input validation
  • Service — contains business logic, depends on a repository interface (not implementation)
  • Repository — Doctrine-based data access, easily swappable

All errors on /api/* routes return JSON via a global event subscriber — no HTML error pages.


🧪 Testing

# Run all tests
docker compose exec app php bin/phpunit

# With coverage report
docker compose exec app php bin/phpunit --coverage-text

🔍 Code Quality

# Static analysis
docker compose exec app vendor/bin/phpstan analyse

# Code style check
docker compose exec app vendor/bin/php-cs-fixer fix --dry-run

👤 Author

Andrii Yasynchuk — Senior Full Stack Developer LinkedIn GitHub


📄 License

MIT © Andrii Yasynchuk

About

REST API for aggregating e-commerce revenue across points of sale. PHP 8.3 / Symfony 7.2 / PostgreSQL / Docker

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors