Database Schema¶
dichit-backend uses PostgreSQL 16 as its primary datastore, described entirely by prisma/schema.prisma. The schema is the single source of truth; migrations and the generated client are derived from it.
At a glance¶
- 95 models, 91 enums, 341 indexes (
grep -conschema.prisma). - IDs are
cuid()-style strings by default (e.g.User.id), amounts/balances use PostgreSQLDecimal, timestamps areDateTimewithcreated_at/updated_at/ optional soft-deletedeleted_at. - Column names are snake_case via
@map; Prisma fields are camelCase.
Domain clusters¶
flowchart LR
USR["User / Auth<br/>User, UserAuthProvider, UserSession, UserLoginEvent"]
SUB["Subscriber / Enrollment<br/>Subscriber, Nominee, Address, EmploymentDetails"]
CO["Company<br/>Company, BankAccount, CompanyManager, Branches"]
PRG["Programs & Cycles<br/>Program, ProgramCycle, EnrolledSubscriber"]
AUC["Auctions & Bids<br/>Auction, AuctionBid, AuctionPrebid, BidActivity*"]
PAY["Billing / Payments<br/>CycleInvoice, CycleTransaction, GatewayPayload, Refunds"]
DOC["Documents<br/>DocumentTemplate, DocumentSubmission, SignatureAsset"]
NOT["Notifications<br/>NotificationTemplate, UserNotification, NotificationQueue"]
CAM["Engagement<br/>Challenges, Campaign, FAQ, Banner, TrackedLink"]
LOC["Locations<br/>Country, State, District, City, Pincode, PostOffice"]
USR --- SUB
USR --- CO
CO --- PRG
PRG --- AUC
PRG --- PAY
USR --- DOC
USR --- NOT
PRG --- CAM
SUB --- LOC
CO --- LOC Core identity¶
User— platform identity,role(SUBSCRIBER/COMPANY/SUPERADMIN),profileStatus,accountType(incl.DEMO,APPLE_APP_REVIEW,INTERNAL_TEST).UserAuthProvider— bound OAuth/SMS sign-in methods (PHONE_OTP,WHATSAPP_OTP,EMAIL_PASSWORD,GOOGLE,APPLE,META,LINKEDIN).UserSession/UserLoginEvent— session + audit trail.Subscriber/Nominee/SubscriberEmploymentDetails— KYC/profile data.
Programs, cycles, auctions¶
Program(chit program) →ProgramCycle(monthly cycles) →EnrolledSubscriber.Auctionholds auction state;AuctionBid+AuctionPrebidare the bidding records;AuctionBidActivitySequence/EventandAuctionActionLogare the event/audit stream that powers the WebSocket log and replay.CycleWinner,CycleInvoice,CycleTransaction,GatewayPayload,Refund*form the billing and payout flow.
Notifications & engagement¶
NotificationTemplate→UserNotification→NotificationQueue(withNotificationEventfor delivery tracking).Challenge,Campaign,FAQ,Banner,TrackedLink/TrackedLinkClick,WebsiteVisitor,Lead.
Auxiliary¶
AppVersion(release gates),SupportTicket,ReminderSchedule,BranchInvitation,DeletedUser,SentryGithubIssueMapping,SuperAdminFileUpload/CompanyFileUpload/SubscriberFileUpload.
Naming and conventions¶
- Model name → table: Prisma
@@mapor default pluralisation; explicit@map("snake_case")on columns. - Timestamps: every mutable model has
created_at,updated_at; soft-delete models adddeleted_at. - Decimal money:
Decimalfields (e.g.CycleInvoice.amount) are returned as strings by the API (Fastifybigint: 'string'serializer covers BigInt;Decimalis serialised by Prisma/JSON as string). - Consistency: adding a model means adding a matching domain entity (see development/folder-structure.md).
How to read the schema¶
Open it in an editor with Prisma support, or browse with: