Clone
1
Project Structure
samantha edited this page 2026-03-27 10:44:53 +00:00

Project Structure

.
├── main.go                          # Entry point — HTTP routes, CORS middleware, shell loop
├── app.db                           # SQLite database (auto-created on first run)
├── build.sh                         # Build script → outputs ./Portifolio binary
├── go.mod / go.sum
└── internal/
    ├── database/
    │   └── main.go                  # InitDB (all CREATE TABLE statements)
    │                                # GetTrades, UpdatePositions, and other DB helpers
    ├── handlers/
    │   ├── main.go                  # HealthHandler
    │   ├── company.go               # AddCompanyHandler, GetCompaniesHandler,
    │   │                            # GetCompanyRevenueCategories
    │   ├── currency.go              # AddCurrencyHandler, GetCurrenciesHandler
    │   ├── revenue.go               # AddRevenueEntryHandler
    │   └── trade.go                 # AddTradeHandler, GetTradeListHandler,
    │                                # GetPositionListHandler
    ├── model/
    │   ├── company.go               # Company struct
    │   ├── currency.go              # Currency struct
    │   ├── periode.go               # Period struct + QuarterPeriod, HalfYearPeriod,
    │   │                            # FullYearPeriod helpers
    │   ├── portifolio.go            # Position, Trade, TradeProduct, TradeType,
    │   │                            # AddTradeRequest (with Validate()), Portfolio
    │   └── revenue.go               # Revenue, RevenueReport, RevSum structs
    ├── service/
    │   ├── currency.go              # Currency business logic
    │   └── portfolio.go             # UpdatePositionByTradeList — rebuilds positions
    │                                # from full trade history
    └── shell/
        ├── company.go               # add-company, list-companies
        ├── currency.go              # add-currency, list-currency
        └── revenue.go               # add-revenue, list-revenue

Key Design Points

main.go wires together the HTTP mux and the shell loop. Both run concurrently — the HTTP server is started in a goroutine and the shell blocks on stdin.

internal/database owns all SQL. Handlers and services call functions here rather than writing raw queries themselves.

internal/model contains only structs, enums, and validation. No SQL lives here.

internal/service contains business logic that spans multiple database calls. UpdatePositionByTradeList replays the full trade history to compute current positions, then writes them back to the database.

internal/handlers are thin — they decode the request, call a service or database function, and encode the response.