I would also highly recommend Greenspun's Software Engineering for Internet Application ("SEIA") [0] and in particular the metadata section of that book [1] wherein he goes over defining an ontology of a system, implementing a metadata model in SQL and then generating code based on that metadata model.