How 0xboji/note-sol-core works
Main Components
• API Entry Point: Start with the main bootstrapping in cmd/api/main.go. This is where the server is started and routes are registered.
• Router & Handlers: The REST endpoints are defined in multiple locations:
• The api/v1/handlers directory (e.g., user_handler.go) and the routes directory (routes/routes.go) indicate the endpoints and associated request routing.
• Additional handler logic is also found in the handlers and internal/users directories.
• Service Layer: There are clear service components:
• In api/v1/services (user_service.go)
• Also in internal/services and internal/users/service.go, handling business logic.
• Repository Layer: This is where data persistence is managed:
• The internal/repositories directory (with a base repository and user_repository.go) abstracts database operations.
• The pkg/config/database.go shows how the database (PostgreSQL) is configured.
• Domain & Models:
• internal/domain and models directories contain business entities (e.g., user.go, post.go) and migration definitions.
• Authentication & Middleware:
• The internal/auth and internal/middleware directories indicate usage of JWT and request filtering.
• Additional Components:
• Wallet functionality in internal/wallet/solana.go suggests integration with external services or blockchain functions.
• Migrations folder provides SQL scripts to set up the database schema.
Relationships and Interactions
• Client requests hit the API endpoint (via the bootstrapping in cmd/api/main.go), then get routed by routes/routes.go.
• Requests are handled by the appropriate handler (e.g., user_handler.go in api/v1/handlers or internal/users/handler.go) which then calls the respective service layer.
• The service layer contains business logic and interacts with the repository layer to fetch or update data in the PostgreSQL database.
• Middleware (authentication) intercepts requests (found in internal/middleware/auth.go) to perform tasks like JWT verification before reaching handlers.
• External configuration (pkg/config/database.go) is used to establish the database connection, and database migrations initialize the database schema.
Architectural Patterns & Principles
• Layered Architecture: There is a clear separation between the API layer, business logic (services), data layer (repositories/models), and configuration/infrastructure.
• Modular Design: The existence of versioned API endpoints (api/v1) and separate components for authentication, middleware, and external integrations (wallet) emphasizes an extensible, maintainable architecture.
• Separation of Concerns: Handlers manage HTTP level interactions, services perform business logic, and repositories handle database interactions.
• Infrastructure as Code: Use of migrations and environment configuration emphasizes a robust deployment pipeline for database provisioning and service start-up.
Relevant Technologies
• Go & Gin for the web framework.
• PostgreSQL (or Supabase) for database operations.
• Swagger (via swag) for API documentation.
• JWT for authentication.
• If applicable, integration with blockchain services (Solana).