This project demonstrates an account opening process using a state machine implemented with Marten DB, a .NET Transactional Document DB and Event Store on PostgreSQL.
This application showcases a simple account opening workflow using a state machine approach. It utilizes Marten DB for persistence and event sourcing, allowing for a robust and scalable solution.
- AccountOpeningStateMachine: Manages the state transitions of the account opening process.
- Account Model: Represents the account entity with its properties and status.
- API Endpoints: Provides HTTP endpoints to interact with the account opening process.
- Docker Setup: Includes a Docker Compose file for easy setup of the PostgreSQL database.
- .NET 6.0 or later
- Docker and Docker Compose
-
Clone the repository
-
Navigate to the project directory
-
Start the PostgreSQL database:
docker-compose up -d
-
Run the application:
dotnet run
The application exposes the following endpoints:
POST /account
: Create a new accountGET /account/{id}
: Retrieve account detailsGET /account/{id}/state
: Get the current state of an accountGET /account/{id}/event/{eventName}
: Trigger a state transition event (Submit, Approve, Activate)GET /account/{id}/events
: Get the event stream for an account
You can use the provided AccountOpeningApi.http
file to test these endpoints. This file contains pre-configured HTTP requests that you can execute directly from compatible IDEs like Visual Studio Code (with the REST Client extension) or JetBrains Rider.
To use the AccountOpeningApi.http
file:
- Open the file in your IDE
- Ensure your application is running on
http://localhost:5290
- Click on the "Send Request" link above each request
- View the response in the output window
This file includes requests for:
- Creating a new account
- Retrieving account details
- Getting the current state of an account
- Submitting an account for review
- Approving an account
- Activating an account
- Retrieving the event stream for an account
It also demonstrates handling of invalid state transitions.
This allows for quick and easy testing of the API without the need for external tools like Postman.
Program.cs
: Entry point of the application, sets up the web application and Marten DBServices/AccountOpeningStateMachine.cs
: Implements the state machine logicModels/Account.cs
: Defines the Account modeldocker-compose.yml
: Configures the PostgreSQL database for local developmentAccountOpeningApi.http
: Contains sample API requests for testing
- ASP.NET Core
- Marten DB
- PostgreSQL
- Docker
Contributions are welcome! Please feel free to submit a Pull Request.
This project is open-source and available under the MIT License.