An open API service indexing awesome lists of open source software.

https://github.com/felipegf/ambev.omnia.eval

Technical assessment for a .NET position in the Omnia project (Ambev), using .NET 8 and best practices. Implements CQRS, Event Sourcing, and Clean Architecture with PostgreSQL, MongoDB, MediatR, and Serilog. Follows Dependency Injection, Unit Testing, and API versioning for scalability.
https://github.com/felipegf/ambev.omnia.eval

api-versioning clean-architecture cqrs-pattern dependency-injection dotnet dotnet-core event-sourcing mediatr mongodb postgresql serilog unit-testing

Last synced: 18 days ago
JSON representation

Technical assessment for a .NET position in the Omnia project (Ambev), using .NET 8 and best practices. Implements CQRS, Event Sourcing, and Clean Architecture with PostgreSQL, MongoDB, MediatR, and Serilog. Follows Dependency Injection, Unit Testing, and API versioning for scalability.

Awesome Lists containing this project

README

          

# Ambev Developer Evaluation - Sales API πŸš€

![Build Status](https://img.shields.io/badge/build-passing-brightgreen)
![Test Coverage](https://img.shields.io/badge/coverage-85%25-green)
![Version](https://img.shields.io/badge/version-1.1.0-blue)
![License](https://img.shields.io/badge/license-MIT-yellow)

This project is a **Sales Management API**, developed as part of the Ambev Developer Evaluation process. It provides a **robust CRUD (Create, Read, Update, Delete)** for managing sales while integrating best practices such as **CQRS, dependency injection, validation, unit testing, and event sourcing**.

## πŸ“‹ Table of Contents

- [✨ Features](#-features)
- [πŸš€ Quick Start](#-quick-start)
- [πŸ”§ Technologies Used](#-technologies-used)
- [πŸ“ Prerequisites](#-prerequisites)
- [βš™οΈ Installation](#️-installation)
- [πŸ” Environment Variables](#-environment-variables)
- [πŸƒβ€β™‚οΈ Running the Application](#️-running-the-application)
- [πŸ”’ Authentication](#-authentication)
- [πŸ”Œ API Endpoints](#-api-endpoints)
- [πŸ“Š Architecture](#-architecture)
- [πŸ“œ Event Sourcing & Logging](#-event-sourcing--logging)
- [πŸ§ͺ Running Tests](#-running-tests)
- [❓ Troubleshooting](#-troubleshooting)
- [πŸ›£οΈ Roadmap](#️-roadmap)
- [🀝 Contributing](#-contributing)
- [πŸ“œ License](#-license)
- [πŸ‘€ Author](#-author)

## ✨ Features

- βœ… **CRUD operations** for sales (create, read, update, delete)
- βœ… **CQRS pattern** with MediatR for better separation of concerns
- βœ… **Event Sourcing** with MongoDB for auditability and tracking
- βœ… **MongoDB-based Log Storage** for scalable logging
- βœ… **FluentValidation** for input validation
- βœ… **AutoMapper** for DTO-to-domain mapping
- βœ… **JWT Authentication** for secure API access
- βœ… **Entity Framework Core** (EF Core) with PostgreSQL
- βœ… **API versioning** for backward compatibility
- βœ… **Comprehensive exception handling**
- βœ… **Performance monitoring**
- βœ… **Unit testing** with xUnit, Moq, and FluentAssertions
- βœ… **Docker support** for seamless deployment

## πŸš€ Quick Start

```bash
# Clone the repository
git clone https://github.com/felipegf/Ambev.Omnia.Eval.git

# Navigate to the project directory
cd Ambev.Omnia.Eval

# Start with Docker (recommended)
docker-compose up -d

# The API is now running at https://localhost:8080
# Swagger UI available at https://localhost:8080/swagger
```

## πŸ”§ Technologies Used

* **.NET 8**: ASP.NET Core Web API with modern features
* **Entity Framework Core**: ORM for PostgreSQL database operations
* **MongoDB**: Used for event storage and log storage
* **Serilog**: Integrated with MongoDB as a logging sink
* **FluentValidation**: Advanced input validation
* **MediatR**: Implements the CQRS pattern
* **AutoMapper**: Simplifies object-to-object mapping
* **xUnit & Moq**: Unit testing framework
* **JWT Authentication**: Secure access to protected endpoints
* **Docker**: Containerized environment for seamless deployment
* **Swagger/OpenAPI**: API documentation

## πŸ“ Prerequisites

Ensure you have the following installed:
* .NET 8 SDK
* PostgreSQL (or use Docker)
* MongoDB (or use Docker)
* Docker (optional)
* Git

## βš™οΈ Installation

### Option 1: Using Docker (Recommended)

```bash
# Clone the repository
git clone https://github.com/felipegf/Ambev.Omnia.Eval.git
cd Ambev.Omnia.Eval

# Start the application and database
docker-compose up -d
```

### Option 2: Manual Setup

```bash
# Clone the repository
git clone https://github.com/felipegf/Ambev.Omnia.Eval.git
cd Ambev.Omnia.Eval

# Configure the database connection in appsettings.json

# Apply database migrations
dotnet ef database update

# Run the application
dotnet run --project src/Ambev.DeveloperEvaluation.WebApi
```

## πŸ” Environment Variables

| Variable | Description | Default | Required |
|----------|-------------|---------|----------|
| `Jwt:SecretKey` | Secret key for JWT token encryption | - | Yes |
| `MongoDB:ConnectionString` | Connection string for MongoDB | - | Yes |
| `MongoDB:DatabaseName` | Name of MongoDB database | events_db | No |
| `Jwt:Issuer` | Token issuer | api.ambev.com | No |
| `Jwt:Audience` | Token audience | ambev.users | No |
| `Jwt:ExpiryMinutes` | Token expiry in minutes | 60 | No |
| `ConnectionStrings:DefaultConnection` | PostgreSQL connection string | - | Yes |

## πŸƒβ€β™‚οΈ Running the Application

After installation, the API will be available at:
- API Endpoint: `https://localhost:8080`
- Swagger Documentation: `https://localhost:8080/swagger`

## πŸ”’ Authentication

The API uses JWT Bearer token authentication:
1. Obtain a token via the `/api/auth/login` endpoint
2. Include the token in the Authorization header: `Bearer {token}`

## πŸ”Œ API Endpoints

| Method | Endpoint | Description | Authentication |
|--------|----------|-------------|----------------|
| GET | `/api/v1/sales` | List all sales | Required |
| GET | `/api/v1/sales/{id}` | Get sale by ID | Required |
| POST | `/api/v1/sales` | Create new sale | Required |
| PUT | `/api/v1/sales/{id}` | Update existing sale | Required |
| DELETE | `/api/v1/sales/{id}` | Delete sale | Required |
| POST | `/api/auth/login` | Authenticate user | Not Required |

## πŸ“Š Architecture

This project implements **CQRS and Event Sourcing** for scalability and maintainability.

```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Controllers │────▢│ MediatR │────▢│ Commands β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”
β”‚ Database │◀────│ Repositories │◀────│ Handlers β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

## πŸ“œ Event Sourcing & Logging

This API utilizes **event sourcing** and **centralized logging** to enhance traceability:

1. **MongoDB Event Store**
* Stores domain events related to sales transactions.
* Provides a historical timeline of all modifications.

2. **MongoDB Log Storage**
* Uses **Serilog MongoDB Sink** for scalable log storage.
* Supports structured and queryable logs.

## πŸ§ͺ Running Tests

```bash
# Run all tests
dotnet test

# Run tests with coverage report
dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=opencover

# Run specific test category
dotnet test --filter "Category=Integration"

# Run specific test class
dotnet test --filter "FullyQualifiedName~CreateSaleHandlerTests"
```

## ❓ Troubleshooting

### Common Issues & Fixes

1. **Database connection failures**
* Ensure PostgreSQL and MongoDB are running
* Verify connection strings in `appsettings.json`
* Check network connectivity

2. **JWT Authentication issues**
* Ensure token is valid and not expired
* Verify secret key configuration
* Check if roles are properly assigned

3. **Event store not persisting data**
* Verify MongoDB connection
* Check if the `events` collection exists

## πŸ›£οΈ Roadmap

* Implement **Product Management Module**
* Develop **Customer Management Module**
* Enhance **Reporting Features**
* Build **Admin Dashboard**
* Integrate with **Ambev Inventory System**
* Develop a **Mobile Application**
* Add **Offline Capabilities**

## 🀝 Contributing

Contributions are welcome! Follow these steps:

1. Fork the repository
2. Create a feature branch: `git checkout -b feature/new-feature`
3. Commit changes: `git commit -m 'feat: add new feature'`
4. Push to branch: `git push origin feature/new-feature`
5. Open a Pull Request

Adhere to the Conventional Commits standard.

## πŸ“œ License

This project is licensed under the **MIT License**. See the LICENSE file for details.

## πŸ‘€ Author

* πŸ‘¨β€πŸ’» **Felipe GonΓ§alves Ferreira**
* πŸ“§ Contact: **contato@felipegf.com.br**
* πŸ“Œ [GitHub](https://github.com/yourusername) | [LinkedIn](https://linkedin.com/in/yourusername)

Made with ❀️ for Ambev Developer Evaluation