How afaanbilal/moneyflow works
Main Components
• REST API Server: Represent the Actix Web server as the gateway. Note that the project listens on a configurable host/port (set to 0.0.0.0 and port 80 for Docker).
• Controllers: Modules under src/controllers (for authentication, category management, transactions, and user data via the “me” endpoint) should each be viewed as distinct API entry points that handle HTTP requests/responses.
• Business/Database Layer: The controllers call into database modules (inside src/db) to perform CRUD operations and execute SQL queries (note the SQLx queries stored in the .sqlx folder).
• Middleware: The authentication middleware (src/middleware/auth.rs) intercepts requests for endpoints that require JWT validation. This component is essential for maintaining security.
• Database: The underlying relational database, which is configured by the DATABASE_URL environment variable. Include migrations (found in the migrations directory) that set up tables for users, categories, and transactions.
• Authentication and Security: A dedicated component for processing JWT tokens (using a secret provided as an environment variable) and managing the authentication flow.
• Docker Container: Since the project includes a Dockerfile and instructions to run via Docker, include a container representation that encapsulates the entire API server.
• External Clients: Represent clients (web/mobile applications or API consumers) which interact with the REST endpoints.
Out the Relationships and Interactions
• External clients send HTTP requests (with or without a JWT token) to the Actix server.
• The Actix routing layer directs requests to specific controllers based on the API endpoints (e.g., /auth, /api/categories, /api/transactions).
• Requests that require authentication are intercepted by the JWT middleware. The middleware verifies token validity before passing the request to the controller.
• Controllers invoke database functions (from modules in src/db) to interact with the database and perform CRUD operations.
• The server, upon completion of a request, returns HTTP responses (including tokens on authentication events in /auth/sign-in).
• Docker encapsulates the server environment and binds the correct ports, ensuring the application is served from an isolated environment.
Important Architectural Patterns & Technologies
• MVC-like Separation: Controllers (handling HTTP requests) are logically separated from the business logic (inside the db modules) and middleware (for authentication).
• RESTful API: Emphasis is on well-defined REST endpoints for resources like users, categories, and transactions.
• Containerization: Docker is used to guarantee consistency across environments.
• Environment Configurations: Important environment variables (DATABASE_URL, JWT_SECRET) and the use of migrations for database initialization.
• Rust Ecosystem: Utilizing Actix Web for asynchronous web server capabilities and SQLx for compile-time checked SQL queries.
Specific Elements
• Controllers (auth, me, categories, transactions).
• Middleware (“Auth Middleware”) for JWT token verification.
• A “Docker Container” outline encapsulating the API server, demonstrating the deployment and configuration (showing environment variables like DATABASE_URL and JWT_SECRET).
• The direction of the HTTP request flow from the client to the API server.
• The validation step via middleware.
• The invocation of database functions by the controllers.
• The flow of HTTP responses back from the server to the client.