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.
- Host: GitHub
- URL: https://github.com/felipegf/ambev.omnia.eval
- Owner: felipegf
- License: mit
- Created: 2025-03-03T22:20:39.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-03-11T22:07:10.000Z (about 1 year ago)
- Last Synced: 2025-03-23T14:18:31.080Z (about 1 year ago)
- Topics: api-versioning, clean-architecture, cqrs-pattern, dependency-injection, dotnet, dotnet-core, event-sourcing, mediatr, mongodb, postgresql, serilog, unit-testing
- Language: C#
- Homepage: https://github.com/felipegf/Ambev.Omnia.Eval
- Size: 138 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Ambev Developer Evaluation - Sales API π




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