JK
>ΦΟΡΤΩΣΗ // ΦΟΡΤΩΣΗ
ΑΡΧΙΚΟΠΟΙΗΣΗ ΠΡΟΒΟΛΗΣ
Ολοκληρωμένη αρχιτεκτονική μικροϋπηρεσιών με NestJS, PostgreSQL και Docker μέσω κεντρικού API Gateway.
Διαχωρισμός δρομολόγησης (API Gateway), επιχειρησιακής λογικής (ανεξάρτητες υπηρεσίες) και βάσης δεδομένων για αυτόνομη ανάπτυξη και κλιμάκωση.
| Τεχνολογία | Έκδοση | Σκοπός | Γιατί επιλέχθηκε |
|---|---|---|---|
| TypeScript | ^5.7.3 | Primary language for all services | Type safety, NestJS ecosystem standard |
| NestJS | ^11.0.1 | Application framework | Modular architecture, dependency injection, TypeScript-first |
| TypeORM | ^0.3.27 | ORM for PostgreSQL access | Active Record/Repository pattern, NestJS integration |
| PostgreSQL | 15 | Primary database | JSONB support, ACID compliance, reliability |
| Docker | — | Containerization for all services | Consistent environments, reproducible deployments |
| Turborepo | ^2.5.8 | Monorepo task orchestration | Fast parallel builds, caching, npm workspaces integration |
| GitHub Actions | — | CI/CD pipeline execution | Free for public repos, tight Git integration |
| Jest | ^30.0.0 | Unit testing framework | NestJS default, snapshot support |
| Swagger | ^11.2.0 | API documentation | Auto-generates OpenAPI from decorators |
| Μέθοδος | Διαδρομή | Σκοπός |
|---|---|---|
| GET | /products | List all products |
| GET | /products/:id | Get product by ID |
| POST | /products | Create product |
| PATCH | /products/:id | Update product |
| DELETE | /products/:id | Delete product |
| GET | /orders | List all orders |
| GET | /orders/:id | Get order by ID |
| POST | /orders | Create order |
| Μέθοδος | Διαδρομή | Σκοπός |
|---|---|---|
| POST | /products | Create product |
| GET | /products | List all products |
| GET | /products/:id | Get product by ID |
| PATCH | /products/:id | Update product |
| DELETE | /products/:id | Delete product |
| Μέθοδος | Διαδρομή | Σκοπός |
|---|---|---|
| POST | /orders | Create order |
| GET | /orders | List all orders |
| GET | /orders/:id | Get order by ID |
| Στήλη | Τύπος | Σημειώσεις |
|---|---|---|
| idPK | SERIAL | Auto-generated primary key |
| code | VARCHAR | Product SKU/code |
| name | VARCHAR | Product display name |
| description | VARCHAR | Product description |
| price | DECIMAL | Product price |
| image | VARCHAR | Image URL |
No explicit indexes beyond primary key. No unique constraints on code.
| Στήλη | Τύπος | Σημειώσεις |
|---|---|---|
| idPK | SERIAL | Auto-generated primary key |
| customer | JSONB | Stores {name, phone} |
| products | JSONB | Array of {id, name, rate, qty} |
| totalAmount | DECIMAL | Total order amount |
Products stored as JSONB snapshot — intentional denormalization. No foreign keys to product table.
No foreign key relationships. Order.products is a JSONB snapshot — orders are self-contained records that do not reference the product table. Product price changes do not affect existing orders.
Απόφαση: Both services connect to the same PostgreSQL instance and database (procura_db)
Λόγος: Simplifies development and deployment — one database to manage
Οφέλη: Simpler infrastructure, lower resource usage, easier local development
Ανταλλάγματα: Violates database-per-service principle, creates hidden coupling, makes independent scaling harder
Απόφαση: Order entity stores product data as JSONB rather than foreign key references
Λόγος: Decouples order data from product lifecycle — orders are immutable snapshots
Οφέλη: Orders are self-contained, product changes don't affect historical orders
Ανταλλάγματα: No referential integrity, data duplication, no automatic product validation on order creation
Απόφαση: Simple static API key in x-api-key header, compared against environment variable
Λόγος: Simplest possible authentication for demonstration purposes
Οφέλη: Minimal implementation, no token management, no state
Ανταλλάγματα: No user identity, no fine-grained permissions, key is static and shared
Απόφαση: API Gateway communicates with downstream services via synchronous HTTP (Axios)
Λόγος: Simplest approach for synchronous request-response pattern
Οφέλη: Easy to understand, debug, and test; standard HTTP tooling
Ανταλλάγματα: Synchronous coupling, no retry/circuit breaker, no async processing
Απόφαση: Each service uses a 3-stage Dockerfile (deps → builder → runner)
Λόγος: Minimizes final image size and attack surface
Οφέλη: Production images contain only runtime dependencies and compiled code
Ανταλλάγματα: Build time for each stage, no layer caching optimization for src changes
Απόφαση: Both services use synchronize: true in TypeORM config
Λόγος: Auto-creates/updates database schema from entities during development
Οφέλη: No migration files needed, schema stays in sync with code
Ανταλλάγματα: Dangerous in production — can cause data loss on schema changes