How sunls24/tmail works
Main Components
• Backend Server: Highlight the Go application. Mark the entry point (cmd/main.go) that brings together configuration (config/config.go) and internal application logic.
• ORM/Data Layer: Emphasize the “ent” directory, which includes model schemas (attachment, envelope), migration scripts (ent/migrate), query and mutation logic, and test scaffolding. This layer serves as the bridge between the app and the database.
• Internal Business Logic: Group components under the “internal” folder. Include:
– API endpoints (internal/api) that process incoming HTTP requests.
– Domain or business logic (internal/api/domain.go, fetch.go, report.go).
– Pub/sub mechanics (internal/pubsub) that may support the long polling mechanism.
– Scheduling (internal/schedule) for tasks like email expiration or clean-up.
– Utility functions overall (internal/utils).
• Frontend/UI: Represent the “web” folder containing Astro configurations, React/TSX components, pages, layouts, and styling. Note that the frontend is responsible for presenting UI elements (such as email lists, attachments, theme switching) and handling user interactions.
• Deployment/Infrastructure: Include Docker configuration files (.dockerignore, Dockerfile), CI/CD scripts (.github/workflows), and deployment instructions (deploy.md).
Out the Relationships and Data Flow
• Frontend to the Backend API, showing HTTP connections (or long polling channels) that allow users to request email information.
• That the Backend (cmd/main.go, internal/api) processes requests and, when needed, interacts with the ORM/Data Layer (ent) to store or retrieve email data and attachments.
• Database as an external component that the “ent” ORM interacts with. Even if the database is not explicitly visible in the file tree, it is an essential part of the architecture due to the migration scripts and data model definitions.
• Additional flows such as the internal Pub/Sub mechanism for pushing email updates to long polling connections.
Architectural Patterns and Technologies
• Separation of concerns: Clearly differentiate between the backend (handling data, API, business logic), the ORM/data layer (modeling emails/attachments), and the frontend (UI rendering with Astro and React).
• Long Polling: Mark the asynchronous, event-driven communication between the frontend and backend for real-time email retrieval.
• Micro Modularization: The use of designated directories (cmd, internal, ent, web) shows modular design with each piece handling a distinct responsibility.
• Tools & Frameworks:
• Golang for the backend logic.
• Ent as the ORM to define and manipulate the data schema.
• Astro and React used in the frontend for rendering components and managing interactive UI.
• Docker & GitHub Actions for containerization and CI/CD processes.